Skip to content

Commit 7eab8fa

Browse files
[FREELDR:UEFI] Determine boot partition number from device path (reactos#9376)
Determine the actual partition number, walking the boot handle's device path to find the Hard Drive media node, which carries the partition number. - Walk EFI_DEVICE_PATH_PROTOCOL for the boot handle looking for a MEDIA_HARDDRIVE_DP node. - Use HARDDRIVE_DEVICE_PATH.PartitionNumber (already 1-based per spec) as the real boot partition. CORE-11954
1 parent 47a5660 commit 7eab8fa

1 file changed

Lines changed: 32 additions & 5 deletions

File tree

‎boot/freeldr/freeldr/arch/uefi/uefidisk.c‎

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,11 +1011,38 @@ UefiSetBootpath(VOID)
10111011
/* If boot handle is a logical partition, we need to determine which partition number */
10121012
if (BootBlockIo->Media->LogicalPartition)
10131013
{
1014-
/* For logical partitions, we need to find the partition number.
1015-
* This is tricky - we'll use partition 1 as default for now. */
1016-
// TODO: Properly determine partition number from boot handle.
1017-
BootPartition = FIRST_PARTITION;
1018-
TRACE("Boot handle is logical partition, using partition %lu\n", BootPartition);
1014+
EFI_GUID DevicePathGuid = EFI_DEVICE_PATH_PROTOCOL_GUID;
1015+
EFI_DEVICE_PATH_PROTOCOL *DevicePath = NULL;
1016+
EFI_DEVICE_PATH_PROTOCOL *Node;
1017+
HARDDRIVE_DEVICE_PATH *HdNode;
1018+
1019+
BootPartition = FIRST_PARTITION; /* Fallback if the walk below fails */
1020+
1021+
Status = GlobalSystemTable->BootServices->HandleProtocol(
1022+
handles[UefiBootRootIndex],
1023+
&DevicePathGuid,
1024+
(VOID**)&DevicePath);
1025+
1026+
if (!EFI_ERROR(Status) && (DevicePath != NULL))
1027+
{
1028+
/* Walk the device path looking for the Hard Drive node */
1029+
for (Node = DevicePath; !IsDevicePathEnd(Node); Node = NextDevicePathNode(Node))
1030+
{
1031+
if (DevicePathNodeLength(Node) < sizeof(EFI_DEVICE_PATH_PROTOCOL))
1032+
break; /* Malformed path */
1033+
1034+
if ((DevicePathType(Node) == MEDIA_DEVICE_PATH) &&
1035+
(DevicePathSubType(Node) == MEDIA_HARDDRIVE_DP))
1036+
{
1037+
HdNode = (HARDDRIVE_DEVICE_PATH*)Node;
1038+
BootPartition = HdNode->PartitionNumber;
1039+
TRACE("Found partition number %lu from device path\n", BootPartition);
1040+
break;
1041+
}
1042+
}
1043+
}
1044+
1045+
TRACE("Boot handle is a logical partition, using partition %lu\n", BootPartition);
10191046
}
10201047
else
10211048
{

0 commit comments

Comments
 (0)