mirror of
https://github.com/pbatard/rufus.git
synced 2025-05-23 11:17:03 -04:00
[core] invoke VDS to delete all partitions before format/write
This commit is contained in:
parent
7745edbb92
commit
c0526b3e8b
6 changed files with 397 additions and 17 deletions
21
src/format.c
21
src/format.c
|
@ -1760,13 +1760,13 @@ DWORD WINAPI FormatThread(void* param)
|
|||
extra_partitions = XP_COMPAT;
|
||||
|
||||
PrintInfoDebug(0, MSG_225);
|
||||
hPhysicalDrive = GetPhysicalHandle(DriveIndex, lock_drive, TRUE, !lock_drive);
|
||||
hPhysicalDrive = GetPhysicalHandle(DriveIndex, lock_drive, FALSE, !lock_drive);
|
||||
if (hPhysicalDrive == INVALID_HANDLE_VALUE) {
|
||||
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_OPEN_FAILED;
|
||||
goto out;
|
||||
}
|
||||
|
||||
// At this stage we should have both a handle and a lock to the physical drive...
|
||||
// At this stage we have both a handle and a lock to the physical drive
|
||||
if (!GetDriveLetters(DriveIndex, drive_letters)) {
|
||||
uprintf("Failed to get a drive letter\n");
|
||||
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_CANT_ASSIGN_LETTER);
|
||||
|
@ -1783,7 +1783,7 @@ DWORD WINAPI FormatThread(void* param)
|
|||
} else {
|
||||
// Unmount all mounted volumes that belong to this drive
|
||||
// Do it in reverse so that we always end on the first volume letter
|
||||
for (i=(int)safe_strlen(drive_letters); i>0; i--) {
|
||||
for (i = (int)safe_strlen(drive_letters); i > 0; i--) {
|
||||
drive_name[0] = drive_letters[i-1];
|
||||
if (bt == BT_IMAGE) {
|
||||
// If we are using an image, check that it isn't located on the drive we are trying to format
|
||||
|
@ -1801,7 +1801,20 @@ DWORD WINAPI FormatThread(void* param)
|
|||
}
|
||||
uprintf("Will use '%c:' as volume mountpoint\n", drive_name[0]);
|
||||
|
||||
// ...but we need a lock to the logical drive to be able to write anything to it
|
||||
// It kind of blows, but we have to relinquish access to the physical drive
|
||||
// for VDS to be able to delete the partitions that reside on it...
|
||||
safe_unlockclose(hPhysicalDrive);
|
||||
PrintInfoDebug(0, MSG_239);
|
||||
DeletePartitions(DriveIndex);
|
||||
|
||||
// Now get RW access to the physical drive...
|
||||
hPhysicalDrive = GetPhysicalHandle(DriveIndex, lock_drive, TRUE, !lock_drive);
|
||||
if (hPhysicalDrive == INVALID_HANDLE_VALUE) {
|
||||
FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_OPEN_FAILED;
|
||||
goto out;
|
||||
}
|
||||
|
||||
// ...and get a lock to the logical drive so that we can actually write something
|
||||
hLogicalVolume = GetLogicalHandle(DriveIndex, TRUE, FALSE, !lock_drive);
|
||||
if (hLogicalVolume == INVALID_HANDLE_VALUE) {
|
||||
uprintf("Could not lock volume\n");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue