mirror of
https://github.com/pbatard/rufus.git
synced 2024-08-14 23:57:05 +00:00
[core] lock the logical drive when DeletePartition() fails
* Yeah, that's another SUPER EMPIRICAL behaviour you have to figure out the hard way when you try to use VDS. Thanks for nothing, Microsoft!
This commit is contained in:
parent
460ab5dd73
commit
29205b3a0e
2 changed files with 16 additions and 13 deletions
19
src/format.c
19
src/format.c
|
@ -1670,6 +1670,7 @@ DWORD WINAPI FormatThread(void* param)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
BOOL ret, use_large_fat32, windows_to_go, actual_lock_drive = lock_drive;
|
BOOL ret, use_large_fat32, windows_to_go, actual_lock_drive = lock_drive;
|
||||||
|
BOOL need_logical = FALSE;
|
||||||
DWORD cr, DriveIndex = (DWORD)(uintptr_t)param, ClusterSize, Flags;
|
DWORD cr, DriveIndex = (DWORD)(uintptr_t)param, ClusterSize, Flags;
|
||||||
HANDLE hPhysicalDrive = INVALID_HANDLE_VALUE;
|
HANDLE hPhysicalDrive = INVALID_HANDLE_VALUE;
|
||||||
HANDLE hLogicalVolume = INVALID_HANDLE_VALUE;
|
HANDLE hLogicalVolume = INVALID_HANDLE_VALUE;
|
||||||
|
@ -1738,8 +1739,10 @@ DWORD WINAPI FormatThread(void* param)
|
||||||
PrintInfo(0, MSG_239, lmprintf(MSG_307));
|
PrintInfo(0, MSG_239, lmprintf(MSG_307));
|
||||||
if (!DeletePartition(DriveIndex, 0, FALSE)) {
|
if (!DeletePartition(DriveIndex, 0, FALSE)) {
|
||||||
SetLastError(FormatStatus);
|
SetLastError(FormatStatus);
|
||||||
uprintf("Notice: Could not delete partitions: %s", WindowsErrorString());
|
|
||||||
FormatStatus = 0;
|
FormatStatus = 0;
|
||||||
|
// If we couldn't delete partitions, Windows give us trouble unless we
|
||||||
|
// request access to the logical drive. Don't ask me why!
|
||||||
|
need_logical = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// An extra refresh of the (now empty) partition data here appears to be helpful
|
// An extra refresh of the (now empty) partition data here appears to be helpful
|
||||||
|
@ -1755,17 +1758,17 @@ DWORD WINAPI FormatThread(void* param)
|
||||||
|
|
||||||
// If we write an image that contains an ESP, Windows forcibly reassigns/removes the target
|
// 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.
|
// drive, which causes a write error. To work around this, we must lock the logical drive.
|
||||||
if ((boot_type == BT_IMAGE) && write_as_image) {
|
// Also need to lock logical drive if we couldn't delete partitions, to keep Windows happy...
|
||||||
// ...and get a lock to the logical drive so that we can actually write something
|
if (((boot_type == BT_IMAGE) && write_as_image) || (need_logical)) {
|
||||||
|
uprintf("Requesting logical volume handle...");
|
||||||
hLogicalVolume = GetLogicalHandle(DriveIndex, 0, TRUE, FALSE, !actual_lock_drive);
|
hLogicalVolume = GetLogicalHandle(DriveIndex, 0, TRUE, FALSE, !actual_lock_drive);
|
||||||
if (hLogicalVolume == INVALID_HANDLE_VALUE) {
|
if (hLogicalVolume == INVALID_HANDLE_VALUE) {
|
||||||
uprintf("Could not lock volume");
|
uprintf("Could not access logical volume");
|
||||||
FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_OPEN_FAILED;
|
FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_OPEN_FAILED;
|
||||||
goto out;
|
goto out;
|
||||||
} else if (hLogicalVolume == NULL) {
|
// If the call succeeds (and we don't get a NULL logical handle as returned for
|
||||||
// NULL is returned for cases where the drive is not yet partitioned
|
// unpartitioned drives), try to unmount the volume.
|
||||||
uprintf("Drive does not appear to be partitioned");
|
} else if ((hLogicalVolume == NULL) && (!UnmountVolume(hLogicalVolume))) {
|
||||||
} else if (!UnmountVolume(hLogicalVolume)) {
|
|
||||||
uprintf("Trying to continue regardless...");
|
uprintf("Trying to continue regardless...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
src/rufus.rc
10
src/rufus.rc
|
@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
|
||||||
IDD_DIALOG DIALOGEX 12, 12, 232, 326
|
IDD_DIALOG DIALOGEX 12, 12, 232, 326
|
||||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||||
EXSTYLE WS_EX_ACCEPTFILES
|
EXSTYLE WS_EX_ACCEPTFILES
|
||||||
CAPTION "Rufus 3.13.1726"
|
CAPTION "Rufus 3.13.1727"
|
||||||
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
|
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
|
||||||
BEGIN
|
BEGIN
|
||||||
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
|
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
|
||||||
|
@ -395,8 +395,8 @@ END
|
||||||
//
|
//
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
VS_VERSION_INFO VERSIONINFO
|
||||||
FILEVERSION 3,13,1726,0
|
FILEVERSION 3,13,1727,0
|
||||||
PRODUCTVERSION 3,13,1726,0
|
PRODUCTVERSION 3,13,1727,0
|
||||||
FILEFLAGSMASK 0x3fL
|
FILEFLAGSMASK 0x3fL
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
FILEFLAGS 0x1L
|
FILEFLAGS 0x1L
|
||||||
|
@ -414,13 +414,13 @@ BEGIN
|
||||||
VALUE "Comments", "https://rufus.ie"
|
VALUE "Comments", "https://rufus.ie"
|
||||||
VALUE "CompanyName", "Akeo Consulting"
|
VALUE "CompanyName", "Akeo Consulting"
|
||||||
VALUE "FileDescription", "Rufus"
|
VALUE "FileDescription", "Rufus"
|
||||||
VALUE "FileVersion", "3.13.1726"
|
VALUE "FileVersion", "3.13.1727"
|
||||||
VALUE "InternalName", "Rufus"
|
VALUE "InternalName", "Rufus"
|
||||||
VALUE "LegalCopyright", "© 2011-2020 Pete Batard (GPL v3)"
|
VALUE "LegalCopyright", "© 2011-2020 Pete Batard (GPL v3)"
|
||||||
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
|
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
|
||||||
VALUE "OriginalFilename", "rufus-3.13.exe"
|
VALUE "OriginalFilename", "rufus-3.13.exe"
|
||||||
VALUE "ProductName", "Rufus"
|
VALUE "ProductName", "Rufus"
|
||||||
VALUE "ProductVersion", "3.13.1726"
|
VALUE "ProductVersion", "3.13.1727"
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
|
|
Loading…
Reference in a new issue