[core] work around Windows handling of ESP for removable drives

* Remove early locking of logical volume (no longer necessary due to previous commits).
* Relax exclusive locking of physical drive when an ESP is created.
* This should help with #1637 and #1640
* Also add an extra check for sector size in WriteDrive()
This commit is contained in:
Pete Batard 2020-10-26 13:50:19 +00:00
parent b2b621cec7
commit f027e562b3
No known key found for this signature in database
GPG Key ID: 38E0CF5E69EDD671
2 changed files with 15 additions and 22 deletions

View File

@ -1485,6 +1485,11 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, HANDLE hSourceImage)
uint8_t *cmp_buffer = NULL;
int i, *ptr, zero_data, throttle_fast_zeroing = 0;
if (SelectedDrive.SectorSize < 512) {
uprintf("Unexpected sector size (%d) - Aborting", SelectedDrive.SectorSize);
return FALSE;
}
// We poked the MBR and other stuff, so we need to rewind
li.QuadPart = 0;
if (!SetFilePointerEx(hPhysicalDrive, li, NULL, FILE_BEGIN))
@ -1697,8 +1702,8 @@ DWORD WINAPI FormatThread(void* param)
else if (IsChecked(IDC_OLD_BIOS_FIXES))
extra_partitions = XP_COMPAT;
// On pre 1703 platforms (and even on later ones), anything with ext2/ext3 doesn't sit
// too well with Windows. Relaxing our locking rules seems to help...
if ((extra_partitions == XP_CASPER) || (fs_type >= FS_EXT2))
// too well with Windows. Same with ESPs. Relaxing our locking rules seems to help...
if ((extra_partitions & (XP_ESP | XP_CASPER)) || (fs_type >= FS_EXT2))
actual_lock_drive = FALSE;
PrintInfoDebug(0, MSG_225);
@ -1737,26 +1742,13 @@ DWORD WINAPI FormatThread(void* param)
// An extra refresh of the (now empty) partition data here appears to be helpful
GetDrivePartitionData(SelectedDrive.DeviceNumber, fs_name, sizeof(fs_name), TRUE);
// Now get RW access to the physical drive...
// Now get RW access to the physical drive
hPhysicalDrive = GetPhysicalHandle(DriveIndex, actual_lock_drive, TRUE, !actual_lock_drive);
if (hPhysicalDrive == INVALID_HANDLE_VALUE) {
FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_OPEN_FAILED;
goto out;
}
RefreshDriveLayout(hPhysicalDrive);
// ...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) {
@ -1877,7 +1869,8 @@ DWORD WINAPI FormatThread(void* param)
UpdateProgress(OP_ZERO_MBR, -1.0f);
CHECK_FOR_USER_CANCEL;
if (!CreatePartition(hPhysicalDrive, partition_type, fs_type, (partition_type==PARTITION_STYLE_MBR) && (target_type==TT_UEFI), extra_partitions)) {
if (!CreatePartition(hPhysicalDrive, partition_type, fs_type, (partition_type == PARTITION_STYLE_MBR)
&& (target_type == TT_UEFI), extra_partitions)) {
FormatStatus = (LastWriteError != 0) ? LastWriteError : (ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_PARTITION_FAILURE);
goto out;
}

View File

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 3.13.1714"
CAPTION "Rufus 3.13.1715"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -395,8 +395,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,13,1714,0
PRODUCTVERSION 3,13,1714,0
FILEVERSION 3,13,1715,0
PRODUCTVERSION 3,13,1715,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -414,13 +414,13 @@ BEGIN
VALUE "Comments", "https://rufus.ie"
VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "3.13.1714"
VALUE "FileVersion", "3.13.1715"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2020 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-3.13.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.13.1714"
VALUE "ProductVersion", "3.13.1715"
END
END
BLOCK "VarFileInfo"