From a3b61053bcfdb7175706635089f97c56ef157d96 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 23 Jun 2011 22:34:03 +0000 Subject: [PATCH] [VFATLIB] - Lock the volume before formatting to prevent concurrent access during formatting - This should (in theory) fix our formatting issue on mounted devices but currently we don't support FSCTL_LOCK_VOLUME in our FS drivers svn path=/trunk/; revision=52435 --- reactos/lib/fslib/vfatlib/vfatlib.c | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/reactos/lib/fslib/vfatlib/vfatlib.c b/reactos/lib/fslib/vfatlib/vfatlib.c index 11847b2c688..c8c9c54f388 100644 --- a/reactos/lib/fslib/vfatlib/vfatlib.c +++ b/reactos/lib/fslib/vfatlib/vfatlib.c @@ -194,6 +194,21 @@ VfatFormat(IN PUNICODE_STRING DriveRoot, Context.Percent = 0; Callback (PROGRESS, 0, (PVOID)&Context.Percent); } + + Status = NtFsControlFile(FileHandle, + NULL, + NULL, + NULL, + &Iosb, + FSCTL_LOCK_VOLUME, + NULL, + 0, + NULL, + 0); + if (!NT_SUCCESS(Status)) + { + DPRINT1("WARNING: Failed to lock volume for formatting! Format may fail! (Status: 0x%x)\n", Status); + } if (PartitionInfo.PartitionType == PARTITION_FAT_12) { @@ -235,6 +250,21 @@ VfatFormat(IN PUNICODE_STRING DriveRoot, { Status = STATUS_INVALID_PARAMETER; } + + Status = NtFsControlFile(FileHandle, + NULL, + NULL, + NULL, + &Iosb, + FSCTL_UNLOCK_VOLUME, + NULL, + 0, + NULL, + 0); + if (!NT_SUCCESS(Status)) + { + DPRINT1("Failed to unlock volume (Status: 0x%x)\n", Status); + } NtClose(FileHandle);