1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00

[core] refactor fast-zeroing code and fix warnings

* Fox coverity and MinGW warnings
This commit is contained in:
Pete Batard 2018-07-15 12:27:21 +01:00
parent f9275e4780
commit 59aab9b61d
3 changed files with 24 additions and 33 deletions

View file

@ -1553,7 +1553,7 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, HANDLE hSourceImage)
int64_t bled_ret; int64_t bled_ret;
uint8_t *buffer = NULL; uint8_t *buffer = NULL;
uint8_t *cmp_buffer = NULL; uint8_t *cmp_buffer = NULL;
int i, throttle_fast_zeroing = 0; int i, *ptr, zero_data, throttle_fast_zeroing = 0;
// We poked the MBR and other stuff, so we need to rewind // We poked the MBR and other stuff, so we need to rewind
li.QuadPart = 0; li.QuadPart = 0;
@ -1630,11 +1630,10 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, HANDLE hSourceImage)
// we might speed things up by skipping empty blocks, or skipping the write if the data is the same. // we might speed things up by skipping empty blocks, or skipping the write if the data is the same.
// Notes: A block is declared empty when all bits are either 0 (zeros) or 1 (flash block erased). // Notes: A block is declared empty when all bits are either 0 (zeros) or 1 (flash block erased).
// Also, a back-off strategy is used to limit reading. // Also, a back-off strategy is used to limit reading.
if (throttle_fast_zeroing) { if (throttle_fast_zeroing) {
throttle_fast_zeroing--; throttle_fast_zeroing--;
} else if ((fast_zeroing) && (hSourceImage == NULL)) { // currently only enabled for erase } else if (fast_zeroing) {
assert(hSourceImage == NULL); // Only enabled for zeroing
CHECK_FOR_USER_CANCEL; CHECK_FOR_USER_CANCEL;
// Read block and compare against the block that needs to be written // Read block and compare against the block that needs to be written
@ -1644,30 +1643,22 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, HANDLE hSourceImage)
goto out; goto out;
} }
// erase or write // Check for an empty block
if (hSourceImage == NULL) { ptr = (int*)(cmp_buffer);
// Erase, check for an empty block
int *ptr = (int*)(cmp_buffer);
// Get first element // Get first element
int value = ptr[0]; zero_data = ptr[0];
// Check all bits are the same // Check all bits are the same
if ((value != 0) && (value != -1)) { if ((zero_data == 0) || (zero_data == -1)) {
goto blocknotempty;
}
// Compare the rest of the block against the first element // Compare the rest of the block against the first element
for (i = 1; i < (int)(rSize / sizeof(int)); i++) { for (i = 1; i < (int)(rSize / sizeof(int)); i++) {
if (ptr[i] != value) if (ptr[i] != zero_data)
goto blocknotempty; break;
} }
if (i >= (int)(rSize / sizeof(int))) {
// Block is empty, skip write // Block is empty, skip write
wSize = rSize; wSize = rSize;
continue; continue;
blocknotempty: }
;
} else if (memcmp(cmp_buffer, buffer, rSize) == 0) {
// Write, block is unchanged, skip write
wSize = rSize;
continue;
} }
// Move the file pointer position back for writing // Move the file pointer position back for writing
@ -1676,7 +1667,7 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, HANDLE hSourceImage)
uprintf("Error: Could not reset position - %s", WindowsErrorString()); uprintf("Error: Could not reset position - %s", WindowsErrorString());
goto out; goto out;
} }
// throttle read operations // Throttle read operations
throttle_fast_zeroing = 15; throttle_fast_zeroing = 15;
} }

View file

@ -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.2.1338" CAPTION "Rufus 3.2.1339"
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
@ -392,8 +392,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,2,1338,0 FILEVERSION 3,2,1339,0
PRODUCTVERSION 3,2,1338,0 PRODUCTVERSION 3,2,1339,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -411,13 +411,13 @@ BEGIN
VALUE "Comments", "https://akeo.ie" VALUE "Comments", "https://akeo.ie"
VALUE "CompanyName", "Akeo Consulting" VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus" VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "3.2.1338" VALUE "FileVersion", "3.2.1339"
VALUE "InternalName", "Rufus" VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2018 Pete Batard (GPL v3)" VALUE "LegalCopyright", "© 2011-2018 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/copyleft/gpl.html" VALUE "LegalTrademarks", "https://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus-3.2.exe" VALUE "OriginalFilename", "rufus-3.2.exe"
VALUE "ProductName", "Rufus" VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.2.1338" VALUE "ProductVersion", "3.2.1339"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View file

@ -638,7 +638,7 @@ void ToggleAdvancedFormatOptions(BOOL enable)
void SetPersistenceSize(uint64_t pos, uint64_t max) void SetPersistenceSize(uint64_t pos, uint64_t max)
{ {
char tmp[12]; char tmp[12];
int i, proposed_unit_selection; int i, proposed_unit_selection = 0;
LONGLONG base_unit = MB; LONGLONG base_unit = MB;
HWND hCtrl; HWND hCtrl;