ReactOS  0.4.10-dev-7-g0d308f4
chkdsk.c File Reference
#include <stdio.h>
#include <windef.h>
#include <winbase.h>
#include <wincon.h>
#include <conutils.h>
#include <ndk/ntndk.h>
#include <fmifs/fmifs.h>
Include dependency graph for chkdsk.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define NTOS_MODE_USER
 
#define FMIFS_IMPORT_DLL
 

Functions

static VOID PrintWin32Error (LPWSTR Message, DWORD ErrorCode)
 
BOOL WINAPI CtrlCIntercept (DWORD dwCtrlType)
 
static VOID Usage (PWCHAR ProgramName)
 
static int ParseCommandLine (int argc, WCHAR *argv[])
 
BOOLEAN WINAPI ChkdskCallback (CALLBACKCOMMAND Command, DWORD Modifier, PVOID Argument)
 
int wmain (int argc, WCHAR *argv[])
 

Variables

BOOL Error = FALSE
 
BOOL FixErrors = FALSE
 
BOOL SkipClean = FALSE
 
BOOL ScanSectors = FALSE
 
BOOL Verbose = FALSE
 
PWCHAR Drive = NULL
 
WCHAR CurrentDirectory [1024]
 

Macro Definition Documentation

#define FMIFS_IMPORT_DLL

Definition at line 58 of file chkdsk.c.

#define NTOS_MODE_USER

Definition at line 52 of file chkdsk.c.

#define WIN32_NO_STATUS

Definition at line 45 of file chkdsk.c.

Function Documentation

BOOLEAN WINAPI ChkdskCallback ( CALLBACKCOMMAND  Command,
DWORD  Modifier,
PVOID  Argument 
)

Definition at line 226 of file chkdsk.c.

Referenced by wmain().

230 {
231  BOOLEAN Ret;
232  PDWORD percent;
235 
236  //
237  // We get other types of commands,
238  // but we don't have to pay attention to them
239  //
240  Ret = TRUE;
241  switch (Command)
242  {
243  case UNKNOWN2:
244  ConPuts(StdOut, L"UNKNOWN2\r");
245  break;
246 
247  case UNKNOWN3:
248  ConPuts(StdOut, L"UNKNOWN3\n");
249  break;
250 
251  case UNKNOWN4:
252  ConPuts(StdOut, L"UNKNOWN4\n");
253  break;
254 
255  case UNKNOWN5:
256  ConPuts(StdOut, L"UNKNOWN5\n");
257  break;
258 
259  case FSNOTSUPPORTED:
260  ConPuts(StdOut, L"FSNOTSUPPORTED\n");
261  break;
262 
263  case VOLUMEINUSE:
264  ConPuts(StdOut, L"Volume is in use and cannot be locked\n");
265  Ret = FALSE;
266  break;
267 
268  case UNKNOWN9:
269  ConPuts(StdOut, L"UNKNOWN9\n");
270  break;
271 
272  case UNKNOWNA:
273  ConPuts(StdOut, L"UNKNOWNA\n");
274  break;
275 
276  case UNKNOWNC:
277  ConPuts(StdOut, L"UNKNOWNC\n");
278  break;
279 
280  case UNKNOWND:
281  ConPuts(StdOut, L"UNKNOWND\n");
282  break;
283 
284  case INSUFFICIENTRIGHTS:
285  ConPuts(StdOut, L"INSUFFICIENTRIGHTS\n");
286  break;
287 
288  case STRUCTUREPROGRESS:
289  ConPuts(StdOut, L"STRUCTUREPROGRESS\n");
290  break;
291 
292  case DONEWITHSTRUCTURE:
293  ConPuts(StdOut, L"DONEWITHSTRUCTURE\n");
294  break;
295 
296  case CLUSTERSIZETOOSMALL:
297  ConPuts(StdOut, L"CLUSTERSIZETOOSMALL\n");
298  break;
299 
300  case PROGRESS:
301  percent = (PDWORD)Argument;
302  ConPrintf(StdOut, L"%d percent completed.\r", *percent);
303  break;
304 
305  case OUTPUT:
306  output = (PTEXTOUTPUT)Argument;
307  ConPrintf(StdOut, L"%S", output->Output);
308  break;
309 
310  case DONE:
311  status = (PBOOLEAN)Argument;
312  if (*status == FALSE)
313  {
314  ConPuts(StdOut, L"Chkdsk was unable to complete successfully.\n\n");
315  Error = TRUE;
316  }
317  break;
318  }
319  return Ret;
320 }
#define TRUE
Definition: types.h:120
Definition: fmifs.h:71
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
Definition: fmifs.h:72
Definition: bidi.c:85
Definition: fmifs.h:70
Definition: fmifs.h:68
Definition: fmifs.h:78
Definition: fmifs.h:73
Definition: shell.h:41
struct TEXTOUTPUT * PTEXTOUTPUT
Definition: fmifs.h:77
Definition: fmifs.h:80
#define FALSE
Definition: types.h:117
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:506
PCHAR Output
Definition: fmifs.h:33
unsigned char BOOLEAN
BOOL Error
Definition: chkdsk.c:63
char * PBOOLEAN
Definition: retypes.h:11
DWORD * PDWORD
Definition: pedump.c:68
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:413
Definition: fmifs.h:81
#define StdOut
Definition: stream.h:76
#define DONE
Definition: rnr20lib.h:14
Definition: fmifs.h:82
static SERVICE_STATUS status
Definition: service.c:31
BOOL WINAPI CtrlCIntercept ( DWORD  dwCtrlType)

Definition at line 107 of file chkdsk.c.

Referenced by wmain().

108 {
109  //
110  // Handle the event so that the default handler doesn't
111  //
112  return TRUE;
113 }
#define TRUE
Definition: types.h:120
static int ParseCommandLine ( int  argc,
WCHAR argv[] 
)
static

Definition at line 145 of file chkdsk.c.

Referenced by wmain().

146 {
147  int i;
148  BOOLEAN gotFix = FALSE;
149  BOOLEAN gotVerbose = FALSE;
150  BOOLEAN gotClean = FALSE;
151  // BOOLEAN gotScan = FALSE;
152 
153  for (i = 1; i < argc; i++)
154  {
155  switch (argv[i][0])
156  {
157  case L'-': case L'/':
158 
159  switch (argv[i][1])
160  {
161  // case L'?':
162  // Usage(argv[0]);
163  // return i;
164 
165  case L'F': case L'f':
166  {
167  if (gotFix) return i;
168  FixErrors = TRUE;
169  gotFix = TRUE;
170  break;
171  }
172 
173  case L'V': case L'v':
174  {
175  if (gotVerbose) return i;
176  Verbose = TRUE;
177  gotVerbose = TRUE;
178  break;
179  }
180 
181  case L'R': case L'r':
182  {
183  if (gotFix) return i;
184  ScanSectors = TRUE;
185  gotFix = TRUE;
186  break;
187  }
188 
189  case L'C': case L'c':
190  {
191  if (gotClean) return i;
192  SkipClean = TRUE;
193  gotClean = TRUE;
194  break;
195  }
196 
197  default:
198  return i;
199  }
200  break;
201 
202  default:
203  {
204  if (Drive) return i;
205  if (argv[i][1] != L':') return i;
206 
207  Drive = argv[i];
208  break;
209  }
210  }
211  }
212  return 0;
213 }
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
Definition: bidi.c:85
BOOL Verbose
Definition: chkdsk.c:69
BOOL SkipClean
Definition: chkdsk.c:67
BOOL ScanSectors
Definition: chkdsk.c:68
static char ** argv
Definition: ServiceArgs.c:11
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
PWCHAR Drive
Definition: chkdsk.c:70
unsigned char BOOLEAN
BOOL FixErrors
Definition: chkdsk.c:66
static VOID PrintWin32Error ( LPWSTR  Message,
DWORD  ErrorCode 
)
static

Definition at line 88 of file chkdsk.c.

Referenced by wmain().

89 {
90  ConPrintf(StdErr, L"%s: ", Message);
93  ConPuts(StdErr, L"\n");
94 }
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4418
Definition: bidi.c:85
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:506
smooth NULL
Definition: ftsmooth.c:416
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
INT ConMsgPuts(IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId)
Definition: outstream.c:823
#define StdErr
Definition: stream.h:77
CHAR Message[80]
Definition: alive.c:5
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:413
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
static VOID Usage ( PWCHAR  ProgramName)
static

Definition at line 124 of file chkdsk.c.

Referenced by wmain().

125 {
127  L"Usage: %s [drive:] [-F] [-V] [-R] [-C]\n\n"
128  L"[drive:] Specifies the drive to check.\n"
129  L"-F Fixes errors on the disk.\n"
130  L"-V Displays the full path of every file on the disk.\n"
131  L"-R Locates bad sectors and recovers readable information.\n"
132  L"-C Checks the drive only if it is dirty.\n\n",
133  ProgramName);
134 }
Definition: bidi.c:85
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:506
#define StdOut
Definition: stream.h:76
int wmain ( int  argc,
WCHAR argv[] 
)

Definition at line 362 of file chkdsk.c.

363 {
364  int badArg;
365  HANDLE volumeHandle;
366  WCHAR fileSystem[1024];
367  WCHAR volumeName[1024];
369  DWORD flags, maxComponent;
370 
371  /* Initialize the Console Standard Streams */
373 
374  ConPuts(StdOut,
375  L"\n"
376  L"Chkdskx v1.0.1 by Mark Russinovich\n"
377  L"Systems Internals - http://www.sysinternals.com\n"
378  L"ReactOS adaptation 1999 by Emanuele Aliberti\n\n");
379 
380 #ifndef FMIFS_IMPORT_DLL
381  //
382  // Get function pointers
383  //
384  if (!LoadFMIFSEntryPoints())
385  {
386  ConPuts(StdErr, L"Could not located FMIFS entry points.\n\n");
387  return -1;
388  }
389 #endif
390 
391  //
392  // Parse command line
393  //
394  badArg = ParseCommandLine(argc, argv);
395  if (badArg)
396  {
397  ConPrintf(StdOut, L"Unknown argument: %s\n", argv[badArg]);
398  Usage(argv[0]);
399  return -1;
400  }
401 
402  //
403  // Get the drive's format
404  //
405  if (!Drive)
406  {
408  {
409  PrintWin32Error(L"Could not get current directory", GetLastError());
410  return -1;
411  }
412  }
413  else
414  {
416  }
417  CurrentDirectory[2] = L'\\';
418  CurrentDirectory[3] = L'\0';
420 
421  //
422  // Determine the drive's file system format, which we need to
423  // tell chkdsk
424  //
426  volumeName,
427  ARRAYSIZE(volumeName),
428  &serialNumber,
429  &maxComponent,
430  &flags,
431  fileSystem,
432  ARRAYSIZE(fileSystem)))
433  {
434  PrintWin32Error(L"Could not query volume", GetLastError());
435  return -1;
436  }
437 
438  //
439  // If they want to fix, we need to have access to the drive
440  //
441  if (FixErrors)
442  {
443  swprintf(volumeName, L"\\\\.\\%C:", Drive[0]);
444  volumeHandle = CreateFileW(volumeName,
446  0,
447  NULL,
449  0,
450  0);
451  if (volumeHandle == INVALID_HANDLE_VALUE)
452  {
453  ConPuts(StdErr, L"Chkdsk cannot run because the volume is in use by another process.\n\n");
454  return -1;
455  }
456  CloseHandle(volumeHandle);
457 
458  //
459  // Can't let the user break out of a chkdsk that can modify the drive
460  //
462  }
463 
464  //
465  // Just do it
466  //
467  ConPrintf(StdOut, L"The type of file system is %s.\n", fileSystem);
468  Chkdsk(Drive,
469  fileSystem,
470  FixErrors,
471  Verbose,
472  SkipClean,
473  ScanSectors,
474  NULL,
475  NULL,
477 
478  if (Error) return -1;
479  return 0;
480 }
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
static const BYTE serialNumber[]
Definition: msg.c:2848
Definition: bidi.c:85
static VOID Usage(PWCHAR ProgramName)
Definition: chkdsk.c:124
BOOL Verbose
Definition: chkdsk.c:69
WCHAR CurrentDirectory[1024]
Definition: chkdsk.c:71
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:413
BOOL SkipClean
Definition: chkdsk.c:67
BOOL ScanSectors
Definition: chkdsk.c:68
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
DWORD DWORD
Definition: winlogon.h:75
static char ** argv
Definition: ServiceArgs.c:11
static VOID PrintWin32Error(LPWSTR Message, DWORD ErrorCode)
Definition: chkdsk.c:88
#define ConInitStdStreams()
Definition: stream.h:122
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine, BOOL Add)
Definition: console.c:2111
#define GENERIC_WRITE
Definition: nt_native.h:90
PWCHAR Drive
Definition: chkdsk.c:70
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:506
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:426
#define swprintf(buf, format,...)
Definition: sprintf.c:56
BOOL Error
Definition: chkdsk.c:63
#define StdErr
Definition: stream.h:77
GLbitfield flags
Definition: glext.h:7161
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
BOOLEAN WINAPI ChkdskCallback(CALLBACKCOMMAND Command, DWORD Modifier, PVOID Argument)
Definition: chkdsk.c:226
BOOL WINAPI GetVolumeInformationW(IN LPCWSTR lpRootPathName, IN LPWSTR lpVolumeNameBuffer, IN DWORD nVolumeNameSize, OUT LPDWORD lpVolumeSerialNumber OPTIONAL, OUT LPDWORD lpMaximumComponentLength OPTIONAL, OUT LPDWORD lpFileSystemFlags OPTIONAL, OUT LPWSTR lpFileSystemNameBuffer OPTIONAL, IN DWORD nFileSystemNameSize)
Definition: volume.c:226
DWORD *typedef HANDLE
Definition: winlogon.h:52
VOID NTAPI Chkdsk(IN PWCHAR DriveRoot, IN PWCHAR Format, IN BOOLEAN CorrectErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PVOID Unused2, IN PVOID Unused3, IN PFMIFSCALLBACK Callback)
Definition: chkdsk.c:18
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:413
BOOL FixErrors
Definition: chkdsk.c:66
#define CreateFileW
Definition: compat.h:400
BOOL WINAPI CtrlCIntercept(DWORD dwCtrlType)
Definition: chkdsk.c:107
#define StdOut
Definition: stream.h:76
static int ParseCommandLine(int argc, WCHAR *argv[])
Definition: chkdsk.c:145

Variable Documentation

return Error = FALSE

Definition at line 63 of file chkdsk.c.

Referenced by AcceptDataConnection(), AcceptProc(), AdapterDiscoveryThread(), add_route(), AllocEventLogFilter(), append_multi_sz_value(), AreLegacyFunctionsSupported(), ChkdskCallback(), CloseProcessAndVerify_(), CopyKey(), CreateStandardProfile(), CreateUserHive(), CreateUserProfileExW(), del_route(), do_reg_operation(), DoEntry(), DoLoadItems(), CShellCommandSACL::Execute(), FindAdapterKey(), ftGdiGetFontData(), ftGdiGetTextMetricsW(), FTPAbortDataTransfer(), FTPAllocateHost(), FTPChdirAndGetCWD(), FTPCmd(), FTPEndDataCmd(), FTPFileExistsStat(), FTPFileModificationTime(), FTPFileSize(), FTPGetCWD(), FTPGetFiles3(), FTPGetOneF(), FTPList(), FTPListToMemory2(), FTPLocalRecursiveFileList2(), FTPLoginHost(), FTPMkdir2(), FTPMListOneFile(), FTPPutOneF(), FTPRemoteHelp(), FTPSetTransferType(), FTPStartDataCmd(), FTPUtime(), GetAllUsersProfileDirectoryW(), GetCurrentUserKey(), GetDefaultUserProfileDirectoryW(), GetDesktopPath(), GetDeviceDataCallback(), GetDiskGeometry(), GetProcessVersion(), GetProfilesDirectoryW(), GetProgramsPath(), GetRegKeys(), GetResponse(), GetSocketAddress(), GetSubkeyNames(), GetUserProfileDirectoryW(), InitializeProfiles(), InitializeProgramFilesDir(), IntCreateWindow(), IntGdiLoadFontsFromMemory(), IntGetFontLocalizedName(), IntGetOutlineTextMetrics(), IntSetOwner(), KeConnectInterrupt(), KiNpxHandler(), KiTrap13Handler(), KmtCloseDriver(), KmtCloseService(), KmtCreateAndStartService(), KmtDeleteService(), KmtEnsureServiceState(), KmtFltAddAltitude(), KmtFltConnect(), KmtFltDisconnect(), KmtFltGetMessage(), KmtFltGetMessageResult(), KmtFltLoad(), KmtFltLoadDriver(), KmtFltReplyMessage(), KmtFltSendBufferToDriver(), KmtFltSendMessage(), KmtFltUnload(), KmtFltUnloadDriver(), KmtLoadDriver(), KmtOpenDriver(), KmtpCreateService(), KmtRunKernelTest(), KmtServiceCleanup(), KmtServiceInit(), KmtStartService(), KmtStopService(), KmtUnloadDriver(), KmtUserCallbackThread(), LazyUnixLocalGlob(), LibTCPConnectCallback(), ListTests(), LoadInstallableVDD(), LoadModule(), LoadSettings(), LoadUserProfileW(), Main(), main(), MainWnd_OnUpdateRegistry(), MapAndLoad(), MiMapLockedPagesInUserSpace(), OpenControlConnection(), OpenDataConnection(), OutputResult(), Passive(), pointer_default(), PrepareAdapterForService(), PrintErrorMessage(), PrintFileDacl(), PrintRoutes(), ProcessStartupItems(), QueryDeviceName(), QueryRegistryValue(), QuerySuggestedLinkName(), QueryUniqueId(), RegInitCurrentControlSet(), RegReadString(), ReplaceFileW(), RunTest(), ScmLogAccountHack(), SelectPartitionPage(), SendCommand(), SendPort(), SendTelnetInterrupt(), SetStartOffset(), SetSystemEnvironment(), SetUserEnvironment(), SHCreateSessionKey(), SpiProcessCompletedRequest(), START_TEST(), startup(), StatisticsMain(), test_NhGetInterfaceNameFromDeviceGuid(), test_NhGetInterfaceNameFromGuid(), Test_Truncate(), TestBind(), TestGetComputerNameEx(), TestNodeName(), TestServiceName(), Traverse(), UDFEjectReqWaiter(), UDFPrepareForWriteOperation(), UDFRecoverFromError(), UnloadUserProfile(), UpdateUsersShellFolderSettings(), Utf8Convert_(), VBEGetVideoChildDescriptor(), VBEInitialize(), VbeSetColorLookup(), VBESetCurrentMode(), VerifyMenu(), VerifyWnd(), VideoPortIsNoVesa(), WaitExpect_(), wmain(), WsTcFindIfsProviderForSocket(), XboxVmpGetPowerState(), XboxVmpInitialize(), XboxVmpMapVideoMemory(), and XboxVmpSetPowerState().

BOOL FixErrors = FALSE

Definition at line 66 of file chkdsk.c.

Referenced by ParseCommandLine(), and wmain().

BOOL ScanSectors = FALSE

Definition at line 68 of file chkdsk.c.

Referenced by ParseCommandLine(), and wmain().

BOOL SkipClean = FALSE

Definition at line 67 of file chkdsk.c.

Referenced by ParseCommandLine(), and wmain().

BOOL Verbose = FALSE

Definition at line 69 of file chkdsk.c.

Referenced by DoLAYOUT(), DoParsing(), DoSHIFTSTATE(), getCharacterInfo(), ParseCommandLine(), and wmain().