[ext2fs] use physical + offset always for extfs partition creation

This commit is contained in:
Pete Batard 2020-09-10 17:50:06 +01:00
parent 1e56c8812e
commit f04ed61805
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
4 changed files with 31 additions and 11 deletions

View file

@ -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
*/