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
This commit is contained in:
Warner Losh 2018-07-23 20:36:54 +00:00
parent c6c2a73c0c
commit 00a47597a3
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=336655
2 changed files with 23 additions and 0 deletions

View File

@ -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);

View File

@ -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)
{