Index: trunk/src/kernel32/disk.cpp
===================================================================
--- trunk/src/kernel32/disk.cpp	(revision 8256)
+++ trunk/src/kernel32/disk.cpp	(revision 8257)
@@ -1,3 +1,3 @@
-/* $Id: disk.cpp,v 1.32 2002-02-09 12:45:12 sandervl Exp $ */
+/* $Id: disk.cpp,v 1.33 2002-04-13 06:20:36 bird Exp $ */
 
 /*
@@ -85,7 +85,7 @@
        TVFSTOHPFS = 1
        */
-    if(lpSectorsPerCluster!=NULL) 
+    if(lpSectorsPerCluster!=NULL)
     {
-      if(*lpSectorsPerCluster==1024 && PROFILE_GetOdinIniBool("DRIVESPACE","CLUSTERTO32",0)) 
+      if(*lpSectorsPerCluster==1024 && PROFILE_GetOdinIniBool("DRIVESPACE","CLUSTERTO32",0))
       {/* TVFS returns 1024 sectors per cluster */
         dprintf(("KERNEL32:  GetDiskFreeSpaceA, TVFS-Drive detected. Faking clustersize to 32.\n"));
@@ -206,33 +206,125 @@
     return(rc);
 }
-//******************************************************************************
-//Note: NT4, SP6 does not change the last error, regardless of the junk it receives!
-//******************************************************************************
+
+
+/**
+ * Determin the type of a specific drive or the current drive.
+ *
+ * @returns DRIVE_UNKNOWN
+ *          DRIVE_NO_ROOT_DIR
+ *          DRIVE_CANNOTDETERMINE
+ *          DRIVE_DOESNOTEXIST
+ *          DRIVE_REMOVABLE
+ *          DRIVE_FIXED
+ *          DRIVE_REMOTE
+ *          DRIVE_CDROM
+ *          DRIVE_RAMDISK
+ *
+ * @param   lpszDrive   Root path of the drive in question.
+ *                      NULL means the current drive.
+ * @sketch
+ *          If no drive Then
+ *              Get Current Drive Index.
+ *          ElseIf valid drive letter Then
+ *              Convert to Drive Index.
+ *          Else
+ *              Return Error: Invalid root dir.
+ *          Endif
+ *          Call the OSLib worker function with the index.
+ *          return it's result.
+ *
+ * @status  completely implemented and tested
+ * @author  Sander
+ * @remark  NT4, SP6 does not change the last error, regardless of the junk it receives!
+ */
 UINT WIN32API GetDriveTypeA(LPCSTR lpszDrive)
 {
-   UINT rc;
-   ULONG driveIndex;
-
-    if(lpszDrive == 0) {
-        driveIndex = OSLibDosQueryCurrentDisk() - 1;
-    }
-    else
-    if(*lpszDrive >= 'A' && *lpszDrive <= 'Z')
-        driveIndex = (DWORD)(*lpszDrive - 'A');
-    else
-    if(*lpszDrive >= 'a' && *lpszDrive <= 'z') {
-        driveIndex = (DWORD)(*lpszDrive - 'a');
-    }
-    else {
+    UINT    rc;
+    ULONG   ulDrive = ~0;
+
+    /* validate and convert input */
+    if (!lpszDrive)
+        ulDrive = OSLibDosQueryCurrentDisk() - 1;
+    else if (*lpszDrive != '\0' && lpszDrive[1] == ':')
+    {
+        if (*lpszDrive >= 'A' && *lpszDrive <= 'Z')
+            ulDrive = *lpszDrive - 'A';
+        else if (*lpszDrive >= 'a' && *lpszDrive <= 'z')
+            ulDrive = *lpszDrive - 'a';
+
+        /*
+         * Validate the rest of the path.
+         * Note:    This validate is kind of weird.
+         *          "c:\\\\\\\\\\\\" is ok
+         *          "c:\\\\\\\\\\\\." is ok
+         *          "c:\\\\\\\\\\\\........" is ok
+         *          "c:\\\\\\\\\\\.\" is not ok
+         *          "c:..............." is ok
+         *          "c:\\ \ \ \ \ \\\\\" is not ok
+         *          "c:\\ \ \ \ \ \\\\\" is not ok
+         *          "c:\ . . . . . ." is ok
+         *          "c:\/\/\/ . . . . ." is ok
+         *          "c:\\\.\\\/\." is ok
+         * I hope I got it right.
+         */
+        if (ulDrive != ~0)
+        {
+            LPCSTR lpsz = lpszDrive + 2;
+
+            /* skip slashes and dots */
+            while (*lpsz == '.' || *lpsz == '\\' || *lpsz == '/')
+                lpsz++;
+            /* skip dot's and spaces. */
+            while (*lpsz == ' ' || *lpsz == '.')
+                lpsz++;
+            if (*lpsz)
+                ulDrive = ~0;
+        }
+    }
+
+    /* check if validation failed */
+    if (ulDrive == ~0)
+    {
+        dprintf(("KERNEL32:  GetDriveType(""%s"") -> DRIVE_NO_ROOT_DIR (%d)", lpszDrive, DRIVE_NO_ROOT_DIR));
         return DRIVE_NO_ROOT_DIR;   //return value checked in NT4, SP6 (GetDriveType(""), GetDriveType("4");
     }
 
     //NOTE: Although GetDriveTypeW handles -1, GetDriveTypeA crashes in NT 4, SP6
-    rc = OSLibGetDriveType(driveIndex);
+    rc = OSLibGetDriveType(ulDrive);
     dprintf(("KERNEL32:  GetDriveType %s = %d", lpszDrive, rc));
     return rc;
 }
-//******************************************************************************
-//******************************************************************************
+
+
+/**
+ * Determin the type of a specific drive or the current drive.
+ *
+ * @returns DRIVE_UNKNOWN
+ *          DRIVE_NO_ROOT_DIR
+ *          DRIVE_CANNOTDETERMINE
+ *          DRIVE_DOESNOTEXIST
+ *          DRIVE_REMOVABLE
+ *          DRIVE_FIXED
+ *          DRIVE_REMOTE
+ *          DRIVE_CDROM
+ *          DRIVE_RAMDISK
+ *
+ * @param   lpszDrive   Root path of the drive in question.
+ *                      NULL means the current drive.
+ * @sketch
+ *          If no drive Then
+ *              Get Current Drive Index.
+ *          ElseIf valid drive letter Then
+ *              Convert to Drive Index.
+ *          Else
+ *              Return Error: Invalid root dir.
+ *          Endif
+ *          Call the OSLib worker function with the index.
+ *          return it's result.
+ *
+ * @status  completely implemented and tested
+ * @author  Sander
+ * @remark  NT4, SP6 does not change the last error, regardless of the junk it receives!
+ */
 UINT WIN32API GetDriveTypeW(LPCWSTR lpszDrive)
 {
@@ -293,5 +385,5 @@
         }
     }
-    if(lpFileSystemNameBuffer || lpMaximumComponentLength || lpFileSystemFlags) 
+    if(lpFileSystemNameBuffer || lpMaximumComponentLength || lpFileSystemFlags)
     {
         if(!lpFileSystemNameBuffer) {
@@ -303,8 +395,8 @@
         if(rc == ERROR_SUCCESS) strcpy(szOrgFileSystemName, lpFileSystemNameBuffer);
 
-        if(lpFileSystemNameBuffer) 
+        if(lpFileSystemNameBuffer)
         {
             dprintf2(("File system name: %s", lpFileSystemNameBuffer));
-            if(!strcmp(lpFileSystemNameBuffer, "JFS")) 
+            if(!strcmp(lpFileSystemNameBuffer, "JFS"))
             {
                 strcpy(lpFileSystemNameBuffer, "NTFS");
@@ -316,5 +408,5 @@
                 //do nothing
             }
-            else 
+            else
             {//pretend everything else is FAT16 (HPFS and FAT have the same file size limit)
                 strcpy(lpFileSystemNameBuffer, "FAT16");
