From: Jan Janssen Date: Tue, 18 Jan 2022 11:24:26 +0000 (+0100) Subject: boot: Search for the partition node directly X-Git-Tag: v251-rc1~505^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=45a24eb7e991eba9c2aff6e981617a3634666ef5;p=thirdparty%2Fsystemd.git boot: Search for the partition node directly Some firmware creates partition device paths without a messaging device path node, making the search for the xboot loader partition fail. Fixes: #17756 --- diff --git a/src/boot/efi/xbootldr.c b/src/boot/efi/xbootldr.c index 4972877d209..26b77c93448 100644 --- a/src/boot/efi/xbootldr.c +++ b/src/boot/efi/xbootldr.c @@ -12,20 +12,17 @@ union GptHeaderBuffer { uint8_t space[CONST_ALIGN_TO(sizeof(EFI_PARTITION_TABLE_HEADER), 512)]; }; -static EFI_DEVICE_PATH *path_parent(EFI_DEVICE_PATH *path, EFI_DEVICE_PATH *node) { - EFI_DEVICE_PATH *parent; - UINTN len; - +static EFI_DEVICE_PATH *path_chop(EFI_DEVICE_PATH *path, EFI_DEVICE_PATH *node) { assert(path); assert(node); - len = (UINT8*) NextDevicePathNode(node) - (UINT8*) path; - parent = (EFI_DEVICE_PATH*) xallocate_pool(len + sizeof(EFI_DEVICE_PATH)); + UINTN len = (UINT8 *) node - (UINT8 *) path; + EFI_DEVICE_PATH *chopped = xallocate_pool(len + END_DEVICE_PATH_LENGTH); - CopyMem(parent, path, len); - CopyMem((UINT8*) parent + len, EndDevicePath, sizeof(EFI_DEVICE_PATH)); + CopyMem(chopped, path, len); + SetDevicePathEndNode((EFI_DEVICE_PATH *) ((UINT8 *) chopped + len)); - return parent; + return chopped; } static BOOLEAN verify_gpt(union GptHeaderBuffer *gpt_header_buffer, EFI_LBA lba_expected) { @@ -183,13 +180,14 @@ static EFI_STATUS find_device( EFI_BLOCK_IO *block_io; EFI_DEVICE_PATH *p; - /* First, Let's look for the SCSI/SATA/USB/… device path node, i.e. one above the media - * devices */ - if (DevicePathType(node) != MESSAGING_DEVICE_PATH) + if (DevicePathType(node) != MEDIA_DEVICE_PATH) + continue; + + if (DevicePathSubType(node) != MEDIA_HARDDRIVE_DP) continue; - /* Determine the device path one level up */ - disk_path = p = path_parent(partition_path, node); + /* Chop off the partition part, leaving us with the path to the disk itself. */ + disk_path = p = path_chop(partition_path, node); if (!disk_path) continue;