mirror of
https://github.com/pbatard/rufus.git
synced 2025-05-24 19:54:25 -04:00
[core] reinstate locking of the logical drive when writing images
* When writing images such as tails, that contain a large ESP, Windows forcibly removes the media while we are writing it, unless we lock the logical drive. * Also fix a Bled Coverity warning.
This commit is contained in:
parent
69bf32dd33
commit
65a0c2c42d
4 changed files with 30 additions and 9 deletions
17
src/format.c
17
src/format.c
|
@ -1746,6 +1746,23 @@ DWORD WINAPI FormatThread(void* param)
|
|||
goto out;
|
||||
}
|
||||
RefreshDriveLayout(hPhysicalDrive);
|
||||
|
||||
// If we write an image that contains an ESP, Windows forcibly reassigns/removes the target
|
||||
// drive, which causes a write error. To work around this, we must lock the logical drive.
|
||||
if ((boot_type == BT_IMAGE) && write_as_image) {
|
||||
// ...and get a lock to the logical drive so that we can actually write something
|
||||
hLogicalVolume = GetLogicalHandle(DriveIndex, 0, TRUE, FALSE, !actual_lock_drive);
|
||||
if (hLogicalVolume == INVALID_HANDLE_VALUE) {
|
||||
uprintf("Could not lock volume");
|
||||
FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_OPEN_FAILED;
|
||||
goto out;
|
||||
} else if (hLogicalVolume == NULL) {
|
||||
// NULL is returned for cases where the drive is not yet partitioned
|
||||
uprintf("Drive does not appear to be partitioned");
|
||||
} else if (!UnmountVolume(hLogicalVolume)) {
|
||||
uprintf("Trying to continue regardless...");
|
||||
}
|
||||
}
|
||||
CHECK_FOR_USER_CANCEL;
|
||||
|
||||
if (!zero_drive && !write_as_image) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue