mirror of
https://github.com/pbatard/rufus.git
synced 2024-08-14 23:57:05 +00:00
[core] speed up the clearing of MBR/GPT sectors
* write_sector() should really only be used when writing single sectors as it
is way to slow for anything else => Switch to using WriteFileWithRetry().
* Also revert an unwarranted change from f0047986e7
.
This commit is contained in:
parent
f0047986e7
commit
9dc045a701
5 changed files with 27 additions and 26 deletions
|
@ -11,7 +11,7 @@
|
||||||
<Identity
|
<Identity
|
||||||
Name="19453.net.Rufus"
|
Name="19453.net.Rufus"
|
||||||
Publisher="CN=7AC86D13-3E5A-491A-ADD5-80095C212740"
|
Publisher="CN=7AC86D13-3E5A-491A-ADD5-80095C212740"
|
||||||
Version="3.16.1819.0" />
|
Version="3.16.1820.0" />
|
||||||
|
|
||||||
<Properties>
|
<Properties>
|
||||||
<DisplayName>Rufus</DisplayName>
|
<DisplayName>Rufus</DisplayName>
|
||||||
|
|
36
src/format.c
36
src/format.c
|
@ -710,19 +710,16 @@ out:
|
||||||
static BOOL ClearMBRGPT(HANDLE hPhysicalDrive, LONGLONG DiskSize, DWORD SectorSize, BOOL add1MB)
|
static BOOL ClearMBRGPT(HANDLE hPhysicalDrive, LONGLONG DiskSize, DWORD SectorSize, BOOL add1MB)
|
||||||
{
|
{
|
||||||
BOOL r = FALSE;
|
BOOL r = FALSE;
|
||||||
uint64_t i, last_sector = DiskSize/SectorSize, num_sectors_to_clear;
|
LARGE_INTEGER liFilePointer;
|
||||||
unsigned char* pBuf = (unsigned char*) calloc(SectorSize, 1);
|
uint64_t num_sectors_to_clear;
|
||||||
|
unsigned char* pZeroBuf = NULL;
|
||||||
|
|
||||||
PrintInfoDebug(0, MSG_224);
|
PrintInfoDebug(0, MSG_224);
|
||||||
if (pBuf == NULL) {
|
|
||||||
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_NOT_ENOUGH_MEMORY;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
// http://en.wikipedia.org/wiki/GUID_Partition_Table tells us we should clear 34 sectors at the
|
// http://en.wikipedia.org/wiki/GUID_Partition_Table tells us we should clear 34 sectors at the
|
||||||
// beginning and 33 at the end. We bump these values to MAX_SECTORS_TO_CLEAR each end to help
|
// beginning and 33 at the end. We bump these values to MAX_SECTORS_TO_CLEAR each end to help
|
||||||
// with reluctant access to large drive.
|
// with reluctant access to large drive.
|
||||||
|
|
||||||
// We try to clear at least 1MB + the PBR when Large FAT32 is selected (add1MB), but
|
// We try to clear at least 1MB + the VBR when Large FAT32 is selected (add1MB), but
|
||||||
// don't do it otherwise, as it seems unnecessary and may take time for slow drives.
|
// don't do it otherwise, as it seems unnecessary and may take time for slow drives.
|
||||||
// Also, for various reasons (one of which being that Windows seems to have issues
|
// Also, for various reasons (one of which being that Windows seems to have issues
|
||||||
// with GPT drives that contain a lot of small partitions) we try not not to clear
|
// with GPT drives that contain a lot of small partitions) we try not not to clear
|
||||||
|
@ -733,22 +730,23 @@ 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++) {
|
pZeroBuf = calloc(SectorSize, num_sectors_to_clear);
|
||||||
CHECK_FOR_USER_CANCEL;
|
if (pZeroBuf == NULL) {
|
||||||
if (write_sectors(hPhysicalDrive, SectorSize, i, 1, pBuf) != SectorSize)
|
FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_NOT_ENOUGH_MEMORY;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
|
||||||
for (i = last_sector - MAX_SECTORS_TO_CLEAR; i < last_sector; i++) {
|
|
||||||
CHECK_FOR_USER_CANCEL;
|
|
||||||
// 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.
|
|
||||||
if (write_sectors(hPhysicalDrive, SectorSize, i, 1, pBuf) != SectorSize)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
if (!WriteFileWithRetry(hPhysicalDrive, pZeroBuf, (DWORD)(SectorSize * num_sectors_to_clear), NULL, WRITE_RETRIES))
|
||||||
|
goto out;
|
||||||
|
CHECK_FOR_USER_CANCEL;
|
||||||
|
liFilePointer.QuadPart = DiskSize - (LONGLONG)SectorSize * MAX_SECTORS_TO_CLEAR;
|
||||||
|
SetFilePointerEx(hPhysicalDrive, liFilePointer, &liFilePointer, FILE_BEGIN);
|
||||||
|
// 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.
|
||||||
|
WriteFileWithRetry(hPhysicalDrive, pZeroBuf, SectorSize * MAX_SECTORS_TO_CLEAR, NULL, WRITE_RETRIES);
|
||||||
r = TRUE;
|
r = TRUE;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
safe_free(pBuf);
|
safe_free(pZeroBuf);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,6 @@ static str_score_t str_adjust[] = {
|
||||||
{ "Gadget", -10 },
|
{ "Gadget", -10 },
|
||||||
{ "Flash", -10 },
|
{ "Flash", -10 },
|
||||||
{ "HDD", +20 },
|
{ "HDD", +20 },
|
||||||
{ "SDXC", +10 },
|
|
||||||
{ "SSD", +20 }
|
{ "SSD", +20 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
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.16.1819"
|
CAPTION "Rufus 3.16.1820"
|
||||||
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
|
||||||
|
@ -395,8 +395,8 @@ END
|
||||||
//
|
//
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
VS_VERSION_INFO VERSIONINFO
|
||||||
FILEVERSION 3,16,1819,0
|
FILEVERSION 3,16,1820,0
|
||||||
PRODUCTVERSION 3,16,1819,0
|
PRODUCTVERSION 3,16,1820,0
|
||||||
FILEFLAGSMASK 0x3fL
|
FILEFLAGSMASK 0x3fL
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
FILEFLAGS 0x1L
|
FILEFLAGS 0x1L
|
||||||
|
@ -414,13 +414,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.16.1819"
|
VALUE "FileVersion", "3.16.1820"
|
||||||
VALUE "InternalName", "Rufus"
|
VALUE "InternalName", "Rufus"
|
||||||
VALUE "LegalCopyright", "© 2011-2021 Pete Batard (GPL v3)"
|
VALUE "LegalCopyright", "© 2011-2021 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.16.exe"
|
VALUE "OriginalFilename", "rufus-3.16.exe"
|
||||||
VALUE "ProductName", "Rufus"
|
VALUE "ProductName", "Rufus"
|
||||||
VALUE "ProductVersion", "3.16.1819"
|
VALUE "ProductVersion", "3.16.1820"
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
|
|
|
@ -855,6 +855,10 @@ BOOL WriteFileWithRetry(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWr
|
||||||
DWORD nTry;
|
DWORD nTry;
|
||||||
BOOL readFilePointer;
|
BOOL readFilePointer;
|
||||||
LARGE_INTEGER liFilePointer, liZero = { { 0,0 } };
|
LARGE_INTEGER liFilePointer, liZero = { { 0,0 } };
|
||||||
|
DWORD NumberOfBytesWritten;
|
||||||
|
|
||||||
|
if (lpNumberOfBytesWritten == NULL)
|
||||||
|
lpNumberOfBytesWritten = &NumberOfBytesWritten;
|
||||||
|
|
||||||
// Need to get the current file pointer in case we need to retry
|
// Need to get the current file pointer in case we need to retry
|
||||||
readFilePointer = SetFilePointerEx(hFile, liZero, &liFilePointer, FILE_CURRENT);
|
readFilePointer = SetFilePointerEx(hFile, liZero, &liFilePointer, FILE_CURRENT);
|
||||||
|
|
Loading…
Reference in a new issue