From 18dcfea9ac30a02914af2e86f3ce69e48a40ed10 Mon Sep 17 00:00:00 2001 From: Aleksey Bragin Date: Fri, 8 Aug 2008 09:53:13 +0000 Subject: [PATCH] - Plugin the filesystem checker into vfatlib, however leave its invocation #if0-ed out until all problems are solved. svn path=/trunk/; revision=35180 --- reactos/lib/fslib/vfatlib/vfatlib.c | 96 +++++++++++++++++++++++- reactos/lib/fslib/vfatlib/vfatlib.h | 12 +++ reactos/lib/fslib/vfatlib/vfatlib.rbuild | 10 +++ 3 files changed, 115 insertions(+), 3 deletions(-) diff --git a/reactos/lib/fslib/vfatlib/vfatlib.c b/reactos/lib/fslib/vfatlib/vfatlib.c index 8f21dd07750..bbe72705429 100755 --- a/reactos/lib/fslib/vfatlib/vfatlib.c +++ b/reactos/lib/fslib/vfatlib/vfatlib.c @@ -12,6 +12,11 @@ #define NDEBUG #include +PFMIFSCALLBACK ChkdskCallback = NULL; +PVOID FsCheckMemQueue; +ULONG FsCheckFlags; +ULONG FsCheckTotalFiles; + NTSTATUS NTAPI VfatFormat (PUNICODE_STRING DriveRoot, FMIFS_MEDIA_FLAG MediaFlag, @@ -50,7 +55,7 @@ VfatFormat (PUNICODE_STRING DriveRoot, FILE_SYNCHRONOUS_IO_ALERT); if (!NT_SUCCESS(Status)) { - DPRINT("NtOpenFile() failed with status 0x%.08x\n", Status); + DPRINT1("NtOpenFile() failed with status 0x%.08x\n", Status); return Status; } @@ -203,6 +208,25 @@ UpdateProgress (PFORMAT_CONTEXT Context, } } +VOID +VfatPrint(PCHAR Format, ...) +{ + TEXTOUTPUT TextOut; + CHAR TextBuf[512]; + va_list valist; + + va_start(valist, Format); + _vsnprintf(TextBuf, sizeof(TextBuf), Format, valist); + va_end(valist); + + /* Prepare parameters */ + TextOut.Lines = 1; + TextOut.Output = TextBuf; + + /* Do the callback */ + if (ChkdskCallback) ChkdskCallback(OUTPUT, 0, &TextOut); +} + NTSTATUS WINAPI VfatChkdsk( IN PUNICODE_STRING DriveRoot, @@ -212,8 +236,74 @@ VfatChkdsk( IN BOOLEAN ScanDrive, IN PFMIFSCALLBACK Callback) { - UNIMPLEMENTED; - return STATUS_SUCCESS; + BOOLEAN verify, salvage_files; + //ULONG free_clusters; + //DOS_FS fs; + + /* Store callback pointer */ + ChkdskCallback = Callback; + FsCheckMemQueue = NULL; + + /* Set parameters */ + FsCheckFlags = 0; + if (Verbose) FsCheckFlags |= FSCHECK_VERBOSE; + + FsCheckTotalFiles = 0; + + verify = TRUE; + salvage_files = TRUE; +#if 0 + /* Open filesystem */ + fs_open(DriveRoot,FixErrors); + + if (CheckOnlyIfDirty && !fs_isdirty(DriveRoot)) + { + /* No need to check FS */ + return fs_close(FALSE); + } + + read_boot(&fs); + if (verify) VfatPrint("Starting check/repair pass.\n"); + while (read_fat(&fs), scan_root(&fs)) qfree(&FsCheckMemQueue); + if (ScanDrive) fix_bad(&fs); + if (salvage_files) + reclaim_file(&fs); + else + reclaim_free(&fs); + free_clusters = update_free(&fs); + file_unused(); + qfree(&FsCheckMemQueue); + if (verify) + { + VfatPrint("Starting verification pass.\n"); + read_fat(&fs); + scan_root(&fs); + reclaim_free(&fs); + qfree(&FsCheckMemQueue); + } + + if (fs_changed()) + { + if (FixErrors) + { + if (FsCheckFlags & FSCHECK_INTERACTIVE) + FixErrors = get_key("yn","Perform changes ? (y/n)") == 'y'; + else + VfatPrint("Performing changes.\n"); + } + else + { + VfatPrint("Leaving file system unchanged.\n"); + } + } + + VfatPrint("%wZ: %u files, %lu/%lu clusters\n", DriveRoot, + FsCheckTotalFiles, fs.clusters - free_clusters, fs.clusters ); + + return fs_close(FixErrors) ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL; +#else + return STATUS_SUCCESS; +#endif } /* EOF */ diff --git a/reactos/lib/fslib/vfatlib/vfatlib.h b/reactos/lib/fslib/vfatlib/vfatlib.h index e8eca1efbaf..7430a51558b 100755 --- a/reactos/lib/fslib/vfatlib/vfatlib.h +++ b/reactos/lib/fslib/vfatlib/vfatlib.h @@ -10,6 +10,15 @@ #include #include +#include "check/dosfsck.h" +#include "check/common.h" +#include "check/io.h" +#include "check/lfn.h" +#include "check/boot.h" +#include "check/fat.h" +#include "check/file.h" +#include "check/check.h" + #define SECTORSIZE 512 #include @@ -130,4 +139,7 @@ VOID UpdateProgress (PFORMAT_CONTEXT Context, ULONG Increment); +VOID +VfatPrint(PCHAR Format, ...); + /* EOF */ diff --git a/reactos/lib/fslib/vfatlib/vfatlib.rbuild b/reactos/lib/fslib/vfatlib/vfatlib.rbuild index 7569d6eac98..f84c671e5e1 100644 --- a/reactos/lib/fslib/vfatlib/vfatlib.rbuild +++ b/reactos/lib/fslib/vfatlib/vfatlib.rbuild @@ -7,4 +7,14 @@ fat16.c fat32.c vfatlib.c + + + boot.c + check.c + common.c + fat.c + file.c + io.c + lfn.c +