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

[core] work around a Windows bug that may render a disk inaccessible on cleanup

* The root of the issue is that Windows IOCTL_DISK_CREATE_DISK does not properly
  zero all of the MBR/GPT/PBR structure with PARTITION_STYLE_RAW (which is what
  diskpart uses to clean a disk), and leaves plenty of partition artefacts behind.
* This means that, when an image with complex partitioning has been applied, such
  as Chromium/ChromeOS, you may end up with a drive that can not be repartitioned
  or reformatted in Windows (and this is completely independent of whether Rufus
  was used to perform these operations - For instance you will get the same issue
  if you use Win32DiskImager and diskpart + clean).
* The only option left for users then is to reset/repartition their drives in Linux
  or some other OS, as Windows' VDS becomes incapacitated to handle the drive, as
  the problem persists independently of reset/re-plug/Windows platform being used.
* To work around this, we ensure that we zero the MBR/GPT/PBR sectors BEFORE calling
  IOCTL_DISK_CREATE_DISK.
* Also move zeroing of the drive before partition reset.
* Closes #759
This commit is contained in:
Pete Batard 2016-05-21 16:34:34 +01:00
parent 935679dd85
commit 258a4f7ca0
4 changed files with 25 additions and 23 deletions

View file

@ -1247,8 +1247,8 @@ BOOL RefreshDriveLayout(HANDLE hDrive)
return r;
}
/* Delete the disk partition table */
BOOL DeletePartitions(HANDLE hDrive)
/* Initialize disk for partitioning */
BOOL InitializeDisk(HANDLE hDrive)
{
BOOL r;
DWORD size;

View file

@ -97,6 +97,6 @@ BOOL AltUnmountVolume(const char* drive_name);
char* AltMountVolume(const char* drive_name, uint8_t part_nr);
BOOL RemountVolume(char* drive_name);
BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system, BOOL mbr_uefi_marker, uint8_t extra_partitions);
BOOL DeletePartitions(HANDLE hDrive);
BOOL InitializeDisk(HANDLE hDrive);
BOOL RefreshDriveLayout(HANDLE hDrive);
const char* GetPartitionType(BYTE Type);

View file

@ -1668,20 +1668,22 @@ DWORD WINAPI FormatThread(void* param)
UpdateProgress(OP_ANALYZE_MBR, -1.0f);
}
if (zero_drive) {
WriteDrive(hPhysicalDrive, NULL);
goto out;
}
// Zap any existing partitions. This helps prevent access errors.
// As this creates issues with FAT16 formatted MS drives, only do this for other filesystems
if ( (fs != FS_FAT16) && (!DeletePartitions(hPhysicalDrive)) ) {
// Note, Microsoft's way of cleaning partitions (IOCTL_DISK_CREATE_DISK, which is what we apply
// in InitializeDisk) is *NOT ENOUGH* to reset a disk and can render it inoperable for partitioning
// or formatting under Windows. See https://github.com/pbatard/rufus/issues/759 for details.
if ((!ClearMBRGPT(hPhysicalDrive, SelectedDrive.DiskSize, SectorSize, FALSE)) || (!InitializeDisk(hPhysicalDrive)) ) {
uprintf("Could not reset partitions\n");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_PARTITION_FAILURE;
goto out;
}
CreateThread(NULL, 0, CloseFormatPromptThread, NULL, 0, NULL);
if (zero_drive) {
WriteDrive(hPhysicalDrive, NULL);
goto out;
}
if (IsChecked(IDC_BADBLOCKS)) {
do {
// create a log file for bad blocks report. Since %USERPROFILE% may
@ -1736,15 +1738,15 @@ DWORD WINAPI FormatThread(void* param)
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_CANCELLED;
goto out;
}
}
// Especially after destructive badblocks test, you must zero the MBR/GPT completely
// before repartitioning. Else, all kind of bad things happen.
if (!ClearMBRGPT(hPhysicalDrive, SelectedDrive.DiskSize, SectorSize, use_large_fat32)) {
uprintf("unable to zero MBR/GPT\n");
if (!IS_ERROR(FormatStatus))
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT;
goto out;
// Especially after destructive badblocks test, you must zero the MBR/GPT completely
// before repartitioning. Else, all kind of bad things happen.
if (!ClearMBRGPT(hPhysicalDrive, SelectedDrive.DiskSize, SectorSize, use_large_fat32)) {
uprintf("unable to zero MBR/GPT\n");
if (!IS_ERROR(FormatStatus))
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT;
goto out;
}
}
// Write an image file

View file

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 242, 376
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 2.9.935"
CAPTION "Rufus 2.9.936"
FONT 8, "Segoe UI Symbol", 400, 0, 0x0
BEGIN
LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8
@ -320,8 +320,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 2,9,935,0
PRODUCTVERSION 2,9,935,0
FILEVERSION 2,9,936,0
PRODUCTVERSION 2,9,936,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -338,13 +338,13 @@ BEGIN
BEGIN
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "2.9.935"
VALUE "FileVersion", "2.9.936"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2016 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "2.9.935"
VALUE "ProductVersion", "2.9.936"
END
END
BLOCK "VarFileInfo"