libefi: add efi_devpath_next_instance()

UEFI device path may be path to one device, or concatenated list of instances
to different devices (textually represented as comma separated list).

Provide generic function to get next instance from device path.
Returns next instance or end node.

The use case is like:

EFI_DEVICE_PATH *node = (EFI_DEVICE_PATH *)buf;
while (!IsDevicePathEnd(node)) {
	process(node);
	node = efi_devpath_next_instance(node);
}

Where buf is pointing to either single device path or
concatenated list of device paths (such as from ConIn or ConOut).

Reviewers: imp
Differential Revision: https://reviews.freebsd.org/D40081
This commit is contained in:
Toomas Soome 2023-05-12 18:41:14 +03:00
parent 46f35bf28d
commit f2b3bf5c4d
2 changed files with 18 additions and 0 deletions

View file

@ -97,6 +97,7 @@ void efi_close_devpath(EFI_HANDLE);
EFI_HANDLE efi_devpath_handle(EFI_DEVICE_PATH *);
EFI_DEVICE_PATH *efi_devpath_last_node(EFI_DEVICE_PATH *);
EFI_DEVICE_PATH *efi_devpath_trim(EFI_DEVICE_PATH *);
EFI_DEVICE_PATH *efi_devpath_next_instance(EFI_DEVICE_PATH *);
bool efi_devpath_match(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *);
bool efi_devpath_match_node(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *);
bool efi_devpath_is_prefix(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *);

View file

@ -575,6 +575,23 @@ efi_devpath_last_node(EFI_DEVICE_PATH *devpath)
return (devpath);
}
/*
* Walk device path nodes, return next instance or end node.
*/
EFI_DEVICE_PATH *
efi_devpath_next_instance(EFI_DEVICE_PATH *devpath)
{
while (!IsDevicePathEnd(devpath)) {
devpath = NextDevicePathNode(devpath);
if (IsDevicePathEndType(devpath) &&
devpath->SubType == END_INSTANCE_DEVICE_PATH_SUBTYPE) {
devpath = NextDevicePathNode(devpath);
break;
}
}
return (devpath);
}
EFI_DEVICE_PATH *
efi_devpath_trim(EFI_DEVICE_PATH *devpath)
{