ReactOS  r76032
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  PDWORD percent;
234 
235  //
236  // We get other types of commands,
237  // but we don't have to pay attention to them
238  //
239  switch (Command)
240  {
241  case UNKNOWN2:
242  ConPuts(StdOut, L"UNKNOWN2\r");
243  break;
244 
245  case UNKNOWN3:
246  ConPuts(StdOut, L"UNKNOWN3\n");
247  break;
248 
249  case UNKNOWN4:
250  ConPuts(StdOut, L"UNKNOWN4\n");
251  break;
252 
253  case UNKNOWN5:
254  ConPuts(StdOut, L"UNKNOWN5\n");
255  break;
256 
257  case FSNOTSUPPORTED:
258  ConPuts(StdOut, L"FSNOTSUPPORTED\n");
259  break;
260 
261  case VOLUMEINUSE:
262  ConPuts(StdOut, L"VOLUMEINUSE\n");
263  break;
264 
265  case UNKNOWN9:
266  ConPuts(StdOut, L"UNKNOWN9\n");
267  break;
268 
269  case UNKNOWNA:
270  ConPuts(StdOut, L"UNKNOWNA\n");
271  break;
272 
273  case UNKNOWNC:
274  ConPuts(StdOut, L"UNKNOWNC\n");
275  break;
276 
277  case UNKNOWND:
278  ConPuts(StdOut, L"UNKNOWND\n");
279  break;
280 
281  case INSUFFICIENTRIGHTS:
282  ConPuts(StdOut, L"INSUFFICIENTRIGHTS\n");
283  break;
284 
285  case STRUCTUREPROGRESS:
286  ConPuts(StdOut, L"STRUCTUREPROGRESS\n");
287  break;
288 
289  case DONEWITHSTRUCTURE:
290  ConPuts(StdOut, L"DONEWITHSTRUCTURE\n");
291  break;
292 
293  case CLUSTERSIZETOOSMALL:
294  ConPuts(StdOut, L"CLUSTERSIZETOOSMALL\n");
295  break;
296 
297  case PROGRESS:
298  percent = (PDWORD)Argument;
299  ConPrintf(StdOut, L"%d percent completed.\r", *percent);
300  break;
301 
302  case OUTPUT:
303  output = (PTEXTOUTPUT)Argument;
304  ConPrintf(StdOut, L"%S", output->Output);
305  break;
306 
307  case DONE:
308  status = (PBOOLEAN)Argument;
309  if (*status == FALSE)
310  {
311  ConPuts(StdOut, L"Chkdsk was unable to complete successfully.\n\n");
312  Error = TRUE;
313  }
314  break;
315  }
316  return TRUE;
317 }
#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:75
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
PCHAR Output
Definition: fmifs.h:33
BOOL Error
Definition: chkdsk.c:63
char * PBOOLEAN
Definition: retypes.h:11
DWORD * PDWORD
Definition: pedump.c:68
Definition: fmifs.h:81
#define StdOut
Definition: stream.h:69
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: stream.c:691
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: stream.c:644
#define DONE
Definition: rnr20lib.h:14
Definition: fmifs.h:82
static SERVICE_STATUS status
Definition: service.c:26
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:15
#define TRUE
Definition: types.h:120
Definition: bidi.c:75
BOOL Verbose
Definition: chkdsk.c:69
BOOL SkipClean
Definition: chkdsk.c:67
BOOL ScanSectors
Definition: chkdsk.c:68
static char ** argv
Definition: ServiceArgs.c:14
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 }
INT ConMsgPuts(IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId)
Definition: stream.c:801
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4417
Definition: bidi.c:75
smooth NULL
Definition: ftsmooth.c:557
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:395
#define StdErr
Definition: stream.h:70
CHAR Message[80]
Definition: alive.c:5
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: stream.c:691
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: stream.c:644
#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:75
#define StdOut
Definition: stream.h:69
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: stream.c:691
int wmain ( int  argc,
WCHAR argv[] 
)

Definition at line 359 of file chkdsk.c.

360 {
361  int badArg;
362  HANDLE volumeHandle;
363  WCHAR fileSystem[1024];
364  WCHAR volumeName[1024];
366  DWORD flags, maxComponent;
367 
368  /* Initialize the Console Standard Streams */
370 
371  ConPuts(StdOut,
372  L"\n"
373  L"Chkdskx v1.0.1 by Mark Russinovich\n"
374  L"Systems Internals - http://www.sysinternals.com\n"
375  L"ReactOS adaptation 1999 by Emanuele Aliberti\n\n");
376 
377 #ifndef FMIFS_IMPORT_DLL
378  //
379  // Get function pointers
380  //
381  if (!LoadFMIFSEntryPoints())
382  {
383  ConPuts(StdErr, L"Could not located FMIFS entry points.\n\n");
384  return -1;
385  }
386 #endif
387 
388  //
389  // Parse command line
390  //
391  badArg = ParseCommandLine(argc, argv);
392  if (badArg)
393  {
394  ConPrintf(StdOut, L"Unknown argument: %s\n", argv[badArg]);
395  Usage(argv[0]);
396  return -1;
397  }
398 
399  //
400  // Get the drive's format
401  //
402  if (!Drive)
403  {
405  {
406  PrintWin32Error(L"Could not get current directory", GetLastError());
407  return -1;
408  }
409  }
410  else
411  {
413  }
414  CurrentDirectory[2] = L'\\';
415  CurrentDirectory[3] = L'\0';
417 
418  //
419  // Determine the drive's file system format, which we need to
420  // tell chkdsk
421  //
423  volumeName,
424  ARRAYSIZE(volumeName),
425  &serialNumber,
426  &maxComponent,
427  &flags,
428  fileSystem,
429  ARRAYSIZE(fileSystem)))
430  {
431  PrintWin32Error(L"Could not query volume", GetLastError());
432  return -1;
433  }
434 
435  //
436  // If they want to fix, we need to have access to the drive
437  //
438  if (FixErrors)
439  {
440  swprintf(volumeName, L"\\\\.\\%C:", Drive[0]);
441  volumeHandle = CreateFileW(volumeName,
443  0,
444  NULL,
446  0,
447  0);
448  if (volumeHandle == INVALID_HANDLE_VALUE)
449  {
450  ConPuts(StdErr, L"Chkdsk cannot run because the volume is in use by another process.\n\n");
451  return -1;
452  }
453  CloseHandle(volumeHandle);
454 
455  //
456  // Can't let the user break out of a chkdsk that can modify the drive
457  //
459  }
460 
461  //
462  // Just do it
463  //
464  ConPrintf(StdOut, L"The type of file system is %s.\n", fileSystem);
465  Chkdsk(Drive,
466  fileSystem,
467  FixErrors,
468  Verbose,
469  SkipClean,
470  ScanSectors,
471  NULL,
472  NULL,
474 
475  if (Error) return -1;
476  return 0;
477 }
static int argc
Definition: ServiceArgs.c:15
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
static const BYTE serialNumber[]
Definition: msg.c:2848
Definition: bidi.c:75
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:28
#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:14
static VOID PrintWin32Error(LPWSTR Message, DWORD ErrorCode)
Definition: chkdsk.c:88
#define ConInitStdStreams()
Definition: stream.h:119
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
smooth NULL
Definition: ftsmooth.c:557
#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:70
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
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:69
static int ParseCommandLine(int argc, WCHAR *argv[])
Definition: chkdsk.c:145
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: stream.c:691
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: stream.c:644

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(), KmtCreateService(), KmtDeleteService(), KmtLoadDriver(), KmtOpenDriver(), 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(), RegInitCurrentControlSet(), RegReadString(), ReplaceFileW(), RunTest(), ScmLogAccountHack(), SelectPartitionPage(), SendCommand(), SendPort(), SendTelnetInterrupt(), SetStartOffset(), SetSystemEnvironment(), SetUserEnvironment(), SHCreateSessionKey(), SpiProcessCompletedRequest(), START_TEST(), startup(), StatisticsMain(), 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().