1
1
Fork 0
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:
Pete Batard 2020-10-25 12:31:30 +00:00
parent a17ca005ce
commit 8085a2846d
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
4 changed files with 27 additions and 40 deletions

View file

@ -74,7 +74,7 @@ PF_TYPE_DECL(NTAPI, NTSTATUS, NtQueryVolumeInformationFile, (HANDLE, PIO_STATUS_
RUFUS_DRIVE_INFO SelectedDrive;
extern BOOL installed_uefi_ntfs, write_as_esp;
extern int nWindowsVersion, nWindowsBuildNumber;
uint64_t partition_offset[3];
uint64_t partition_offset[PI_MAX];
uint64_t persistence_size = 0;
/*
@ -93,9 +93,8 @@ BOOL SetAutoMount(BOOL enable)
DWORD size;
BOOL ret = FALSE;
hMountMgr = CreateFileA(MOUNTMGR_DOS_DEVICE_NAME, GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hMountMgr == NULL)
hMountMgr = CreateFileA(MOUNTMGR_DOS_DEVICE_NAME, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hMountMgr == INVALID_HANDLE_VALUE)
return FALSE;
ret = DeviceIoControl(hMountMgr, IOCTL_MOUNTMGR_SET_AUTO_MOUNT, &enable, sizeof(enable), NULL, 0, &size, NULL);
CloseHandle(hMountMgr);
@ -110,9 +109,8 @@ BOOL GetAutoMount(BOOL* enabled)
if (enabled == NULL)
return FALSE;
hMountMgr = CreateFileA(MOUNTMGR_DOS_DEVICE_NAME, GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hMountMgr == NULL)
hMountMgr = CreateFileA(MOUNTMGR_DOS_DEVICE_NAME, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hMountMgr == INVALID_HANDLE_VALUE)
return FALSE;
ret = DeviceIoControl(hMountMgr, IOCTL_MOUNTMGR_QUERY_AUTO_MOUNT, NULL, 0, enabled, sizeof(*enabled), &size, NULL);
CloseHandle(hMountMgr);
@ -1292,8 +1290,10 @@ BOOL ToggleEsp(DWORD DriveIndex, uint64_t PartitionOffset)
}
} else {
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;
break;
}
}
}
if (i >= DriveLayout->PartitionCount) {
@ -1853,6 +1853,8 @@ BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system, BOOL m
} else {
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) -
extra_part_size_in_tracks) * SelectedDrive.SectorsPerTrack;
}

View file

@ -41,6 +41,7 @@
#define PI_MAIN 0
#define PI_ESP 1
#define PI_CASPER 2
#define PI_MAX 3
// The following should match VDS_FSOF_FLAGS as much as possible
#define FP_FORCE 0x00000001
@ -362,7 +363,7 @@ typedef struct {
} ClusterSize[FS_MAX];
} RUFUS_DRIVE_INFO;
extern RUFUS_DRIVE_INFO SelectedDrive;
extern uint64_t partition_offset[3];
extern uint64_t partition_offset[PI_MAX];
BOOL SetAutoMount(BOOL enable);
BOOL GetAutoMount(BOOL* enabled);

View file

@ -705,7 +705,7 @@ out:
static BOOL ClearMBRGPT(HANDLE hPhysicalDrive, LONGLONG DiskSize, DWORD SectorSize, BOOL add1MB)
{
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);
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);
for (i = 0; i < num_sectors_to_clear; i++) {
for (j = 1; j <= WRITE_RETRIES; j++) {
CHECK_FOR_USER_CANCEL;
if (write_sectors(hPhysicalDrive, SectorSize, i, 1, pBuf) == SectorSize)
break;
if (j >= WRITE_RETRIES)
if (write_sectors(hPhysicalDrive, SectorSize, i, 1, pBuf) != SectorSize)
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 (j = 1; j <= WRITE_RETRIES; j++) {
CHECK_FOR_USER_CANCEL;
if (write_sectors(hPhysicalDrive, SectorSize, i, 1, pBuf) == SectorSize)
break;
if (j >= WRITE_RETRIES) {
// 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));
}
if (write_sectors(hPhysicalDrive, SectorSize, i, 1, pBuf) != SectorSize)
break;
}
r = TRUE;
@ -2195,7 +2179,7 @@ out:
safe_unlockclose(hLogicalVolume);
safe_unlockclose(hPhysicalDrive); // This can take a while
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 (MountVolume(drive_name, volume_name))
uprintf("Re-mounted volume as %C: after error", drive_name[0]);

View file

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 3.12.1711"
CAPTION "Rufus 3.12.1712"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -395,8 +395,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,12,1711,0
PRODUCTVERSION 3,12,1711,0
FILEVERSION 3,12,1712,0
PRODUCTVERSION 3,12,1712,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -414,13 +414,13 @@ BEGIN
VALUE "Comments", "https://rufus.ie"
VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "3.12.1711"
VALUE "FileVersion", "3.12.1712"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2020 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-3.12.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.12.1711"
VALUE "ProductVersion", "3.12.1712"
END
END
BLOCK "VarFileInfo"