diff --git a/src/drive.c b/src/drive.c index 55c08124ba7..b8cc95682e5 100644 --- a/src/drive.c +++ b/src/drive.c @@ -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; diff --git a/src/drive.h b/src/drive.h index dd6de5e952d..22b12da2937 100644 --- a/src/drive.h +++ b/src/drive.h @@ -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); diff --git a/src/format.c b/src/format.c index eadde70bc11..4d047f139ce 100644 --- a/src/format.c +++ b/src/format.c @@ -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 diff --git a/src/rufus.rc b/src/rufus.rc index 9c7c7a6272d..419a5aa6610 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -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"