OcAppleBootPolicyLib: Do not return unused APFS handle by OC API

The handle is unused by all calls within OC and finding it has a considerable overhead considering scanning many partitions, hence limit it to Apple protocol API.
This commit is contained in:
Download-Fritz 2020-05-07 17:31:19 +02:00
parent f2e2edc4fe
commit b7bb88473f
2 changed files with 57 additions and 36 deletions

View File

@ -103,17 +103,11 @@ OcBootPolicyGetBootFileEx (
/**
Retrieves information about DevicePath.
@param[in] DevicePath
@param[in] PredefinedPaths An array of file paths to scan for if no file
was blessed.
@param[in] NumPredefinedPaths The number of paths in PredefinedPaths.
@param[in] DevicePath The device path to describe.
@param[out] BootPathName A pointer into which the folder portion of
DevicePath is returned.
@param[out] Device A pointer into which the device handle of
DevicePath is returned.
@param[out] ApfsVolumeHandle A pointer into which the device handle of the
APFS volume DevicePath refers is returned if
it is bootable, or NULL otherwise.
@retval EFI_SUCCESS The operation has been completed successfully.
@retval other DevicePath is not a valid file path.
@ -121,11 +115,8 @@ OcBootPolicyGetBootFileEx (
EFI_STATUS
OcBootPolicyDevicePathToDirPath (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN CONST CHAR16 **PredefinedPaths,
IN UINTN NumPredefinedPaths,
OUT CHAR16 **BootPathName,
OUT EFI_HANDLE *Device,
OUT EFI_HANDLE *ApfsVolumeHandle
OUT EFI_HANDLE *Device
);
/**

View File

@ -1055,6 +1055,40 @@ BootPolicyGetBootFileEx (
EFI_STATUS
OcBootPolicyDevicePathToDirPath (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
OUT CHAR16 **BootPathName,
OUT EFI_HANDLE *Device
)
{
EFI_STATUS Status;
ASSERT (DevicePath != NULL);
ASSERT (BootPathName != NULL);
ASSERT (Device != NULL);
*BootPathName = NULL;
*Device = NULL;
Status = gBS->LocateDevicePath (
&gEfiSimpleFileSystemProtocolGuid,
&DevicePath,
Device
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = InternalGetBootPathName (DevicePath, BootPathName);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
STATIC
EFI_STATUS
OcBootPolicyDevicePathToDirPathAndApfsHandle (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN CONST CHAR16 **PredefinedPaths,
IN UINTN NumPredefinedPaths,
@ -1063,44 +1097,30 @@ OcBootPolicyDevicePathToDirPath (
OUT EFI_HANDLE *ApfsVolumeHandle
)
{
EFI_STATUS Status;
EFI_HANDLE DeviceHandle;
CHAR16 *PathName;
EFI_STATUS Status;
ASSERT (DevicePath != NULL);
ASSERT (BootPathName != NULL);
ASSERT (Device != NULL);
ASSERT (ApfsVolumeHandle != NULL);
*BootPathName = NULL;
*Device = NULL;
*ApfsVolumeHandle = NULL;
Status = gBS->LocateDevicePath (
&gEfiSimpleFileSystemProtocolGuid,
&DevicePath,
&DeviceHandle
);
Status = OcBootPolicyDevicePathToDirPath (
DevicePath,
BootPathName,
Device
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = InternalGetBootPathName (DevicePath, &PathName);
if (EFI_ERROR (Status)) {
return Status;
}
*Device = DeviceHandle;
*BootPathName = PathName;
//
// InternalGetApfsVolumeHandle status code is ignored, as ApfsVolumeHandle
// may not exist.
//
*ApfsVolumeHandle = NULL;
(VOID) InternalGetApfsVolumeHandle (
DeviceHandle,
PathName,
*Device,
*BootPathName,
PredefinedPaths,
NumPredefinedPaths,
ApfsVolumeHandle
@ -1118,6 +1138,8 @@ BootPolicyDevicePathToDirPath (
OUT EFI_HANDLE *ApfsVolumeHandle
)
{
EFI_STATUS Status;
if (DevicePath == NULL
|| BootPathName == NULL
|| Device == NULL
@ -1125,7 +1147,7 @@ BootPolicyDevicePathToDirPath (
return EFI_INVALID_PARAMETER;
}
return OcBootPolicyDevicePathToDirPath (
Status = OcBootPolicyDevicePathToDirPathAndApfsHandle (
DevicePath,
gAppleBootPolicyPredefinedPaths,
ARRAY_SIZE (gAppleBootPolicyPredefinedPaths),
@ -1133,6 +1155,14 @@ BootPolicyDevicePathToDirPath (
Device,
ApfsVolumeHandle
);
if (EFI_ERROR (Status)) {
*BootPathName = NULL;
*Device = NULL;
*ApfsVolumeHandle = NULL;
return Status;
}
return EFI_SUCCESS;
}
EFI_STATUS
@ -1185,7 +1215,7 @@ OcBootPolicyGetApfsRecoveryFilePath (
*Root = NULL;
*FullPathName = NULL;
Status = OcBootPolicyDevicePathToDirPath (
Status = OcBootPolicyDevicePathToDirPathAndApfsHandle (
DevicePath,
PredefinedPaths,
NumPredefinedPaths,