From 4274a76991dcd5734aa30cefd227070e938310fa Mon Sep 17 00:00:00 2001 From: Pierre Schweitzer Date: Tue, 5 Sep 2017 19:11:02 +0000 Subject: [PATCH] [FSUTIL] Implement setting the dirty bit (fsutil dirty set) on a volume. This doesn't allow to trigger a chkdsk on reboot with ReactOS, because of the way we handle the dirty bit in our FAT implementation is a bit... weird. This works on W2K3 though! svn path=/trunk/; revision=75768 --- .../base/applications/cmdutils/fsutil/dirty.c | 43 +++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/reactos/base/applications/cmdutils/fsutil/dirty.c b/reactos/base/applications/cmdutils/fsutil/dirty.c index e20d4317b06..bd5be20a2d1 100644 --- a/reactos/base/applications/cmdutils/fsutil/dirty.c +++ b/reactos/base/applications/cmdutils/fsutil/dirty.c @@ -60,15 +60,50 @@ QueryMain(int argc, const TCHAR *argv[]) /* Print the status */ _ftprintf(stdout, _T("The %s volume is %s\n"), argv[1], (VolumeStatus & VOLUME_IS_DIRTY ? _T("dirty") : _T("clean"))); - return 1; + return 0; } static int SetMain(int argc, const TCHAR *argv[]) { - /* FIXME */ - _ftprintf(stderr, _T("Not implemented\n")); - return 1; + HANDLE Volume; + DWORD BytesRead; + TCHAR VolumeID[PATH_MAX]; + + /* We need a volume (letter or GUID) */ + if (argc < 2) + { + _ftprintf(stderr, _T("Usage: fsutil dirty set \n")); + _ftprintf(stderr, _T("\tFor example: fsutil dirty set c:\n")); + return 1; + } + + /* Create full name */ + _stprintf(VolumeID, _T("\\\\.\\%s"), argv[1]); + + /* Open the volume */ + Volume = CreateFile(VolumeID, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (Volume == INVALID_HANDLE_VALUE) + { + _ftprintf(stderr, _T("Error: %d\n"), GetLastError()); + return 1; + } + + /* And set the dirty bit */ + if (DeviceIoControl(Volume, FSCTL_MARK_VOLUME_DIRTY, NULL, 0, NULL, 0, &BytesRead, NULL) == FALSE) + { + _ftprintf(stderr, _T("Error: %d\n"), GetLastError()); + CloseHandle(Volume); + return 1; + } + + CloseHandle(Volume); + + /* Print the status */ + _ftprintf(stdout, _T("The %s volume is now marked as dirty\n"), argv[1]); + + return 0; } static void