[CMAKE]
[reactos.git] / dll / win32 / kernel32 / file / volume.c
index 0283def..1f64e0b 100644 (file)
  */
 
 #include <k32.h>
-#include <wine/debug.h>
-
-WINE_DEFAULT_DEBUG_CHANNEL(kernel32file);
+#define NDEBUG
+#include <debug.h>
+DEBUG_CHANNEL(kernel32file);
 
 #define MAX_DOS_DRIVES 26
 
 
 static HANDLE
 InternalOpenDirW(LPCWSTR DirName,
-                BOOLEAN Write)
+                 BOOLEAN Write)
 {
-  UNICODE_STRING NtPathU;
-  OBJECT_ATTRIBUTES ObjectAttributes;
-  NTSTATUS errCode;
-  IO_STATUS_BLOCK IoStatusBlock;
-  HANDLE hFile;
-
-  if (!RtlDosPathNameToNtPathName_U(DirName,
-                                   &NtPathU,
-                                   NULL,
-                                   NULL))
+    UNICODE_STRING NtPathU;
+    OBJECT_ATTRIBUTES ObjectAttributes;
+    NTSTATUS errCode;
+    IO_STATUS_BLOCK IoStatusBlock;
+    HANDLE hFile;
+
+    if (!RtlDosPathNameToNtPathName_U(DirName,
+                                      &NtPathU,
+                                      NULL,
+                                      NULL))
     {
-       WARN("Invalid path\n");
-       SetLastError(ERROR_BAD_PATHNAME);
-       return INVALID_HANDLE_VALUE;
+        WARN("Invalid path\n");
+        SetLastError(ERROR_BAD_PATHNAME);
+        return INVALID_HANDLE_VALUE;
     }
 
     InitializeObjectAttributes(&ObjectAttributes,
-                              &NtPathU,
-                              OBJ_CASE_INSENSITIVE,
-                              NULL,
-                              NULL);
+                               &NtPathU,
+                               OBJ_CASE_INSENSITIVE,
+                               NULL,
+                               NULL);
 
     errCode = NtCreateFile (&hFile,
-                           Write ? FILE_GENERIC_WRITE : FILE_GENERIC_READ,
-                           &ObjectAttributes,
-                           &IoStatusBlock,
-                           NULL,
-                           0,
-                           FILE_SHARE_READ|FILE_SHARE_WRITE,
-                           FILE_OPEN,
-                           0,
-                           NULL,
-                           0);
+                            Write ? FILE_GENERIC_WRITE : FILE_GENERIC_READ,
+                            &ObjectAttributes,
+                            &IoStatusBlock,
+                            NULL,
+                            0,
+                            FILE_SHARE_READ|FILE_SHARE_WRITE,
+                            FILE_OPEN,
+                            0,
+                            NULL,
+                            0);
 
     RtlFreeHeap(RtlGetProcessHeap(),
                 0,
@@ -71,8 +71,8 @@ InternalOpenDirW(LPCWSTR DirName,
 
     if (!NT_SUCCESS(errCode))
     {
-       SetLastErrorByStatus (errCode);
-       return INVALID_HANDLE_VALUE;
+        SetLastErrorByStatus (errCode);
+        return INVALID_HANDLE_VALUE;
     }
     return hFile;
 }
@@ -84,34 +84,34 @@ InternalOpenDirW(LPCWSTR DirName,
 /* Synced to Wine-2008/12/28 */
 DWORD WINAPI
 GetLogicalDriveStringsA(DWORD nBufferLength,
-                       LPSTR lpBuffer)
+                        LPSTR lpBuffer)
 {
-   DWORD drive, count;
-   DWORD dwDriveMap;
-   LPSTR p;
+    DWORD drive, count;
+    DWORD dwDriveMap;
+    LPSTR p;
 
-   dwDriveMap = GetLogicalDrives();
+    dwDriveMap = GetLogicalDrives();
 
-   for (drive = count = 0; drive < MAX_DOS_DRIVES; drive++)
-     {
-       if (dwDriveMap & (1<<drive))
-          count++;
-     }
+    for (drive = count = 0; drive < MAX_DOS_DRIVES; drive++)
+    {
+        if (dwDriveMap & (1<<drive))
+            count++;
+    }
 
 
-   if ((count * 4) + 1 > nBufferLength) return ((count * 4) + 1);
+    if ((count * 4) + 1 > nBufferLength) return ((count * 4) + 1);
 
-       p = lpBuffer;
+    p = lpBuffer;
 
-       for (drive = 0; drive < MAX_DOS_DRIVES; drive++)
-         if (dwDriveMap & (1<<drive))
-         {
-            *p++ = 'A' + (UCHAR)drive;
-            *p++ = ':';
-            *p++ = '\\';
-            *p++ = '\0';
-         }
-       *p = '\0';
+    for (drive = 0; drive < MAX_DOS_DRIVES; drive++)
+        if (dwDriveMap & (1<<drive))
+        {
+            *p++ = 'A' + (UCHAR)drive;
+            *p++ = ':';
+            *p++ = '\\';
+            *p++ = '\0';
+        }
+    *p = '\0';
 
     return (count * 4);
 }
@@ -123,19 +123,19 @@ GetLogicalDriveStringsA(DWORD nBufferLength,
 /* Synced to Wine-2008/12/28 */
 DWORD WINAPI
 GetLogicalDriveStringsW(DWORD nBufferLength,
-                       LPWSTR lpBuffer)
+                        LPWSTR lpBuffer)
 {
-   DWORD drive, count;
-   DWORD dwDriveMap;
-   LPWSTR p;
+    DWORD drive, count;
+    DWORD dwDriveMap;
+    LPWSTR p;
 
-   dwDriveMap = GetLogicalDrives();
+    dwDriveMap = GetLogicalDrives();
 
-   for (drive = count = 0; drive < MAX_DOS_DRIVES; drive++)
-     {
-       if (dwDriveMap & (1<<drive))
-          count++;
-     }
+    for (drive = count = 0; drive < MAX_DOS_DRIVES; drive++)
+    {
+        if (dwDriveMap & (1<<drive))
+            count++;
+    }
 
     if ((count * 4) + 1 > nBufferLength) return ((count * 4) + 1);
 
@@ -161,24 +161,24 @@ GetLogicalDriveStringsW(DWORD nBufferLength,
 DWORD WINAPI
 GetLogicalDrives(VOID)
 {
-       NTSTATUS Status;
-       PROCESS_DEVICEMAP_INFORMATION ProcessDeviceMapInfo;
-
-       /* Get the Device Map for this Process */
-       Status = NtQueryInformationProcess(NtCurrentProcess(),
-                                          ProcessDeviceMap,
-                                          &ProcessDeviceMapInfo,
-                                          sizeof(ProcessDeviceMapInfo),
-                                          NULL);
-
-       /* Return the Drive Map */
-       if (!NT_SUCCESS(Status))
-       {
-               SetLastErrorByStatus(Status);
-               return 0;
-       }
-
-        return ProcessDeviceMapInfo.Query.DriveMap;
+    NTSTATUS Status;
+    PROCESS_DEVICEMAP_INFORMATION ProcessDeviceMapInfo;
+
+    /* Get the Device Map for this Process */
+    Status = NtQueryInformationProcess(NtCurrentProcess(),
+                                       ProcessDeviceMap,
+                                       &ProcessDeviceMapInfo,
+                                       sizeof(ProcessDeviceMapInfo),
+                                       NULL);
+
+    /* Return the Drive Map */
+    if (!NT_SUCCESS(Status))
+    {
+        SetLastErrorByStatus(Status);
+        return 0;
+    }
+
+    return ProcessDeviceMapInfo.Query.DriveMap;
 }
 
 
@@ -187,26 +187,26 @@ GetLogicalDrives(VOID)
  */
 BOOL WINAPI
 GetDiskFreeSpaceA (
-       LPCSTR  lpRootPathName,
-       LPDWORD lpSectorsPerCluster,
-       LPDWORD lpBytesPerSector,
-       LPDWORD lpNumberOfFreeClusters,
-       LPDWORD lpTotalNumberOfClusters
-       )
+    LPCSTR     lpRootPathName,
+    LPDWORD    lpSectorsPerCluster,
+    LPDWORD    lpBytesPerSector,
+    LPDWORD    lpNumberOfFreeClusters,
+    LPDWORD    lpTotalNumberOfClusters
+)
 {
-   PWCHAR RootPathNameW=NULL;
-
-   if (lpRootPathName)
-   {
-      if (!(RootPathNameW = FilenameA2W(lpRootPathName, FALSE)))
-         return FALSE;
-   }
-
-       return GetDiskFreeSpaceW (RootPathNameW,
-                                   lpSectorsPerCluster,
-                                   lpBytesPerSector,
-                                   lpNumberOfFreeClusters,
-                                   lpTotalNumberOfClusters);
+    PWCHAR RootPathNameW=NULL;
+
+    if (lpRootPathName)
+    {
+        if (!(RootPathNameW = FilenameA2W(lpRootPathName, FALSE)))
+            return FALSE;
+    }
+
+    return GetDiskFreeSpaceW (RootPathNameW,
+                              lpSectorsPerCluster,
+                              lpBytesPerSector,
+                              lpNumberOfFreeClusters,
+                              lpTotalNumberOfClusters);
 }
 
 
@@ -220,7 +220,7 @@ GetDiskFreeSpaceW(
     LPDWORD lpBytesPerSector,
     LPDWORD lpNumberOfFreeClusters,
     LPDWORD lpTotalNumberOfClusters
-    )
+)
 {
     FILE_FS_SIZE_INFORMATION FileFsSize;
     IO_STATUS_BLOCK IoStatusBlock;
@@ -238,11 +238,11 @@ GetDiskFreeSpaceW(
     }
     RootPathName[3] = 0;
 
-  hFile = InternalOpenDirW(RootPathName, FALSE);
-  if (INVALID_HANDLE_VALUE == hFile)
+    hFile = InternalOpenDirW(RootPathName, FALSE);
+    if (INVALID_HANDLE_VALUE == hFile)
     {
-      SetLastError(ERROR_PATH_NOT_FOUND);
-      return FALSE;
+        SetLastError(ERROR_PATH_NOT_FOUND);
+        return FALSE;
     }
 
     errCode = NtQueryVolumeInformationFile(hFile,
@@ -276,24 +276,24 @@ GetDiskFreeSpaceW(
  */
 BOOL WINAPI
 GetDiskFreeSpaceExA (
-       LPCSTR lpDirectoryName   OPTIONAL,
-       PULARGE_INTEGER lpFreeBytesAvailableToCaller,
-       PULARGE_INTEGER lpTotalNumberOfBytes,
-       PULARGE_INTEGER lpTotalNumberOfFreeBytes
-       )
+    LPCSTR lpDirectoryName   OPTIONAL,
+    PULARGE_INTEGER    lpFreeBytesAvailableToCaller,
+    PULARGE_INTEGER    lpTotalNumberOfBytes,
+    PULARGE_INTEGER    lpTotalNumberOfFreeBytes
+)
 {
-   PWCHAR DirectoryNameW=NULL;
-
-       if (lpDirectoryName)
-       {
-      if (!(DirectoryNameW = FilenameA2W(lpDirectoryName, FALSE)))
-         return FALSE;
-       }
-
-   return GetDiskFreeSpaceExW (DirectoryNameW ,
-                                     lpFreeBytesAvailableToCaller,
-                                     lpTotalNumberOfBytes,
-                                     lpTotalNumberOfFreeBytes);
+    PWCHAR DirectoryNameW=NULL;
+
+    if (lpDirectoryName)
+    {
+        if (!(DirectoryNameW = FilenameA2W(lpDirectoryName, FALSE)))
+            return FALSE;
+    }
+
+    return GetDiskFreeSpaceExW (DirectoryNameW ,
+                                lpFreeBytesAvailableToCaller,
+                                lpTotalNumberOfBytes,
+                                lpTotalNumberOfFreeBytes);
 }
 
 
@@ -306,7 +306,7 @@ GetDiskFreeSpaceExW(
     PULARGE_INTEGER lpFreeBytesAvailableToCaller,
     PULARGE_INTEGER lpTotalNumberOfBytes,
     PULARGE_INTEGER lpTotalNumberOfFreeBytes
-    )
+)
 {
     union
     {
@@ -417,12 +417,12 @@ GetDiskFreeSpaceExW(
 UINT WINAPI
 GetDriveTypeA(LPCSTR lpRootPathName)
 {
-   PWCHAR RootPathNameW;
+    PWCHAR RootPathNameW;
 
-   if (!(RootPathNameW = FilenameA2W(lpRootPathName, FALSE)))
-      return DRIVE_UNKNOWN;
+    if (!(RootPathNameW = FilenameA2W(lpRootPathName, FALSE)))
+        return DRIVE_UNKNOWN;
 
-   return GetDriveTypeW(RootPathNameW);
+    return GetDriveTypeW(RootPathNameW);
 }
 
 
@@ -432,52 +432,105 @@ GetDriveTypeA(LPCSTR lpRootPathName)
 UINT WINAPI
 GetDriveTypeW(LPCWSTR lpRootPathName)
 {
-       FILE_FS_DEVICE_INFORMATION FileFsDevice;
-       IO_STATUS_BLOCK IoStatusBlock;
-
-       HANDLE hFile;
-       NTSTATUS errCode;
-
-       hFile = InternalOpenDirW(lpRootPathName, FALSE);
-       if (hFile == INVALID_HANDLE_VALUE)
-       {
-           return DRIVE_NO_ROOT_DIR;   /* According to WINE regression tests */
-       }
-
-       errCode = NtQueryVolumeInformationFile (hFile,
-                                               &IoStatusBlock,
-                                               &FileFsDevice,
-                                               sizeof(FILE_FS_DEVICE_INFORMATION),
-                                               FileFsDeviceInformation);
-       if (!NT_SUCCESS(errCode))
-       {
-               CloseHandle(hFile);
-               SetLastErrorByStatus (errCode);
-               return 0;
-       }
-       CloseHandle(hFile);
-
-        switch (FileFsDevice.DeviceType)
+    FILE_FS_DEVICE_INFORMATION FileFsDevice;
+    IO_STATUS_BLOCK IoStatusBlock;
+    HANDLE hFile;
+    NTSTATUS Status;
+    UNICODE_STRING NtPath;
+    OBJECT_ATTRIBUTES ObjectAttributes;
+    WCHAR Buffer[MAX_PATH+1];
+
+    if (!lpRootPathName)
+    {
+        DWORD cBytes;
+
+        /* Get current directory */
+        cBytes = RtlGetCurrentDirectory_U(sizeof(Buffer), Buffer);
+        if(cBytes < sizeof(Buffer))
         {
-               case FILE_DEVICE_CD_ROM:
-               case FILE_DEVICE_CD_ROM_FILE_SYSTEM:
-                       return DRIVE_CDROM;
-               case FILE_DEVICE_VIRTUAL_DISK:
-                       return DRIVE_RAMDISK;
-               case FILE_DEVICE_NETWORK_FILE_SYSTEM:
-                       return DRIVE_REMOTE;
-               case FILE_DEVICE_DISK:
-               case FILE_DEVICE_DISK_FILE_SYSTEM:
-                       if (FileFsDevice.Characteristics & FILE_REMOTE_DEVICE)
-                               return DRIVE_REMOTE;
-                       if (FileFsDevice.Characteristics & FILE_REMOVABLE_MEDIA)
-                               return DRIVE_REMOVABLE;
-                       return DRIVE_FIXED;
-        }
+            ASSERT(cBytes < MAX_PATH*sizeof(WCHAR));
+            Buffer[cBytes/sizeof(WCHAR)] = L'\\';
+            Buffer[cBytes/sizeof(WCHAR)+1] = L'\0';
+            lpRootPathName = Buffer;
+        } /* else fail... should we allow longer current dirs? */
+    }
+
+    if (!RtlDosPathNameToNtPathName_U(lpRootPathName, &NtPath, NULL, NULL))
+    {
+        WARN("Invalid path: %ls\n", lpRootPathName);
+        return DRIVE_NO_ROOT_DIR;
+    }
+
+    /* Path from RtlDosPathNameToNtPathName_U does not contain '/' and multiple '\\' in a row */
+    if(!NtPath.Length || NtPath.Buffer[NtPath.Length/sizeof(WCHAR)-1] != L'\\')
+    {
+        /* Path must be ended by slash */
+        WARN("Invalid path: %ls\n", NtPath.Buffer);
+        return DRIVE_NO_ROOT_DIR;
+    }
 
-        ERR("Returning DRIVE_UNKNOWN for device type %d\n", FileFsDevice.DeviceType);
+    /* Remove ending slash */
+    NtPath.Length -= sizeof(WCHAR);
 
-       return DRIVE_UNKNOWN;
+    InitializeObjectAttributes(&ObjectAttributes,
+                               &NtPath,
+                               OBJ_CASE_INSENSITIVE,
+                               NULL,
+                               NULL);
+
+    Status = NtCreateFile(&hFile,
+                          FILE_GENERIC_READ,
+                          &ObjectAttributes,
+                          &IoStatusBlock,
+                          NULL,
+                          0,
+                          FILE_SHARE_READ|FILE_SHARE_WRITE,
+                          FILE_OPEN,
+                          0,
+                          NULL,
+                          0);
+
+    RtlFreeUnicodeString(&NtPath);
+
+    if (!NT_SUCCESS(Status))
+    {
+        WARN("Invalid path: %ls\n", lpRootPathName);
+        return DRIVE_NO_ROOT_DIR;      /* According to WINE regression tests */
+    }
+
+    Status = NtQueryVolumeInformationFile (hFile,
+                                           &IoStatusBlock,
+                                           &FileFsDevice,
+                                           sizeof(FILE_FS_DEVICE_INFORMATION),
+                                           FileFsDeviceInformation);
+    CloseHandle(hFile);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("NtQueryVolumeInformationFile failed for %ls\n", lpRootPathName);
+        return DRIVE_UNKNOWN;
+    }
+
+    switch (FileFsDevice.DeviceType)
+    {
+    case FILE_DEVICE_CD_ROM:
+    case FILE_DEVICE_CD_ROM_FILE_SYSTEM:
+        return DRIVE_CDROM;
+    case FILE_DEVICE_VIRTUAL_DISK:
+        return DRIVE_RAMDISK;
+    case FILE_DEVICE_NETWORK_FILE_SYSTEM:
+        return DRIVE_REMOTE;
+    case FILE_DEVICE_DISK:
+    case FILE_DEVICE_DISK_FILE_SYSTEM:
+        if (FileFsDevice.Characteristics & FILE_REMOTE_DEVICE)
+            return DRIVE_REMOTE;
+        if (FileFsDevice.Characteristics & FILE_REMOVABLE_MEDIA)
+            return DRIVE_REMOVABLE;
+        return DRIVE_FIXED;
+    }
+
+    ERR("Returning DRIVE_UNKNOWN for device type %d\n", FileFsDevice.DeviceType);
+
+    return DRIVE_UNKNOWN;
 }
 
 
@@ -486,134 +539,134 @@ GetDriveTypeW(LPCWSTR lpRootPathName)
  */
 BOOL WINAPI
 GetVolumeInformationA(
-       LPCSTR  lpRootPathName,
-       LPSTR   lpVolumeNameBuffer,
-       DWORD   nVolumeNameSize,
-       LPDWORD lpVolumeSerialNumber,
-       LPDWORD lpMaximumComponentLength,
-       LPDWORD lpFileSystemFlags,
-       LPSTR   lpFileSystemNameBuffer,
-       DWORD   nFileSystemNameSize
-       )
+    LPCSTR     lpRootPathName,
+    LPSTR      lpVolumeNameBuffer,
+    DWORD      nVolumeNameSize,
+    LPDWORD    lpVolumeSerialNumber,
+    LPDWORD    lpMaximumComponentLength,
+    LPDWORD    lpFileSystemFlags,
+    LPSTR      lpFileSystemNameBuffer,
+    DWORD      nFileSystemNameSize
+)
 {
-  UNICODE_STRING FileSystemNameU;
-  UNICODE_STRING VolumeNameU = { 0, 0, NULL };
-  ANSI_STRING VolumeName;
-  ANSI_STRING FileSystemName;
-  PWCHAR RootPathNameW;
-  BOOL Result;
+    UNICODE_STRING FileSystemNameU;
+    UNICODE_STRING VolumeNameU = { 0, 0, NULL };
+    ANSI_STRING VolumeName;
+    ANSI_STRING FileSystemName;
+    PWCHAR RootPathNameW;
+    BOOL Result;
 
-  if (!(RootPathNameW = FilenameA2W(lpRootPathName, FALSE)))
-     return FALSE;
+    if (!(RootPathNameW = FilenameA2W(lpRootPathName, FALSE)))
+        return FALSE;
 
-  if (lpVolumeNameBuffer)
+    if (lpVolumeNameBuffer)
     {
-      VolumeNameU.MaximumLength = (USHORT)nVolumeNameSize * sizeof(WCHAR);
-      VolumeNameU.Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
-                                           0,
-                                           VolumeNameU.MaximumLength);
-      if (VolumeNameU.Buffer == NULL)
-      {
-          goto FailNoMem;
-      }
+        VolumeNameU.MaximumLength = (USHORT)nVolumeNameSize * sizeof(WCHAR);
+        VolumeNameU.Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
+                                              0,
+                                              VolumeNameU.MaximumLength);
+        if (VolumeNameU.Buffer == NULL)
+        {
+            goto FailNoMem;
+        }
     }
 
-  if (lpFileSystemNameBuffer)
+    if (lpFileSystemNameBuffer)
     {
-      FileSystemNameU.Length = 0;
-      FileSystemNameU.MaximumLength = (USHORT)nFileSystemNameSize * sizeof(WCHAR);
-      FileSystemNameU.Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
-                                               0,
-                                               FileSystemNameU.MaximumLength);
-      if (FileSystemNameU.Buffer == NULL)
-      {
-          if (VolumeNameU.Buffer != NULL)
-          {
-              RtlFreeHeap(RtlGetProcessHeap(),
-                          0,
-                          VolumeNameU.Buffer);
-          }
+        FileSystemNameU.Length = 0;
+        FileSystemNameU.MaximumLength = (USHORT)nFileSystemNameSize * sizeof(WCHAR);
+        FileSystemNameU.Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
+                                 0,
+                                 FileSystemNameU.MaximumLength);
+        if (FileSystemNameU.Buffer == NULL)
+        {
+            if (VolumeNameU.Buffer != NULL)
+            {
+                RtlFreeHeap(RtlGetProcessHeap(),
+                            0,
+                            VolumeNameU.Buffer);
+            }
 
 FailNoMem:
-          SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-          return FALSE;
-      }
+            SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+            return FALSE;
+        }
     }
 
-  Result = GetVolumeInformationW (RootPathNameW,
-                                 lpVolumeNameBuffer ? VolumeNameU.Buffer : NULL,
-                                 nVolumeNameSize,
-                                 lpVolumeSerialNumber,
-                                 lpMaximumComponentLength,
-                                 lpFileSystemFlags,
-                                 lpFileSystemNameBuffer ? FileSystemNameU.Buffer : NULL,
-                                 nFileSystemNameSize);
+    Result = GetVolumeInformationW (RootPathNameW,
+                                    lpVolumeNameBuffer ? VolumeNameU.Buffer : NULL,
+                                    nVolumeNameSize,
+                                    lpVolumeSerialNumber,
+                                    lpMaximumComponentLength,
+                                    lpFileSystemFlags,
+                                    lpFileSystemNameBuffer ? FileSystemNameU.Buffer : NULL,
+                                    nFileSystemNameSize);
 
-  if (Result)
+    if (Result)
     {
-      if (lpVolumeNameBuffer)
+        if (lpVolumeNameBuffer)
         {
-          VolumeNameU.Length = wcslen(VolumeNameU.Buffer) * sizeof(WCHAR);
-         VolumeName.Length = 0;
-         VolumeName.MaximumLength = (USHORT)nVolumeNameSize;
-         VolumeName.Buffer = lpVolumeNameBuffer;
-       }
-
-      if (lpFileSystemNameBuffer)
-       {
-         FileSystemNameU.Length = wcslen(FileSystemNameU.Buffer) * sizeof(WCHAR);
-         FileSystemName.Length = 0;
-         FileSystemName.MaximumLength = (USHORT)nFileSystemNameSize;
-         FileSystemName.Buffer = lpFileSystemNameBuffer;
-       }
-
-      /* convert unicode strings to ansi (or oem) */
-      if (bIsFileApiAnsi)
+            VolumeNameU.Length = wcslen(VolumeNameU.Buffer) * sizeof(WCHAR);
+            VolumeName.Length = 0;
+            VolumeName.MaximumLength = (USHORT)nVolumeNameSize;
+            VolumeName.Buffer = lpVolumeNameBuffer;
+        }
+
+        if (lpFileSystemNameBuffer)
         {
-         if (lpVolumeNameBuffer)
-           {
-             RtlUnicodeStringToAnsiString (&VolumeName,
-                                           &VolumeNameU,
-                                           FALSE);
-           }
-         if (lpFileSystemNameBuffer)
-           {
-             RtlUnicodeStringToAnsiString (&FileSystemName,
-                                           &FileSystemNameU,
-                                           FALSE);
-           }
-       }
-      else
+            FileSystemNameU.Length = wcslen(FileSystemNameU.Buffer) * sizeof(WCHAR);
+            FileSystemName.Length = 0;
+            FileSystemName.MaximumLength = (USHORT)nFileSystemNameSize;
+            FileSystemName.Buffer = lpFileSystemNameBuffer;
+        }
+
+        /* convert unicode strings to ansi (or oem) */
+        if (bIsFileApiAnsi)
+        {
+            if (lpVolumeNameBuffer)
+            {
+                RtlUnicodeStringToAnsiString (&VolumeName,
+                                              &VolumeNameU,
+                                              FALSE);
+            }
+            if (lpFileSystemNameBuffer)
+            {
+                RtlUnicodeStringToAnsiString (&FileSystemName,
+                                              &FileSystemNameU,
+                                              FALSE);
+            }
+        }
+        else
         {
-         if (lpVolumeNameBuffer)
-           {
-             RtlUnicodeStringToOemString (&VolumeName,
-                                          &VolumeNameU,
-                                          FALSE);
-           }
-          if (lpFileSystemNameBuffer)
-           {
-             RtlUnicodeStringToOemString (&FileSystemName,
-                                          &FileSystemNameU,
-                                          FALSE);
-           }
-       }
+            if (lpVolumeNameBuffer)
+            {
+                RtlUnicodeStringToOemString (&VolumeName,
+                                             &VolumeNameU,
+                                             FALSE);
+            }
+            if (lpFileSystemNameBuffer)
+            {
+                RtlUnicodeStringToOemString (&FileSystemName,
+                                             &FileSystemNameU,
+                                             FALSE);
+            }
+        }
     }
 
-  if (lpVolumeNameBuffer)
+    if (lpVolumeNameBuffer)
     {
-      RtlFreeHeap (RtlGetProcessHeap (),
-                  0,
-                  VolumeNameU.Buffer);
+        RtlFreeHeap (RtlGetProcessHeap (),
+                     0,
+                     VolumeNameU.Buffer);
     }
-  if (lpFileSystemNameBuffer)
+    if (lpFileSystemNameBuffer)
     {
-      RtlFreeHeap (RtlGetProcessHeap (),
-                  0,
-                  FileSystemNameU.Buffer);
+        RtlFreeHeap (RtlGetProcessHeap (),
+                     0,
+                     FileSystemNameU.Buffer);
     }
 
-  return Result;
+    return Result;
 }
 
 #define FS_VOLUME_BUFFER_SIZE (MAX_PATH * sizeof(WCHAR) + sizeof(FILE_FS_VOLUME_INFORMATION))
@@ -633,106 +686,106 @@ GetVolumeInformationW(
     LPDWORD lpFileSystemFlags,
     LPWSTR lpFileSystemNameBuffer,
     DWORD nFileSystemNameSize
-    )
+)
 {
-  PFILE_FS_VOLUME_INFORMATION FileFsVolume;
-  PFILE_FS_ATTRIBUTE_INFORMATION FileFsAttribute;
-  IO_STATUS_BLOCK IoStatusBlock;
-  WCHAR RootPathName[MAX_PATH];
-  UCHAR Buffer[max(FS_VOLUME_BUFFER_SIZE, FS_ATTRIBUTE_BUFFER_SIZE)];
-
-  HANDLE hFile;
-  NTSTATUS errCode;
-
-  FileFsVolume = (PFILE_FS_VOLUME_INFORMATION)Buffer;
-  FileFsAttribute = (PFILE_FS_ATTRIBUTE_INFORMATION)Buffer;
-
-  TRACE("FileFsVolume %p\n", FileFsVolume);
-  TRACE("FileFsAttribute %p\n", FileFsAttribute);
-
-  if (!lpRootPathName || !wcscmp(lpRootPathName, L""))
-  {
-      GetCurrentDirectoryW (MAX_PATH, RootPathName);
-  }
-  else
-  {
-      wcsncpy (RootPathName, lpRootPathName, 3);
-  }
-  RootPathName[3] = 0;
-
-  hFile = InternalOpenDirW(RootPathName, FALSE);
-  if (hFile == INVALID_HANDLE_VALUE)
+    PFILE_FS_VOLUME_INFORMATION FileFsVolume;
+    PFILE_FS_ATTRIBUTE_INFORMATION FileFsAttribute;
+    IO_STATUS_BLOCK IoStatusBlock;
+    WCHAR RootPathName[MAX_PATH];
+    UCHAR Buffer[max(FS_VOLUME_BUFFER_SIZE, FS_ATTRIBUTE_BUFFER_SIZE)];
+
+    HANDLE hFile;
+    NTSTATUS errCode;
+
+    FileFsVolume = (PFILE_FS_VOLUME_INFORMATION)Buffer;
+    FileFsAttribute = (PFILE_FS_ATTRIBUTE_INFORMATION)Buffer;
+
+    TRACE("FileFsVolume %p\n", FileFsVolume);
+    TRACE("FileFsAttribute %p\n", FileFsAttribute);
+
+    if (!lpRootPathName || !wcscmp(lpRootPathName, L""))
+    {
+        GetCurrentDirectoryW (MAX_PATH, RootPathName);
+    }
+    else
     {
-      return FALSE;
+        wcsncpy (RootPathName, lpRootPathName, 3);
     }
+    RootPathName[3] = 0;
 
-  TRACE("hFile: %x\n", hFile);
-  errCode = NtQueryVolumeInformationFile(hFile,
-                                         &IoStatusBlock,
-                                         FileFsVolume,
-                                         FS_VOLUME_BUFFER_SIZE,
-                                         FileFsVolumeInformation);
-  if ( !NT_SUCCESS(errCode) )
+    hFile = InternalOpenDirW(RootPathName, FALSE);
+    if (hFile == INVALID_HANDLE_VALUE)
     {
-      WARN("Status: %x\n", errCode);
-      CloseHandle(hFile);
-      SetLastErrorByStatus (errCode);
-      return FALSE;
+        return FALSE;
     }
 
-  if (lpVolumeSerialNumber)
-    *lpVolumeSerialNumber = FileFsVolume->VolumeSerialNumber;
+    TRACE("hFile: %x\n", hFile);
+    errCode = NtQueryVolumeInformationFile(hFile,
+                                           &IoStatusBlock,
+                                           FileFsVolume,
+                                           FS_VOLUME_BUFFER_SIZE,
+                                           FileFsVolumeInformation);
+    if ( !NT_SUCCESS(errCode) )
+    {
+        WARN("Status: %x\n", errCode);
+        CloseHandle(hFile);
+        SetLastErrorByStatus (errCode);
+        return FALSE;
+    }
 
-  if (lpVolumeNameBuffer)
+    if (lpVolumeSerialNumber)
+        *lpVolumeSerialNumber = FileFsVolume->VolumeSerialNumber;
+
+    if (lpVolumeNameBuffer)
     {
-      if (nVolumeNameSize * sizeof(WCHAR) >= FileFsVolume->VolumeLabelLength + sizeof(WCHAR))
+        if (nVolumeNameSize * sizeof(WCHAR) >= FileFsVolume->VolumeLabelLength + sizeof(WCHAR))
         {
-         memcpy(lpVolumeNameBuffer,
-                FileFsVolume->VolumeLabel,
-                FileFsVolume->VolumeLabelLength);
-         lpVolumeNameBuffer[FileFsVolume->VolumeLabelLength / sizeof(WCHAR)] = 0;
-       }
-      else
+            memcpy(lpVolumeNameBuffer,
+                   FileFsVolume->VolumeLabel,
+                   FileFsVolume->VolumeLabelLength);
+            lpVolumeNameBuffer[FileFsVolume->VolumeLabelLength / sizeof(WCHAR)] = 0;
+        }
+        else
         {
-         CloseHandle(hFile);
-         SetLastError(ERROR_MORE_DATA);
-         return FALSE;
-       }
+            CloseHandle(hFile);
+            SetLastError(ERROR_MORE_DATA);
+            return FALSE;
+        }
     }
 
-  errCode = NtQueryVolumeInformationFile (hFile,
-                                         &IoStatusBlock,
-                                         FileFsAttribute,
-                                         FS_ATTRIBUTE_BUFFER_SIZE,
-                                         FileFsAttributeInformation);
-  CloseHandle(hFile);
-  if (!NT_SUCCESS(errCode))
+    errCode = NtQueryVolumeInformationFile (hFile,
+                                            &IoStatusBlock,
+                                            FileFsAttribute,
+                                            FS_ATTRIBUTE_BUFFER_SIZE,
+                                            FileFsAttributeInformation);
+    CloseHandle(hFile);
+    if (!NT_SUCCESS(errCode))
     {
-      WARN("Status: %x\n", errCode);
-      SetLastErrorByStatus (errCode);
-      return FALSE;
+        WARN("Status: %x\n", errCode);
+        SetLastErrorByStatus (errCode);
+        return FALSE;
     }
 
-  if (lpFileSystemFlags)
-    *lpFileSystemFlags = FileFsAttribute->FileSystemAttributes;
-  if (lpMaximumComponentLength)
-    *lpMaximumComponentLength = FileFsAttribute->MaximumComponentNameLength;
-  if (lpFileSystemNameBuffer)
+    if (lpFileSystemFlags)
+        *lpFileSystemFlags = FileFsAttribute->FileSystemAttributes;
+    if (lpMaximumComponentLength)
+        *lpMaximumComponentLength = FileFsAttribute->MaximumComponentNameLength;
+    if (lpFileSystemNameBuffer)
     {
-      if (nFileSystemNameSize * sizeof(WCHAR) >= FileFsAttribute->FileSystemNameLength + sizeof(WCHAR))
+        if (nFileSystemNameSize * sizeof(WCHAR) >= FileFsAttribute->FileSystemNameLength + sizeof(WCHAR))
         {
-         memcpy(lpFileSystemNameBuffer,
-                FileFsAttribute->FileSystemName,
-                FileFsAttribute->FileSystemNameLength);
-         lpFileSystemNameBuffer[FileFsAttribute->FileSystemNameLength / sizeof(WCHAR)] = 0;
-       }
-      else
+            memcpy(lpFileSystemNameBuffer,
+                   FileFsAttribute->FileSystemName,
+                   FileFsAttribute->FileSystemNameLength);
+            lpFileSystemNameBuffer[FileFsAttribute->FileSystemNameLength / sizeof(WCHAR)] = 0;
+        }
+        else
         {
-         SetLastError(ERROR_MORE_DATA);
-         return FALSE;
-       }
+            SetLastError(ERROR_MORE_DATA);
+            return FALSE;
+        }
     }
-  return TRUE;
+    return TRUE;
 }
 
 
@@ -742,34 +795,34 @@ GetVolumeInformationW(
 BOOL
 WINAPI
 SetVolumeLabelA (
-       LPCSTR  lpRootPathName,
-       LPCSTR  lpVolumeName /* NULL if deleting label */
-       )
+    LPCSTR     lpRootPathName,
+    LPCSTR     lpVolumeName /* NULL if deleting label */
+)
 {
-       PWCHAR RootPathNameW;
-   PWCHAR VolumeNameW = NULL;
-       BOOL Result;
-
-   if (!(RootPathNameW = FilenameA2W(lpRootPathName, FALSE)))
-      return FALSE;
-
-   if (lpVolumeName)
-   {
-      if (!(VolumeNameW = FilenameA2W(lpVolumeName, TRUE)))
-         return FALSE;
-   }
-
-   Result = SetVolumeLabelW (RootPathNameW,
-                             VolumeNameW);
-
-   if (VolumeNameW)
-   {
-          RtlFreeHeap (RtlGetProcessHeap (),
-                       0,
-                   VolumeNameW );
-   }
-
-       return Result;
+    PWCHAR RootPathNameW;
+    PWCHAR VolumeNameW = NULL;
+    BOOL Result;
+
+    if (!(RootPathNameW = FilenameA2W(lpRootPathName, FALSE)))
+        return FALSE;
+
+    if (lpVolumeName)
+    {
+        if (!(VolumeNameW = FilenameA2W(lpVolumeName, TRUE)))
+            return FALSE;
+    }
+
+    Result = SetVolumeLabelW (RootPathNameW,
+                              VolumeNameW);
+
+    if (VolumeNameW)
+    {
+        RtlFreeHeap (RtlGetProcessHeap (),
+                     0,
+                     VolumeNameW );
+    }
+
+    return Result;
 }
 
 
@@ -778,61 +831,61 @@ SetVolumeLabelA (
  */
 BOOL WINAPI
 SetVolumeLabelW(
-   LPCWSTR lpRootPathName,
-   LPCWSTR lpVolumeName /* NULL if deleting label */
-   )
+    LPCWSTR lpRootPathName,
+    LPCWSTR lpVolumeName /* NULL if deleting label */
+)
 {
-   PFILE_FS_LABEL_INFORMATION LabelInfo;
-   IO_STATUS_BLOCK IoStatusBlock;
-   ULONG LabelLength;
-   HANDLE hFile;
-   NTSTATUS Status;
-
-   LabelLength = wcslen(lpVolumeName) * sizeof(WCHAR);
-   LabelInfo = RtlAllocateHeap(RtlGetProcessHeap(),
-                              0,
-                              sizeof(FILE_FS_LABEL_INFORMATION) +
-                              LabelLength);
-   if (LabelInfo == NULL)
-   {
-       SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-       return FALSE;
-   }
-   LabelInfo->VolumeLabelLength = LabelLength;
-   memcpy(LabelInfo->VolumeLabel,
-         lpVolumeName,
-         LabelLength);
-
-   hFile = InternalOpenDirW(lpRootPathName, TRUE);
-   if (INVALID_HANDLE_VALUE == hFile)
-   {
+    PFILE_FS_LABEL_INFORMATION LabelInfo;
+    IO_STATUS_BLOCK IoStatusBlock;
+    ULONG LabelLength;
+    HANDLE hFile;
+    NTSTATUS Status;
+
+    LabelLength = wcslen(lpVolumeName) * sizeof(WCHAR);
+    LabelInfo = RtlAllocateHeap(RtlGetProcessHeap(),
+                                0,
+                                sizeof(FILE_FS_LABEL_INFORMATION) +
+                                LabelLength);
+    if (LabelInfo == NULL)
+    {
+        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+        return FALSE;
+    }
+    LabelInfo->VolumeLabelLength = LabelLength;
+    memcpy(LabelInfo->VolumeLabel,
+           lpVolumeName,
+           LabelLength);
+
+    hFile = InternalOpenDirW(lpRootPathName, TRUE);
+    if (INVALID_HANDLE_VALUE == hFile)
+    {
         RtlFreeHeap(RtlGetProcessHeap(),
-                   0,
-                   LabelInfo);
+                    0,
+                    LabelInfo);
+        return FALSE;
+    }
+
+    Status = NtSetVolumeInformationFile(hFile,
+                                        &IoStatusBlock,
+                                        LabelInfo,
+                                        sizeof(FILE_FS_LABEL_INFORMATION) +
+                                        LabelLength,
+                                        FileFsLabelInformation);
+
+    RtlFreeHeap(RtlGetProcessHeap(),
+                0,
+                LabelInfo);
+
+    if (!NT_SUCCESS(Status))
+    {
+        WARN("Status: %x\n", Status);
+        CloseHandle(hFile);
+        SetLastErrorByStatus(Status);
         return FALSE;
-   }
-
-   Status = NtSetVolumeInformationFile(hFile,
-                                      &IoStatusBlock,
-                                      LabelInfo,
-                                      sizeof(FILE_FS_LABEL_INFORMATION) +
-                                      LabelLength,
-                                      FileFsLabelInformation);
-
-   RtlFreeHeap(RtlGetProcessHeap(),
-              0,
-              LabelInfo);
-
-   if (!NT_SUCCESS(Status))
-     {
-       WARN("Status: %x\n", Status);
-       CloseHandle(hFile);
-       SetLastErrorByStatus(Status);
-       return FALSE;
-     }
-
-   CloseHandle(hFile);
-   return TRUE;
+    }
+
+    CloseHandle(hFile);
+    return TRUE;
 }
 
 /**
@@ -856,217 +909,217 @@ SetVolumeLabelW(
 
 BOOL WINAPI
 GetVolumeNameForVolumeMountPointW(
-   IN LPCWSTR VolumeMountPoint,
-   OUT LPWSTR VolumeName,
-   IN DWORD VolumeNameLength)
+    IN LPCWSTR VolumeMountPoint,
+    OUT LPWSTR VolumeName,
+    IN DWORD VolumeNameLength)
 {
-   UNICODE_STRING NtFileName;
-   OBJECT_ATTRIBUTES ObjectAttributes;
-   HANDLE FileHandle;
-   IO_STATUS_BLOCK Iosb;
-   ULONG BufferLength;
-   PMOUNTDEV_NAME MountDevName;
-   PMOUNTMGR_MOUNT_POINT MountPoint;
-   ULONG MountPointSize;
-   PMOUNTMGR_MOUNT_POINTS MountPoints;
-   ULONG Index;
-   PUCHAR SymbolicLinkName;
-   BOOL Result;
-   NTSTATUS Status;
-
-   if (!VolumeMountPoint || !VolumeMountPoint[0])
-   {
-       SetLastError(ERROR_PATH_NOT_FOUND);
-       return FALSE;
-   }
-
-   /*
-    * First step is to convert the passed volume mount point name to
-    * an NT acceptable name.
-    */
-
-   if (!RtlDosPathNameToNtPathName_U(VolumeMountPoint, &NtFileName, NULL, NULL))
-   {
-      SetLastError(ERROR_PATH_NOT_FOUND);
-      return FALSE;
-   }
-
-   if (NtFileName.Length > sizeof(WCHAR) &&
-       NtFileName.Buffer[(NtFileName.Length / sizeof(WCHAR)) - 1] == '\\')
-   {
-      NtFileName.Length -= sizeof(WCHAR);
-   }
-
-   /*
-    * Query mount point device name which we will later use for determining
-    * the volume name.
-    */
-
-   InitializeObjectAttributes(&ObjectAttributes, &NtFileName, 0, NULL, NULL);
-   Status = NtOpenFile(&FileHandle, FILE_READ_ATTRIBUTES | SYNCHRONIZE,
-                       &ObjectAttributes, &Iosb,
-                       FILE_SHARE_READ | FILE_SHARE_WRITE,
-                       FILE_SYNCHRONOUS_IO_NONALERT);
-   RtlFreeUnicodeString(&NtFileName);
-   if (!NT_SUCCESS(Status))
-   {
-      SetLastErrorByStatus(Status);
-      return FALSE;
-   }
-
-   BufferLength = sizeof(MOUNTDEV_NAME) + 50 * sizeof(WCHAR);
-   do
-   {
-      MountDevName = RtlAllocateHeap(RtlGetProcessHeap(), 0, BufferLength);
-      if (MountDevName == NULL)
-      {
-         NtClose(FileHandle);
-         SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-         return FALSE;
-      }
-
-      Status = NtDeviceIoControlFile(FileHandle, NULL, NULL, NULL, &Iosb,
-                                     IOCTL_MOUNTDEV_QUERY_DEVICE_NAME,
-                                     NULL, 0, MountDevName, BufferLength);
-      if (!NT_SUCCESS(Status))
-      {
-         RtlFreeHeap(GetProcessHeap(), 0, MountDevName);
-         if (Status == STATUS_BUFFER_OVERFLOW)
-         {
-            BufferLength = sizeof(MOUNTDEV_NAME) + MountDevName->NameLength;
-            continue;
-         }
-         else
-         {
+    UNICODE_STRING NtFileName;
+    OBJECT_ATTRIBUTES ObjectAttributes;
+    HANDLE FileHandle;
+    IO_STATUS_BLOCK Iosb;
+    ULONG BufferLength;
+    PMOUNTDEV_NAME MountDevName;
+    PMOUNTMGR_MOUNT_POINT MountPoint;
+    ULONG MountPointSize;
+    PMOUNTMGR_MOUNT_POINTS MountPoints;
+    ULONG Index;
+    PUCHAR SymbolicLinkName;
+    BOOL Result;
+    NTSTATUS Status;
+
+    if (!VolumeMountPoint || !VolumeMountPoint[0])
+    {
+        SetLastError(ERROR_PATH_NOT_FOUND);
+        return FALSE;
+    }
+
+    /*
+     * First step is to convert the passed volume mount point name to
+     * an NT acceptable name.
+     */
+
+    if (!RtlDosPathNameToNtPathName_U(VolumeMountPoint, &NtFileName, NULL, NULL))
+    {
+        SetLastError(ERROR_PATH_NOT_FOUND);
+        return FALSE;
+    }
+
+    if (NtFileName.Length > sizeof(WCHAR) &&
+            NtFileName.Buffer[(NtFileName.Length / sizeof(WCHAR)) - 1] == '\\')
+    {
+        NtFileName.Length -= sizeof(WCHAR);
+    }
+
+    /*
+     * Query mount point device name which we will later use for determining
+     * the volume name.
+     */
+
+    InitializeObjectAttributes(&ObjectAttributes, &NtFileName, 0, NULL, NULL);
+    Status = NtOpenFile(&FileHandle, FILE_READ_ATTRIBUTES | SYNCHRONIZE,
+                        &ObjectAttributes, &Iosb,
+                        FILE_SHARE_READ | FILE_SHARE_WRITE,
+                        FILE_SYNCHRONOUS_IO_NONALERT);
+    RtlFreeUnicodeString(&NtFileName);
+    if (!NT_SUCCESS(Status))
+    {
+        SetLastErrorByStatus(Status);
+        return FALSE;
+    }
+
+    BufferLength = sizeof(MOUNTDEV_NAME) + 50 * sizeof(WCHAR);
+    do
+    {
+        MountDevName = RtlAllocateHeap(RtlGetProcessHeap(), 0, BufferLength);
+        if (MountDevName == NULL)
+        {
             NtClose(FileHandle);
-            SetLastErrorByStatus(Status);
+            SetLastError(ERROR_NOT_ENOUGH_MEMORY);
             return FALSE;
-         }
-      }
-   }
-   while (!NT_SUCCESS(Status));
-
-   NtClose(FileHandle);
-
-   /*
-    * Get the mount point information from mount manager.
-    */
-
-   MountPointSize = MountDevName->NameLength + sizeof(MOUNTMGR_MOUNT_POINT);
-   MountPoint = RtlAllocateHeap(GetProcessHeap(), 0, MountPointSize);
-   if (MountPoint == NULL)
-   {
-      RtlFreeHeap(GetProcessHeap(), 0, MountDevName);
-      SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-      return FALSE;
-   }
-   RtlZeroMemory(MountPoint, sizeof(MOUNTMGR_MOUNT_POINT));
-   MountPoint->DeviceNameOffset = sizeof(MOUNTMGR_MOUNT_POINT);
-   MountPoint->DeviceNameLength = MountDevName->NameLength;
-   RtlCopyMemory(MountPoint + 1, MountDevName->Name, MountDevName->NameLength);
-   RtlFreeHeap(RtlGetProcessHeap(), 0, MountDevName);
-
-   RtlInitUnicodeString(&NtFileName, L"\\??\\MountPointManager");
-   InitializeObjectAttributes(&ObjectAttributes, &NtFileName, 0, NULL, NULL);
-   Status = NtOpenFile(&FileHandle, FILE_GENERIC_READ, &ObjectAttributes,
-                       &Iosb, FILE_SHARE_READ | FILE_SHARE_WRITE,
-                       FILE_SYNCHRONOUS_IO_NONALERT);
-   if (!NT_SUCCESS(Status))
-   {
-      SetLastErrorByStatus(Status);
-      RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoint);
-      return FALSE;
-   }
-
-   BufferLength = sizeof(MOUNTMGR_MOUNT_POINTS);
-   do
-   {
-      MountPoints = RtlAllocateHeap(RtlGetProcessHeap(), 0, BufferLength);
-      if (MountPoints == NULL)
-      {
-         RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoint);
-         NtClose(FileHandle);
-         SetLastError(ERROR_NOT_ENOUGH_MEMORY);
-         return FALSE;
-      }
-
-      Status = NtDeviceIoControlFile(FileHandle, NULL, NULL, NULL, &Iosb,
-                                     IOCTL_MOUNTMGR_QUERY_POINTS,
-                                     MountPoint, MountPointSize,
-                                     MountPoints, BufferLength);
-      if (!NT_SUCCESS(Status))
-      {
-         if (Status == STATUS_BUFFER_OVERFLOW)
-         {
-            BufferLength = MountPoints->Size;
-            RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoints);
-            continue;
-         }
-         else if (!NT_SUCCESS(Status))
-         {
+        }
+
+        Status = NtDeviceIoControlFile(FileHandle, NULL, NULL, NULL, &Iosb,
+                                       IOCTL_MOUNTDEV_QUERY_DEVICE_NAME,
+                                       NULL, 0, MountDevName, BufferLength);
+        if (!NT_SUCCESS(Status))
+        {
+            RtlFreeHeap(GetProcessHeap(), 0, MountDevName);
+            if (Status == STATUS_BUFFER_OVERFLOW)
+            {
+                BufferLength = sizeof(MOUNTDEV_NAME) + MountDevName->NameLength;
+                continue;
+            }
+            else
+            {
+                NtClose(FileHandle);
+                SetLastErrorByStatus(Status);
+                return FALSE;
+            }
+        }
+    }
+    while (!NT_SUCCESS(Status));
+
+    NtClose(FileHandle);
+
+    /*
+     * Get the mount point information from mount manager.
+     */
+
+    MountPointSize = MountDevName->NameLength + sizeof(MOUNTMGR_MOUNT_POINT);
+    MountPoint = RtlAllocateHeap(GetProcessHeap(), 0, MountPointSize);
+    if (MountPoint == NULL)
+    {
+        RtlFreeHeap(GetProcessHeap(), 0, MountDevName);
+        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+        return FALSE;
+    }
+    RtlZeroMemory(MountPoint, sizeof(MOUNTMGR_MOUNT_POINT));
+    MountPoint->DeviceNameOffset = sizeof(MOUNTMGR_MOUNT_POINT);
+    MountPoint->DeviceNameLength = MountDevName->NameLength;
+    RtlCopyMemory(MountPoint + 1, MountDevName->Name, MountDevName->NameLength);
+    RtlFreeHeap(RtlGetProcessHeap(), 0, MountDevName);
+
+    RtlInitUnicodeString(&NtFileName, L"\\??\\MountPointManager");
+    InitializeObjectAttributes(&ObjectAttributes, &NtFileName, 0, NULL, NULL);
+    Status = NtOpenFile(&FileHandle, FILE_GENERIC_READ | SYNCHRONIZE, &ObjectAttributes,
+                        &Iosb, FILE_SHARE_READ | FILE_SHARE_WRITE,
+                        FILE_SYNCHRONOUS_IO_NONALERT);
+    if (!NT_SUCCESS(Status))
+    {
+        SetLastErrorByStatus(Status);
+        RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoint);
+        return FALSE;
+    }
+
+    BufferLength = sizeof(MOUNTMGR_MOUNT_POINTS);
+    do
+    {
+        MountPoints = RtlAllocateHeap(RtlGetProcessHeap(), 0, BufferLength);
+        if (MountPoints == NULL)
+        {
             RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoint);
-            RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoints);
             NtClose(FileHandle);
-            SetLastErrorByStatus(Status);
+            SetLastError(ERROR_NOT_ENOUGH_MEMORY);
             return FALSE;
-         }
-      }
-   }
-   while (!NT_SUCCESS(Status));
-
-   RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoint);
-   NtClose(FileHandle);
-
-   /*
-    * Now we've gathered info about all mount points mapped to our device, so
-    * select the correct one and copy it into the output buffer.
-    */
-
-   for (Index = 0; Index < MountPoints->NumberOfMountPoints; Index++)
-   {
-      MountPoint = MountPoints->MountPoints + Index;
-      SymbolicLinkName = (PUCHAR)MountPoints + MountPoint->SymbolicLinkNameOffset;
-
-      /*
-       * Check for "\\?\Volume{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}\"
-       * (with the last slash being optional) style symbolic links.
-       */
-
-      if (MountPoint->SymbolicLinkNameLength == 48 * sizeof(WCHAR) ||
-          (MountPoint->SymbolicLinkNameLength == 49 * sizeof(WCHAR) &&
-           SymbolicLinkName[48] == L'\\'))
-      {
-         if (RtlCompareMemory(SymbolicLinkName, L"\\??\\Volume{",
-                              11 * sizeof(WCHAR)) == 11 * sizeof(WCHAR) &&
-             SymbolicLinkName[19] == L'-' && SymbolicLinkName[24] == L'-' &&
-             SymbolicLinkName[29] == L'-' && SymbolicLinkName[34] == L'-' &&
-             SymbolicLinkName[47] == L'}')
-         {
-            if (VolumeNameLength >= MountPoint->SymbolicLinkNameLength / sizeof(WCHAR))
+        }
+
+        Status = NtDeviceIoControlFile(FileHandle, NULL, NULL, NULL, &Iosb,
+                                       IOCTL_MOUNTMGR_QUERY_POINTS,
+                                       MountPoint, MountPointSize,
+                                       MountPoints, BufferLength);
+        if (!NT_SUCCESS(Status))
+        {
+            if (Status == STATUS_BUFFER_OVERFLOW)
             {
-               RtlCopyMemory(VolumeName,
-                             (PUCHAR)MountPoints + MountPoint->SymbolicLinkNameOffset,
-                             MountPoint->SymbolicLinkNameLength);
-               VolumeName[1] = L'\\';
-               Result = TRUE;
+                BufferLength = MountPoints->Size;
+                RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoints);
+                continue;
             }
-            else
+            else if (!NT_SUCCESS(Status))
             {
-               SetLastError(ERROR_FILENAME_EXCED_RANGE);
-               Result = FALSE;
+                RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoint);
+                RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoints);
+                NtClose(FileHandle);
+                SetLastErrorByStatus(Status);
+                return FALSE;
             }
+        }
+    }
+    while (!NT_SUCCESS(Status));
 
-            RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoints);
+    RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoint);
+    NtClose(FileHandle);
 
-            return Result;
-         }
-      }
-   }
+    /*
+     * Now we've gathered info about all mount points mapped to our device, so
+     * select the correct one and copy it into the output buffer.
+     */
+
+    for (Index = 0; Index < MountPoints->NumberOfMountPoints; Index++)
+    {
+        MountPoint = MountPoints->MountPoints + Index;
+        SymbolicLinkName = (PUCHAR)MountPoints + MountPoint->SymbolicLinkNameOffset;
+
+        /*
+         * Check for "\\?\Volume{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}\"
+         * (with the last slash being optional) style symbolic links.
+         */
+
+        if (MountPoint->SymbolicLinkNameLength == 48 * sizeof(WCHAR) ||
+                (MountPoint->SymbolicLinkNameLength == 49 * sizeof(WCHAR) &&
+                 SymbolicLinkName[48] == L'\\'))
+        {
+            if (RtlCompareMemory(SymbolicLinkName, L"\\??\\Volume{",
+                                 11 * sizeof(WCHAR)) == 11 * sizeof(WCHAR) &&
+                    SymbolicLinkName[19] == L'-' && SymbolicLinkName[24] == L'-' &&
+                    SymbolicLinkName[29] == L'-' && SymbolicLinkName[34] == L'-' &&
+                    SymbolicLinkName[47] == L'}')
+            {
+                if (VolumeNameLength >= MountPoint->SymbolicLinkNameLength / sizeof(WCHAR))
+                {
+                    RtlCopyMemory(VolumeName,
+                                  (PUCHAR)MountPoints + MountPoint->SymbolicLinkNameOffset,
+                                  MountPoint->SymbolicLinkNameLength);
+                    VolumeName[1] = L'\\';
+                    Result = TRUE;
+                }
+                else
+                {
+                    SetLastError(ERROR_FILENAME_EXCED_RANGE);
+                    Result = FALSE;
+                }
+
+                RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoints);
+
+                return Result;
+            }
+        }
+    }
 
-   RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoints);
-   SetLastError(ERROR_INVALID_PARAMETER);
+    RtlFreeHeap(RtlGetProcessHeap(), 0, MountPoints);
+    SetLastError(ERROR_INVALID_PARAMETER);
 
-   return FALSE;
+    return FALSE;
 }
 
 /*
@@ -1078,7 +1131,7 @@ GetVolumeNameForVolumeMountPointA(
     LPCSTR lpszVolumeMountPoint,
     LPSTR lpszVolumeName,
     DWORD cchBufferLength
-    )
+)
 {
     BOOL ret;
     WCHAR volumeW[50], *pathW = NULL;
@@ -1102,9 +1155,9 @@ GetVolumeNameForVolumeMountPointA(
 HANDLE
 WINAPI
 FindFirstVolumeW(
-       LPWSTR volume,
-       DWORD len
-    )
+    LPWSTR volume,
+    DWORD len
+)
 {
     DWORD size = 1024;
     HANDLE mgr = CreateFileW( MOUNTMGR_DOS_DEVICE_NAME, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
@@ -1151,9 +1204,9 @@ FindFirstVolumeW(
 HANDLE
 WINAPI
 FindFirstVolumeA(
-       LPSTR volume,
-       DWORD len
-    )
+    LPSTR volume,
+    DWORD len
+)
 {
     WCHAR *buffer = NULL;
     HANDLE handle;
@@ -1187,7 +1240,7 @@ BOOL
 WINAPI
 FindVolumeClose(
     HANDLE hFindVolume
-    )
+)
 {
     return RtlFreeHeap(RtlGetProcessHeap(), 0, hFindVolume);
 }
@@ -1275,12 +1328,12 @@ GetVolumePathNameW(LPCWSTR lpszFileName,
         }
 
         while (!GetVolumeNameForVolumeMountPointW(UnicodeFilePath.Buffer,
-                                                  VolumeName,
-                                                  MAX_PATH))
+                VolumeName,
+                MAX_PATH))
         {
             if (((UnicodeFilePath.Length == 4) && (UnicodeFilePath.Buffer[0] == '\\') &&
-                (UnicodeFilePath.Buffer[1] == '\\')) || ((UnicodeFilePath.Length == 6) &&
-                (UnicodeFilePath.Buffer[1] == ':')))
+                    (UnicodeFilePath.Buffer[1] == '\\')) || ((UnicodeFilePath.Length == 6) &&
+                            (UnicodeFilePath.Buffer[1] == ':')))
             {
                 break;
             }