https://git.reactos.org/?p=reactos.git;a=commitdiff;h=76ac898bc55a6c4c40a4f1...
commit 76ac898bc55a6c4c40a4f1b503bcb0aac0d51dd0 Author: Jérôme Gardou jerome.gardou@reactos.org AuthorDate: Thu Dec 3 17:13:38 2020 +0100 Commit: Jérôme Gardou jerome.gardou@reactos.org CommitDate: Wed Feb 3 09:41:22 2021 +0100
[SETUPLIB] Lock the volume before writing MBR boot code --- base/setup/lib/bootsup.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/base/setup/lib/bootsup.c b/base/setup/lib/bootsup.c index 37f7bdb43ab..b1e11d108d4 100644 --- a/base/setup/lib/bootsup.c +++ b/base/setup/lib/bootsup.c @@ -555,7 +555,7 @@ InstallBootCodeToDisk( IN PCWSTR RootPath, IN PFS_INSTALL_BOOTCODE InstallBootCode) { - NTSTATUS Status; + NTSTATUS Status, LockStatus; UNICODE_STRING Name; OBJECT_ATTRIBUTES ObjectAttributes; IO_STATUS_BLOCK IoStatusBlock; @@ -584,9 +584,32 @@ InstallBootCodeToDisk( if (!NT_SUCCESS(Status)) return Status;
+ /* Lock the volume */ + LockStatus = NtFsControlFile(PartitionHandle, NULL, NULL, NULL, &IoStatusBlock, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0); + if (!NT_SUCCESS(LockStatus)) + { + DPRINT1("Unable to lock the volume before installing boot code. Status 0x%08x. Expect problems.\n", LockStatus); + } + /* Install the bootcode (MBR, VBR) */ Status = InstallBootCode(SrcPath, PartitionHandle, PartitionHandle);
+ /* dismount & Unlock the volume */ + if (NT_SUCCESS(LockStatus)) + { + LockStatus = NtFsControlFile(PartitionHandle, NULL, NULL, NULL, &IoStatusBlock, FSCTL_DISMOUNT_VOLUME, NULL, 0, NULL, 0); + if (!NT_SUCCESS(LockStatus)) + { + DPRINT1("Unable to unlock the volume after installing boot code. Status 0x%08x. Expect problems.\n", LockStatus); + } + + LockStatus = NtFsControlFile(PartitionHandle, NULL, NULL, NULL, &IoStatusBlock, FSCTL_UNLOCK_VOLUME, NULL, 0, NULL, 0); + if (!NT_SUCCESS(LockStatus)) + { + DPRINT1("Unable to unlock the volume after installing boot code. Status 0x%08x. Expect problems.\n", LockStatus); + } + } + /* Close the partition */ NtClose(PartitionHandle);
@@ -1076,6 +1099,7 @@ InstallFatBootcodeToPartition(
DPRINT1("Install FAT32 bootcode: %S ==> %S\n", SrcPath, SystemRootPath->Buffer); Status = InstallBootCodeToDisk(SrcPath, SystemRootPath->Buffer, InstallFat32BootCode); + DPRINT1("Status: 0x%08X\n", Status); if (!NT_SUCCESS(Status)) { DPRINT1("InstallBootCodeToDisk(FAT32) failed (Status %lx)\n", Status);