From 00a47597a3eed2af1935be4f7cd7f71ef56aed50 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Mon, 23 Jul 2018 20:36:54 +0000 Subject: [PATCH] Implement efiblk_get_pdinfo_by_device_path Lookup a block device by it's device path. We use a 'loose' lookup whereby we scan forward to the first Media Path portion of the device path, then look at all our handles for one whose first Media Path matches. This will also work if the device path pointed to has a following file path (or paths) as that's ignored. It assumes that there's only one media path node that describes the entire device, which is true as of the latest UEFI spec (2.7 Errata A) as far as I've been able to determine. Sponsored by: Netflix --- stand/efi/include/efilib.h | 1 + stand/efi/libefi/efipart.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/stand/efi/include/efilib.h b/stand/efi/include/efilib.h index b3db5d2aadf..7288e5fb56e 100644 --- a/stand/efi/include/efilib.h +++ b/stand/efi/include/efilib.h @@ -66,6 +66,7 @@ typedef struct pdinfo pdinfo_list_t *efiblk_get_pdinfo_list(struct devsw *dev); pdinfo_t *efiblk_get_pdinfo(struct devdesc *dev); pdinfo_t *efiblk_get_pdinfo_by_handle(EFI_HANDLE h); +pdinfo_t *efiblk_get_pdinfo_by_device_path(EFI_DEVICE_PATH *path); void *efi_get_table(EFI_GUID *tbl); diff --git a/stand/efi/libefi/efipart.c b/stand/efi/libefi/efipart.c index ee7d30e545a..6f7f621b70c 100644 --- a/stand/efi/libefi/efipart.c +++ b/stand/efi/libefi/efipart.c @@ -137,6 +137,28 @@ efiblk_get_pdinfo(struct devdesc *dev) return (pd); } +pdinfo_t * +efiblk_get_pdinfo_by_device_path(EFI_DEVICE_PATH *path) +{ + unsigned i; + EFI_DEVICE_PATH *media, *devpath; + EFI_HANDLE h; + + media = efi_devpath_to_media_path(path); + if (media == NULL) + return (NULL); + for (i = 0; i < efipart_nhandles; i++) { + h = efipart_handles[i]; + devpath = efi_lookup_devpath(h); + if (devpath == NULL) + continue; + if (!efi_devpath_match_node(media, efi_devpath_to_media_path(devpath))) + continue; + return (efiblk_get_pdinfo_by_handle(h)); + } + return (NULL); +} + static bool same_handle(pdinfo_t *pd, EFI_HANDLE h) {