[KERNEL32]
authorDmitry Chapyshev <dmitry@reactos.org>
Tue, 30 Aug 2016 19:22:00 +0000 (19:22 +0000)
committerDmitry Chapyshev <dmitry@reactos.org>
Tue, 30 Aug 2016 19:22:00 +0000 (19:22 +0000)
- Failure if does not come to an end a way with a symbol '\' (exception - a path of a looks like 'C:')

* Fixes 2 tests for kernel32_apitest GetDriveType (all tests for GetDriveType passed now)

svn path=/trunk/; revision=72512

reactos/dll/win32/kernel32/client/file/disk.c

index 5c45181..4f29f47 100644 (file)
@@ -19,6 +19,8 @@
  */
 
 #include <k32.h>
+#include <strsafe.h>
+
 #define NDEBUG
 #include <debug.h>
 DEBUG_CHANNEL(kernel32file);
@@ -401,12 +403,35 @@ GetDriveTypeW(IN LPCWSTR lpRootPathName)
         if (wcslen(CurrentDir) > 3)
             CurrentDir[3] = 0;
 
-        lpRootPath = (PCWSTR)CurrentDir;
+        lpRootPath = CurrentDir;
     }
     else
     {
+        size_t Length = wcslen(lpRootPathName);
+
         TRACE("lpRootPathName: %S\n", lpRootPathName);
-        lpRootPath = lpRootPathName;
+
+        if (Length == 2)
+        {
+            WCHAR DriveLetter = RtlUpcaseUnicodeChar(lpRootPathName[0]);
+
+            if (DriveLetter >= L'A' && DriveLetter <= L'Z' && lpRootPathName[1] == L':')
+            {
+                Length = (Length + 2) * sizeof(WCHAR);
+
+                CurrentDir = HeapAlloc(GetProcessHeap(), 0, Length);
+                if (!CurrentDir)
+                    return DRIVE_UNKNOWN;
+
+                StringCbPrintfW(CurrentDir, Length, L"%s\\", lpRootPathName);
+
+                lpRootPath = CurrentDir;
+            }
+        }
+        else
+        {
+            lpRootPath = lpRootPathName;
+        }
     }
 
     TRACE("lpRootPath: %S\n", lpRootPath);
@@ -424,6 +449,11 @@ GetDriveTypeW(IN LPCWSTR lpRootPathName)
     if (CurrentDir != NULL)
         HeapFree(GetProcessHeap(), 0, CurrentDir);
 
+    if (PathName.Buffer[(PathName.Length >> 1) - 1] != L'\\')
+    {
+        return DRIVE_NO_ROOT_DIR;
+    }
+
     InitializeObjectAttributes(&ObjectAttributes,
                                &PathName,
                                OBJ_CASE_INSENSITIVE,
@@ -436,6 +466,7 @@ GetDriveTypeW(IN LPCWSTR lpRootPathName)
                         &IoStatusBlock,
                         FILE_SHARE_READ | FILE_SHARE_WRITE,
                         FILE_SYNCHRONOUS_IO_NONALERT);
+
     RtlFreeHeap(RtlGetProcessHeap(), 0, PathName.Buffer);
     if (!NT_SUCCESS(Status))
         return DRIVE_NO_ROOT_DIR; /* According to WINE regression tests */
@@ -453,19 +484,19 @@ GetDriveTypeW(IN LPCWSTR lpRootPathName)
 
     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)
+        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;
-        if (FileFsDevice.Characteristics & FILE_REMOVABLE_MEDIA)
-            return DRIVE_REMOVABLE;
+        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;
     }