From 60ce0304865e02e9a71cca4cc799d116f85b013a Mon Sep 17 00:00:00 2001 From: vit9696 Date: Sat, 8 Jun 2019 23:17:58 +0300 Subject: [PATCH] OcBootManagementLib: Display (external) suffix for external drives --- Include/Library/OcBootManagementLib.h | 4 + .../BootManagementInternal.h | 3 +- .../OcBootManagementLib/OcBootManagementLib.c | 5 +- .../OcBootManagementLib/PolicyManagement.c | 141 ++++++++++-------- 4 files changed, 91 insertions(+), 62 deletions(-) diff --git a/Include/Library/OcBootManagementLib.h b/Include/Library/OcBootManagementLib.h index de9b6dc7..b38c3755 100755 --- a/Include/Library/OcBootManagementLib.h +++ b/Include/Library/OcBootManagementLib.h @@ -41,6 +41,10 @@ typedef struct OC_BOOT_ENTRY_ { // BOOLEAN IsCustom; // + // Set when this entry is an externally available entry (e.g. USB). + // + BOOLEAN IsExternal; + // // Should try booting from first dmg found in DevicePath. // BOOLEAN IsFolder; diff --git a/Library/OcBootManagementLib/BootManagementInternal.h b/Library/OcBootManagementLib/BootManagementInternal.h index 9622648a..fff9d088 100644 --- a/Library/OcBootManagementLib/BootManagementInternal.h +++ b/Library/OcBootManagementLib/BootManagementInternal.h @@ -34,7 +34,8 @@ EFI_STATUS InternalCheckScanPolicy ( IN EFI_HANDLE Handle, IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFs, - IN UINT32 Policy + IN UINT32 Policy, + OUT BOOLEAN *External OPTIONAL ); EFI_DEVICE_PATH_PROTOCOL * diff --git a/Library/OcBootManagementLib/OcBootManagementLib.c b/Library/OcBootManagementLib/OcBootManagementLib.c index 9663a39c..d6bb2d02 100644 --- a/Library/OcBootManagementLib/OcBootManagementLib.c +++ b/Library/OcBootManagementLib/OcBootManagementLib.c @@ -306,7 +306,7 @@ OcFillBootEntry ( Count = 0; - Status = InternalCheckScanPolicy (Handle, SimpleFs, Policy); + Status = InternalCheckScanPolicy (Handle, SimpleFs, Policy, &BootEntry->IsExternal); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_INFO, "OCB: Skipping handle %p due to scan policy %x\n", Handle, Policy)); return 0; @@ -553,6 +553,9 @@ OcShowSimpleBootMenu ( gST->ConOut->OutputString (gST->ConOut, Code); gST->ConOut->OutputString (gST->ConOut, L". "); gST->ConOut->OutputString (gST->ConOut, BootEntries[Index].Name); + if (BootEntries[Index].IsExternal) { + gST->ConOut->OutputString (gST->ConOut, L" (external)"); + } if (BootEntries[Index].IsFolder) { gST->ConOut->OutputString (gST->ConOut, L" (dmg)"); } diff --git a/Library/OcBootManagementLib/PolicyManagement.c b/Library/OcBootManagementLib/PolicyManagement.c index 519d07ae..adefed4b 100644 --- a/Library/OcBootManagementLib/PolicyManagement.c +++ b/Library/OcBootManagementLib/PolicyManagement.c @@ -32,79 +32,100 @@ #include #include -EFI_STATUS -InternalCheckScanPolicy ( - IN EFI_HANDLE Handle, - IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFs, - IN UINT32 Policy +STATIC +UINT32 +InternalGetRequestedPolicyType ( + IN EFI_HANDLE Handle, + OUT BOOLEAN *External OPTIONAL ) { EFI_STATUS Status; EFI_DEVICE_PATH_PROTOCOL *DevicePath; - EFI_FILE_PROTOCOL *Root; - UINTN BufferSize; + UINT8 SubType; - Status = EFI_SUCCESS; + if (External != NULL) { + *External = FALSE; + } + Status = gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **) &DevicePath); + if (EFI_ERROR (Status)) { + return 0; + } - if ((Policy & OC_SCAN_DEVICE_LOCK) != 0) { - Status = gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **) &DevicePath); - if (EFI_ERROR (Status)) { - return Status; - } - - Status = EFI_SECURITY_VIOLATION; - - while (!IsDevicePathEnd (DevicePath)) { - if (DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) { - if ((Policy & OC_SCAN_ALLOW_DEVICE_SATA) != 0 - && DevicePathSubType (DevicePath) == MSG_SATA_DP) { - Status = EFI_SUCCESS; - } else if ((Policy & OC_SCAN_ALLOW_DEVICE_SASEX) != 0 - && DevicePathSubType (DevicePath) == MSG_SASEX_DP) { - Status = EFI_SUCCESS; - } else if ((Policy & OC_SCAN_ALLOW_DEVICE_SCSI) != 0 - && DevicePathSubType (DevicePath) == MSG_SCSI_DP) { - Status = EFI_SUCCESS; - } else if ((Policy & OC_SCAN_ALLOW_DEVICE_NVME) != 0 - && DevicePathSubType (DevicePath) == MSG_NVME_NAMESPACE_DP) { - Status = EFI_SUCCESS; - } else if ((Policy & OC_SCAN_ALLOW_DEVICE_ATAPI) != 0 - && DevicePathSubType (DevicePath) == MSG_ATAPI_DP) { - Status = EFI_SUCCESS; - } else if ((Policy & OC_SCAN_ALLOW_DEVICE_USB) != 0 - && DevicePathSubType (DevicePath) == MSG_USB_DP) { - Status = EFI_SUCCESS; - } else if ((Policy & OC_SCAN_ALLOW_DEVICE_FIREWIRE) != 0 - && DevicePathSubType (DevicePath) == MSG_1394_DP) { - Status = EFI_SUCCESS; - } else if ((Policy & OC_SCAN_ALLOW_DEVICE_SDCARD) != 0 - && (DevicePathSubType (DevicePath) == MSG_EMMC_DP - || DevicePathSubType (DevicePath) == MSG_SD_DP)) { - Status = EFI_SUCCESS; - } - - // - // We do not have good protection against device tunneling. - // These things must be considered: - // - Thunderbolt 2 PCI-e pass-through - // - Thunderbolt 3 PCI-e pass-through (Type-C, may be different from 2) - // - FireWire devices - // For now we hope that first messaging type protects us, and all - // subsequent messaging types are tunneled. - // - - break; + while (!IsDevicePathEnd (DevicePath)) { + if (DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) { + SubType = DevicePathSubType (DevicePath); + switch (SubType) { + case MSG_SATA_DP: + return OC_SCAN_ALLOW_DEVICE_SATA; + case MSG_SASEX_DP: + return OC_SCAN_ALLOW_DEVICE_SASEX; + case MSG_SCSI_DP: + return OC_SCAN_ALLOW_DEVICE_SCSI; + case MSG_NVME_NAMESPACE_DP: + return OC_SCAN_ALLOW_DEVICE_NVME; + case MSG_ATAPI_DP: + if (External != NULL) { + *External = TRUE; + } + return OC_SCAN_ALLOW_DEVICE_ATAPI; + case MSG_USB_DP: + if (External != NULL) { + *External = TRUE; + } + return OC_SCAN_ALLOW_DEVICE_USB; + case MSG_1394_DP: + if (External != NULL) { + *External = TRUE; + } + return OC_SCAN_ALLOW_DEVICE_FIREWIRE; + case MSG_SD_DP: + case MSG_EMMC_DP: + if (External != NULL) { + *External = TRUE; + } + return OC_SCAN_ALLOW_DEVICE_SDCARD; } - DevicePath = NextDevicePathNode (DevicePath); + // + // We do not have good protection against device tunneling. + // These things must be considered: + // - Thunderbolt 2 PCI-e pass-through + // - Thunderbolt 3 PCI-e pass-through (Type-C, may be different from 2) + // - FireWire devices + // For now we hope that first messaging type protects us, and all + // subsequent messaging types are tunneled. + // + + break; } - if (EFI_ERROR (Status)) { - return Status; - } + DevicePath = NextDevicePathNode (DevicePath); } + return 0; +} + +EFI_STATUS +InternalCheckScanPolicy ( + IN EFI_HANDLE Handle, + IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFs, + IN UINT32 Policy, + OUT BOOLEAN *External OPTIONAL + ) +{ + EFI_STATUS Status; + EFI_FILE_PROTOCOL *Root; + UINTN BufferSize; + UINT32 RequestedPolicy; + + RequestedPolicy = InternalGetRequestedPolicyType (Handle, External); + if ((Policy & OC_SCAN_DEVICE_LOCK) != 0 && (Policy & RequestedPolicy) == 0) { + return EFI_SECURITY_VIOLATION; + } + + Status = EFI_SUCCESS; + if ((Policy & OC_SCAN_FILE_SYSTEM_LOCK) != 0) { Status = SimpleFs->OpenVolume (SimpleFs, &Root);