diff --git a/src/br.c b/src/br.c index df5b352a..86379856 100644 --- a/src/br.c +++ b/src/br.c @@ -189,3 +189,9 @@ int write_zero_mbr(FILE *fp) write_data(fp, 0x0, mbr_zero_0x0, sizeof(mbr_zero_0x0)) && write_data(fp, 0x1FE, aucRef, sizeof(aucRef)); } /* write_zero_mbr */ + +int clear_mbr(FILE *fp) +{ + unsigned char buf[512] = { 0 }; + return write_data(fp, 0x0, buf, sizeof(buf)); +} /* clear_mbr */ diff --git a/src/format.c b/src/format.c index 3eabd3cc..84760d52 100644 --- a/src/format.c +++ b/src/format.c @@ -212,6 +212,16 @@ static BOOL AnalyzeMBR(HANDLE hPhysicalDrive) return TRUE; } + +static BOOL ClearMBR(HANDLE hPhysicalDrive) +{ + FILE fake_fd; + + fake_fd._ptr = (char*)hPhysicalDrive; + fake_fd._bufsiz = SelectedDrive.Geometry.BytesPerSector; + return clear_mbr(&fake_fd); +} + /* * Process the Master Boot Record */ @@ -335,11 +345,20 @@ void __cdecl FormatThread(void* param) SelectedDrive.Geometry.BytesPerSector, BADBLOCKS_RW)) { // TODO: report block failure number, etc uprintf("Bad blocks check failed.\n"); + FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_BADBLOCKS); goto out; } safe_unlockclose(hLogicalVolume); } + // Especially after destructive badblocks test, you must zero the MBR completely + // before repartitioning. Else, all kind of bad things happen + if (!ClearMBR(hPhysicalDrive)) { + uprintf("unable to zero MBR\n"); + FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT; + goto out; + } + if (!CreatePartition(hPhysicalDrive)) { FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_PARTITION_FAILURE; goto out; diff --git a/src/inc/br.h b/src/inc/br.h index d07ec2f2..9d477f72 100644 --- a/src/inc/br.h +++ b/src/inc/br.h @@ -72,4 +72,8 @@ int write_syslinux_mbr(FILE *fp); FALSE */ int write_zero_mbr(FILE *fp); +/* Completely clears (zeroes) master boot record, returns TRUE on success, otherwise + FALSE */ +int clear_mbr(FILE *fp); + #endif diff --git a/src/rufus.c b/src/rufus.c index 0b08555c..6b6e0b3f 100644 --- a/src/rufus.c +++ b/src/rufus.c @@ -742,7 +742,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA if (IsChecked(IDC_QUICKFORMAT)) { SendMessage(hProgress, PBM_SETMARQUEE, FALSE, 0); SetWindowLongPtr(hProgress, GWL_STYLE, ProgressStyle); - // This is the only way to achieve instantenous progress transition + // This is the only way to achieve instantanenous progress transition SendMessage(hProgress, PBM_SETRANGE, 0, 101<<16); SendMessage(hProgress, PBM_SETPOS, 101, 0); SendMessage(hProgress, PBM_SETRANGE, 0, 100<<16); diff --git a/src/rufus.h b/src/rufus.h index 3bb0a369..c1ab4f8c 100644 --- a/src/rufus.h +++ b/src/rufus.h @@ -183,3 +183,4 @@ typedef struct { #define ERROR_INVALID_CLUSTER_SIZE 0x1203 #define ERROR_INVALID_VOLUME_SIZE 0x1204 #define ERROR_CANT_START_THREAD 0x1205 +#define ERROR_BADBLOCKS 0x1206 diff --git a/src/rufus.rc b/src/rufus.rc index 5a33d686..72f439b7 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -30,7 +30,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 206, 278 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_APPWINDOW -CAPTION "Rufus v1.0.2.79" +CAPTION "Rufus v1.0.2.80" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN DEFPUSHBUTTON "Start",IDC_START,94,236,50,14 @@ -65,7 +65,7 @@ BEGIN DEFPUSHBUTTON "OK",IDOK,231,175,50,14,WS_GROUP CONTROL "https://github.com/pbatard/rufus",IDC_ABOUT_RUFUS_URL, "SysLink",WS_TABSTOP,46,47,114,9 - LTEXT "Version 1.0.2 (Build 79)",IDC_STATIC,46,19,78,8 + LTEXT "Version 1.0.2 (Build 80)",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 @@ -164,8 +164,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,0,2,79 - PRODUCTVERSION 1,0,2,79 + FILEVERSION 1,0,2,80 + PRODUCTVERSION 1,0,2,80 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -182,13 +182,13 @@ BEGIN BEGIN VALUE "CompanyName", "akeo.ie" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "1.0.2.79" + VALUE "FileVersion", "1.0.2.80" 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.0.2.79" + VALUE "ProductVersion", "1.0.2.80" END END BLOCK "VarFileInfo" diff --git a/src/stdio.c b/src/stdio.c index 5080d3b5..b06b90e6 100644 --- a/src/stdio.c +++ b/src/stdio.c @@ -192,6 +192,8 @@ const char* StrError(DWORD error_code) return "Cancelled by user"; case ERROR_CANT_START_THREAD: return "Unable to create formatting thread"; + case ERROR_BADBLOCKS: + return "Bad blocks detected"; default: uprintf("StrError: hit default - %08X\n", error_code); SetLastError(error_code);