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
17
src/format.c
17
src/format.c
|
@ -717,10 +717,11 @@ static BOOL ClearMBRGPT(HANDLE hPhysicalDrive, LONGLONG DiskSize, DWORD SectorSi
|
||||||
num_sectors_to_clear = (DWORD)((add1MB ? 2048 : 0) + MAX_SECTORS_TO_CLEAR);
|
num_sectors_to_clear = (DWORD)((add1MB ? 2048 : 0) + MAX_SECTORS_TO_CLEAR);
|
||||||
|
|
||||||
uprintf("Erasing %d sectors", num_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++) {
|
for (j = 1; j <= WRITE_RETRIES; j++) {
|
||||||
CHECK_FOR_USER_CANCEL;
|
CHECK_FOR_USER_CANCEL;
|
||||||
if (write_sectors(hPhysicalDrive, SectorSize, i, 1, pBuf) != SectorSize) {
|
if (write_sectors(hPhysicalDrive, SectorSize, i, 1, pBuf) == SectorSize)
|
||||||
|
break;
|
||||||
if (j >= WRITE_RETRIES)
|
if (j >= WRITE_RETRIES)
|
||||||
goto out;
|
goto out;
|
||||||
uprintf("Retrying in %d seconds...", WRITE_TIMEOUT / 1000);
|
uprintf("Retrying in %d seconds...", WRITE_TIMEOUT / 1000);
|
||||||
|
@ -728,22 +729,20 @@ static BOOL ClearMBRGPT(HANDLE hPhysicalDrive, LONGLONG DiskSize, DWORD SectorSi
|
||||||
Sleep(CheckDriveAccess(WRITE_TIMEOUT, FALSE));
|
Sleep(CheckDriveAccess(WRITE_TIMEOUT, FALSE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
for (i = last_sector - MAX_SECTORS_TO_CLEAR; i < last_sector; i++) {
|
for (i = last_sector - MAX_SECTORS_TO_CLEAR; i < last_sector; i++) {
|
||||||
for (j = 1; j <= WRITE_RETRIES; j++) {
|
for (j = 1; j <= WRITE_RETRIES; j++) {
|
||||||
CHECK_FOR_USER_CANCEL;
|
CHECK_FOR_USER_CANCEL;
|
||||||
if (write_sectors(hPhysicalDrive, SectorSize, i, 1, pBuf) != SectorSize) {
|
if (write_sectors(hPhysicalDrive, SectorSize, i, 1, pBuf) == SectorSize)
|
||||||
if (j < WRITE_RETRIES) {
|
break;
|
||||||
uprintf("Retrying in %d seconds...", WRITE_TIMEOUT / 1000);
|
if (j >= WRITE_RETRIES) {
|
||||||
Sleep(CheckDriveAccess(WRITE_TIMEOUT, FALSE));
|
|
||||||
} else {
|
|
||||||
// Windows seems to be an ass about keeping a lock on a backup GPT,
|
// 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.
|
// so we try to be lenient about not being able to clear it.
|
||||||
uprintf("Warning: Failed to clear backup GPT...");
|
uprintf("Warning: Failed to clear backup GPT...");
|
||||||
r = TRUE;
|
r = TRUE;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
uprintf("Retrying in %d seconds...", WRITE_TIMEOUT / 1000);
|
||||||
|
Sleep(CheckDriveAccess(WRITE_TIMEOUT, FALSE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
r = TRUE;
|
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
|
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.9.1608"
|
CAPTION "Rufus 3.9.1609"
|
||||||
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
|
||||||
|
@ -394,8 +394,8 @@ END
|
||||||
//
|
//
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
VS_VERSION_INFO VERSIONINFO
|
||||||
FILEVERSION 3,9,1608,0
|
FILEVERSION 3,9,1609,0
|
||||||
PRODUCTVERSION 3,9,1608,0
|
PRODUCTVERSION 3,9,1609,0
|
||||||
FILEFLAGSMASK 0x3fL
|
FILEFLAGSMASK 0x3fL
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
FILEFLAGS 0x1L
|
FILEFLAGS 0x1L
|
||||||
|
@ -413,13 +413,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.9.1608"
|
VALUE "FileVersion", "3.9.1609"
|
||||||
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.9.exe"
|
VALUE "OriginalFilename", "rufus-3.9.exe"
|
||||||
VALUE "ProductName", "Rufus"
|
VALUE "ProductName", "Rufus"
|
||||||
VALUE "ProductVersion", "3.9.1608"
|
VALUE "ProductVersion", "3.9.1609"
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
|
|
Loading…
Reference in a new issue