[AUTOCHK][CHKDSK]
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Fri, 4 Mar 2016 17:09:34 +0000 (17:09 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Fri, 4 Mar 2016 17:09:34 +0000 (17:09 +0000)
- Whitespace fixes;
- Remove useless comments.

[FORMAT]
- Whitespace (tabs -> spaces) and indentation fixes.

[VFATLIB]
- Change of name of variable.

svn path=/trunk/; revision=70917

reactos/base/system/autochk/autochk.c
reactos/base/system/chkdsk/chkdsk.c
reactos/base/system/format/format.c
reactos/lib/fslib/vfatlib/vfatlib.c

index 88b9b08..05cc85d 100644 (file)
@@ -297,7 +297,7 @@ CheckVolume(
     /* Get the file system */
     Status = GetFileSystem(DrivePath,
                            FileSystem,
-                           sizeof(FileSystem) / sizeof(FileSystem[0]));
+                           ARRAYSIZE(FileSystem));
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("GetFileSystem() failed with status 0x%08lx\n", Status);
@@ -334,7 +334,7 @@ CheckVolume(
     NtDrivePath[wcslen(NtDrivePath)-1] = 0;
     RtlInitUnicodeString(&DrivePathU, NtDrivePath);
 
-    DPRINT("AUTOCHK: Checking %wZ\n", &DrivePathU);
+    DPRINT1("AUTOCHK: Checking %wZ\n", &DrivePathU);
     Status = ChkdskFunc(&DrivePathU,
                         TRUE, // FixErrors
                         TRUE, // Verbose
index 5edf7d6..262e85a 100644 (file)
 // --------------------------------------------------------------------
 //
 // 1999 February (Emanuele Aliberti)
-//  Adapted for ReactOS and lcc-win32.
+//      Adapted for ReactOS and lcc-win32.
 //
 // 1999 April (Emanuele Aliberti)
-//  Adapted for ReactOS and egcs.
+//      Adapted for ReactOS and egcs.
 //
 // 2008 July (Aleksey Bragin)
-//  Cleanup, use ReactOS's fmifs.h
+//      Cleanup, use ReactOS's fmifs.h
 //
 //======================================================================
 
@@ -70,10 +70,10 @@ WCHAR   CurrentDirectory[1024];
 
 #ifndef FMIFS_IMPORT_DLL
 //
-// FMIFS function
+// Functions in FMIFS.DLL
 //
-// PCHKDSK   Chkdsk;
-#endif /* ndef FMIFS_IMPORT_DLL */
+PCHKDSK Chkdsk;
+#endif
 
 
 //----------------------------------------------------------------------
@@ -144,10 +144,7 @@ Usage(PWCHAR ProgramName)
 //
 //----------------------------------------------------------------------
 static int
-ParseCommandLine(
-    int argc,
-    WCHAR *argv[]
-    )
+ParseCommandLine(int argc, WCHAR *argv[])
 {
     int i;
     BOOLEAN gotFix = FALSE;
@@ -231,8 +228,7 @@ WINAPI
 ChkdskCallback(
     CALLBACKCOMMAND Command,
     DWORD       Modifier,
-    PVOID       Argument
-    )
+    PVOID       Argument)
 {
     PDWORD      percent;
     PBOOLEAN    status;
@@ -329,8 +325,6 @@ ChkdskCallback(
 //
 // Loads FMIFS.DLL and locates the entry point(s) we are going to use
 //
-// 19990216 EA Used wide functions
-//
 //----------------------------------------------------------------------
 static BOOLEAN
 LoadFMIFSEntryPoints(VOID)
@@ -340,7 +334,6 @@ LoadFMIFSEntryPoints(VOID)
         return FALSE;
 
     Chkdsk = (PCHKDSK)GetProcAddress(hFmifs, "Chkdsk");
-
     if (!Chkdsk)
     {
         FreeLibrary(hFmifs);
@@ -349,7 +342,7 @@ LoadFMIFSEntryPoints(VOID)
 
     return TRUE;
 }
-#endif /* ndef FMIFS_IMPORT_DLL */
+#endif
 
 
 //----------------------------------------------------------------------
@@ -374,10 +367,10 @@ wmain(int argc, WCHAR *argv[])
     DWORD   serialNumber;
     DWORD   flags, maxComponent;
 
-    wprintf(L"\n\
-Chkdskx v1.0.1 by Mark Russinovich\n\
-Systems Internals - http://www.sysinternals.com/\n\
-ReactOS adaptation 1999 by Emanuele Aliberti\n\n");
+    wprintf(L"\n"
+            L"Chkdskx v1.0.1 by Mark Russinovich\n"
+            L"Systems Internals - http://www.sysinternals.com\n"
+            L"ReactOS adaptation 1999 by Emanuele Aliberti\n\n");
 
 #ifndef FMIFS_IMPORT_DLL
     //
@@ -388,7 +381,7 @@ ReactOS adaptation 1999 by Emanuele Aliberti\n\n");
         wprintf(L"Could not located FMIFS entry points.\n\n");
         return -1;
     }
-#endif /* ndef FMIFS_IMPORT_DLL */
+#endif
 
     //
     // Parse command line
index cb2f10d..38f5d16 100644 (file)
 #define FMIFS_IMPORT_DLL
 
 // Globals
-BOOL   Error = FALSE;
+BOOL    Error = FALSE;
 
 // switches
-BOOL   QuickFormat = FALSE;
-DWORD  ClusterSize = 0;
-BOOL   CompressDrive = FALSE;
-BOOL   GotALabel = FALSE;
-PWCHAR Label = L"";
-PWCHAR Drive = NULL;
-PWCHAR FileSystem = L"FAT";
+BOOL    QuickFormat = FALSE;
+DWORD   ClusterSize = 0;
+BOOL    CompressDrive = FALSE;
+BOOL    GotALabel = FALSE;
+PWCHAR  Label = L"";
+PWCHAR  Drive = NULL;
+PWCHAR  FileSystem = L"FAT";
 
-WCHAR  RootDirectory[MAX_PATH];
-WCHAR  LabelString[12];
+WCHAR   RootDirectory[MAX_PATH];
+WCHAR   LabelString[12];
 
 #ifndef FMIFS_IMPORT_DLL
 //
@@ -88,22 +88,22 @@ PQUERYAVAILABLEFILESYSTEMFORMAT QueryAvailableFileSystemFormat;
 // Size array
 //
 typedef struct {
-       WCHAR SizeString[16];
-       DWORD ClusterSize;
+    WCHAR SizeString[16];
+    DWORD ClusterSize;
 } SIZEDEFINITION, *PSIZEDEFINITION;
 
 SIZEDEFINITION LegalSizes[] = {
-       { L"512", 512 },
-       { L"1024", 1024 },
-       { L"2048", 2048 },
-       { L"4096", 4096 },
-       { L"8192", 8192 },
-       { L"16K", 16384 },
-       { L"32K", 32768 },
-       { L"64K", 65536 },
-       { L"128K", 65536 * 2 },
-       { L"256K", 65536 * 4 },
-       { L"", 0 },
+    { L"512", 512 },
+    { L"1024", 1024 },
+    { L"2048", 2048 },
+    { L"4096", 4096 },
+    { L"8192", 8192 },
+    { L"16K", 16384 },
+    { L"32K", 32768 },
+    { L"64K", 65536 },
+    { L"128K", 65536 * 2 },
+    { L"256K", 65536 * 4 },
+    { L"", 0 },
 };
 
 
@@ -147,17 +147,17 @@ VOID PrintResourceString(UINT uID, ...)
 // Takes the win32 error code and prints the text version.
 //
 //----------------------------------------------------------------------
-static VOID PrintWin32Error( LPWSTR Message, DWORD ErrorCode )
+static VOID PrintWin32Error(LPWSTR Message, DWORD ErrorCode)
 {
-       LPWSTR lpMsgBuf;
+    LPWSTR lpMsgBuf;
 
-       FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
-                                       NULL, ErrorCode,
-                                       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                                       (LPWSTR)&lpMsgBuf, 0, NULL );
+    FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+                   NULL, ErrorCode,
+                   MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+                   (LPWSTR)&lpMsgBuf, 0, NULL);
 
-       PrintString(L"%s: %s\n", Message, lpMsgBuf );
-       LocalFree( lpMsgBuf );
+    PrintString(L"%s: %s\n", Message, lpMsgBuf);
+    LocalFree(lpMsgBuf);
 }
 
 
@@ -168,73 +168,77 @@ static VOID PrintWin32Error( LPWSTR Message, DWORD ErrorCode )
 // Get the switches.
 //
 //----------------------------------------------------------------------
-static int ParseCommandLine( int argc, WCHAR *argv[] )
+static int ParseCommandLine(int argc, WCHAR *argv[])
 {
-       int i, j;
-       BOOLEAN gotFormat = FALSE;
-       BOOLEAN gotQuick = FALSE;
-       BOOLEAN gotSize = FALSE;
-       BOOLEAN gotLabel = FALSE;
-       BOOLEAN gotCompressed = FALSE;
-
-
-       for( i = 1; i < argc; i++ ) {
-
-               switch( argv[i][0] ) {
-
-               case L'-':
-               case L'/':
-
-                       if( !_wcsnicmp( &argv[i][1], L"FS:", 3 )) {
-
-                               if( gotFormat) return -1;
-                               FileSystem = &argv[i][4];
-                               gotFormat = TRUE;
-
-
-                       } else if( !_wcsnicmp( &argv[i][1], L"A:", 2 )) {
-
-                               if( gotSize ) return -1;
-                               j = 0;
-                               while( LegalSizes[j].ClusterSize &&
-                                        wcsicmp( LegalSizes[j].SizeString, &argv[i][3] )) j++;
-
-                               if( !LegalSizes[j].ClusterSize ) return i;
-                               ClusterSize = LegalSizes[j].ClusterSize;
-                               gotSize = TRUE;
-
-                       } else if( ! _wcsnicmp( &argv[i][1], L"V:", 2 )) {
-
-                               if( gotLabel ) return -1;
-                               Label = &argv[i][3];
-                               gotLabel = TRUE;
-                               GotALabel = TRUE;
-
-                       } else if( !wcsicmp( &argv[i][1], L"Q" )) {
-
-                               if( gotQuick ) return -1;
-                               QuickFormat = TRUE;
-                               gotQuick = TRUE;
-
-                       } else if( !wcsicmp( &argv[i][1], L"C" )) {
-
-                               if( gotCompressed ) return -1;
-                               CompressDrive = TRUE;
-                               gotCompressed = TRUE;
-
-                       } else return i;
-                       break;
-
-               default:
-
-                       if( Drive ) return i;
-                       if( argv[i][1] != L':' ) return i;
-
-                       Drive = argv[i];
-                       break;
-               }
-       }
-       return 0;
+    int i, j;
+    BOOLEAN gotFormat = FALSE;
+    BOOLEAN gotQuick = FALSE;
+    BOOLEAN gotSize = FALSE;
+    BOOLEAN gotLabel = FALSE;
+    BOOLEAN gotCompressed = FALSE;
+
+    for (i = 1; i < argc; i++)
+    {
+        switch (argv[i][0])
+        {
+            case L'-': case L'/':
+
+                if (!_wcsnicmp(&argv[i][1], L"FS:", 3))
+                {
+                    if (gotFormat) return -1;
+                    FileSystem = &argv[i][4];
+                    gotFormat = TRUE;
+                }
+                else if (!_wcsnicmp(&argv[i][1], L"A:", 2))
+                {
+                    if (gotSize) return -1;
+                    j = 0;
+                    while (LegalSizes[j].ClusterSize &&
+                           wcsicmp(LegalSizes[j].SizeString, &argv[i][3]))
+                    {
+                        j++;
+                    }
+
+                    if (!LegalSizes[j].ClusterSize) return i;
+                    ClusterSize = LegalSizes[j].ClusterSize;
+                    gotSize = TRUE;
+                }
+                else if (!_wcsnicmp(&argv[i][1], L"V:", 2))
+                {
+                    if (gotLabel) return -1;
+                    Label = &argv[i][3];
+                    gotLabel = TRUE;
+                    GotALabel = TRUE;
+                }
+                else if (!wcsicmp(&argv[i][1], L"Q"))
+                {
+                    if (gotQuick) return -1;
+                    QuickFormat = TRUE;
+                    gotQuick = TRUE;
+                }
+                else if (!wcsicmp(&argv[i][1], L"C"))
+                {
+                    if (gotCompressed) return -1;
+                    CompressDrive = TRUE;
+                    gotCompressed = TRUE;
+                }
+                else
+                {
+                    return i;
+                }
+                break;
+
+            default:
+            {
+                if (Drive) return i;
+                if (argv[i][1] != L':') return i;
+
+                Drive = argv[i];
+                break;
+            }
+        }
+    }
+    return 0;
 }
 
 //----------------------------------------------------------------------
@@ -246,56 +250,57 @@ static int ParseCommandLine( int argc, WCHAR *argv[] )
 //
 //----------------------------------------------------------------------
 BOOLEAN WINAPI
-FormatExCallback (
-               CALLBACKCOMMAND Command,
-               ULONG Modifier,
-               PVOID Argument)
+FormatExCallback(
+    CALLBACKCOMMAND Command,
+    ULONG Modifier,
+    PVOID Argument)
 {
-       PDWORD percent;
-       PTEXTOUTPUT output;
-       PBOOLEAN status;
-
-       //
-       // We get other types of commands, but we don't have to pay attention to them
-       //
-       switch( Command ) {
-
-       case PROGRESS:
-               percent = (PDWORD) Argument;
-               PrintResourceString(STRING_COMPLETE, *percent);
-               break;
-
-       case OUTPUT:
-               output = (PTEXTOUTPUT) Argument;
-               wprintf(L"%S", output->Output);
-               break;
-
-       case DONE:
-               status = (PBOOLEAN) Argument;
-               if( *status == FALSE ) {
-
-            PrintResourceString(STRING_FORMAT_FAIL);
-                       Error = TRUE;
-               }
-               break;
-       case DONEWITHSTRUCTURE:
-       case UNKNOWN2:
-       case UNKNOWN3:
-       case UNKNOWN4:
-       case UNKNOWN5:
-       case INSUFFICIENTRIGHTS:
-       case FSNOTSUPPORTED:
-       case VOLUMEINUSE:
-       case UNKNOWN9:
-       case UNKNOWNA:
-       case UNKNOWNC:
-       case UNKNOWND:
-       case STRUCTUREPROGRESS:
-       case CLUSTERSIZETOOSMALL:
-        PrintResourceString(STRING_NO_SUPPORT);
-               return FALSE;
-       }
-       return TRUE;
+    PDWORD      percent;
+    PTEXTOUTPUT output;
+    PBOOLEAN    status;
+
+    //
+    // We get other types of commands, but we don't have to pay attention to them
+    //
+    switch (Command)
+    {
+        case PROGRESS:
+            percent = (PDWORD)Argument;
+            PrintResourceString(STRING_COMPLETE, *percent);
+            break;
+
+        case OUTPUT:
+            output = (PTEXTOUTPUT)Argument;
+            wprintf(L"%S", output->Output);
+            break;
+
+        case DONE:
+            status = (PBOOLEAN)Argument;
+            if (*status == FALSE)
+            {
+                PrintResourceString(STRING_FORMAT_FAIL);
+                Error = TRUE;
+            }
+            break;
+
+        case DONEWITHSTRUCTURE:
+        case UNKNOWN2:
+        case UNKNOWN3:
+        case UNKNOWN4:
+        case UNKNOWN5:
+        case INSUFFICIENTRIGHTS:
+        case FSNOTSUPPORTED:
+        case VOLUMEINUSE:
+        case UNKNOWN9:
+        case UNKNOWNA:
+        case UNKNOWNC:
+        case UNKNOWND:
+        case STRUCTUREPROGRESS:
+        case CLUSTERSIZETOOSMALL:
+            PrintResourceString(STRING_NO_SUPPORT);
+            return FALSE;
+    }
+    return TRUE;
 }
 
 #ifndef FMIFS_IMPORT_DLL
@@ -308,30 +313,32 @@ FormatExCallback (
 //----------------------------------------------------------------------
 static BOOLEAN LoadFMIFSEntryPoints(VOID)
 {
-       HMODULE hFmifs = LoadLibraryW( L"fmifs.dll" );
-       if (hFmifs == NULL) {
-               return FALSE;
-       }
+    HMODULE hFmifs = LoadLibraryW( L"fmifs.dll");
+    if (hFmifs == NULL)
+        return FALSE;
 
     FormatEx = (PFORMATEX)GetProcAddress(hFmifs, "FormatEx");
-       if (!FormatEx) {
-               FreeLibrary(hFmifs);
-               return FALSE;
-       }
+    if (!FormatEx)
+    {
+        FreeLibrary(hFmifs);
+        return FALSE;
+    }
 
     EnableVolumeCompression = (PENABLEVOLUMECOMPRESSION)GetProcAddress(hFmifs, "EnableVolumeCompression");
-       if (!EnableVolumeCompression) {
-               FreeLibrary(hFmifs);
-               return FALSE;
-       }
+    if (!EnableVolumeCompression)
+    {
+        FreeLibrary(hFmifs);
+        return FALSE;
+    }
 
     QueryAvailableFileSystemFormat = (PQUERYAVAILABLEFILESYSTEMFORMAT)GetProcAddress(hFmifs, "QueryAvailableFileSystemFormat");
-       if (!QueryAvailableFileSystemFormat) {
-               FreeLibrary(hFmifs);
-               return FALSE;
-       }
+    if (!QueryAvailableFileSystemFormat)
+    {
+        FreeLibrary(hFmifs);
+        return FALSE;
+    }
 
-       return TRUE;
+    return TRUE;
 }
 #endif
 
@@ -343,36 +350,36 @@ static BOOLEAN LoadFMIFSEntryPoints(VOID)
 // Tell the user how to use the program
 //
 //----------------------------------------------------------------------
-static VOID Usage( LPWSTR ProgramName )
+static VOID Usage(LPWSTR ProgramName)
 {
-       WCHAR szMsg[RC_STRING_MAX_SIZE];
-       WCHAR szFormats[MAX_PATH];
-       WCHAR szFormatW[MAX_PATH];
-       DWORD Index = 0;
-       BYTE dummy;
-       BOOLEAN latestVersion;
+    WCHAR szMsg[RC_STRING_MAX_SIZE];
+    WCHAR szFormats[MAX_PATH];
+    WCHAR szFormatW[MAX_PATH];
+    DWORD Index = 0;
+    BYTE dummy;
+    BOOLEAN latestVersion;
 
     LoadStringW(GetModuleHandle(NULL), STRING_HELP, szMsg, ARRAYSIZE(szMsg));
 
 #ifndef FMIFS_IMPORT_DLL
-       if (!LoadFMIFSEntryPoints())
-       {
+    if (!LoadFMIFSEntryPoints())
+    {
         PrintString(szMsg, ProgramName, L"");
-               return;
-       }
+        return;
+    }
 #endif
 
-       szFormats[0] = 0;
-       while (QueryAvailableFileSystemFormat(Index++, szFormatW, &dummy, &dummy, &latestVersion))
-       {
-               if (!latestVersion)
-                       continue;
-               if (szFormats[0])
-                       wcscat(szFormats, L", ");
-
-               wcscat(szFormats, szFormatW);
-       }
-       PrintString(szMsg, ProgramName, szFormats);
+    szFormats[0] = 0;
+    while (QueryAvailableFileSystemFormat(Index++, szFormatW, &dummy, &dummy, &latestVersion))
+    {
+        if (!latestVersion)
+            continue;
+        if (szFormats[0])
+            wcscat(szFormats, L", ");
+
+        wcscat(szFormats, szFormatW);
+    }
+    PrintString(szMsg, ProgramName, szFormats);
 }
 
 
@@ -390,274 +397,276 @@ static VOID Usage( LPWSTR ProgramName )
 //----------------------------------------------------------------------
 int wmain(int argc, WCHAR *argv[])
 {
-       int badArg;
-       DWORD media = FMIFS_HARDDISK;
-       DWORD driveType;
-       WCHAR fileSystem[1024];
-       WCHAR volumeName[1024];
-       WCHAR input[1024];
-       DWORD serialNumber;
-       DWORD flags, maxComponent;
-       ULARGE_INTEGER freeBytesAvailableToCaller, totalNumberOfBytes, totalNumberOfFreeBytes;
-       WCHAR szMsg[RC_STRING_MAX_SIZE];
-
-       wprintf(L"\n"
+    int badArg;
+    DWORD media = FMIFS_HARDDISK;
+    DWORD driveType;
+    WCHAR fileSystem[1024];
+    WCHAR volumeName[1024];
+    WCHAR input[1024];
+    DWORD serialNumber;
+    DWORD flags, maxComponent;
+    ULARGE_INTEGER freeBytesAvailableToCaller, totalNumberOfBytes, totalNumberOfFreeBytes;
+    WCHAR szMsg[RC_STRING_MAX_SIZE];
+
+    wprintf(L"\n"
             L"Formatx v1.0 by Mark Russinovich\n"
             L"Systems Internals - http://www.sysinternals.com\n"
             L"ReactOS adaptation 1999 by Emanuele Aliberti\n\n");
 
 #ifndef FMIFS_IMPORT_DLL
-       //
-       // Get function pointers
-       //
-       if( !LoadFMIFSEntryPoints()) {
-               PrintResourceString(STRING_FMIFS_FAIL);
-               return -1;
-       }
+    //
+    // Get function pointers
+    //
+    if (!LoadFMIFSEntryPoints())
+    {
+        PrintResourceString(STRING_FMIFS_FAIL);
+        return -1;
+    }
 #endif
 
-       //
-       // Parse command line
-       //
-       if( (badArg = ParseCommandLine( argc, argv ))) {
-
-               PrintResourceString(STRING_UNKNOW_ARG, argv[badArg]);
-
-               Usage(argv[0]);
-               return -1;
-       }
-
-       //
-       // Get the drive's format
-       //
-       if( !Drive ) {
-
-               PrintResourceString(STRING_DRIVE_PARM);
-               Usage( argv[0] );
-               return -1;
-
-       } else {
-
-               wcscpy( RootDirectory, Drive );
-       }
-       RootDirectory[2] = L'\\';
-       RootDirectory[3] = L'\0';
-
-       //
-       // See if the drive is removable or not
-       //
-       driveType = GetDriveTypeW( RootDirectory );
-       switch (driveType)
-       {
-               case DRIVE_UNKNOWN :
-                       LoadStringW(GetModuleHandle(NULL), STRING_ERROR_DRIVE_TYPE, szMsg, ARRAYSIZE(szMsg));
-                       PrintWin32Error( szMsg, GetLastError());
-                       return -1;
-
-               case DRIVE_REMOTE:
-               case DRIVE_CDROM:
-                       PrintResourceString(STRING_NO_SUPPORT);
-                       return -1;
-
-               case DRIVE_NO_ROOT_DIR:
-                       LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME, szMsg, ARRAYSIZE(szMsg));
-                       PrintWin32Error( szMsg, GetLastError());
-                       return -1;
-
-               case DRIVE_REMOVABLE:
-                       PrintResourceString(STRING_INSERT_DISK, RootDirectory[0]);
-                       fgetws( input, ARRAYSIZE(input), stdin );
-                       media = FMIFS_FLOPPY;
-                       break;
-
-               case DRIVE_FIXED:
-               case DRIVE_RAMDISK:
-                       media = FMIFS_HARDDISK;
-                       break;
-       }
-
-       // Reject attempts to format the system drive
-       {
-               WCHAR path[MAX_PATH + 1];
-               UINT rc;
-               rc = GetWindowsDirectoryW(path, MAX_PATH);
-               if (rc == 0 || rc > MAX_PATH)
-                       // todo: Report "Unable to query system directory"
-                       return -1;
-               if (towlower(path[0]) == towlower(Drive[0]))
-               {
-                       // todo: report "Cannot format system drive"
-                       PrintResourceString(STRING_NO_SUPPORT);
-                       return -1;
-               }
-       }
-
-       //
-       // Determine the drive's file system format
-       //
-       if( !GetVolumeInformationW( RootDirectory,
-                                               volumeName, ARRAYSIZE(volumeName),
-                                               &serialNumber, &maxComponent, &flags,
-                                               fileSystem, ARRAYSIZE(fileSystem))) {
-
-               LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME, szMsg, ARRAYSIZE(szMsg));
-               PrintWin32Error( szMsg, GetLastError());
-               return -1;
-       }
-
-       if( !GetDiskFreeSpaceExW( RootDirectory,
-                       &freeBytesAvailableToCaller,
-                       &totalNumberOfBytes,
-                       &totalNumberOfFreeBytes )) {
-
-               LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME_SIZE, szMsg, ARRAYSIZE(szMsg));
-               PrintWin32Error( szMsg, GetLastError());
-               return -1;
-       }
-       PrintResourceString(STRING_FILESYSTEM, fileSystem);
-
-       //
-       // Make sure they want to do this
-       //
-       if( driveType == DRIVE_FIXED ) {
-
-               if( volumeName[0] ) {
-
-                       while(1 ) {
-
-                               PrintResourceString(STRING_LABEL_NAME_EDIT, RootDirectory[0]);
-                               fgetws( input, ARRAYSIZE(input), stdin );
-                               input[ wcslen( input ) - 1] = 0;
-
-                               if( !wcsicmp( input, volumeName )) {
-
-                                       break;
-                               }
-                               PrintResourceString(STRING_ERROR_LABEL);
-                       }
-               }
-
-               PrintResourceString(STRING_YN_FORMAT, RootDirectory[0]);
-
-               LoadStringW(GetModuleHandle(NULL), STRING_YES_NO_FAQ, szMsg, ARRAYSIZE(szMsg));
-
-               while( 1 ) {
-                       fgetws( input, ARRAYSIZE(input), stdin );
-                       if(_wcsnicmp(&input[0],&szMsg[0],1) == 0) break;
-                       if(_wcsnicmp(&input[0],&szMsg[1],1) == 0) {
-                               wprintf(L"\n");
-                               return 0;
-                       }
-               }
-       }
-
-       //
-       // Tell the user we're doing a long format if appropriate
-       //
-       if( !QuickFormat ) {
-
-               LoadStringW(GetModuleHandle(NULL), STRING_VERIFYING, szMsg, ARRAYSIZE(szMsg));
-
-               if( totalNumberOfBytes.QuadPart > 1024*1024*10 ) {
-
-                       PrintString(L"%s %luM\n",szMsg, (DWORD) (totalNumberOfBytes.QuadPart/(1024*1024)));
-
-               } else {
-
-                       PrintString(L"%s %.1fM\n",szMsg,
-                               ((float)(LONGLONG)totalNumberOfBytes.QuadPart)/(float)(1024.0*1024.0));
-               }
-       } else {
-
-               LoadStringW(GetModuleHandle(NULL), STRING_FAST_FMT, szMsg, ARRAYSIZE(szMsg));
-               if( totalNumberOfBytes.QuadPart > 1024*1024*10 ) {
-
-                       PrintString(L"%s %luM\n",szMsg, (DWORD) (totalNumberOfBytes.QuadPart/(1024*1024)));
-
-               } else {
-
-                       PrintString(L"%s %.2fM\n",szMsg,
-                               ((float)(LONGLONG)totalNumberOfBytes.QuadPart)/(float)(1024.0*1024.0));
-               }
-               PrintResourceString(STRING_CREATE_FSYS);
-       }
-
-       //
-       // Format away!
-       //
-       FormatEx( RootDirectory, media, FileSystem, Label, QuickFormat,
-                       ClusterSize, FormatExCallback );
-       if( Error ) return -1;
-       PrintResourceString(STRING_FMT_COMPLETE);
-
-       //
-       // Enable compression if desired
-       //
-       if( CompressDrive ) {
-
-               if( !EnableVolumeCompression( RootDirectory, TRUE )) {
-
-                       PrintResourceString(STRING_VOL_COMPRESS);
-               }
-       }
-
-       //
-       // Get the label if we don't have it
-       //
-       if( !GotALabel ) {
-
-               PrintResourceString(STRING_ENTER_LABEL);
-               fgetws( input, ARRAYSIZE(LabelString), stdin );
-
-               input[ wcslen(input)-1] = 0;
-               if( !SetVolumeLabelW( RootDirectory, input )) {
-
-                       LoadStringW(GetModuleHandle(NULL), STRING_NO_LABEL, szMsg, ARRAYSIZE(szMsg));
-                       PrintWin32Error(szMsg, GetLastError());
-                       return -1;
-               }
-       }
-
-       if( !GetVolumeInformationW( RootDirectory,
-                                               volumeName, ARRAYSIZE(volumeName),
-                                               &serialNumber, &maxComponent, &flags,
-                                               fileSystem, ARRAYSIZE(fileSystem))) {
-
-               LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME, szMsg, ARRAYSIZE(szMsg));
-               PrintWin32Error( szMsg, GetLastError());
-               return -1;
-       }
-
-       //
-       // Print out some stuff including the formatted size
-       //
-       if( !GetDiskFreeSpaceExW( RootDirectory,
-                       &freeBytesAvailableToCaller,
-                       &totalNumberOfBytes,
-                       &totalNumberOfFreeBytes )) {
-
-               LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME_SIZE, szMsg, ARRAYSIZE(szMsg));
-               PrintWin32Error(szMsg, GetLastError());
-               return -1;
-       }
-
-       PrintResourceString(STRING_FREE_SPACE, totalNumberOfBytes.QuadPart, totalNumberOfFreeBytes.QuadPart );
-
-       //
-       // Get the drive's serial number
-       //
-       if( !GetVolumeInformationW( RootDirectory,
-                                               volumeName, ARRAYSIZE(volumeName),
-                                               &serialNumber, &maxComponent, &flags,
-                                               fileSystem, ARRAYSIZE(fileSystem))) {
-
-               LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME, szMsg, ARRAYSIZE(szMsg));
-               PrintWin32Error( szMsg, GetLastError());
-               return -1;
-       }
-       PrintResourceString(STRING_SERIAL_NUMBER,
-                    (unsigned int)(serialNumber >> 16),
-                                       (unsigned int)(serialNumber & 0xFFFF));
-
-       return 0;
+    //
+    // Parse command line
+    //
+    badArg = ParseCommandLine(argc, argv);
+    if (badArg)
+    {
+        PrintResourceString(STRING_UNKNOW_ARG, argv[badArg]);
+        Usage(argv[0]);
+        return -1;
+    }
+
+    //
+    // Get the drive's format
+    //
+    if (!Drive)
+    {
+        PrintResourceString(STRING_DRIVE_PARM);
+        Usage(argv[0]);
+        return -1;
+    }
+    else
+    {
+        wcscpy(RootDirectory, Drive);
+    }
+    RootDirectory[2] = L'\\';
+    RootDirectory[3] = L'\0';
+
+    //
+    // See if the drive is removable or not
+    //
+    driveType = GetDriveTypeW(RootDirectory);
+    switch (driveType)
+    {
+        case DRIVE_UNKNOWN :
+            LoadStringW(GetModuleHandle(NULL), STRING_ERROR_DRIVE_TYPE, szMsg, ARRAYSIZE(szMsg));
+            PrintWin32Error(szMsg, GetLastError());
+            return -1;
+
+        case DRIVE_REMOTE:
+        case DRIVE_CDROM:
+            PrintResourceString(STRING_NO_SUPPORT);
+            return -1;
+
+        case DRIVE_NO_ROOT_DIR:
+            LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME, szMsg, ARRAYSIZE(szMsg));
+            PrintWin32Error(szMsg, GetLastError());
+            return -1;
+
+        case DRIVE_REMOVABLE:
+            PrintResourceString(STRING_INSERT_DISK, RootDirectory[0]);
+            fgetws(input, ARRAYSIZE(input), stdin);
+            media = FMIFS_FLOPPY;
+            break;
+
+        case DRIVE_FIXED:
+        case DRIVE_RAMDISK:
+            media = FMIFS_HARDDISK;
+            break;
+    }
+
+    // Reject attempts to format the system drive
+    {
+        WCHAR path[MAX_PATH + 1];
+        UINT rc;
+        rc = GetWindowsDirectoryW(path, MAX_PATH);
+        if (rc == 0 || rc > MAX_PATH)
+            // todo: Report "Unable to query system directory"
+            return -1;
+        if (towlower(path[0]) == towlower(Drive[0]))
+        {
+            // todo: report "Cannot format system drive"
+            PrintResourceString(STRING_NO_SUPPORT);
+            return -1;
+        }
+    }
+
+    //
+    // Determine the drive's file system format
+    //
+    if (!GetVolumeInformationW(RootDirectory,
+                               volumeName, ARRAYSIZE(volumeName),
+                               &serialNumber, &maxComponent, &flags,
+                               fileSystem, ARRAYSIZE(fileSystem)))
+    {
+        LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME, szMsg, ARRAYSIZE(szMsg));
+        PrintWin32Error(szMsg, GetLastError());
+        return -1;
+    }
+
+    if (!GetDiskFreeSpaceExW(RootDirectory,
+                             &freeBytesAvailableToCaller,
+                             &totalNumberOfBytes,
+                             &totalNumberOfFreeBytes))
+    {
+        LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME_SIZE, szMsg, ARRAYSIZE(szMsg));
+        PrintWin32Error(szMsg, GetLastError());
+        return -1;
+    }
+    PrintResourceString(STRING_FILESYSTEM, fileSystem);
+
+    //
+    // Make sure they want to do this
+    //
+    if (driveType == DRIVE_FIXED)
+    {
+        if (volumeName[0])
+        {
+            while (TRUE)
+            {
+                PrintResourceString(STRING_LABEL_NAME_EDIT, RootDirectory[0]);
+                fgetws(input, ARRAYSIZE(input), stdin);
+                input[wcslen(input) - 1] = 0;
+
+                if (!wcsicmp(input, volumeName))
+                    break;
+
+                PrintResourceString(STRING_ERROR_LABEL);
+            }
+        }
+
+        PrintResourceString(STRING_YN_FORMAT, RootDirectory[0]);
+
+        LoadStringW(GetModuleHandle(NULL), STRING_YES_NO_FAQ, szMsg, ARRAYSIZE(szMsg));
+        while (TRUE)
+        {
+            fgetws(input, ARRAYSIZE(input), stdin);
+            if (_wcsnicmp(&input[0], &szMsg[0], 1) == 0) break;
+            if (_wcsnicmp(&input[0], &szMsg[1], 1) == 0)
+            {
+                wprintf(L"\n");
+                return 0;
+            }
+        }
+    }
+
+    //
+    // Tell the user we're doing a long format if appropriate
+    //
+    if (!QuickFormat)
+    {
+        LoadStringW(GetModuleHandle(NULL), STRING_VERIFYING, szMsg, ARRAYSIZE(szMsg));
+        if (totalNumberOfBytes.QuadPart > 1024*1024*10)
+        {
+            PrintString(L"%s %luM\n", szMsg, (DWORD)(totalNumberOfBytes.QuadPart/(1024*1024)));
+        }
+        else
+        {
+            PrintString(L"%s %.1fM\n", szMsg,
+                ((float)(LONGLONG)totalNumberOfBytes.QuadPart)/(float)(1024.0*1024.0));
+        }
+    }
+    else
+    {
+        LoadStringW(GetModuleHandle(NULL), STRING_FAST_FMT, szMsg, ARRAYSIZE(szMsg));
+        if (totalNumberOfBytes.QuadPart > 1024*1024*10)
+        {
+            PrintString(L"%s %luM\n", szMsg, (DWORD)(totalNumberOfBytes.QuadPart/(1024*1024)));
+        }
+        else
+        {
+            PrintString(L"%s %.2fM\n", szMsg,
+                ((float)(LONGLONG)totalNumberOfBytes.QuadPart)/(float)(1024.0*1024.0));
+        }
+        PrintResourceString(STRING_CREATE_FSYS);
+    }
+
+    //
+    // Format away!
+    //
+    FormatEx(RootDirectory, media, FileSystem, Label, QuickFormat,
+             ClusterSize, FormatExCallback);
+    if (Error) return -1;
+    PrintResourceString(STRING_FMT_COMPLETE);
+
+    //
+    // Enable compression if desired
+    //
+    if (CompressDrive)
+    {
+        if (!EnableVolumeCompression(RootDirectory, TRUE))
+            PrintResourceString(STRING_VOL_COMPRESS);
+    }
+
+    //
+    // Get the label if we don't have it
+    //
+    if (!GotALabel)
+    {
+        PrintResourceString(STRING_ENTER_LABEL);
+        fgetws(input, ARRAYSIZE(LabelString), stdin);
+
+        input[wcslen(input) - 1] = 0;
+        if (!SetVolumeLabelW(RootDirectory, input))
+        {
+            LoadStringW(GetModuleHandle(NULL), STRING_NO_LABEL, szMsg, ARRAYSIZE(szMsg));
+            PrintWin32Error(szMsg, GetLastError());
+            return -1;
+        }
+    }
+
+    if (!GetVolumeInformationW(RootDirectory,
+                               volumeName, ARRAYSIZE(volumeName),
+                               &serialNumber, &maxComponent, &flags,
+                               fileSystem, ARRAYSIZE(fileSystem)))
+    {
+        LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME, szMsg, ARRAYSIZE(szMsg));
+        PrintWin32Error(szMsg, GetLastError());
+        return -1;
+    }
+
+    //
+    // Print out some stuff including the formatted size
+    //
+    if (!GetDiskFreeSpaceExW(RootDirectory,
+                             &freeBytesAvailableToCaller,
+                             &totalNumberOfBytes,
+                             &totalNumberOfFreeBytes))
+    {
+        LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME_SIZE, szMsg, ARRAYSIZE(szMsg));
+        PrintWin32Error(szMsg, GetLastError());
+        return -1;
+    }
+
+    PrintResourceString(STRING_FREE_SPACE, totalNumberOfBytes.QuadPart,
+                                           totalNumberOfFreeBytes.QuadPart);
+
+    //
+    // Get the drive's serial number
+    //
+    if (!GetVolumeInformationW(RootDirectory,
+                               volumeName, ARRAYSIZE(volumeName),
+                               &serialNumber, &maxComponent, &flags,
+                               fileSystem, ARRAYSIZE(fileSystem)))
+    {
+        LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME, szMsg, ARRAYSIZE(szMsg));
+        PrintWin32Error(szMsg, GetLastError());
+        return -1;
+    }
+    PrintResourceString(STRING_SERIAL_NUMBER,
+                        (unsigned int)(serialNumber >> 16),
+                        (unsigned int)(serialNumber & 0xFFFF));
+
+    return 0;
 }
+
+/* EOF */
index a2bc390..5ef5618 100644 (file)
@@ -362,11 +362,11 @@ VfatPrintV(PCHAR Format, va_list args)
 VOID
 VfatPrint(PCHAR Format, ...)
 {
-    va_list valist;
+    va_list args;
 
-    va_start(valist, Format);
-    VfatPrintV(Format, valist);
-    va_end(valist);
+    va_start(args, Format);
+    VfatPrintV(Format, args);
+    va_end(args);
 }