mirror of
https://github.com/pbatard/rufus.git
synced 2025-05-21 10:25:12 -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
19
src/format.c
19
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue