From f04ed618052e95f06bb7dce06fc8322cc023d9d2 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Thu, 10 Sep 2020 17:50:06 +0100 Subject: [PATCH] [ext2fs] use physical + offset always for extfs partition creation --- src/drive.c | 27 +++++++++++++++++++++++---- src/drive.h | 1 + src/format_ext.c | 4 ++-- src/rufus.rc | 10 +++++----- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/drive.c b/src/drive.c index 676f013c..783c8208 100644 --- a/src/drive.c +++ b/src/drive.c @@ -406,11 +406,7 @@ char* AltGetLogicalName(DWORD DriveIndex, uint64_t PartitionOffset, BOOL bKeepTr static_strcpy(volume_name, groot_name); if (!QueryDosDeviceA(path, &volume_name[groot_len], (DWORD)(MAX_PATH - groot_len)) || (strlen(volume_name) < 20)) { suprintf("Could not find a DOS volume name for '%s': %s", path, WindowsErrorString()); - // If we are on the right drive, we enable a custom access mode through physical + offset - if (!matching_drive) goto out; - static_sprintf(volume_name, "\\\\.\\PhysicalDrive%lu%s %I64u %I64u", DriveIndex, bKeepTrailingBackslash ? "\\" : "", - SelectedDrive.PartitionOffset[i], SelectedDrive.PartitionSize[i]); } else if (bKeepTrailingBackslash) { static_strcat(volume_name, "\\"); } @@ -420,6 +416,29 @@ out: return ret; } +/* + * Custom volume name for extfs formatting (that includes partition offset and partition size) + * so that these can be created and accessed on pre 1703 versions of Windows. + */ +char* GetExtPartitionName(DWORD DriveIndex, uint64_t PartitionOffset) +{ + DWORD i; + char* ret = NULL, volume_name[MAX_PATH]; + + // Can't operate if we're not on the selected drive + if (DriveIndex != SelectedDrive.DeviceNumber) + goto out; + CheckDriveIndex(DriveIndex); + for (i = 0; (i < MAX_PARTITIONS) && (PartitionOffset != SelectedDrive.PartitionOffset[i]); i++); + if (i >= MAX_PARTITIONS) + goto out; + static_sprintf(volume_name, "\\\\.\\PhysicalDrive%lu %I64u %I64u", DriveIndex, + SelectedDrive.PartitionOffset[i], SelectedDrive.PartitionSize[i]); + ret = safe_strdup(volume_name); +out: + return ret; +} + /* * Call on VDS to refresh the drive layout */ diff --git a/src/drive.h b/src/drive.h index 99d9cde7..1c5ccf39 100644 --- a/src/drive.h +++ b/src/drive.h @@ -371,6 +371,7 @@ BOOL DeletePartitions(DWORD DriveIndex); HANDLE GetPhysicalHandle(DWORD DriveIndex, BOOL bLockDrive, BOOL bWriteAccess, BOOL bWriteShare); char* GetLogicalName(DWORD DriveIndex, uint64_t PartitionOffset, BOOL bKeepTrailingBackslash, BOOL bSilent); char* AltGetLogicalName(DWORD DriveIndex, uint64_t PartitionOffset, BOOL bKeepTrailingBackslash, BOOL bSilent); +char* GetExtPartitionName(DWORD DriveIndex, uint64_t PartitionOffset); BOOL WaitForLogical(DWORD DriveIndex, uint64_t PartitionOffset); HANDLE GetLogicalHandle(DWORD DriveIndex, uint64_t PartitionOffset, BOOL bLockDrive, BOOL bWriteAccess, BOOL bWriteShare); int GetDriveNumber(HANDLE hDrive, char* path); diff --git a/src/format_ext.c b/src/format_ext.c index 364da35a..2769d006 100644 --- a/src/format_ext.c +++ b/src/format_ext.c @@ -203,7 +203,7 @@ const char* GetExtFsLabel(DWORD DriveIndex, uint64_t PartitionOffset) errcode_t r; ext2_filsys ext2fs = NULL; io_manager manager = nt_io_manager(); - char* volume_name = AltGetLogicalName(DriveIndex, PartitionOffset, FALSE, TRUE); + char* volume_name = GetExtPartitionName(DriveIndex, PartitionOffset); if (volume_name == NULL) return NULL; @@ -266,7 +266,7 @@ BOOL FormatExtFs(DWORD DriveIndex, uint64_t PartitionOffset, DWORD BlockSize, LP } CloseHandle(h); #else - volume_name = AltGetLogicalName(DriveIndex, PartitionOffset, FALSE, TRUE); + volume_name = GetExtPartitionName(DriveIndex, PartitionOffset); #endif if ((volume_name == NULL) | (strlen(FSName) != 4) || (strncmp(FSName, "ext", 3) != 0)) { FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_INVALID_PARAMETER; diff --git a/src/rufus.rc b/src/rufus.rc index 18616856..c7fb6546 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -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.1698" +CAPTION "Rufus 3.12.1699" 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,1698,0 - PRODUCTVERSION 3,12,1698,0 + FILEVERSION 3,12,1699,0 + PRODUCTVERSION 3,12,1699,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.1698" + VALUE "FileVersion", "3.12.1699" 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.1698" + VALUE "ProductVersion", "3.12.1699" END END BLOCK "VarFileInfo"