- Integrate chkdsk into our build system.
- Whitespace fixes.

svn path=/trunk/; revision=70868
This commit is contained in:
Hermès Bélusca-Maïto 2016-03-02 22:05:19 +00:00
parent 4dc68af961
commit 9723b5e974
3 changed files with 310 additions and 314 deletions

View file

@ -1,7 +1,7 @@
include_directories(${REACTOS_SOURCE_DIR}/include/reactos/libs/fmifs)
add_executable(chkdsk chkdsk.c chkdsk.rc)
include_directories(${REACTOS_SOURCE_DIR}/include/reactos/libs/fmifs)
set_module_type(chkdsk win32cui UNICODE)
target_link_libraries(chkdsk win32err)
add_importlibs(chkdsk fmifs msvcrt kernel32 ntdll)
add_cd_file(TARGET chkdsk DESTINATION reactos/system32 FOR all)

View file

@ -6,6 +6,9 @@
// Systems Internals
// http://www.sysinternals.com/
//
// Chkdsk clone that demonstrates the use of the FMIFS file system
// utility library.
//
// --------------------------------------------------------------------
//
// This software is free software; you can redistribute it and/or
@ -25,9 +28,6 @@
//
// --------------------------------------------------------------------
//
// Chkdsk clone that demonstrates the use of the FMIFS file system
// utility library.
//
// 1999 February (Emanuele Aliberti)
// Adapted for ReactOS and lcc-win32.
//
@ -38,16 +38,18 @@
// Cleanup, use ReactOS's fmifs.h
//
//======================================================================
#define WIN32_NO_STATUS
#define NTOS_MODE_USER
#include <windows.h>
#include <stdio.h>
/* PSDK/NDK Headers */
#define WIN32_NO_STATUS
#include <windows.h>
#define NTOS_MODE_USER
#include <ndk/ntndk.h>
#include <fmifs/fmifs.h>
#define _UNICODE 1
#include <tchar.h>
#include "../config.h"
#include "../win32err.h"
#define FMIFS_IMPORT_DLL
//
// Globals
@ -70,6 +72,27 @@ WCHAR CurrentDirectory[1024];
#endif /* ndef FMIFS_IMPORT_DLL */
//----------------------------------------------------------------------
//
// PrintWin32Error
//
// Takes the win32 error code and prints the text version.
//
//----------------------------------------------------------------------
static VOID PrintWin32Error(LPWSTR Message, DWORD ErrorCode)
{
LPWSTR lpMsgBuf;
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, ErrorCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPWSTR)&lpMsgBuf, 0, NULL);
wprintf(L"%s: %s\n", Message, lpMsgBuf);
LocalFree(lpMsgBuf);
}
//--------------------------------------------------------------------
//
// CtrlCIntercept
@ -100,16 +123,13 @@ CtrlCIntercept( DWORD dwCtrlType )
VOID
Usage(PWCHAR ProgramName)
{
_tprintf(
L"\
Usage: %s [drive:] [-F] [-V] [-R] [-C]\n\n\
[drive:] Specifies the drive to check.\n\
-F Fixes errors on the disk.\n\
-V Displays the full path of every file on the disk.\n\
-R Locates bad sectors and recovers readable information.\n\
-C Checks the drive only if it is dirty.\n\n",
ProgramName
);
wprintf(L"Usage: %s [drive:] [-F] [-V] [-R] [-C]\n\n"
L"[drive:] Specifies the drive to check.\n"
L"-F Fixes errors on the disk.\n"
L"-V Displays the full path of every file on the disk.\n"
L"-R Locates bad sectors and recovers readable information.\n"
L"-C Checks the drive only if it is dirty.\n\n",
ProgramName);
}
@ -130,51 +150,51 @@ ParseCommandLine(
BOOLEAN gotFix = FALSE;
BOOLEAN gotVerbose = FALSE;
BOOLEAN gotClean = FALSE;
/*BOOLEAN gotScan = FALSE;*/
// BOOLEAN gotScan = FALSE;
for ( i = 1;
(i < argc);
i++
) {
for (i = 1; i < argc; i++)
{
switch (argv[i][0])
{
case L'-':
case L'/':
case L'-': case L'/':
switch (argv[i][1])
{
case L'F':
case L'f':
case L'?':
Usage(argv[0]);
break;
case L'F': case L'f':
{
if (gotFix) return i;
FixErrors = TRUE;
gotFix = TRUE;
break;
}
case L'V':
case L'v':
case L'V': case L'v':
{
if (gotVerbose) return i;
Verbose = TRUE;
gotVerbose = TRUE;
break;
}
case L'R':
case L'r':
case L'R': case L'r':
{
if (gotFix) return i;
ScanSectors = TRUE;
gotFix = TRUE;
break;
}
case L'C':
case L'c':
case L'C': case L'c':
{
if (gotClean) return i;
SkipClean = TRUE;
gotClean = TRUE;
break;
}
default:
return i;
@ -182,7 +202,7 @@ ParseCommandLine(
break;
default:
{
if (Drive) return i;
if (argv[i][1] != L':') return i;
@ -190,6 +210,7 @@ ParseCommandLine(
break;
}
}
}
return 0;
}
@ -225,55 +246,55 @@ ChkdskCallback(
break;
case UNKNOWN3:
wprintf(L"UNKNOWN3\r");
wprintf(L"UNKNOWN3\n");
break;
case UNKNOWN4:
wprintf(L"UNKNOWN4\r");
wprintf(L"UNKNOWN4\n");
break;
case UNKNOWN5:
wprintf(L"UNKNOWN5\r");
wprintf(L"UNKNOWN5\n");
break;
case FSNOTSUPPORTED:
wprintf(L"FSNOTSUPPORTED\r");
wprintf(L"FSNOTSUPPORTED\n");
break;
case VOLUMEINUSE:
wprintf(L"VOLUMEINUSE\r");
wprintf(L"VOLUMEINUSE\n");
break;
case UNKNOWN9:
wprintf(L"UNKNOWN9\r");
wprintf(L"UNKNOWN9\n");
break;
case UNKNOWNA:
wprintf(L"UNKNOWNA\r");
wprintf(L"UNKNOWNA\n");
break;
case UNKNOWNC:
wprintf(L"UNKNOWNC\r");
wprintf(L"UNKNOWNC\n");
break;
case UNKNOWND:
wprintf(L"UNKNOWND\r");
wprintf(L"UNKNOWND\n");
break;
case INSUFFICIENTRIGHTS:
wprintf(L"INSUFFICIENTRIGHTS\r");
wprintf(L"INSUFFICIENTRIGHTS\n");
break;
case STRUCTUREPROGRESS:
wprintf(L"STRUCTUREPROGRESS\r");
wprintf(L"STRUCTUREPROGRESS\n");
break;
case DONEWITHSTRUCTURE:
wprintf(L"DONEWITHSTRUCTURE\r");
wprintf(L"DONEWITHSTRUCTURE\n");
break;
case CLUSTERSIZETOOSMALL:
wprintf(L"CLUSTERSIZETOOSMALL\r");
wprintf(L"CLUSTERSIZETOOSMALL\n");
break;
case PROGRESS:
@ -283,7 +304,7 @@ ChkdskCallback(
case OUTPUT:
output = (PTEXTOUTPUT)Argument;
fwprintf(stdout, L"%s", output->Output);
wprintf(L"%S", output->Output);
break;
case DONE:
@ -311,16 +332,18 @@ ChkdskCallback(
BOOLEAN
LoadFMIFSEntryPoints(VOID)
{
LoadLibraryW( L"fmifs.dll" );
HMODULE hFmifs = LoadLibraryW(L"fmifs.dll");
if (hFmifs == NULL)
return FALSE;
if( !(Chkdsk =
(void *) GetProcAddress(
GetModuleHandleW(L"fmifs.dll"),
"Chkdsk" ))
)
Chkdsk = (PCHKDSK)GetProcAddress(hFmifs, "Chkdsk");
if (!Chkdsk)
{
FreeLibrary(hFmifs);
return FALSE;
}
return TRUE;
}
#endif /* ndef FMIFS_IMPORT_DLL */
@ -346,15 +369,13 @@ wmain( int argc, WCHAR *argv[] )
WCHAR fileSystem[1024];
WCHAR volumeName[1024];
DWORD serialNumber;
DWORD flags,
maxComponent;
DWORD flags, maxComponent;
wprintf(
L"\n\
wprintf(L"\n\
Chkdskx v1.0.1 by Mark Russinovich\n\
Systems Internals - http://www.sysinternals.com/\n\
ReactOS adaptation 1999 by Emanuele Aliberti\n\n"
);
ReactOS adaptation 1999 by Emanuele Aliberti\n\n");
#ifndef FMIFS_IMPORT_DLL
//
// Get function pointers
@ -365,16 +386,14 @@ ReactOS adaptation 1999 by Emanuele Aliberti\n\n"
return -1;
}
#endif /* ndef FMIFS_IMPORT_DLL */
//
// Parse command line
//
if( (badArg = ParseCommandLine( argc, argv )))
badArg = ParseCommandLine(argc, argv);
if (badArg)
{
wprintf(
L"Unknown argument: %s\n",
argv[badArg]
);
wprintf(L"Unknown argument: %s\n", argv[badArg]);
Usage(argv[0]);
return -1;
}
@ -384,21 +403,14 @@ ReactOS adaptation 1999 by Emanuele Aliberti\n\n"
//
if (!Drive)
{
if( !GetCurrentDirectoryW(
sizeof(CurrentDirectory),
CurrentDirectory
)
) {
PrintWin32Error(
L"Could not get current directory",
GetLastError()
);
if (!GetCurrentDirectoryW(ARRAYSIZE(CurrentDirectory), CurrentDirectory))
{
PrintWin32Error(L"Could not get current directory", GetLastError());
return -1;
}
} else {
}
else
{
wcscpy(CurrentDirectory, Drive);
}
CurrentDirectory[2] = L'\\';
@ -409,21 +421,16 @@ ReactOS adaptation 1999 by Emanuele Aliberti\n\n"
// Determine the drive's file system format, which we need to
// tell chkdsk
//
if( !GetVolumeInformationW(
Drive,
if (!GetVolumeInformationW(Drive,
volumeName,
sizeof volumeName,
ARRAYSIZE(volumeName),
&serialNumber,
&maxComponent,
&flags,
fileSystem,
sizeof fileSystem
)
) {
PrintWin32Error(
L"Could not query volume",
GetLastError()
);
ARRAYSIZE(fileSystem)))
{
PrintWin32Error(L"Could not query volume", GetLastError());
return -1;
}
@ -432,20 +439,14 @@ ReactOS adaptation 1999 by Emanuele Aliberti\n\n"
//
if (FixErrors)
{
swprintf(
volumeName,
L"\\\\.\\%C:",
Drive[0]
);
volumeHandle = CreateFileW(
volumeName,
swprintf(volumeName, L"\\\\.\\%C:", Drive[0]);
volumeHandle = CreateFileW(volumeName,
GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
0
);
0);
if (volumeHandle == INVALID_HANDLE_VALUE)
{
wprintf(L"Chdskx cannot run because the volume is in use by another process.\n\n");
@ -462,12 +463,8 @@ ReactOS adaptation 1999 by Emanuele Aliberti\n\n"
//
// Just do it
//
wprintf(
L"The type of file system is %s.\n",
fileSystem
);
Chkdsk(
Drive,
wprintf(L"The type of file system is %s.\n", fileSystem);
Chkdsk(Drive,
fileSystem,
FixErrors,
Verbose,
@ -475,8 +472,7 @@ ReactOS adaptation 1999 by Emanuele Aliberti\n\n"
ScanSectors,
NULL,
NULL,
ChkdskCallback
);
ChkdskCallback);
if (Error) return -1;
return 0;

View file

@ -1,6 +1,6 @@
#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Disk Checking Utility\0"
#define REACTOS_STR_INTERNAL_NAME "chkdsk\0"
#define REACTOS_STR_ORIGINAL_FILENAME "chkdsk.exe\0"
#define REACTOS_STR_ORIGINAL_COPYRIGHT "1998 Mark Russinovich\0"
#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Disk Checking Utility"
#define REACTOS_STR_INTERNAL_NAME "chkdsk"
#define REACTOS_STR_ORIGINAL_FILENAME "chkdsk.exe"
#define REACTOS_STR_ORIGINAL_COPYRIGHT "1998 Mark Russinovich"
#include <reactos/version.rc>