[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:
Pete Batard 2020-10-28 21:41:43 +00:00
parent 69bf32dd33
commit 65a0c2c42d
No known key found for this signature in database
GPG Key ID: 38E0CF5E69EDD671
4 changed files with 30 additions and 9 deletions

View File

@ -1214,13 +1214,18 @@ unpack_gz_stream(transformer_state_t *xstate)
total = 0;
ALLOC_STATE;
if (state == NULL)
if (state == NULL) {
bb_error_msg("alloc error");
return -1;
}
to_read = -1;
// bytebuffer_max = 0x8000;
bytebuffer = xmalloc(bytebuffer_max);
if (bytebuffer == NULL)
return -1;
if (bytebuffer == NULL) {
bb_error_msg("alloc error");
total = -1;
goto ret;
}
gunzip_src_fd = xstate->src_fd;
again:

View File

@ -1099,7 +1099,6 @@ UINT GetDriveTypeFromIndex(DWORD DriveIndex)
return drive_type;
}
// Removes all drive letters associated with the specific drive, and return
// either the first or last letter that was removed, according to bReturnLast.
char RemoveDriveLetters(DWORD DriveIndex, BOOL bReturnLast, BOOL bSilent)

View File

@ -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) {

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.1716"
CAPTION "Rufus 3.13.1717"
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,1716,0
PRODUCTVERSION 3,13,1716,0
FILEVERSION 3,13,1717,0
PRODUCTVERSION 3,13,1717,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.1716"
VALUE "FileVersion", "3.13.1717"
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.1716"
VALUE "ProductVersion", "3.13.1717"
END
END
BLOCK "VarFileInfo"