mirror of
				https://github.com/pbatard/rufus.git
				synced 2024-08-14 23:57:05 +00:00 
			
		
		
		
	[misc] fix small issues
* SetAutoMount()/GetAutoMount() should check for INVALID_HANDLE_VALUE and not NULL. Also we don't actually need to open MOUNTMGR_DOS_DEVICE_NAME rw to issue an IOCTL. * ToggleEsp() failed to exit properly when an ESP offset was specified. * Introduce PI_MAX to explicitly set the size of the partition_information table. * write_sectors() has write retry, so there's no need to perform one on top of it. * When we exit FormatThread(), GetLogicalName() should attempt to look for the the main partition and be silent.
This commit is contained in:
		
							parent
							
								
									a17ca005ce
								
							
						
					
					
						commit
						8085a2846d
					
				
					 4 changed files with 27 additions and 40 deletions
				
			
		
							
								
								
									
										18
									
								
								src/drive.c
									
										
									
									
									
								
							
							
						
						
									
										18
									
								
								src/drive.c
									
										
									
									
									
								
							|  | @ -74,7 +74,7 @@ PF_TYPE_DECL(NTAPI, NTSTATUS, NtQueryVolumeInformationFile, (HANDLE, PIO_STATUS_ | ||||||
| RUFUS_DRIVE_INFO SelectedDrive; | RUFUS_DRIVE_INFO SelectedDrive; | ||||||
| extern BOOL installed_uefi_ntfs, write_as_esp; | extern BOOL installed_uefi_ntfs, write_as_esp; | ||||||
| extern int nWindowsVersion, nWindowsBuildNumber; | extern int nWindowsVersion, nWindowsBuildNumber; | ||||||
| uint64_t partition_offset[3]; | uint64_t partition_offset[PI_MAX]; | ||||||
| uint64_t persistence_size = 0; | uint64_t persistence_size = 0; | ||||||
| 
 | 
 | ||||||
| /*
 | /*
 | ||||||
|  | @ -93,9 +93,8 @@ BOOL SetAutoMount(BOOL enable) | ||||||
| 	DWORD size; | 	DWORD size; | ||||||
| 	BOOL ret = FALSE; | 	BOOL ret = FALSE; | ||||||
| 
 | 
 | ||||||
| 	hMountMgr = CreateFileA(MOUNTMGR_DOS_DEVICE_NAME, GENERIC_READ|GENERIC_WRITE, | 	hMountMgr = CreateFileA(MOUNTMGR_DOS_DEVICE_NAME, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | ||||||
| 		FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | 	if (hMountMgr == INVALID_HANDLE_VALUE) | ||||||
| 	if (hMountMgr == NULL) |  | ||||||
| 		return FALSE; | 		return FALSE; | ||||||
| 	ret = DeviceIoControl(hMountMgr, IOCTL_MOUNTMGR_SET_AUTO_MOUNT, &enable, sizeof(enable), NULL, 0, &size, NULL); | 	ret = DeviceIoControl(hMountMgr, IOCTL_MOUNTMGR_SET_AUTO_MOUNT, &enable, sizeof(enable), NULL, 0, &size, NULL); | ||||||
| 	CloseHandle(hMountMgr); | 	CloseHandle(hMountMgr); | ||||||
|  | @ -110,9 +109,8 @@ BOOL GetAutoMount(BOOL* enabled) | ||||||
| 
 | 
 | ||||||
| 	if (enabled == NULL) | 	if (enabled == NULL) | ||||||
| 		return FALSE; | 		return FALSE; | ||||||
| 	hMountMgr = CreateFileA(MOUNTMGR_DOS_DEVICE_NAME, GENERIC_READ|GENERIC_WRITE, | 	hMountMgr = CreateFileA(MOUNTMGR_DOS_DEVICE_NAME, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | ||||||
| 		FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | 	if (hMountMgr == INVALID_HANDLE_VALUE) | ||||||
| 	if (hMountMgr == NULL) |  | ||||||
| 		return FALSE; | 		return FALSE; | ||||||
| 	ret = DeviceIoControl(hMountMgr, IOCTL_MOUNTMGR_QUERY_AUTO_MOUNT, NULL, 0, enabled, sizeof(*enabled), &size, NULL); | 	ret = DeviceIoControl(hMountMgr, IOCTL_MOUNTMGR_QUERY_AUTO_MOUNT, NULL, 0, enabled, sizeof(*enabled), &size, NULL); | ||||||
| 	CloseHandle(hMountMgr); | 	CloseHandle(hMountMgr); | ||||||
|  | @ -1292,8 +1290,10 @@ BOOL ToggleEsp(DWORD DriveIndex, uint64_t PartitionOffset) | ||||||
| 		} | 		} | ||||||
| 	} else { | 	} else { | ||||||
| 		for (i = 0, j = 0; i < DriveLayout->PartitionCount; i++) { | 		for (i = 0, j = 0; i < DriveLayout->PartitionCount; i++) { | ||||||
| 			if (DriveLayout->PartitionEntry[i].StartingOffset.QuadPart == PartitionOffset) | 			if (DriveLayout->PartitionEntry[i].StartingOffset.QuadPart == PartitionOffset) { | ||||||
| 				DriveLayout->PartitionEntry[i].Gpt.PartitionType = PARTITION_GENERIC_ESP; | 				DriveLayout->PartitionEntry[i].Gpt.PartitionType = PARTITION_GENERIC_ESP; | ||||||
|  | 				break; | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	if (i >= DriveLayout->PartitionCount) { | 	if (i >= DriveLayout->PartitionCount) { | ||||||
|  | @ -1853,6 +1853,8 @@ BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system, BOOL m | ||||||
| 		} else { | 		} else { | ||||||
| 			assert(FALSE); | 			assert(FALSE); | ||||||
| 		} | 		} | ||||||
|  | 		// NB: Because we already subtracted the backup GPT size from the main partition size and
 | ||||||
|  | 		// this extra partition is indexed on main size, it does not overflow into the backup GPT.
 | ||||||
| 		main_part_size_in_sectors = ((main_part_size_in_sectors / SelectedDrive.SectorsPerTrack) - | 		main_part_size_in_sectors = ((main_part_size_in_sectors / SelectedDrive.SectorsPerTrack) - | ||||||
| 			extra_part_size_in_tracks) * SelectedDrive.SectorsPerTrack; | 			extra_part_size_in_tracks) * SelectedDrive.SectorsPerTrack; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -41,6 +41,7 @@ | ||||||
| #define PI_MAIN                             0 | #define PI_MAIN                             0 | ||||||
| #define PI_ESP                              1 | #define PI_ESP                              1 | ||||||
| #define PI_CASPER                           2 | #define PI_CASPER                           2 | ||||||
|  | #define PI_MAX                              3 | ||||||
| 
 | 
 | ||||||
| // The following should match VDS_FSOF_FLAGS as much as possible
 | // The following should match VDS_FSOF_FLAGS as much as possible
 | ||||||
| #define FP_FORCE                            0x00000001 | #define FP_FORCE                            0x00000001 | ||||||
|  | @ -362,7 +363,7 @@ typedef struct { | ||||||
| 	} ClusterSize[FS_MAX]; | 	} ClusterSize[FS_MAX]; | ||||||
| } RUFUS_DRIVE_INFO; | } RUFUS_DRIVE_INFO; | ||||||
| extern RUFUS_DRIVE_INFO SelectedDrive; | extern RUFUS_DRIVE_INFO SelectedDrive; | ||||||
| extern uint64_t partition_offset[3]; | extern uint64_t partition_offset[PI_MAX]; | ||||||
| 
 | 
 | ||||||
| BOOL SetAutoMount(BOOL enable); | BOOL SetAutoMount(BOOL enable); | ||||||
| BOOL GetAutoMount(BOOL* enabled); | BOOL GetAutoMount(BOOL* enabled); | ||||||
|  |  | ||||||
							
								
								
									
										36
									
								
								src/format.c
									
										
									
									
									
								
							
							
						
						
									
										36
									
								
								src/format.c
									
										
									
									
									
								
							|  | @ -705,7 +705,7 @@ out: | ||||||
| static BOOL ClearMBRGPT(HANDLE hPhysicalDrive, LONGLONG DiskSize, DWORD SectorSize, BOOL add1MB) | static BOOL ClearMBRGPT(HANDLE hPhysicalDrive, LONGLONG DiskSize, DWORD SectorSize, BOOL add1MB) | ||||||
| { | { | ||||||
| 	BOOL r = FALSE; | 	BOOL r = FALSE; | ||||||
| 	uint64_t i, j, last_sector = DiskSize/SectorSize, num_sectors_to_clear; | 	uint64_t i, last_sector = DiskSize/SectorSize, num_sectors_to_clear; | ||||||
| 	unsigned char* pBuf = (unsigned char*) calloc(SectorSize, 1); | 	unsigned char* pBuf = (unsigned char*) calloc(SectorSize, 1); | ||||||
| 
 | 
 | ||||||
| 	PrintInfoDebug(0, MSG_224); | 	PrintInfoDebug(0, MSG_224); | ||||||
|  | @ -729,32 +729,16 @@ static BOOL ClearMBRGPT(HANDLE hPhysicalDrive, LONGLONG DiskSize, DWORD SectorSi | ||||||
| 
 | 
 | ||||||
| 	uprintf("Erasing %d sectors", num_sectors_to_clear); | 	uprintf("Erasing %d sectors", num_sectors_to_clear); | ||||||
| 	for (i = 0; i < num_sectors_to_clear; i++) { | 	for (i = 0; i < num_sectors_to_clear; i++) { | ||||||
| 		for (j = 1; j <= WRITE_RETRIES; j++) { | 		CHECK_FOR_USER_CANCEL; | ||||||
| 			CHECK_FOR_USER_CANCEL; | 		if (write_sectors(hPhysicalDrive, SectorSize, i, 1, pBuf) != SectorSize) | ||||||
| 			if (write_sectors(hPhysicalDrive, SectorSize, i, 1, pBuf) == SectorSize) | 			goto out; | ||||||
| 				break; |  | ||||||
| 			if (j >= WRITE_RETRIES) |  | ||||||
| 				goto out; |  | ||||||
| 			uprintf("Retrying in %d seconds...", WRITE_TIMEOUT / 1000); |  | ||||||
| 			// Don't sit idly but use the downtime to check for conflicting processes...
 |  | ||||||
| 			Sleep(CheckDriveAccess(WRITE_TIMEOUT, FALSE)); |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| 	for (i = last_sector - MAX_SECTORS_TO_CLEAR; i < last_sector; i++) { | 	for (i = last_sector - MAX_SECTORS_TO_CLEAR; i < last_sector; i++) { | ||||||
| 		for (j = 1; j <= WRITE_RETRIES; j++) { | 		CHECK_FOR_USER_CANCEL; | ||||||
| 			CHECK_FOR_USER_CANCEL; | 		// Windows seems to be an ass about keeping a lock on a backup GPT,
 | ||||||
| 			if (write_sectors(hPhysicalDrive, SectorSize, i, 1, pBuf) == SectorSize) | 		// so we try to be lenient about not being able to clear it.
 | ||||||
| 				break; | 		if (write_sectors(hPhysicalDrive, SectorSize, i, 1, pBuf) != SectorSize) | ||||||
| 			if (j >= WRITE_RETRIES) { | 			break; | ||||||
| 				// Windows seems to be an ass about keeping a lock on a backup GPT,
 |  | ||||||
| 				// so we try to be lenient about not being able to clear it.
 |  | ||||||
| 				uprintf("Warning: Failed to clear backup GPT..."); |  | ||||||
| 				r = TRUE; |  | ||||||
| 				goto out; |  | ||||||
| 			} |  | ||||||
| 			uprintf("Retrying in %d seconds...", WRITE_TIMEOUT / 1000); |  | ||||||
| 			Sleep(CheckDriveAccess(WRITE_TIMEOUT, FALSE)); |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| 	r = TRUE; | 	r = TRUE; | ||||||
| 
 | 
 | ||||||
|  | @ -2195,7 +2179,7 @@ out: | ||||||
| 	safe_unlockclose(hLogicalVolume); | 	safe_unlockclose(hLogicalVolume); | ||||||
| 	safe_unlockclose(hPhysicalDrive);	// This can take a while
 | 	safe_unlockclose(hPhysicalDrive);	// This can take a while
 | ||||||
| 	if (IS_ERROR(FormatStatus)) { | 	if (IS_ERROR(FormatStatus)) { | ||||||
| 		volume_name = GetLogicalName(DriveIndex, 0, TRUE, FALSE); | 		volume_name = GetLogicalName(DriveIndex, partition_offset[PI_MAIN], TRUE, TRUE); | ||||||
| 		if (volume_name != NULL) { | 		if (volume_name != NULL) { | ||||||
| 			if (MountVolume(drive_name, volume_name)) | 			if (MountVolume(drive_name, volume_name)) | ||||||
| 				uprintf("Re-mounted volume as %C: after error", drive_name[0]); | 				uprintf("Re-mounted volume as %C: after error", drive_name[0]); | ||||||
|  |  | ||||||
							
								
								
									
										10
									
								
								src/rufus.rc
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								src/rufus.rc
									
										
									
									
									
								
							|  | @ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL | ||||||
| IDD_DIALOG DIALOGEX 12, 12, 232, 326 | IDD_DIALOG DIALOGEX 12, 12, 232, 326 | ||||||
| STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | ||||||
| EXSTYLE WS_EX_ACCEPTFILES | EXSTYLE WS_EX_ACCEPTFILES | ||||||
| CAPTION "Rufus 3.12.1711" | CAPTION "Rufus 3.12.1712" | ||||||
| FONT 9, "Segoe UI Symbol", 400, 0, 0x0 | FONT 9, "Segoe UI Symbol", 400, 0, 0x0 | ||||||
| BEGIN | BEGIN | ||||||
|     LTEXT           "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP |     LTEXT           "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP | ||||||
|  | @ -395,8 +395,8 @@ END | ||||||
| // | // | ||||||
| 
 | 
 | ||||||
| VS_VERSION_INFO VERSIONINFO | VS_VERSION_INFO VERSIONINFO | ||||||
|  FILEVERSION 3,12,1711,0 |  FILEVERSION 3,12,1712,0 | ||||||
|  PRODUCTVERSION 3,12,1711,0 |  PRODUCTVERSION 3,12,1712,0 | ||||||
|  FILEFLAGSMASK 0x3fL |  FILEFLAGSMASK 0x3fL | ||||||
| #ifdef _DEBUG | #ifdef _DEBUG | ||||||
|  FILEFLAGS 0x1L |  FILEFLAGS 0x1L | ||||||
|  | @ -414,13 +414,13 @@ BEGIN | ||||||
|             VALUE "Comments", "https://rufus.ie" |             VALUE "Comments", "https://rufus.ie" | ||||||
|             VALUE "CompanyName", "Akeo Consulting" |             VALUE "CompanyName", "Akeo Consulting" | ||||||
|             VALUE "FileDescription", "Rufus" |             VALUE "FileDescription", "Rufus" | ||||||
|             VALUE "FileVersion", "3.12.1711" |             VALUE "FileVersion", "3.12.1712" | ||||||
|             VALUE "InternalName", "Rufus" |             VALUE "InternalName", "Rufus" | ||||||
|             VALUE "LegalCopyright", "© 2011-2020 Pete Batard (GPL v3)" |             VALUE "LegalCopyright", "© 2011-2020 Pete Batard (GPL v3)" | ||||||
|             VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" |             VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" | ||||||
|             VALUE "OriginalFilename", "rufus-3.12.exe" |             VALUE "OriginalFilename", "rufus-3.12.exe" | ||||||
|             VALUE "ProductName", "Rufus" |             VALUE "ProductName", "Rufus" | ||||||
|             VALUE "ProductVersion", "3.12.1711" |             VALUE "ProductVersion", "3.12.1712" | ||||||
|         END |         END | ||||||
|     END |     END | ||||||
|     BLOCK "VarFileInfo" |     BLOCK "VarFileInfo" | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue