Author: fireball Date: Sat Aug 23 06:41:04 2008 New Revision: 35560
URL: http://svn.reactos.org/svn/reactos?rev=35560&view=rev Log: - Perform volume operations as described in http://msdn.microsoft.com/en-us/library/aa364562(VS.85).aspx : Open, Lock, Work, Dismount, Unlock, Close. - Our fastfat driver doesn't support lock/unlock and dismount operations, so no improvement yet.
Modified: trunk/reactos/lib/fslib/vfatlib/check/io.c trunk/reactos/lib/fslib/vfatlib/check/io.h trunk/reactos/lib/fslib/vfatlib/vfatlib.c
Modified: trunk/reactos/lib/fslib/vfatlib/check/io.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/fslib/vfatlib/check/io.... ============================================================================== --- trunk/reactos/lib/fslib/vfatlib/check/io.c [iso-8859-1] (original) +++ trunk/reactos/lib/fslib/vfatlib/check/io.c [iso-8859-1] Sat Aug 23 06:41:04 2008 @@ -72,6 +72,9 @@ return; }
+ // If rw is specified, then the volume should be exclusively locked + if (rw) fs_lock(TRUE); + // Query geometry and partition info, to have bytes per sector, etc
CurrentOffset.QuadPart = 0LL; @@ -100,6 +103,43 @@
/* Convert Dirty mask to a boolean value */ return (DirtyMask & 1); +} + +NTSTATUS fs_lock(BOOLEAN LockVolume) +{ + NTSTATUS Status; + IO_STATUS_BLOCK IoSb; + + /* Check if volume is dirty */ + Status = NtFsControlFile(fd, + NULL, NULL, NULL, &IoSb, + LockVolume ? FSCTL_LOCK_VOLUME : + FSCTL_UNLOCK_VOLUME, + NULL, 0, NULL, 0); + + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtFsControlFile() failed with Status 0x%08x\n", Status); + } + + return Status; +} + +void fs_dismount() +{ + NTSTATUS Status; + IO_STATUS_BLOCK IoSb; + + /* Check if volume is dirty */ + Status = NtFsControlFile(fd, + NULL, NULL, NULL, &IoSb, + FSCTL_DISMOUNT_VOLUME, + NULL, 0, NULL, 0); + + if (!NT_SUCCESS(Status)) + { + DPRINT1("NtFsControlFile() failed with Status 0x%08x\n", Status); + } }
void fs_read(loff_t pos,int size,void *data)
Modified: trunk/reactos/lib/fslib/vfatlib/check/io.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/fslib/vfatlib/check/io.... ============================================================================== --- trunk/reactos/lib/fslib/vfatlib/check/io.h [iso-8859-1] (original) +++ trunk/reactos/lib/fslib/vfatlib/check/io.h [iso-8859-1] Sat Aug 23 06:41:04 2008 @@ -51,6 +51,14 @@
/* Determines whether the file system has changed. See fs_close. */
+NTSTATUS fs_lock(BOOLEAN LockVolume); + +/* Lock or unlocks the volume */ + +void fs_dismount(); + +/* Dismounts the volume */ + extern unsigned device_no;
/* Major number of device (0 if file) and size (in 512 byte sectors) */
Modified: trunk/reactos/lib/fslib/vfatlib/vfatlib.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/fslib/vfatlib/vfatlib.c... ============================================================================== --- trunk/reactos/lib/fslib/vfatlib/vfatlib.c [iso-8859-1] (original) +++ trunk/reactos/lib/fslib/vfatlib/vfatlib.c [iso-8859-1] Sat Aug 23 06:41:04 2008 @@ -300,6 +300,16 @@ VfatPrint("%wZ: %u files, %lu/%lu clusters\n", DriveRoot, FsCheckTotalFiles, fs.clusters - free_clusters, fs.clusters );
+ if (FixErrors) + { + /* Dismount the volume */ + fs_dismount(); + + /* Unlock the volume */ + fs_lock(FALSE); + } + + /* Close the volume */ return fs_close(FixErrors) ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL; #else return STATUS_SUCCESS;