From 493d818cea744bbeb99e6bc7553a66243f954fa0 Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Thu, 13 Feb 2020 16:19:46 -0600 Subject: [PATCH] [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 --- src/format.c | 37 ++++++++++++++++++------------------- src/rufus.rc | 10 +++++----- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/format.c b/src/format.c index fa7101fe..3cba0603 100644 --- a/src/format.c +++ b/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= 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; diff --git a/src/rufus.rc b/src/rufus.rc index a1bf7b79..b0b17d38 100644 --- a/src/rufus.rc +++ b/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"