From ee4e1d5807ebbf340aa466756cc1182b7421a0b0 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Mon, 23 Jul 2018 20:36:25 +0000 Subject: [PATCH] Implement efi_devpath_to_media_path Takes a generic device path as its input. Scans through it to find the first media_path node in it and returns a pointer to it. If none is found, NULL is returned. Sponsored by: Netflix --- stand/efi/include/efilib.h | 1 + stand/efi/libefi/devpath.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/stand/efi/include/efilib.h b/stand/efi/include/efilib.h index 91a7e95f1c22..4272d321e70b 100644 --- a/stand/efi/include/efilib.h +++ b/stand/efi/include/efilib.h @@ -88,6 +88,7 @@ bool efi_devpath_match(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *); bool efi_devpath_is_prefix(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *); CHAR16 *efi_devpath_name(EFI_DEVICE_PATH *); void efi_free_devpath_name(CHAR16 *); +EFI_DEVICE_PATH *efi_devpath_to_media_path(EFI_DEVICE_PATH *); int efi_status_to_errno(EFI_STATUS); EFI_STATUS errno_to_efi_status(int errno); diff --git a/stand/efi/libefi/devpath.c b/stand/efi/libefi/devpath.c index f881cfce9896..f02a145eed8b 100644 --- a/stand/efi/libefi/devpath.c +++ b/stand/efi/libefi/devpath.c @@ -195,3 +195,19 @@ efi_devpath_is_prefix(EFI_DEVICE_PATH *prefix, EFI_DEVICE_PATH *path) } return (true); } + +/* + * Skip over the 'prefix' part of path and return the part of the path + * that starts with the first node that's a MEDIA_DEVICE_PATH. + */ +EFI_DEVICE_PATH * +efi_devpath_to_media_path(EFI_DEVICE_PATH *path) +{ + + while (!IsDevicePathEnd(path)) { + if (DevicePathType(path) == MEDIA_DEVICE_PATH) + return (path); + path = NextDevicePathNode(path); + } + return (NULL); +}