Mercurial > unleashed > prev-conversion
changeset 18783:7ab45e4db310
8795 loader: add efi_devpath_is_prefix()
author | Toomas Soome <tsoome@me.com> |
---|---|
date | Fri, 10 Nov 2017 14:03:43 +0200 |
parents | 0135e7b0a761 |
children | b8cee8e8b6fe |
files | usr/src/boot/sys/boot/efi/include/efilib.h usr/src/boot/sys/boot/efi/libefi/devpath.c |
diffstat | 2 files changed, 31 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/usr/src/boot/sys/boot/efi/include/efilib.h Tue Oct 17 14:20:31 2017 +0300 +++ b/usr/src/boot/sys/boot/efi/include/efilib.h Fri Nov 10 14:03:43 2017 +0200 @@ -74,6 +74,7 @@ EFI_DEVICE_PATH *efi_devpath_last_node(EFI_DEVICE_PATH *); EFI_DEVICE_PATH *efi_devpath_trim(EFI_DEVICE_PATH *); 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 *);
--- a/usr/src/boot/sys/boot/efi/libefi/devpath.c Tue Oct 17 14:20:31 2017 +0300 +++ b/usr/src/boot/sys/boot/efi/libefi/devpath.c Fri Nov 10 14:03:43 2017 +0200 @@ -141,7 +141,7 @@ bool efi_devpath_match(EFI_DEVICE_PATH *devpath1, EFI_DEVICE_PATH *devpath2) { - size_t len; + size_t len; if (devpath1 == NULL || devpath2 == NULL) return (false); @@ -165,3 +165,32 @@ } return (true); } + +bool +efi_devpath_is_prefix(EFI_DEVICE_PATH *prefix, EFI_DEVICE_PATH *path) +{ + size_t len; + + if (prefix == NULL || path == NULL) + return (false); + + while (1) { + if (IsDevicePathEnd(prefix)) + break; + + if (DevicePathType(prefix) != DevicePathType(path) || + DevicePathSubType(prefix) != DevicePathSubType(path)) + return (false); + + len = DevicePathNodeLength(prefix); + if (len != DevicePathNodeLength(path)) + return (false); + + if (memcmp(prefix, path, len) != 0) + return (false); + + prefix = NextDevicePathNode(prefix); + path = NextDevicePathNode(path); + } + return (true); +}