ReactOS 0.4.15-dev-7931-gfd331f1
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

◆ FMIFS_IMPORT_DLL

#define FMIFS_IMPORT_DLL

Definition at line 61 of file chkdsk.c.

◆ NTOS_MODE_USER

#define NTOS_MODE_USER

Definition at line 55 of file chkdsk.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 45 of file chkdsk.c.

Function Documentation

◆ ChkdskCallback()

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

Definition at line 222 of file chkdsk.c.

226{
227 BOOLEAN Ret;
228 PDWORD percent;
230 PTEXTOUTPUT output;
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
281 ConPuts(StdOut, L"INSUFFICIENTRIGHTS\n");
282 break;
283
285 ConPuts(StdOut, L"STRUCTUREPROGRESS\n");
286 break;
287
289 ConPuts(StdOut, L"DONEWITHSTRUCTURE\n");
290 break;
291
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}
unsigned char BOOLEAN
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
#define StdOut
Definition: fc.c:14
void ConResPrintf(FILE *fp, UINT nID,...)
Definition: fc.c:33
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
BOOL Error
Definition: chkdsk.c:66
#define IDS_PERCENT_COMPL
Definition: resource.h:4
#define IDS_CHKDSK_FAIL
Definition: resource.h:11
#define IDS_VOLUME_IN_USE
Definition: resource.h:10
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
struct TEXTOUTPUT * PTEXTOUTPUT
@ UNKNOWN9
Definition: fmifs.h:77
@ OUTPUT
Definition: fmifs.h:82
@ FSNOTSUPPORTED
Definition: fmifs.h:75
@ UNKNOWND
Definition: fmifs.h:81
@ VOLUMEINUSE
Definition: fmifs.h:76
@ UNKNOWN4
Definition: fmifs.h:72
@ UNKNOWNA
Definition: fmifs.h:78
@ STRUCTUREPROGRESS
Definition: fmifs.h:83
@ CLUSTERSIZETOOSMALL
Definition: fmifs.h:84
@ DONEWITHSTRUCTURE
Definition: fmifs.h:69
@ INSUFFICIENTRIGHTS
Definition: fmifs.h:74
@ PROGRESS
Definition: fmifs.h:68
@ UNKNOWN5
Definition: fmifs.h:73
@ UNKNOWN2
Definition: fmifs.h:70
@ UNKNOWN3
Definition: fmifs.h:71
@ UNKNOWNC
Definition: fmifs.h:80
#define L(x)
Definition: ntvdm.h:50
DWORD * PDWORD
Definition: pedump.c:68
#define DONE
Definition: rnr20lib.h:14
Definition: shell.h:41
PCHAR Output
Definition: fmifs.h:33
Definition: ps.c:97
unsigned char * PBOOLEAN
Definition: typedefs.h:53

◆ CtrlCIntercept()

BOOL WINAPI CtrlCIntercept ( DWORD  dwCtrlType)

Definition at line 110 of file chkdsk.c.

111{
112 //
113 // Handle the event so that the default handler doesn't
114 //
115 return TRUE;
116}

Referenced by wmain().

◆ ParseCommandLine()

static int ParseCommandLine ( int  argc,
WCHAR argv[] 
)
static

Definition at line 141 of file chkdsk.c.

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;
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
BOOL FixErrors
Definition: chkdsk.c:69
PWCHAR Drive
Definition: chkdsk.c:73
BOOL Verbose
Definition: chkdsk.c:72
BOOL SkipClean
Definition: chkdsk.c:70
BOOL ScanSectors
Definition: chkdsk.c:71
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define argv
Definition: mplay32.c:18

Referenced by wmain().

◆ PrintWin32Error()

static VOID PrintWin32Error ( int  Message,
DWORD  ErrorCode 
)
static

Definition at line 91 of file chkdsk.c.

92{
96 ConPuts(StdErr, L"\n");
97}
#define StdErr
Definition: fc.c:15
#define NULL
Definition: types.h:112
static const WCHAR Message[]
Definition: register.c:74
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
INT ConMsgPuts(IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId)
Definition: outstream.c:837
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:423

Referenced by wmain().

◆ Usage()

static VOID Usage ( PWCHAR  ProgramName)
static

Definition at line 127 of file chkdsk.c.

128{
129 ConResPrintf(StdOut, IDS_USAGE, ProgramName);
130}
#define IDS_USAGE
Definition: resource.h:3

◆ wmain()

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),
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);
461 fileSystem,
462 FixErrors,
463 Verbose,
464 SkipClean,
466 NULL,
467 NULL,
469
470 if (Error) return -1;
471 return 0;
472}
#define IDS_ABOUT
Definition: resource.h:29
#define ConInitStdStreams()
Definition: fc.c:13
static VOID PrintWin32Error(int Message, DWORD ErrorCode)
Definition: chkdsk.c:91
static int ParseCommandLine(int argc, WCHAR *argv[])
Definition: chkdsk.c:141
BOOL WINAPI CtrlCIntercept(DWORD dwCtrlType)
Definition: chkdsk.c:110
WCHAR CurrentDirectory[1024]
Definition: chkdsk.c:74
#define IDS_NO_ENTRY_POINT
Definition: resource.h:12
#define IDS_BAD_ARGUMENT
Definition: resource.h:13
#define IDS_NO_QUERY_VOL
Definition: resource.h:15
#define IDS_FILE_SYSTEM
Definition: resource.h:6
#define IDS_VOLUME_IN_USE_PROC
Definition: resource.h:16
#define IDS_NO_CURRENT_DIR
Definition: resource.h:14
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define CloseHandle
Definition: compat.h:739
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:756
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileW
Definition: compat.h:741
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 WINAPI DECLSPEC_HOTPATCH SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine, BOOL Add)
Definition: console.c:2109
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
#define swprintf
Definition: precomp.h:40
unsigned long DWORD
Definition: ntddk_ex.h:95
GLbitfield flags
Definition: glext.h:7161
_Must_inspect_result_ _In_ USAGE _In_ USHORT _In_ USAGE Usage
Definition: hidpi.h:384
static const BYTE serialNumber[]
Definition: msg.c:2848
#define GENERIC_WRITE
Definition: nt_native.h:90
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
PFMIFSCALLBACK ChkdskCallback
Definition: vfatlib.c:43
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
__wchar_t WCHAR
Definition: xmlstorage.h:180

Variable Documentation

◆ CurrentDirectory

◆ Drive

◆ Error

return Error = FALSE

Definition at line 66 of file chkdsk.c.

Referenced by _RpcPrinterMessageBox(), _tWinMain(), AcceptDataConnection(), AcceptProc(), AdapterDiscoveryThread(), add_route(), AllocEventLogFilter(), append_multi_sz_value(), AreLegacyFunctionsSupported(), BochsFindAdapter(), BochsGetControllerInfo(), BochsInitialize(), BochsInitializeSuitableModeInfo(), BochsMapVideoMemory(), BochsSetCurrentMode(), BochsStartIO(), BochsUnmapVideoMemory(), ChkdskCallback(), CloseProcessAndVerify_(), CmpDoFlushNextHive(), CopyKey(), CreateExtendedPartition(), CreatePartition(), CreateStandardProfile(), CreateUserHive(), CreateUserProfileExW(), del_route(), do_reg_operation(), DoEntry(), DoLoadItems(), DoStartStartupItems(), DoTestComputerName(), DoWriteProductOption(), DoWriteSoundEvents(), DriverEntry(), FxPkgIo::EnqueueRequest(), EnumFilesWorker(), ErrMsg(), CShellCommandSACL::Execute(), FindAdapterKey(), ftGdiGetFontData(), ftGdiGetTextMetricsW(), FTPAbortDataTransfer(), FTPAllocateHost(), FTPChdirAndGetCWD(), FTPCmd(), FTPEndDataCmd(), FTPFileExistsStat(), FTPFileModificationTime(), FTPFileSize(), FTPGetCWD(), FTPGetFiles3(), FTPGetLocalCWD(), FTPGetOneF(), FTPList(), FTPListToMemory2(), FTPLocalRecursiveFileList2(), FTPLoginHost(), FTPMkdir2(), FTPMListOneFile(), FTPPutOneF(), FTPRemoteHelp(), FTPSetTransferType(), FTPStartDataCmd(), FTPUtime(), GetAllUsersProfileDirectoryW(), GetCurrentUserKey(), GetDefaultUserProfileDirectoryW(), GetDesktopPath(), GetDeviceDataCallback(), GetDiskGeometry(), GetOwnerModuleFromPidEntry(), GetProcessVersion(), GetProfilesDirectoryW(), GetProgramsPath(), GetRegKeys(), GetResponse(), GetSocketAddress(), GetSubkeyNames(), GetUserProfileDirectoryW(), InitializeProfiles(), InitializeProgramFilesDir(), InitializeSetup(), IntCreateWindow(), IntGdiLoadFontsFromMemory(), IntGetFontLocalizedName(), IntGetOutlineTextMetrics(), IntLoadRegistryParameters(), IntSetOwner(), KeConnectInterrupt(), KiNpxHandler(), KiTrap13Handler(), KmtCloseDriver(), KmtCloseService(), KmtCreateAndStartService(), KmtDeleteService(), KmtEnsureServiceState(), KmtFltAddAltitude(), KmtFltConnect(), KmtFltDisconnect(), KmtFltGetMessage(), KmtFltGetMessageResult(), KmtFltLoad(), KmtFltLoadDriver(), KmtFltReplyMessage(), KmtFltSendBufferToDriver(), KmtFltSendMessage(), KmtFltUnload(), KmtFltUnloadDriver(), KmtLoadAndOpenDriver(), KmtOpenDriver(), KmtpCreateService(), KmtRunKernelTest(), KmtServiceCleanup(), KmtServiceInit(), KmtStartService(), KmtStopService(), KmtUnloadDriver(), KmtUnloadDriverKeepService(), KmtUserCallbackThread(), LazyUnixLocalGlob(), LibTCPConnectCallback(), ListTests(), LoadInstallableVDD(), LoadModule(), LoadSettings(), LoadTcpIpTestDriver(), LoadUserProfileW(), main(), Main(), MainWnd_OnUpdateRegistry(), MapAndLoad(), MiMapLockedPagesInUserSpace(), FxPkgGeneral::OnCreate(), OpenComputerNameKey(), OpenControlConnection(), OpenDataConnection(), OpenHostNameKey(), OpenRegKey(), OutputError(), OutputResult(), Passive(), Pc98VidFindAdapter(), Pc98VidMapVideoMemory(), pointer_default(), PrepareAdapterForService(), PrinterMessageBoxW(), PrintErrorMessage(), PrintFileDacl(), PrintParserError(), PrintRoutes(), QueryDeviceName(), QueryRegistryValue(), QuerySuggestedLinkName(), QueryUniqueId(), RegistryPage(), RegReadString(), ReplaceFileW(), RunOnceExInstance::RunOnceExInstance(), RunOnceExSection::RunOnceExSection(), RunTest(), SelectPartitionPage(), SendCommand(), SendPort(), SendTelnetInterrupt(), SetStartOffset(), SetSystemEnvironment(), SetupStartPage(), SetUserEnvironment(), SHCreateSessionKey(), CZipExtract::ShowExtractError(), SpiProcessCompletedRequest(), START_TEST(), startup(), StatisticsMain(), test_NhGetInterfaceNameFromDeviceGuid(), test_NhGetInterfaceNameFromGuid(), Test_Truncate(), TestBind(), TestEntry(), TestGetComputerNameEx(), TestNodeName(), TestServiceName(), Traverse(), UDFEjectReqWaiter(), UDFPrepareForWriteOperation(), UDFRecoverFromError(), UpdateUsersShellFolderSettings(), Utf8Convert_(), VBEInitialize(), VbeSetColorLookup(), VBESetCurrentMode(), VerifyMenu(), VerifyWnd(), VideoPortDebugPrint(), WaitExpect_(), wmain(), and WsTcFindIfsProviderForSocket().

◆ FixErrors

◆ ScanSectors

BOOL ScanSectors = FALSE

Definition at line 71 of file chkdsk.c.

Referenced by ParseCommandLine(), and wmain().

◆ SkipClean

BOOL SkipClean = FALSE

Definition at line 70 of file chkdsk.c.

Referenced by ParseCommandLine(), and wmain().

◆ Verbose