diff options
author | Michael Brown <mcb30@ipxe.org> | 2022-12-22 13:33:38 +0000 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2022-12-22 13:34:28 +0000 |
commit | 099e4d39b355a10b0bc7d23bb0e96615bf06470b (patch) | |
tree | 0d92cb14109fe07f6055d5c67b256646629bfcc0 /src/interface/efi/efi_path.c | |
parent | 0f3ace92c6f7bd60a6688c0bacfa5aeacfdb5b73 (diff) | |
download | ipxe-099e4d39b355a10b0bc7d23bb0e96615bf06470b.tar.gz |
[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>
Diffstat (limited to 'src/interface/efi/efi_path.c')
-rw-r--r-- | src/interface/efi/efi_path.c | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/src/interface/efi/efi_path.c b/src/interface/efi/efi_path.c index 1a95a3b9a..937d3c704 100644 --- a/src/interface/efi/efi_path.c +++ b/src/interface/efi/efi_path.c @@ -41,18 +41,42 @@ */ /** + * 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 * * @v path Device path, or NULL * @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; |