Skip to content
This repository has been archived by the owner on May 17, 2020. It is now read-only.

Commit

Permalink
ApfsDriverLoader: Respect OpenCore scan policy during apfs driver loa…
Browse files Browse the repository at this point in the history
…ding
  • Loading branch information
vit9696 committed Jun 19, 2019
1 parent 6aab87b commit 0a2eeb4
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 2 deletions.
10 changes: 9 additions & 1 deletion AppleSupportPkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf
PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf
HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
Expand Down Expand Up @@ -64,10 +65,17 @@
PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf
OcTimerLib|OcSupportPkg/Library/OcTimerLib/OcTimerLib.inf
OcMiscLib|OcSupportPkg/Library/OcMiscLib/OcMiscLib.inf
OcAppleBootPolicyLib|OcSupportPkg/Library/OcAppleBootPolicyLib/OcAppleBootPolicyLib.inf
OcAppleChunklistLib|OcSupportPkg/Library/OcAppleChunklistLib/OcAppleChunklistLib.inf
OcAppleDiskImageLib|OcSupportPkg/Library/OcAppleDiskImageLib/OcAppleDiskImageLib.inf
OcAppleRamDiskLib|OcSupportPkg/Library/OcAppleRamDiskLib/OcAppleRamDiskLib.inf
OcBootManagementLib|OcSupportPkg/Library/OcBootManagementLib/OcBootManagementLib.inf
OcCompressionLib|OcSupportPkg/Library/OcCompressionLib/OcCompressionLib.inf
OcDataHubLib|OcSupportPkg/Library/OcDataHubLib/OcDataHubLib.inf
OcDevicePathLib|OcSupportPkg/Library/OcDevicePathLib/OcDevicePathLib.inf
OcDevicePropertyLib|OcSupportPkg/Library/OcDevicePropertyLib/OcDevicePropertyLib.inf
OcStringLib|OcSupportPkg/Library/OcStringLib/OcStringLib.inf
OcDataHubLib|OcSupportPkg/Library/OcDataHubLib/OcDataHubLib.inf
OcXmlLib|OcSupportPkg/Library/OcXmlLib/OcXmlLib.inf
SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
PlatformHookLib|MdeModulePkg/Library/BasePlatformHookLibNull/BasePlatformHookLibNull.inf

Expand Down
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
AppleSupport Changelog
======================

#### v2.0.8
- Respect OpenCore scan policy during apfs driver loading

#### v2.0.7
- Added bless-compatible VBoxHfs driver (by @nms42)
- Added compatibility with OpenCore logging protocols
Expand Down
2 changes: 1 addition & 1 deletion Include/AppleSupportPkgVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#ifndef APPLE_SUPPORT_VERSION_H
#define APPLE_SUPPORT_VERSION_H

#define APPLE_SUPPORT_VERSION L"2.0.7"
#define APPLE_SUPPORT_VERSION L"2.0.8"


#endif // APPLE_SUPPORT_VERSION_H
57 changes: 57 additions & 0 deletions Platform/ApfsDriverLoader/ApfsDriverLoader.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <AppleSupportPkgVersion.h>
#include <Uefi/UefiGpt.h>
#include <Guid/OcVariables.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DevicePathLib.h>
Expand All @@ -26,6 +27,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/OcAppleImageVerificationLib.h>
#include <Library/OcBootManagementLib.h>
#include <Protocol/BlockIo.h>
#include <Protocol/DiskIo.h>
#include <Protocol/BlockIo2.h>
Expand Down Expand Up @@ -427,6 +429,56 @@ LegacyApfsContainerScan (

}

STATIC
EFI_STATUS
CheckOpenCoreScanPolicy (
IN EFI_HANDLE Handle
)
{
EFI_STATUS Status;
UINT32 ScanPolicy;
UINT32 OcScanPolicy;
UINTN OcScanPolicySize;

//
// If scan policy is missing, just ignore.
//
OcScanPolicy = 0;
OcScanPolicySize = sizeof (OcScanPolicy);
Status = gRT->GetVariable (
OC_SCAN_POLICY_VARIABLE_NAME,
&gOcVendorVariableGuid,
NULL,
&OcScanPolicySize,
&OcScanPolicy
);
if (EFI_ERROR (Status)) {
return EFI_SUCCESS;
}

//
// If filesystem limitations are set and APFS is not allowed,
// report failure.
//
if ((OcScanPolicy & OC_SCAN_FILE_SYSTEM_LOCK) != 0
&& (OcScanPolicy & OC_SCAN_ALLOW_FS_APFS) == 0) {
return EFI_UNSUPPORTED;
}

//
// If device type locking is set and this device is not allowed,
// report failure.
//
if ((OcScanPolicy & OC_SCAN_DEVICE_LOCK) != 0) {
ScanPolicy = OcGetDevicePolicyType (Handle, NULL);
if ((ScanPolicy & OcScanPolicy) == 0) {
return EFI_UNSUPPORTED;
}
}

return EFI_SUCCESS;
}

/**
Routine Description:
Expand Down Expand Up @@ -459,6 +511,11 @@ ApfsDriverLoaderSupported (
APPLE_PARTITION_INFO_PROTOCOL *ApplePartitionInfo = NULL;
EFI_PARTITION_INFO_PROTOCOL *Edk2PartitionInfo = NULL;

Status = CheckOpenCoreScanPolicy (ControllerHandle);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}

Status = gBS->OpenProtocol (
ControllerHandle,
&gApfsEfiBootRecordInfoProtocolGuid,
Expand Down
1 change: 1 addition & 0 deletions Platform/ApfsDriverLoader/ApfsDriverLoader.inf
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
DebugLib
PcdLib
OcAppleImageVerificationLib
OcBootManagementLib
OcMiscLib
OcGuardLib

Expand Down

0 comments on commit 0a2eeb4

Please sign in to comment.