From 39f9566070810759b068a28a9b1bf8bc681a32c1 Mon Sep 17 00:00:00 2001 From: Download-Fritz Date: Wed, 12 Jun 2019 15:14:35 +0200 Subject: [PATCH] OcDevicePathLib: Return the number of fixed Apple DP nodes --- Include/Library/OcDevicePathLib.h | 5 ++-- .../OcBootManagementLib/DefaultEntryChoice.c | 7 ++--- Library/OcDevicePathLib/OcDevicePathLib.c | 29 ++++++++++++++----- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/Include/Library/OcDevicePathLib.h b/Include/Library/OcDevicePathLib.h index 45e72d0b..f79f4f45 100755 --- a/Include/Library/OcDevicePathLib.h +++ b/Include/Library/OcDevicePathLib.h @@ -143,10 +143,11 @@ TrailedBooterDevicePath ( On output, the device path pointer is modified to point to the remaining part of the device path. - @returns Whether the device path has been fixed successfully. + @retval -1 DevicePath could not be fixed. + @retval other The number of fixed nodes in DevicePath. **/ -BOOLEAN +INTN OcFixAppleBootDevicePath ( IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath ); diff --git a/Library/OcBootManagementLib/DefaultEntryChoice.c b/Library/OcBootManagementLib/DefaultEntryChoice.c index fb9c0839..f533775b 100644 --- a/Library/OcBootManagementLib/DefaultEntryChoice.c +++ b/Library/OcBootManagementLib/DefaultEntryChoice.c @@ -333,7 +333,7 @@ InternalGetDefaultBootEntry ( OC_BOOT_ENTRY *BootEntry; EFI_STATUS Status; - BOOLEAN Result; + INTN NumPatchedNodes; UINT32 BootNextAttributes; UINTN BootNextSize; @@ -475,7 +475,7 @@ InternalGetDefaultBootEntry ( DebugPrintDevicePath (DEBUG_INFO, "OCB: Default DP pre-fix", UefiDevicePath); UefiRemainingDevicePath = UefiDevicePath; - Result = OcFixAppleBootDevicePath (&UefiRemainingDevicePath); + NumPatchedNodes = OcFixAppleBootDevicePath (&UefiRemainingDevicePath); DebugPrintDevicePath ( DEBUG_INFO, @@ -488,7 +488,7 @@ InternalGetDefaultBootEntry ( UefiRemainingDevicePath ); - if (!Result) { + if (NumPatchedNodes == -1) { DEBUG ((DEBUG_WARN, "OCB: Failed to fix the default boot Device Path,\n")); return NULL; } @@ -535,7 +535,6 @@ InternalGetDefaultBootEntry ( &UefiRemainingDevicePath, &DeviceHandle ); - if (EFI_ERROR (Status)) { continue; } diff --git a/Library/OcDevicePathLib/OcDevicePathLib.c b/Library/OcDevicePathLib/OcDevicePathLib.c index 71dc570b..f8f09209 100755 --- a/Library/OcDevicePathLib/OcDevicePathLib.c +++ b/Library/OcDevicePathLib/OcDevicePathLib.c @@ -220,14 +220,17 @@ TrailedBooterDevicePath ( On output, the device path pointer is modified to point to the remaining part of the device path. - @returns Whether the device path has been fixed successfully. + @retval -1 DevicePath could not be fixed. + @retval other The number of fixed nodes in DevicePath. **/ -BOOLEAN +INTN OcFixAppleBootDevicePath ( IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath ) { + INTN Result; + EFI_DEVICE_PATH_PROTOCOL *OriginalDevPath; EFI_DEV_PATH_PTR InvalidNode; @@ -246,8 +249,18 @@ OcFixAppleBootDevicePath ( // modified and success is returned. // OriginalDevPath = *DevicePath; - + // + // Failure will be returned explicitly within the loop. If this loop is run + // only once, it means the Device Path had already been valid. Hence, Result + // will be 0 on termination. Shall any switch-case continue, which it needs + // to in order to patch subsequent nodes, Result will be incremented. + // + Result = -1; while (TRUE) { + if (Result != MAX_INTN) { + ++Result; + } + RemainingDevPath = OriginalDevPath; gBS->LocateDevicePath ( &gEfiDevicePathProtocolGuid, @@ -277,7 +290,7 @@ OcFixAppleBootDevicePath ( continue; } - return FALSE; + return -1; } case MSG_SASEX_DP: @@ -299,7 +312,7 @@ OcFixAppleBootDevicePath ( continue; } - return FALSE; + return -1; } default: @@ -325,7 +338,7 @@ OcFixAppleBootDevicePath ( continue; } - return FALSE; + return -1; } case ACPI_EXTENDED_DP: @@ -351,7 +364,7 @@ OcFixAppleBootDevicePath ( continue; } - return FALSE; + return -1; } default: @@ -361,7 +374,7 @@ OcFixAppleBootDevicePath ( } } - return TRUE; + return Result; } } -- GitLab