QueryMain(int argc, const TCHAR *argv[])
{
HANDLE Volume;
- TCHAR VolumeID[PATH_MAX];
ULONG VolumeStatus, BytesRead;
/* We need a volume (letter or GUID) */
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);
+ /* Get a handle for the volume */
+ Volume = OpenVolume(argv[1], FALSE);
if (Volume == INVALID_HANDLE_VALUE)
{
- _ftprintf(stderr, _T("Error: %d\n"), GetLastError());
return 1;
}
if (DeviceIoControl(Volume, FSCTL_IS_VOLUME_DIRTY, NULL, 0, &VolumeStatus,
sizeof(ULONG), &BytesRead, NULL) == FALSE)
{
- _ftprintf(stderr, _T("Error: %d\n"), GetLastError());
+ PrintErrorMessage(GetLastError());
CloseHandle(Volume);
return 1;
}
CloseHandle(Volume);
/* Print the status */
- _ftprintf(stdout, _T("The %s volume is %s\n"), argv[1], (VolumeStatus & VOLUME_IS_DIRTY ? _T("dirty") : _T("clean")));
+ _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;
+
+ /* We need a volume (letter or GUID) */
+ if (argc < 2)
+ {
+ _ftprintf(stderr, _T("Usage: fsutil dirty set <volume>\n"));
+ _ftprintf(stderr, _T("\tFor example: fsutil dirty set c:\n"));
+ return 1;
+ }
+
+ /* Get a handle for the volume */
+ Volume = OpenVolume(argv[1], FALSE);
+ if (Volume == INVALID_HANDLE_VALUE)
+ {
+ return 1;
+ }
+
+ /* And set the dirty bit */
+ if (DeviceIoControl(Volume, FSCTL_MARK_VOLUME_DIRTY, NULL, 0, NULL, 0, &BytesRead, NULL) == FALSE)
+ {
+ PrintErrorMessage(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