mirror of
https://github.com/pbatard/rufus.git
synced 2025-05-20 09:55:11 -04:00
[format] fixed corruption issue when MBR is garbage
* after a bb check, MBR could become garbage * when that occurs, Windows might interpret a bad partition table and prevent MBR from being properly written * force a complete zeroing of the whole MBR before partitioning to fix this * also added error code for bb
This commit is contained in:
parent
5c2242beaa
commit
480986b0ae
7 changed files with 39 additions and 7 deletions
6
src/br.c
6
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, 0x0, mbr_zero_0x0, sizeof(mbr_zero_0x0)) &&
|
||||||
write_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
write_data(fp, 0x1FE, aucRef, sizeof(aucRef));
|
||||||
} /* write_zero_mbr */
|
} /* write_zero_mbr */
|
||||||
|
|
||||||
|
int clear_mbr(FILE *fp)
|
||||||
|
{
|
||||||
|
unsigned char buf[512] = { 0 };
|
||||||
|
return write_data(fp, 0x0, buf, sizeof(buf));
|
||||||
|
} /* clear_mbr */
|
||||||
|
|
19
src/format.c
19
src/format.c
|
@ -212,6 +212,16 @@ static BOOL AnalyzeMBR(HANDLE hPhysicalDrive)
|
||||||
return TRUE;
|
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
|
* Process the Master Boot Record
|
||||||
*/
|
*/
|
||||||
|
@ -335,11 +345,20 @@ void __cdecl FormatThread(void* param)
|
||||||
SelectedDrive.Geometry.BytesPerSector, BADBLOCKS_RW)) {
|
SelectedDrive.Geometry.BytesPerSector, BADBLOCKS_RW)) {
|
||||||
// TODO: report block failure number, etc
|
// TODO: report block failure number, etc
|
||||||
uprintf("Bad blocks check failed.\n");
|
uprintf("Bad blocks check failed.\n");
|
||||||
|
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_BADBLOCKS);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
safe_unlockclose(hLogicalVolume);
|
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)) {
|
if (!CreatePartition(hPhysicalDrive)) {
|
||||||
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_PARTITION_FAILURE;
|
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_PARTITION_FAILURE;
|
||||||
goto out;
|
goto out;
|
||||||
|
|
|
@ -72,4 +72,8 @@ int write_syslinux_mbr(FILE *fp);
|
||||||
FALSE */
|
FALSE */
|
||||||
int write_zero_mbr(FILE *fp);
|
int write_zero_mbr(FILE *fp);
|
||||||
|
|
||||||
|
/* Completely clears (zeroes) master boot record, returns TRUE on success, otherwise
|
||||||
|
FALSE */
|
||||||
|
int clear_mbr(FILE *fp);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -742,7 +742,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
|
||||||
if (IsChecked(IDC_QUICKFORMAT)) {
|
if (IsChecked(IDC_QUICKFORMAT)) {
|
||||||
SendMessage(hProgress, PBM_SETMARQUEE, FALSE, 0);
|
SendMessage(hProgress, PBM_SETMARQUEE, FALSE, 0);
|
||||||
SetWindowLongPtr(hProgress, GWL_STYLE, ProgressStyle);
|
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_SETRANGE, 0, 101<<16);
|
||||||
SendMessage(hProgress, PBM_SETPOS, 101, 0);
|
SendMessage(hProgress, PBM_SETPOS, 101, 0);
|
||||||
SendMessage(hProgress, PBM_SETRANGE, 0, 100<<16);
|
SendMessage(hProgress, PBM_SETRANGE, 0, 100<<16);
|
||||||
|
|
|
@ -183,3 +183,4 @@ typedef struct {
|
||||||
#define ERROR_INVALID_CLUSTER_SIZE 0x1203
|
#define ERROR_INVALID_CLUSTER_SIZE 0x1203
|
||||||
#define ERROR_INVALID_VOLUME_SIZE 0x1204
|
#define ERROR_INVALID_VOLUME_SIZE 0x1204
|
||||||
#define ERROR_CANT_START_THREAD 0x1205
|
#define ERROR_CANT_START_THREAD 0x1205
|
||||||
|
#define ERROR_BADBLOCKS 0x1206
|
||||||
|
|
12
src/rufus.rc
12
src/rufus.rc
|
@ -30,7 +30,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
|
||||||
IDD_DIALOG DIALOGEX 12, 12, 206, 278
|
IDD_DIALOG DIALOGEX 12, 12, 206, 278
|
||||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||||
EXSTYLE WS_EX_APPWINDOW
|
EXSTYLE WS_EX_APPWINDOW
|
||||||
CAPTION "Rufus v1.0.2.79"
|
CAPTION "Rufus v1.0.2.80"
|
||||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||||
BEGIN
|
BEGIN
|
||||||
DEFPUSHBUTTON "Start",IDC_START,94,236,50,14
|
DEFPUSHBUTTON "Start",IDC_START,94,236,50,14
|
||||||
|
@ -65,7 +65,7 @@ BEGIN
|
||||||
DEFPUSHBUTTON "OK",IDOK,231,175,50,14,WS_GROUP
|
DEFPUSHBUTTON "OK",IDOK,231,175,50,14,WS_GROUP
|
||||||
CONTROL "<a href=""https://github.com/pbatard/rufus/wiki/Rufus"">https://github.com/pbatard/rufus</a>",IDC_ABOUT_RUFUS_URL,
|
CONTROL "<a href=""https://github.com/pbatard/rufus/wiki/Rufus"">https://github.com/pbatard/rufus</a>",IDC_ABOUT_RUFUS_URL,
|
||||||
"SysLink",WS_TABSTOP,46,47,114,9
|
"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
|
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
|
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
|
LTEXT "Report bugs or request enhancements at:",IDC_STATIC,46,66,187,8
|
||||||
|
@ -164,8 +164,8 @@ END
|
||||||
//
|
//
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
VS_VERSION_INFO VERSIONINFO
|
||||||
FILEVERSION 1,0,2,79
|
FILEVERSION 1,0,2,80
|
||||||
PRODUCTVERSION 1,0,2,79
|
PRODUCTVERSION 1,0,2,80
|
||||||
FILEFLAGSMASK 0x3fL
|
FILEFLAGSMASK 0x3fL
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
FILEFLAGS 0x1L
|
FILEFLAGS 0x1L
|
||||||
|
@ -182,13 +182,13 @@ BEGIN
|
||||||
BEGIN
|
BEGIN
|
||||||
VALUE "CompanyName", "akeo.ie"
|
VALUE "CompanyName", "akeo.ie"
|
||||||
VALUE "FileDescription", "Rufus"
|
VALUE "FileDescription", "Rufus"
|
||||||
VALUE "FileVersion", "1.0.2.79"
|
VALUE "FileVersion", "1.0.2.80"
|
||||||
VALUE "InternalName", "Rufus"
|
VALUE "InternalName", "Rufus"
|
||||||
VALUE "LegalCopyright", "© 2011 Pete Batard (GPL v3)"
|
VALUE "LegalCopyright", "© 2011 Pete Batard (GPL v3)"
|
||||||
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
|
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
|
||||||
VALUE "OriginalFilename", "rufus.exe"
|
VALUE "OriginalFilename", "rufus.exe"
|
||||||
VALUE "ProductName", "Rufus"
|
VALUE "ProductName", "Rufus"
|
||||||
VALUE "ProductVersion", "1.0.2.79"
|
VALUE "ProductVersion", "1.0.2.80"
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
|
|
|
@ -192,6 +192,8 @@ const char* StrError(DWORD error_code)
|
||||||
return "Cancelled by user";
|
return "Cancelled by user";
|
||||||
case ERROR_CANT_START_THREAD:
|
case ERROR_CANT_START_THREAD:
|
||||||
return "Unable to create formatting thread";
|
return "Unable to create formatting thread";
|
||||||
|
case ERROR_BADBLOCKS:
|
||||||
|
return "Bad blocks detected";
|
||||||
default:
|
default:
|
||||||
uprintf("StrError: hit default - %08X\n", error_code);
|
uprintf("StrError: hit default - %08X\n", error_code);
|
||||||
SetLastError(error_code);
|
SetLastError(error_code);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue