mirror of
				https://github.com/pbatard/rufus.git
				synced 2024-08-14 23:57:05 +00:00 
			
		
		
		
	[misc] small enhancements
* Add detection for user cancellation during between atomic format operations * Clear existing PBR along with MBR/GPT data * Improve log messages
This commit is contained in:
		
							parent
							
								
									26f807530d
								
							
						
					
					
						commit
						22808893bc
					
				
					 4 changed files with 27 additions and 18 deletions
				
			
		|  | @ -216,7 +216,6 @@ HANDLE GetLogicalHandle(DWORD DriveIndex, BOOL bWriteAccess, BOOL bLockDrive) | ||||||
| 
 | 
 | ||||||
| /*
 | /*
 | ||||||
|  * Returns the first drive letter for a volume located on the drive identified by DriveIndex |  * Returns the first drive letter for a volume located on the drive identified by DriveIndex | ||||||
|  * TODO: should we return all the drive letters? |  | ||||||
|  */ |  */ | ||||||
| char GetDriveLetter(DWORD DriveIndex) | char GetDriveLetter(DWORD DriveIndex) | ||||||
| { | { | ||||||
|  | @ -456,7 +455,7 @@ BOOL GetDrivePartitionData(DWORD DriveIndex, char* FileSystemName, DWORD FileSys | ||||||
| 	// Populate the filesystem data
 | 	// Populate the filesystem data
 | ||||||
| 	volume_name = GetLogicalName(DriveIndex, TRUE); | 	volume_name = GetLogicalName(DriveIndex, TRUE); | ||||||
| 	if ((volume_name == NULL) || (!GetVolumeInformationA(volume_name, NULL, 0, NULL, NULL, NULL, FileSystemName, FileSystemNameSize))) { | 	if ((volume_name == NULL) || (!GetVolumeInformationA(volume_name, NULL, 0, NULL, NULL, NULL, FileSystemName, FileSystemNameSize))) { | ||||||
| 		uprintf("Did not get volume information for disk 0x%02x\n", DriveIndex); | 		uprintf("No volume information for disk 0x%02x\n", DriveIndex); | ||||||
| 		FileSystemName[0] = 0; | 		FileSystemName[0] = 0; | ||||||
| 	} | 	} | ||||||
| 	safe_free(volume_name); | 	safe_free(volume_name); | ||||||
|  |  | ||||||
							
								
								
									
										26
									
								
								src/format.c
									
										
									
									
									
								
							
							
						
						
									
										26
									
								
								src/format.c
									
										
									
									
									
								
							|  | @ -328,7 +328,7 @@ static DWORD GetFATSizeSectors(DWORD DskSize, DWORD ReservedSecCnt, DWORD SecPer | ||||||
|  * Large FAT32 volume formatting from fat32format by Tom Thornhill |  * Large FAT32 volume formatting from fat32format by Tom Thornhill | ||||||
|  * http://www.ridgecrop.demon.co.uk/index.htm?fat32format.htm
 |  * http://www.ridgecrop.demon.co.uk/index.htm?fat32format.htm
 | ||||||
|  */ |  */ | ||||||
| // TODO: disable slow format for > 32 GB FAT32
 | // TODO: (v1.3.4) disable slow format for > 32 GB FAT32
 | ||||||
| static BOOL FormatFAT32(DWORD DriveIndex) | static BOOL FormatFAT32(DWORD DriveIndex) | ||||||
| { | { | ||||||
| 	BOOL r = FALSE; | 	BOOL r = FALSE; | ||||||
|  | @ -759,15 +759,13 @@ static BOOL AnalyzePBR(HANDLE hLogicalVolume) | ||||||
| 	return TRUE; | 	return TRUE; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // TODO: We may have to clear a few more sectors past the MBR buffer zone
 |  | ||||||
| // so that Windows relinquishes access
 |  | ||||||
| static BOOL ClearMBRGPT(HANDLE hPhysicalDrive, LONGLONG DiskSize, DWORD SectorSize) | static BOOL ClearMBRGPT(HANDLE hPhysicalDrive, LONGLONG DiskSize, DWORD SectorSize) | ||||||
| { | { | ||||||
| 	BOOL r = FALSE; | 	BOOL r = FALSE; | ||||||
| 	uint64_t i, last_sector = DiskSize/SectorSize; | 	uint64_t i, last_sector = DiskSize/SectorSize; | ||||||
| 	unsigned char* pBuf = (unsigned char*) calloc(SectorSize, 1); | 	unsigned char* pBuf = (unsigned char*) calloc(SectorSize, 1); | ||||||
| 
 | 
 | ||||||
| 	PrintStatus(0, TRUE, "Clearing MBR/GPT structures..."); | 	PrintStatus(0, TRUE, "Clearing MBR/PBR/GPT structures..."); | ||||||
| 	if (pBuf == NULL) { | 	if (pBuf == NULL) { | ||||||
| 		FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_NOT_ENOUGH_MEMORY; | 		FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_NOT_ENOUGH_MEMORY; | ||||||
| 		goto out; | 		goto out; | ||||||
|  | @ -785,6 +783,13 @@ static BOOL ClearMBRGPT(HANDLE hPhysicalDrive, LONGLONG DiskSize, DWORD SectorSi | ||||||
| 			goto out; | 			goto out; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | 	// Also attempt to clear the PBR, usually located at the 1 MB mark
 | ||||||
|  | 	for (i=1024*1024/SectorSize; i<MAX_SECTORS_TO_CLEAR; i++) { | ||||||
|  | 		if ((IS_ERROR(FormatStatus)) || (write_sectors(hPhysicalDrive, SectorSize, i, 1, pBuf) != SectorSize)) { | ||||||
|  | 			goto out; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	r = TRUE; | 	r = TRUE; | ||||||
| 
 | 
 | ||||||
| out: | out: | ||||||
|  | @ -1205,7 +1210,7 @@ DWORD WINAPI FormatThread(LPVOID param) | ||||||
| 		} | 		} | ||||||
| 	} else if (!DeleteVolumeMountPointA(drive_name)) { | 	} else if (!DeleteVolumeMountPointA(drive_name)) { | ||||||
| 		uprintf("Failed to delete mountpoint %s: %s\n", drive_name, WindowsErrorString()); | 		uprintf("Failed to delete mountpoint %s: %s\n", drive_name, WindowsErrorString()); | ||||||
| 		// TODO: generate an error?
 | 		// Try to continue. We will bail out if this causes an issue.
 | ||||||
| 	} | 	} | ||||||
| 	uprintf("Will use '%c': as volume mountpoint\n", drive_name[0]); | 	uprintf("Will use '%c': as volume mountpoint\n", drive_name[0]); | ||||||
| 
 | 
 | ||||||
|  | @ -1216,6 +1221,7 @@ DWORD WINAPI FormatThread(LPVOID param) | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
| 	UnmountVolume(hLogicalVolume); | 	UnmountVolume(hLogicalVolume); | ||||||
|  | 	if (FormatStatus) goto out;	// Check for user cancel
 | ||||||
| 
 | 
 | ||||||
| 	PrintStatus(0, TRUE, "Analyzing existing boot records...\n"); | 	PrintStatus(0, TRUE, "Analyzing existing boot records...\n"); | ||||||
| 	AnalyzeMBR(hPhysicalDrive); | 	AnalyzeMBR(hPhysicalDrive); | ||||||
|  | @ -1292,8 +1298,7 @@ DWORD WINAPI FormatThread(LPVOID param) | ||||||
| 	} | 	} | ||||||
| 	hLogicalVolume = INVALID_HANDLE_VALUE; | 	hLogicalVolume = INVALID_HANDLE_VALUE; | ||||||
| 
 | 
 | ||||||
| 	// TODO: check for cancel once in a while!
 | 	// TODO: (v1.4) Our start button should become cancel instead of close
 | ||||||
| 	// TODO: our start button should become cancel instead of close
 |  | ||||||
| 
 | 
 | ||||||
| 	// Especially after destructive badblocks test, you must zero the MBR/GPT completely
 | 	// Especially after destructive badblocks test, you must zero the MBR/GPT completely
 | ||||||
| 	// before repartitioning. Else, all kind of bad things can happen.
 | 	// before repartitioning. Else, all kind of bad things can happen.
 | ||||||
|  | @ -1303,6 +1308,7 @@ DWORD WINAPI FormatThread(LPVOID param) | ||||||
| 			FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT; | 			FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT; | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
|  | 	if (FormatStatus) goto out;	// Check for user cancel
 | ||||||
| 	UpdateProgress(OP_ZERO_MBR, -1.0f); | 	UpdateProgress(OP_ZERO_MBR, -1.0f); | ||||||
| 
 | 
 | ||||||
| 	CreateThread(NULL, 0, CloseFormatPromptThread, NULL, 0, NULL); | 	CreateThread(NULL, 0, CloseFormatPromptThread, NULL, 0, NULL); | ||||||
|  | @ -1342,6 +1348,7 @@ DWORD WINAPI FormatThread(LPVOID param) | ||||||
| 		} | 		} | ||||||
| 		UpdateProgress(OP_FIX_MBR, -1.0f); | 		UpdateProgress(OP_FIX_MBR, -1.0f); | ||||||
| 	} | 	} | ||||||
|  | 	if (FormatStatus) goto out;	// Check for user cancel
 | ||||||
| 
 | 
 | ||||||
| 	if (!SetVolumeMountPointA(drive_name, guid_volume)) { | 	if (!SetVolumeMountPointA(drive_name, guid_volume)) { | ||||||
| 		uprintf("Could not remount %s on %s: %s\n", guid_volume, drive_name, WindowsErrorString()); | 		uprintf("Could not remount %s on %s: %s\n", guid_volume, drive_name, WindowsErrorString()); | ||||||
|  | @ -1386,12 +1393,14 @@ DWORD WINAPI FormatThread(LPVOID param) | ||||||
| 		if (IsChecked(IDC_SET_ICON)) | 		if (IsChecked(IDC_SET_ICON)) | ||||||
| 			SetAutorun(drive_name); | 			SetAutorun(drive_name); | ||||||
| 	} | 	} | ||||||
|  | 	if (FormatStatus) goto out;	// Check for user cancel
 | ||||||
| 
 | 
 | ||||||
| 	// We issue a complete remount of the filesystem at on account of:
 | 	// We issue a complete remount of the filesystem at on account of:
 | ||||||
| 	// - Ensuring the file explorer properly detects that the volume was updated
 | 	// - Ensuring the file explorer properly detects that the volume was updated
 | ||||||
| 	// - Ensuring that an NTFS system will be reparsed so that it becomes bootable
 | 	// - Ensuring that an NTFS system will be reparsed so that it becomes bootable
 | ||||||
| 	if (!RemountVolume(drive_name[0])) | 	if (!RemountVolume(drive_name[0])) | ||||||
| 		goto out; | 		goto out; | ||||||
|  | 	if (FormatStatus) goto out;	// Check for user cancel
 | ||||||
| 
 | 
 | ||||||
| 	if (IsChecked(IDC_BOOT)) { | 	if (IsChecked(IDC_BOOT)) { | ||||||
| 		if ((dt == DT_WINME) || (dt == DT_FREEDOS)) { | 		if ((dt == DT_WINME) || (dt == DT_FREEDOS)) { | ||||||
|  | @ -1413,8 +1422,7 @@ DWORD WINAPI FormatThread(LPVOID param) | ||||||
| 					goto out; | 					goto out; | ||||||
| 				} | 				} | ||||||
| 				if ((bt == BT_UEFI) && (!iso_report.has_efi) && (iso_report.has_win7_efi)) { | 				if ((bt == BT_UEFI) && (!iso_report.has_efi) && (iso_report.has_win7_efi)) { | ||||||
| 					// TODO: better progress
 | 					// TODO: (v1.3.4) check ISO with EFI only
 | ||||||
| 					// TODO: check ISO with EFI only
 |  | ||||||
| 					PrintStatus(0, TRUE, "Win7 EFI boot setup (this may take a while)..."); | 					PrintStatus(0, TRUE, "Win7 EFI boot setup (this may take a while)..."); | ||||||
| 					wim_image[0] = drive_name[0]; | 					wim_image[0] = drive_name[0]; | ||||||
| 					efi_dst[0] = drive_name[0]; | 					efi_dst[0] = drive_name[0]; | ||||||
|  |  | ||||||
|  | @ -1676,6 +1676,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA | ||||||
| 						FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_CANT_START_THREAD); | 						FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_CANT_START_THREAD); | ||||||
| 						PostMessage(hMainDialog, UM_FORMAT_COMPLETED, 0, 0); | 						PostMessage(hMainDialog, UM_FORMAT_COMPLETED, 0, 0); | ||||||
| 					} | 					} | ||||||
|  | 					uprintf("\r\nFormat operation started"); | ||||||
| 					PrintStatus(0, FALSE, ""); | 					PrintStatus(0, FALSE, ""); | ||||||
| 					timer = 0; | 					timer = 0; | ||||||
| 					safe_sprintf(szTimer, sizeof(szTimer), "00:00:00"); | 					safe_sprintf(szTimer, sizeof(szTimer), "00:00:00"); | ||||||
|  | @ -1720,6 +1721,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA | ||||||
| 		EnableWindow(GetDlgItem(hISOProgressDlg, IDC_ISO_ABORT), TRUE); | 		EnableWindow(GetDlgItem(hISOProgressDlg, IDC_ISO_ABORT), TRUE); | ||||||
| 		EnableWindow(GetDlgItem(hMainDialog, IDCANCEL), TRUE); | 		EnableWindow(GetDlgItem(hMainDialog, IDCANCEL), TRUE); | ||||||
| 		EnableControls(TRUE); | 		EnableControls(TRUE); | ||||||
|  | 		uprintf("\r\n"); | ||||||
| 		GetUSBDevices(DeviceNum); | 		GetUSBDevices(DeviceNum); | ||||||
| 		if (!IS_ERROR(FormatStatus)) { | 		if (!IS_ERROR(FormatStatus)) { | ||||||
| 			// This is the only way to achieve instantenous progress transition to 100%
 | 			// This is the only way to achieve instantenous progress transition to 100%
 | ||||||
|  | @ -1910,7 +1912,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine | ||||||
| 	UpdateWindow(hDlg); | 	UpdateWindow(hDlg); | ||||||
| 
 | 
 | ||||||
| 	// Do our own event processing and process "magic" commands
 | 	// Do our own event processing and process "magic" commands
 | ||||||
| 	// TODO: Cheat modes are not handled when the log is at the front - this sucks
 | 	// TODO: (v1.4) Cheat modes are not handled when the log is at the front - this sucks
 | ||||||
| 	while(GetMessage(&msg, NULL, 0, 0)) { | 	while(GetMessage(&msg, NULL, 0, 0)) { | ||||||
| 		// The following ensures the processing of the ISO progress window messages
 | 		// The following ensures the processing of the ISO progress window messages
 | ||||||
| 		if (!IsWindow(hISOProgressDlg) || !IsDialogMessage(hISOProgressDlg, &msg)) { | 		if (!IsWindow(hISOProgressDlg) || !IsDialogMessage(hISOProgressDlg, &msg)) { | ||||||
|  | @ -1922,7 +1924,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine | ||||||
| 				PrintStatus2000("ISO size check", iso_size_check); | 				PrintStatus2000("ISO size check", iso_size_check); | ||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
| 			// TODO: move this option to advanced mode
 | 			// TODO: (v1.4) move this option to advanced mode
 | ||||||
| 			// Alt-F => Toggle detection of fixed disks
 | 			// Alt-F => Toggle detection of fixed disks
 | ||||||
| 			// By default Rufus does not allow formatting USB fixed disk drives, such as USB HDDs
 | 			// By default Rufus does not allow formatting USB fixed disk drives, such as USB HDDs
 | ||||||
| 			// This is a safety feature, to avoid someone unintentionally formatting a backup 
 | 			// This is a safety feature, to avoid someone unintentionally formatting a backup 
 | ||||||
|  |  | ||||||
							
								
								
									
										10
									
								
								src/rufus.rc
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								src/rufus.rc
									
										
									
									
									
								
							|  | @ -30,7 +30,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL | ||||||
| IDD_DIALOG DIALOGEX 12, 12, 206, 316 | IDD_DIALOG DIALOGEX 12, 12, 206, 316 | ||||||
| STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU | ||||||
| EXSTYLE WS_EX_APPWINDOW | EXSTYLE WS_EX_APPWINDOW | ||||||
| CAPTION "Rufus v1.3.3.243" | CAPTION "Rufus v1.3.3.244" | ||||||
| FONT 8, "MS Shell Dlg", 400, 0, 0x1 | FONT 8, "MS Shell Dlg", 400, 0, 0x1 | ||||||
| BEGIN | BEGIN | ||||||
|     DEFPUSHBUTTON   "Start",IDC_START,94,278,50,14 |     DEFPUSHBUTTON   "Start",IDC_START,94,278,50,14 | ||||||
|  | @ -274,8 +274,8 @@ END | ||||||
| // | // | ||||||
| 
 | 
 | ||||||
| VS_VERSION_INFO VERSIONINFO | VS_VERSION_INFO VERSIONINFO | ||||||
|  FILEVERSION 1,3,3,243 |  FILEVERSION 1,3,3,244 | ||||||
|  PRODUCTVERSION 1,3,3,243 |  PRODUCTVERSION 1,3,3,244 | ||||||
|  FILEFLAGSMASK 0x3fL |  FILEFLAGSMASK 0x3fL | ||||||
| #ifdef _DEBUG | #ifdef _DEBUG | ||||||
|  FILEFLAGS 0x1L |  FILEFLAGS 0x1L | ||||||
|  | @ -292,13 +292,13 @@ BEGIN | ||||||
|         BEGIN |         BEGIN | ||||||
|             VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" |             VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" | ||||||
|             VALUE "FileDescription", "Rufus" |             VALUE "FileDescription", "Rufus" | ||||||
|             VALUE "FileVersion", "1.3.3.243" |             VALUE "FileVersion", "1.3.3.244" | ||||||
|             VALUE "InternalName", "Rufus" |             VALUE "InternalName", "Rufus" | ||||||
|             VALUE "LegalCopyright", "(c) 2011-2013 Pete Batard (GPL v3)" |             VALUE "LegalCopyright", "(c) 2011-2013 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.3.3.243" |             VALUE "ProductVersion", "1.3.3.244" | ||||||
|         END |         END | ||||||
|     END |     END | ||||||
|     BLOCK "VarFileInfo" |     BLOCK "VarFileInfo" | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue