17#include <Library/BaseMemoryLib.h>
18#include <Library/DebugLib.h>
19#include <Library/DevicePathLib.h>
20#include <Library/MemoryAllocationLib.h>
21#include <Library/UefiBootServicesTableLib.h>
22#include <Library/UefiLib.h>
23#include <Protocol/BlockIo.h>
24#include <Protocol/PartitionInfo.h>
41 BufferSize =
sizeof (EFI_HANDLE);
42 Status =
gBS->LocateHandle (
49 if (!EFI_ERROR (Status)) {
66 Status =
gBS->CreateEvent (
74 if (!EFI_ERROR (Status)) {
75 Status =
gBS->RegisterProtocolNotify (
81 if (EFI_ERROR (Status)) {
82 gBS->CloseEvent (Event);
91 IN EFI_HANDLE
Handle OPTIONAL,
92 IN BOOLEAN VerifyPolicy
98 EFI_HANDLE *HandleBuffer;
99 EFI_DEVICE_PATH *ParentDevicePath;
100 EFI_DEVICE_PATH *ChildDevicePath;
105 Status =
gBS->LocateHandleBuffer (
113 ParentDevicePath = NULL;
116 Status2 =
gBS->HandleProtocol (
119 (VOID **)&ParentDevicePath
121 if (!EFI_ERROR (Status2)) {
122 PrefixLength = GetDevicePathSize (ParentDevicePath) - END_DEVICE_PATH_LENGTH;
124 DEBUG ((DEBUG_INFO,
"OCJS: No parent device path - %r\n", Status2));
125 ParentDevicePath = NULL;
129 if (!EFI_ERROR (Status)) {
130 Status = EFI_NOT_FOUND;
132 for (Index = 0; Index < HandleCount; ++Index) {
133 if ((ParentDevicePath != NULL) && (PrefixLength > 0)) {
134 Status2 =
gBS->HandleProtocol (
137 (VOID **)&ChildDevicePath
139 if (EFI_ERROR (Status2)) {
140 DEBUG ((DEBUG_INFO,
"OCJS: No child device path - %r\n", Status2));
144 if (
CompareMem (ParentDevicePath, ChildDevicePath, PrefixLength) == 0) {
145 DEBUG ((DEBUG_INFO,
"OCJS: Matched device path\n"));
155 if (!EFI_ERROR (Status2)) {
160 FreePool (HandleBuffer);
162 DEBUG ((DEBUG_INFO,
"OCJS: BlockIo buffer error - %r\n", Status));
174 VOID *PartitionInfoInterface;
177 Status =
gBS->LocateProtocol (
178 &gEfiPartitionInfoProtocolGuid,
180 &PartitionInfoInterface
182 DEBUG ((DEBUG_INFO,
"OCJS: PartitionInfo is %r\n", Status));
187 if (EFI_ERROR (Status)) {
188 DEBUG ((DEBUG_INFO,
"OCJS: Failed to setup drive monitoring - %r\n", Status));
STATIC EFI_STATUS ApfsMonitorNewPartitions(VOID)
STATIC VOID * mApfsNewPartitionsEventKey
EFI_STATUS OcApfsConnectDevices(IN BOOLEAN Monitor)
EFI_STATUS OcApfsConnectParentDevice(IN EFI_HANDLE Handle OPTIONAL, IN BOOLEAN VerifyPolicy)
STATIC VOID EFIAPI ApfsNewPartitionArrived(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS OcApfsConnectHandle(IN EFI_HANDLE Handle, IN BOOLEAN VerifyPolicy)
APPLE_EVENT_HANDLE Handle
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
EFI_GUID gEfiBlockIoProtocolGuid
EFI_GUID gEfiDevicePathProtocolGuid