mirror of
https://github.com/pbatard/rufus.git
synced 2024-08-14 23:57:05 +00:00
[core] fix MBR/GPT sectors being zeroed more than once
* ClearMBRGPT() attempts to write WRITE_RETRIES times, even if all those times succeed. * Instead, skip the remaining retries on success. * Also improve code readability. * Closes #1454
This commit is contained in:
parent
70419d31e9
commit
493d818cea
2 changed files with 23 additions and 24 deletions
37
src/format.c
37
src/format.c
|
@ -717,33 +717,32 @@ static BOOL ClearMBRGPT(HANDLE hPhysicalDrive, LONGLONG DiskSize, DWORD SectorSi
|
|||
num_sectors_to_clear = (DWORD)((add1MB ? 2048 : 0) + MAX_SECTORS_TO_CLEAR);
|
||||
|
||||
uprintf("Erasing %d sectors", num_sectors_to_clear);
|
||||
for (i=0; i<num_sectors_to_clear; i++) {
|
||||
for (i = 0; i < num_sectors_to_clear; i++) {
|
||||
for (j = 1; j <= WRITE_RETRIES; j++) {
|
||||
CHECK_FOR_USER_CANCEL;
|
||||
if (write_sectors(hPhysicalDrive, SectorSize, i, 1, pBuf) != SectorSize) {
|
||||
if (j >= WRITE_RETRIES)
|
||||
goto out;
|
||||
uprintf("Retrying in %d seconds...", WRITE_TIMEOUT / 1000);
|
||||
// Don't sit idly but use the downtime to check for conflicting processes...
|
||||
Sleep(CheckDriveAccess(WRITE_TIMEOUT, FALSE));
|
||||
}
|
||||
if (write_sectors(hPhysicalDrive, SectorSize, i, 1, pBuf) == SectorSize)
|
||||
break;
|
||||
if (j >= WRITE_RETRIES)
|
||||
goto out;
|
||||
uprintf("Retrying in %d seconds...", WRITE_TIMEOUT / 1000);
|
||||
// Don't sit idly but use the downtime to check for conflicting processes...
|
||||
Sleep(CheckDriveAccess(WRITE_TIMEOUT, FALSE));
|
||||
}
|
||||
}
|
||||
for (i = last_sector - MAX_SECTORS_TO_CLEAR; i < last_sector; i++) {
|
||||
for (j = 1; j <= WRITE_RETRIES; j++) {
|
||||
CHECK_FOR_USER_CANCEL;
|
||||
if (write_sectors(hPhysicalDrive, SectorSize, i, 1, pBuf) != SectorSize) {
|
||||
if (j < WRITE_RETRIES) {
|
||||
uprintf("Retrying in %d seconds...", WRITE_TIMEOUT / 1000);
|
||||
Sleep(CheckDriveAccess(WRITE_TIMEOUT, FALSE));
|
||||
} else {
|
||||
// Windows seems to be an ass about keeping a lock on a backup GPT,
|
||||
// so we try to be lenient about not being able to clear it.
|
||||
uprintf("Warning: Failed to clear backup GPT...");
|
||||
r = TRUE;
|
||||
goto out;
|
||||
}
|
||||
if (write_sectors(hPhysicalDrive, SectorSize, i, 1, pBuf) == SectorSize)
|
||||
break;
|
||||
if (j >= WRITE_RETRIES) {
|
||||
// Windows seems to be an ass about keeping a lock on a backup GPT,
|
||||
// so we try to be lenient about not being able to clear it.
|
||||
uprintf("Warning: Failed to clear backup GPT...");
|
||||
r = TRUE;
|
||||
goto out;
|
||||
}
|
||||
uprintf("Retrying in %d seconds...", WRITE_TIMEOUT / 1000);
|
||||
Sleep(CheckDriveAccess(WRITE_TIMEOUT, FALSE));
|
||||
}
|
||||
}
|
||||
r = TRUE;
|
||||
|
|
10
src/rufus.rc
10
src/rufus.rc
|
@ -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.9.1608"
|
||||
CAPTION "Rufus 3.9.1609"
|
||||
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
|
||||
BEGIN
|
||||
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
|
||||
|
@ -394,8 +394,8 @@ END
|
|||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 3,9,1608,0
|
||||
PRODUCTVERSION 3,9,1608,0
|
||||
FILEVERSION 3,9,1609,0
|
||||
PRODUCTVERSION 3,9,1609,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
|
@ -413,13 +413,13 @@ BEGIN
|
|||
VALUE "Comments", "https://rufus.ie"
|
||||
VALUE "CompanyName", "Akeo Consulting"
|
||||
VALUE "FileDescription", "Rufus"
|
||||
VALUE "FileVersion", "3.9.1608"
|
||||
VALUE "FileVersion", "3.9.1609"
|
||||
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.9.exe"
|
||||
VALUE "ProductName", "Rufus"
|
||||
VALUE "ProductVersion", "3.9.1608"
|
||||
VALUE "ProductVersion", "3.9.1609"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
|
Loading…
Reference in a new issue