6    internal static class Kernel32
 
    8        [DllImport(
"kernel32.dll", BestFitMapping = 
false, 
CharSet = 
CharSet.Unicode, EntryPoint = 
"GetDriveTypeW", 
SetLastError = 
true)]
 
   11        [DllImport(
"kernel32.dll", BestFitMapping = 
false, 
CharSet = 
CharSet.Unicode, EntryPoint = 
"GetVolumeInformationW", 
SetLastError = 
true)]
 
   12        internal unsafe 
static extern bool GetVolumeInformation(
string drive, 
char* volumeName, 
int volumeNameBufLen, 
int* volSerialNumber, 
int* maxFileNameLen, out 
int fileSystemFlags, 
char* fileSystemName, 
int fileSystemNameBufLen);
 
   17        [DllImport(
"kernel32.dll", BestFitMapping = 
false, 
CharSet = 
CharSet.Unicode, EntryPoint = 
"GetDiskFreeSpaceExW", 
SetLastError = 
true)]
 
   18        internal static extern bool GetDiskFreeSpaceEx(
string drive, out 
long freeBytesForUser, out 
long totalBytes, out 
long freeBytes);
 
   20        [DllImport(
"kernel32.dll", BestFitMapping = 
false, 
CharSet = 
CharSet.Unicode, EntryPoint = 
"SetVolumeLabelW", 
SetLastError = 
true)]
 
   21        internal static extern bool SetVolumeLabel(
string driveLetter, 
string volumeName);
 
   23        [DllImport(
"kernel32.dll", ExactSpelling = 
true, 
SetLastError = 
true)]
 
   24        [SuppressGCTransition]
 
   27        [DllImport(
"kernel32.dll", BestFitMapping = 
true, 
CharSet = 
CharSet.Unicode, EntryPoint = 
"FormatMessageW", ExactSpelling = 
true, 
SetLastError = 
true)]
 
   28        private unsafe 
static extern int FormatMessage(
int dwFlags, 
IntPtr lpSource, uint dwMessageId, 
int dwLanguageId, 
void* lpBuffer, 
int nSize, 
IntPtr arguments);
 
   43            fixed (
char* lpBuffer = span)
 
   67            return $
"Unknown error (0x{errorCode:x})";
 
 
   73            while (num > 0 && 
buffer[num - 1] <= 
' ')
 
   77            return buffer.Slice(0, num).ToString();
 
 
static unsafe bool GetVolumeInformation(string drive, char *volumeName, int volumeNameBufLen, int *volSerialNumber, int *maxFileNameLen, out int fileSystemFlags, char *fileSystemName, int fileSystemNameBufLen)
static int GetLogicalDrives()
static bool GetDiskFreeSpaceEx(string drive, out long freeBytesForUser, out long totalBytes, out long freeBytes)
static unsafe string GetMessage(int errorCode, IntPtr moduleHandle)
static void SetLastError(int errorCode)
static bool SetThreadErrorMode(uint dwNewMode, out uint lpOldMode)
static string GetMessage(int errorCode)
static unsafe int FormatMessage(int dwFlags, IntPtr lpSource, uint dwMessageId, int dwLanguageId, void *lpBuffer, int nSize, IntPtr arguments)
static int GetDriveType(string drive)
static bool SetVolumeLabel(string driveLetter, string volumeName)
static string GetAndTrimString(Span< char > buffer)
static void FreeHGlobal(IntPtr hglobal)
static int GetLastWin32Error()
static readonly IntPtr Zero
Span< T > Slice(int start)