1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00
* adds check for 'fake' USB drives in bad blocks
This commit is contained in:
Pete Batard 2012-02-24 19:44:24 +00:00
parent b03065b1f5
commit 044398833b
2 changed files with 21 additions and 7 deletions

View file

@ -428,7 +428,8 @@ static unsigned int test_rw(HANDLE hDrive, blk_t last_block, int block_size, blk
const unsigned int pattern[] = {0xaa, 0x55, 0xff, 0x00};
int i, tryout, got, pat_idx;
unsigned int bb_count = 0;
blk_t recover_block = ~0;
blk_t recover_block = ~0, *blk_id;
size_t id_offset;
if ((nb_passes < 1) || (nb_passes > 4)) {
uprintf("Invalid number of passes\n");
@ -452,7 +453,10 @@ static unsigned int test_rw(HANDLE hDrive, blk_t last_block, int block_size, blk
for (pat_idx = 0; pat_idx < nb_passes; pat_idx++) {
if (cancel_ops) goto out;
srand((unsigned int)GetTickCount());
id_offset = rand()* (block_size-sizeof(blk_t)) / RAND_MAX;
pattern_fill(buffer, pattern[pat_idx], blocks_at_once * block_size);
uprintf("Block ID at offset: %d\n", id_offset);
num_blocks = last_block - 1;
currently_testing = first_block;
if (s_flag | v_flag)
@ -472,6 +476,12 @@ static unsigned int test_rw(HANDLE hDrive, blk_t last_block, int block_size, blk
if (cancel_ops) goto out;
if (currently_testing + tryout > last_block)
tryout = last_block - currently_testing;
/* Add the block number at a fixed (random) offset during each pass to
allow for the detection of 'fake' media (eg. 2GB USB masquerading as 16GB) */
for (i=0; i<(int)blocks_at_once; i++) {
blk_id = (blk_t*)(intptr_t)(buffer + id_offset+ i*block_size);
*blk_id = (blk_t)(currently_testing + i);
}
got = do_write(hDrive, buffer, tryout, block_size, currently_testing);
if (v_flag > 1)
print_status();
@ -511,6 +521,10 @@ static unsigned int test_rw(HANDLE hDrive, blk_t last_block, int block_size, blk
}
if (currently_testing + tryout > last_block)
tryout = last_block - currently_testing;
for (i=0; i<(int)blocks_at_once; i++) {
blk_id = (blk_t*)(intptr_t)(buffer + id_offset+ i*block_size);
*blk_id = (blk_t)(currently_testing + i);
}
got = do_read(hDrive, read_buffer, tryout, block_size,
currently_testing);
if (got == 0 && tryout == 1)

View file

@ -33,7 +33,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 206, 289
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "Rufus v1.1.3.145"
CAPTION "Rufus v1.1.3.146"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Start",IDC_START,94,248,50,14
@ -73,7 +73,7 @@ BEGIN
DEFPUSHBUTTON "OK",IDOK,231,175,50,14,WS_GROUP
CONTROL "<a href=""http://rufus.akeo.ie"">http://rufus.akeo.ie</a>",IDC_ABOUT_RUFUS_URL,
"SysLink",WS_TABSTOP,46,47,114,9
LTEXT "Version 1.1.3 (Build 145)",IDC_STATIC,46,19,78,8
LTEXT "Version 1.1.3 (Build 146)",IDC_STATIC,46,19,78,8
PUSHBUTTON "License...",IDC_ABOUT_LICENSE,46,175,50,14,WS_GROUP
EDITTEXT IDC_ABOUT_COPYRIGHTS,46,107,235,63,ES_MULTILINE | ES_READONLY | WS_VSCROLL
LTEXT "Report bugs or request enhancements at:",IDC_STATIC,46,66,187,8
@ -223,8 +223,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,1,3,145
PRODUCTVERSION 1,1,3,145
FILEVERSION 1,1,3,146
PRODUCTVERSION 1,1,3,146
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -241,13 +241,13 @@ BEGIN
BEGIN
VALUE "CompanyName", "akeo.ie"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "1.1.3.145"
VALUE "FileVersion", "1.1.3.146"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "1.1.3.145"
VALUE "ProductVersion", "1.1.3.146"
END
END
BLOCK "VarFileInfo"