[efi] Expose efi_path_next() utility function

Provide a single central implementation of the logic for stepping
through elements of an EFI device path.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2022-12-22 13:34:28 +00:00
parent 0f3ace92c6
commit 099e4d39b3
3 changed files with 41 additions and 15 deletions
+29 -5
View File
@@ -40,6 +40,31 @@
*
*/
/**
* Find next element in device path
*
* @v path Device path, or NULL
* @v next Next element in device path, or NULL if at end
*/
EFI_DEVICE_PATH_PROTOCOL * efi_path_next ( EFI_DEVICE_PATH_PROTOCOL *path ) {
/* Check for non-existent device path */
if ( ! path )
return NULL;
/* Check for end of device path */
if ( path->Type == END_DEVICE_PATH_TYPE )
return NULL;
/* Move to next component of the device path */
path = ( ( ( void * ) path ) +
/* There's this amazing new-fangled thing known as
* a UINT16, but who wants to use one of those? */
( ( path->Length[1] << 8 ) | path->Length[0] ) );
return path;
}
/**
* Find end of device path
*
@@ -47,12 +72,11 @@
* @ret path_end End of device path, or NULL
*/
EFI_DEVICE_PATH_PROTOCOL * efi_path_end ( EFI_DEVICE_PATH_PROTOCOL *path ) {
EFI_DEVICE_PATH_PROTOCOL *next;
while ( path && ( path->Type != END_DEVICE_PATH_TYPE ) ) {
path = ( ( ( void * ) path ) +
/* There's this amazing new-fangled thing known as
* a UINT16, but who wants to use one of those? */
( ( path->Length[1] << 8 ) | path->Length[0] ) );
/* Find end of device path */
while ( ( next = efi_path_next ( path ) ) != NULL ) {
path = next;
}
return path;