1 //======================================================================
7 // Copyright (c) 1998 Mark Russinovich
9 // http://www.sysinternals.com/
11 // --------------------------------------------------------------------
13 // This software is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Library General Public License as
15 // published by the Free Software Foundation; either version 2 of the
16 // License, or (at your option) any later version.
18 // This software is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Library General Public License for more details.
23 // You should have received a copy of the GNU Library General Public
24 // License along with this software; see the file COPYING.LIB. If
25 // not, write to the Free Software Foundation, Inc., 675 Mass Ave,
26 // Cambridge, MA 02139, USA.
28 // --------------------------------------------------------------------
30 // Chkdsk clone that demonstrates the use of the FMIFS file system
33 // 1999 February (Emanuele Aliberti)
34 // Adapted for ReactOS and lcc-win32.
36 // 1999 April (Emanuele Aliberti)
37 // Adapted for ReactOS and egcs.
39 //======================================================================
55 BOOL FixErrors
= FALSE
;
56 BOOL SkipClean
= FALSE
;
57 BOOL ScanSectors
= FALSE
;
60 WCHAR CurrentDirectory
[1024];
62 #ifndef FMIFS_IMPORT_DLL
67 #endif /* ndef FMIFS_IMPORT_DLL */
70 //--------------------------------------------------------------------
74 // Intercepts Ctrl-C's so that the program can't be quit with the
75 // disk in an inconsistent state.
77 //--------------------------------------------------------------------
80 CtrlCIntercept( DWORD dwCtrlType
)
83 // Handle the event so that the default handler doesn't
89 //----------------------------------------------------------------------
93 // Tell the user how to use the program
95 // 19990216 EA Missing printf %s argument
96 //----------------------------------------------------------------------
98 Usage( PWCHAR ProgramName
)
102 Usage: %s [drive:] [-F] [-V] [-R] [-C]\n\n\
103 [drive:] Specifies the drive to check.\n\
104 -F Fixes errors on the disk.\n\
105 -V Displays the full path of every file on the disk.\n\
106 -R Locates bad sectors and recovers readable information.\n\
107 -C Checks the drive only if it is dirty.\n\n",
113 //----------------------------------------------------------------------
119 //----------------------------------------------------------------------
127 BOOLEAN gotFix
= FALSE
;
128 BOOLEAN gotVerbose
= FALSE
;
129 BOOLEAN gotClean
= FALSE
;
130 /*BOOLEAN gotScan = FALSE;*/
147 if( gotFix
) return i
;
155 if( gotVerbose
) return i
;
163 if( gotFix
) return i
;
171 if( gotClean
) return i
;
183 if( Drive
) return i
;
184 if( argv
[i
][1] != L
':' ) return i
;
194 //----------------------------------------------------------------------
198 // The file system library will call us back with commands that we
199 // can interpret. If we wanted to halt the chkdsk we could return FALSE.
201 //----------------------------------------------------------------------
205 CALLBACKCOMMAND Command
,
215 // We get other types of commands,
216 // but we don't have to pay attention to them
221 wprintf(L
"UNKNOWN2\r");
225 wprintf(L
"UNKNOWN3\r");
229 wprintf(L
"UNKNOWN4\r");
233 wprintf(L
"UNKNOWN5\r");
237 wprintf(L
"UNKNOWN7\r");
241 wprintf(L
"UNKNOWN8\r");
245 wprintf(L
"UNKNOWN9\r");
249 wprintf(L
"UNKNOWNA\r");
253 wprintf(L
"UNKNOWNC\r");
257 wprintf(L
"UNKNOWND\r");
260 case INSUFFICIENTRIGHTS
:
261 wprintf(L
"INSUFFICIENTRIGHTS\r");
264 case STRUCTUREPROGRESS
:
265 wprintf(L
"STRUCTUREPROGRESS\r");
268 case DONEWITHSTRUCTURE
:
269 wprintf(L
"DONEWITHSTRUCTURE\r");
273 percent
= (PDWORD
) Argument
;
274 wprintf(L
"%d percent completed.\r", *percent
);
278 output
= (PTEXTOUTPUT
) Argument
;
279 fwprintf(stdout
, L
"%s", output
->Output
);
283 status
= (PBOOLEAN
) Argument
;
284 if ( *status
== TRUE
)
286 wprintf(L
"Chkdsk was unable to complete successfully.\n\n");
294 #ifndef FMIFS_IMPORT_DLL
295 //----------------------------------------------------------------------
297 // LoadFMIFSEntryPoints
299 // Loads FMIFS.DLL and locates the entry point(s) we are going to use
301 // 19990216 EA Used wide functions
303 //----------------------------------------------------------------------
305 LoadFMIFSEntryPoints(VOID
)
307 LoadLibraryW( L
"fmifs.dll" );
310 (void *) GetProcAddress(
311 GetModuleHandleW(L
"fmifs.dll"),
319 #endif /* ndef FMIFS_IMPORT_DLL */
322 //----------------------------------------------------------------------
326 // Engine. Just get command line switches and fire off a chkdsk. This
327 // could also be done in a GUI like Explorer does when you select a
328 // drive and run a check on it.
330 // We do this in UNICODE because the chkdsk command expects PWCHAR
333 //----------------------------------------------------------------------
335 wmain( int argc
, WCHAR
*argv
[] )
339 WCHAR fileSystem
[1024];
340 WCHAR volumeName
[1024];
347 Chkdskx v1.0.1 by Mark Russinovich\n\
348 Systems Internals - http://www.sysinternals.com/\n\
349 ReactOS adaptation 1999 by Emanuele Aliberti\n\n"
351 #ifndef FMIFS_IMPORT_DLL
353 // Get function pointers
355 if( !LoadFMIFSEntryPoints())
357 wprintf(L
"Could not located FMIFS entry points.\n\n");
360 #endif /* ndef FMIFS_IMPORT_DLL */
362 // Parse command line
364 if( (badArg
= ParseCommandLine( argc
, argv
)))
367 L
"Unknown argument: %s\n",
376 // Get the drive's format
380 if( !GetCurrentDirectoryW(
381 sizeof(CurrentDirectory
),
387 L
"Could not get current directory",
395 wcscpy( CurrentDirectory
, Drive
);
397 CurrentDirectory
[2] = L
'\\';
398 CurrentDirectory
[3] = L
'\0';
399 Drive
= CurrentDirectory
;
402 // Determine the drive's file system format, which we need to
405 if( !GetVolumeInformationW(
417 L
"Could not query volume",
424 // If they want to fix, we need to have access to the drive
433 volumeHandle
= CreateFileW(
442 if( volumeHandle
== INVALID_HANDLE_VALUE
)
444 wprintf(L
"Chdskx cannot run because the volume is in use by another process.\n\n");
447 CloseHandle( volumeHandle
);
450 // Can't let the user break out of a chkdsk that can modify the drive
452 SetConsoleCtrlHandler( CtrlCIntercept
, TRUE
);
459 L
"The type of file system is %s.\n",
474 if ( Error
) return -1;