ReactOS  0.4.11-dev-745-g76daaf9
chkdsk.c File Reference
#include <stdio.h>
#include <windef.h>
#include <winbase.h>
#include <wincon.h>
#include <conutils.h>
#include "resource.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 (int 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 61 of file chkdsk.c.

#define NTOS_MODE_USER

Definition at line 55 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 222 of file chkdsk.c.

Referenced by wmain().

226 {
227  BOOLEAN Ret;
228  PDWORD percent;
231 
232  //
233  // We get other types of commands,
234  // but we don't have to pay attention to them
235  //
236  Ret = TRUE;
237  switch (Command)
238  {
239  case UNKNOWN2:
240  ConPuts(StdOut, L"UNKNOWN2\r");
241  break;
242 
243  case UNKNOWN3:
244  ConPuts(StdOut, L"UNKNOWN3\n");
245  break;
246 
247  case UNKNOWN4:
248  ConPuts(StdOut, L"UNKNOWN4\n");
249  break;
250 
251  case UNKNOWN5:
252  ConPuts(StdOut, L"UNKNOWN5\n");
253  break;
254 
255  case FSNOTSUPPORTED:
256  ConPuts(StdOut, L"FSNOTSUPPORTED\n");
257  break;
258 
259  case VOLUMEINUSE:
261  Ret = FALSE;
262  break;
263 
264  case UNKNOWN9:
265  ConPuts(StdOut, L"UNKNOWN9\n");
266  break;
267 
268  case UNKNOWNA:
269  ConPuts(StdOut, L"UNKNOWNA\n");
270  break;
271 
272  case UNKNOWNC:
273  ConPuts(StdOut, L"UNKNOWNC\n");
274  break;
275 
276  case UNKNOWND:
277  ConPuts(StdOut, L"UNKNOWND\n");
278  break;
279 
280  case INSUFFICIENTRIGHTS:
281  ConPuts(StdOut, L"INSUFFICIENTRIGHTS\n");
282  break;
283 
284  case STRUCTUREPROGRESS:
285  ConPuts(StdOut, L"STRUCTUREPROGRESS\n");
286  break;
287 
288  case DONEWITHSTRUCTURE:
289  ConPuts(StdOut, L"DONEWITHSTRUCTURE\n");
290  break;
291 
292  case CLUSTERSIZETOOSMALL:
293  ConPuts(StdOut, L"CLUSTERSIZETOOSMALL\n");
294  break;
295 
296  case PROGRESS:
297  percent = (PDWORD)Argument;
299  break;
300 
301  case OUTPUT:
302  output = (PTEXTOUTPUT)Argument;
303  ConPrintf(StdOut, L"%S", output->Output);
304  break;
305 
306  case DONE:
307  status = (PBOOLEAN)Argument;
308  if (*status == FALSE)
309  {
311  Error = TRUE;
312  }
313  break;
314  }
315  return Ret;
316 }
#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: 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
#define IDS_PERCENT_COMPL
Definition: resource.h:4
Definition: fmifs.h:80
#define FALSE
Definition: types.h:117
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:520
#define IDS_CHKDSK_FAIL
Definition: resource.h:11
PCHAR Output
Definition: fmifs.h:33
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
unsigned char BOOLEAN
BOOL Error
Definition: chkdsk.c:66
#define IDS_VOLUME_IN_USE
Definition: resource.h:10
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
char * PBOOLEAN
Definition: retypes.h:11
static const WCHAR L[]
Definition: oid.c:1087
DWORD * PDWORD
Definition: pedump.c:68
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:427
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 110 of file chkdsk.c.

Referenced by wmain().

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

Definition at line 141 of file chkdsk.c.

Referenced by wmain().

142 {
143  int i;
144  BOOLEAN gotFix = FALSE;
145  BOOLEAN gotVerbose = FALSE;
146  BOOLEAN gotClean = FALSE;
147  // BOOLEAN gotScan = FALSE;
148 
149  for (i = 1; i < argc; i++)
150  {
151  switch (argv[i][0])
152  {
153  case L'-': case L'/':
154 
155  switch (argv[i][1])
156  {
157  // case L'?':
158  // Usage(argv[0]);
159  // return i;
160 
161  case L'F': case L'f':
162  {
163  if (gotFix) return i;
164  FixErrors = TRUE;
165  gotFix = TRUE;
166  break;
167  }
168 
169  case L'V': case L'v':
170  {
171  if (gotVerbose) return i;
172  Verbose = TRUE;
173  gotVerbose = TRUE;
174  break;
175  }
176 
177  case L'R': case L'r':
178  {
179  if (gotFix) return i;
180  ScanSectors = TRUE;
181  gotFix = TRUE;
182  break;
183  }
184 
185  case L'C': case L'c':
186  {
187  if (gotClean) return i;
188  SkipClean = TRUE;
189  gotClean = TRUE;
190  break;
191  }
192 
193  default:
194  return i;
195  }
196  break;
197 
198  default:
199  {
200  if (Drive) return i;
201  if (argv[i][1] != L':') return i;
202 
203  Drive = argv[i];
204  break;
205  }
206  }
207  }
208  return 0;
209 }
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
BOOL Verbose
Definition: chkdsk.c:72
BOOL SkipClean
Definition: chkdsk.c:70
BOOL ScanSectors
Definition: chkdsk.c:71
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:73
unsigned char BOOLEAN
static const WCHAR L[]
Definition: oid.c:1087
BOOL FixErrors
Definition: chkdsk.c:69
static VOID PrintWin32Error ( int  Message,
DWORD  ErrorCode 
)
static

Definition at line 91 of file chkdsk.c.

Referenced by wmain().

92 {
96  ConPuts(StdErr, L"\n");
97 }
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4418
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:837
#define StdErr
Definition: stream.h:77
CHAR Message[80]
Definition: alive.c:5
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
static const WCHAR L[]
Definition: oid.c:1087
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:427
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
static VOID Usage ( PWCHAR  ProgramName)
static

Definition at line 127 of file chkdsk.c.

Referenced by wmain().

128 {
129  ConResPrintf(StdOut, IDS_USAGE, ProgramName);
130 }
#define IDS_USAGE
Definition: resource.h:3
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
#define StdOut
Definition: stream.h:76
int wmain ( int  argc,
WCHAR argv[] 
)

Definition at line 358 of file chkdsk.c.

359 {
360  int badArg;
361  HANDLE volumeHandle;
362  WCHAR fileSystem[1024];
363  WCHAR volumeName[1024];
365  DWORD flags, maxComponent;
366 
367  /* Initialize the Console Standard Streams */
369 
371 
372 #ifndef FMIFS_IMPORT_DLL
373  //
374  // Get function pointers
375  //
376  if (!LoadFMIFSEntryPoints())
377  {
379  return -1;
380  }
381 #endif
382 
383  //
384  // Parse command line
385  //
386  badArg = ParseCommandLine(argc, argv);
387  if (badArg)
388  {
390  Usage(argv[0]);
391  return -1;
392  }
393 
394  //
395  // Get the drive's format
396  //
397  if (!Drive)
398  {
400  {
402  return -1;
403  }
404  }
405  else
406  {
408  }
409  CurrentDirectory[2] = L'\\';
410  CurrentDirectory[3] = L'\0';
412 
413  //
414  // Determine the drive's file system format, which we need to
415  // tell chkdsk
416  //
418  volumeName,
419  ARRAYSIZE(volumeName),
420  &serialNumber,
421  &maxComponent,
422  &flags,
423  fileSystem,
424  ARRAYSIZE(fileSystem)))
425  {
427  return -1;
428  }
429 
430  //
431  // If they want to fix, we need to have access to the drive
432  //
433  if (FixErrors)
434  {
435  swprintf(volumeName, L"\\\\.\\%C:", Drive[0]);
436  volumeHandle = CreateFileW(volumeName,
438  0,
439  NULL,
441  0,
442  0);
443  if (volumeHandle == INVALID_HANDLE_VALUE)
444  {
446  return -1;
447  }
448  CloseHandle(volumeHandle);
449 
450  //
451  // Can't let the user break out of a chkdsk that can modify the drive
452  //
454  }
455 
456  //
457  // Just do it
458  //
459  ConResPrintf(StdOut, IDS_FILE_SYSTEM, fileSystem);
460  Chkdsk(Drive,
461  fileSystem,
462  FixErrors,
463  Verbose,
464  SkipClean,
465  ScanSectors,
466  NULL,
467  NULL,
469 
470  if (Error) return -1;
471  return 0;
472 }
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
static VOID Usage(PWCHAR ProgramName)
Definition: chkdsk.c:127
BOOL Verbose
Definition: chkdsk.c:72
WCHAR CurrentDirectory[1024]
Definition: chkdsk.c:74
#define IDS_NO_CURRENT_DIR
Definition: resource.h:14
__wchar_t WCHAR
Definition: xmlstorage.h:180
static VOID PrintWin32Error(int Message, DWORD ErrorCode)
Definition: chkdsk.c:91
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:413
BOOL SkipClean
Definition: chkdsk.c:70
BOOL ScanSectors
Definition: chkdsk.c:71
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD DWORD
Definition: winlogon.h:84
static char ** argv
Definition: ServiceArgs.c:11
#define IDS_BAD_ARGUMENT
Definition: resource.h:13
#define IDS_ABOUT
Definition: resource.h:29
#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:73
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:426
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
#define swprintf(buf, format,...)
Definition: sprintf.c:56
BOOL Error
Definition: chkdsk.c:66
#define StdErr
Definition: stream.h:77
GLbitfield flags
Definition: glext.h:7161
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1087
BOOLEAN WINAPI ChkdskCallback(CALLBACKCOMMAND Command, DWORD Modifier, PVOID Argument)
Definition: chkdsk.c:222
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:61
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
#define IDS_NO_ENTRY_POINT
Definition: resource.h:12
#define IDS_NO_QUERY_VOL
Definition: resource.h:15
BOOL FixErrors
Definition: chkdsk.c:69
#define CreateFileW
Definition: compat.h:400
BOOL WINAPI CtrlCIntercept(DWORD dwCtrlType)
Definition: chkdsk.c:110
#define StdOut
Definition: stream.h:76
static int ParseCommandLine(int argc, WCHAR *argv[])
Definition: chkdsk.c:141
#define IDS_FILE_SYSTEM
Definition: resource.h:6
#define IDS_VOLUME_IN_USE_PROC
Definition: resource.h:16

Variable Documentation

return Error = FALSE

Definition at line 66 of file chkdsk.c.

Referenced by _tWinMain(), AcceptDataConnection(), AcceptProc(), AdapterDiscoveryThread(), add_route(), AllocEventLogFilter(), append_multi_sz_value(), AreLegacyFunctionsSupported(), ChkdskCallback(), CloseProcessAndVerify_(), CopyKey(), CreateStandardProfile(), CreateUserHive(), CreateUserProfileExW(), del_route(), do_reg_operation(), DoEntry(), DoLoadItems(), DoStartStartupItems(), 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(), InitializeSetup(), 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(), QueryDeviceName(), QueryRegistryValue(), QuerySuggestedLinkName(), QueryUniqueId(), RegInitCurrentControlSet(), RegistryPage(), RegReadString(), ReplaceFileW(), RunTest(), SelectPartitionPage(), SendCommand(), SendPort(), SendTelnetInterrupt(), SetStartOffset(), SetSystemEnvironment(), SetupStartPage(), 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 69 of file chkdsk.c.

Referenced by ParseCommandLine(), and wmain().

BOOL ScanSectors = FALSE

Definition at line 71 of file chkdsk.c.

Referenced by ParseCommandLine(), and wmain().

BOOL SkipClean = FALSE

Definition at line 70 of file chkdsk.c.

Referenced by ParseCommandLine(), and wmain().

BOOL Verbose = FALSE

Definition at line 72 of file chkdsk.c.

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