bf15c55e8c419fb64aebb30d41e346199a7df101
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 // 2008 July (Aleksey Bragin)
40 // Cleanup, use ReactOS's fmifs.h
42 //======================================================================
43 #define WIN32_NO_STATUS
44 #define NTOS_MODE_USER
48 #include <ndk/ntndk.h>
49 #include <fmifs/fmifs.h>
61 BOOL FixErrors
= FALSE
;
62 BOOL SkipClean
= FALSE
;
63 BOOL ScanSectors
= FALSE
;
66 WCHAR CurrentDirectory
[1024];
68 #ifndef FMIFS_IMPORT_DLL
73 #endif /* ndef FMIFS_IMPORT_DLL */
76 //--------------------------------------------------------------------
80 // Intercepts Ctrl-C's so that the program can't be quit with the
81 // disk in an inconsistent state.
83 //--------------------------------------------------------------------
86 CtrlCIntercept( DWORD dwCtrlType
)
89 // Handle the event so that the default handler doesn't
95 //----------------------------------------------------------------------
99 // Tell the user how to use the program
101 // 19990216 EA Missing printf %s argument
102 //----------------------------------------------------------------------
104 Usage( PWCHAR ProgramName
)
108 Usage: %s [drive:] [-F] [-V] [-R] [-C]\n\n\
109 [drive:] Specifies the drive to check.\n\
110 -F Fixes errors on the disk.\n\
111 -V Displays the full path of every file on the disk.\n\
112 -R Locates bad sectors and recovers readable information.\n\
113 -C Checks the drive only if it is dirty.\n\n",
119 //----------------------------------------------------------------------
125 //----------------------------------------------------------------------
133 BOOLEAN gotFix
= FALSE
;
134 BOOLEAN gotVerbose
= FALSE
;
135 BOOLEAN gotClean
= FALSE
;
136 /*BOOLEAN gotScan = FALSE;*/
153 if( gotFix
) return i
;
161 if( gotVerbose
) return i
;
169 if( gotFix
) return i
;
177 if( gotClean
) return i
;
189 if( Drive
) return i
;
190 if( argv
[i
][1] != L
':' ) return i
;
200 //----------------------------------------------------------------------
204 // The file system library will call us back with commands that we
205 // can interpret. If we wanted to halt the chkdsk we could return FALSE.
207 //----------------------------------------------------------------------
211 CALLBACKCOMMAND Command
,
221 // We get other types of commands,
222 // but we don't have to pay attention to them
227 wprintf(L
"UNKNOWN2\r");
231 wprintf(L
"UNKNOWN3\r");
235 wprintf(L
"UNKNOWN4\r");
239 wprintf(L
"UNKNOWN5\r");
243 wprintf(L
"FSNOTSUPPORTED\r");
247 wprintf(L
"VOLUMEINUSE\r");
251 wprintf(L
"UNKNOWN9\r");
255 wprintf(L
"UNKNOWNA\r");
259 wprintf(L
"UNKNOWNC\r");
263 wprintf(L
"UNKNOWND\r");
266 case INSUFFICIENTRIGHTS
:
267 wprintf(L
"INSUFFICIENTRIGHTS\r");
270 case STRUCTUREPROGRESS
:
271 wprintf(L
"STRUCTUREPROGRESS\r");
274 case DONEWITHSTRUCTURE
:
275 wprintf(L
"DONEWITHSTRUCTURE\r");
278 case CLUSTERSIZETOOSMALL
:
279 wprintf(L
"CLUSTERSIZETOOSMALL\r");
283 percent
= (PDWORD
) Argument
;
284 wprintf(L
"%d percent completed.\r", *percent
);
288 output
= (PTEXTOUTPUT
) Argument
;
289 fwprintf(stdout
, L
"%s", output
->Output
);
293 status
= (PBOOLEAN
) Argument
;
294 if ( *status
== TRUE
)
296 wprintf(L
"Chkdsk was unable to complete successfully.\n\n");
304 #ifndef FMIFS_IMPORT_DLL
305 //----------------------------------------------------------------------
307 // LoadFMIFSEntryPoints
309 // Loads FMIFS.DLL and locates the entry point(s) we are going to use
311 // 19990216 EA Used wide functions
313 //----------------------------------------------------------------------
315 LoadFMIFSEntryPoints(VOID
)
317 LoadLibraryW( L
"fmifs.dll" );
320 (void *) GetProcAddress(
321 GetModuleHandleW(L
"fmifs.dll"),
329 #endif /* ndef FMIFS_IMPORT_DLL */
332 //----------------------------------------------------------------------
336 // Engine. Just get command line switches and fire off a chkdsk. This
337 // could also be done in a GUI like Explorer does when you select a
338 // drive and run a check on it.
340 // We do this in UNICODE because the chkdsk command expects PWCHAR
343 //----------------------------------------------------------------------
345 wmain( int argc
, WCHAR
*argv
[] )
349 WCHAR fileSystem
[1024];
350 WCHAR volumeName
[1024];
357 Chkdskx v1.0.1 by Mark Russinovich\n\
358 Systems Internals - http://www.sysinternals.com/\n\
359 ReactOS adaptation 1999 by Emanuele Aliberti\n\n"
361 #ifndef FMIFS_IMPORT_DLL
363 // Get function pointers
365 if( !LoadFMIFSEntryPoints())
367 wprintf(L
"Could not located FMIFS entry points.\n\n");
370 #endif /* ndef FMIFS_IMPORT_DLL */
372 // Parse command line
374 if( (badArg
= ParseCommandLine( argc
, argv
)))
377 L
"Unknown argument: %s\n",
386 // Get the drive's format
390 if( !GetCurrentDirectoryW(
391 sizeof(CurrentDirectory
),
397 L
"Could not get current directory",
405 wcscpy( CurrentDirectory
, Drive
);
407 CurrentDirectory
[2] = L
'\\';
408 CurrentDirectory
[3] = L
'\0';
409 Drive
= CurrentDirectory
;
412 // Determine the drive's file system format, which we need to
415 if( !GetVolumeInformationW(
427 L
"Could not query volume",
434 // If they want to fix, we need to have access to the drive
443 volumeHandle
= CreateFileW(
452 if( volumeHandle
== INVALID_HANDLE_VALUE
)
454 wprintf(L
"Chdskx cannot run because the volume is in use by another process.\n\n");
457 CloseHandle( volumeHandle
);
460 // Can't let the user break out of a chkdsk that can modify the drive
462 SetConsoleCtrlHandler( CtrlCIntercept
, TRUE
);
469 L
"The type of file system is %s.\n",
484 if ( Error
) return -1;