OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
OcApfsLib.c
Go to the documentation of this file.
1
15#include "OcApfsInternal.h"
16#include <Library/OcApfsLib.h>
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>
25
27
28STATIC
29VOID
30EFIAPI
32 IN EFI_EVENT Event,
33 IN VOID *Context
34 )
35{
36 EFI_STATUS Status;
37 UINTN BufferSize;
38 EFI_HANDLE Handle;
39
40 while (TRUE) {
41 BufferSize = sizeof (EFI_HANDLE);
42 Status = gBS->LocateHandle (
43 ByRegisterNotify,
44 NULL,
46 &BufferSize,
47 &Handle
48 );
49 if (!EFI_ERROR (Status)) {
51 } else {
52 break;
53 }
54 }
55}
56
57STATIC
58EFI_STATUS
60 VOID
61 )
62{
63 EFI_STATUS Status;
64 EFI_EVENT Event;
65
66 Status = gBS->CreateEvent (
67 EVT_NOTIFY_SIGNAL,
68 TPL_CALLBACK,
70 NULL,
71 &Event
72 );
73
74 if (!EFI_ERROR (Status)) {
75 Status = gBS->RegisterProtocolNotify (
77 Event,
79 );
80
81 if (EFI_ERROR (Status)) {
82 gBS->CloseEvent (Event);
83 }
84 }
85
86 return Status;
87}
88
89EFI_STATUS
91 IN EFI_HANDLE Handle OPTIONAL,
92 IN BOOLEAN VerifyPolicy
93 )
94{
95 EFI_STATUS Status;
96 EFI_STATUS Status2;
97 UINTN HandleCount;
98 EFI_HANDLE *HandleBuffer;
99 EFI_DEVICE_PATH *ParentDevicePath;
100 EFI_DEVICE_PATH *ChildDevicePath;
101 UINTN Index;
102 UINTN PrefixLength;
103
104 HandleCount = 0;
105 Status = gBS->LocateHandleBuffer (
106 ByProtocol,
108 NULL,
109 &HandleCount,
110 &HandleBuffer
111 );
112
113 ParentDevicePath = NULL;
114 PrefixLength = 0;
115 if (Handle != NULL) {
116 Status2 = gBS->HandleProtocol (
117 Handle,
119 (VOID **)&ParentDevicePath
120 );
121 if (!EFI_ERROR (Status2)) {
122 PrefixLength = GetDevicePathSize (ParentDevicePath) - END_DEVICE_PATH_LENGTH;
123 } else {
124 DEBUG ((DEBUG_INFO, "OCJS: No parent device path - %r\n", Status2));
125 ParentDevicePath = NULL;
126 }
127 }
128
129 if (!EFI_ERROR (Status)) {
130 Status = EFI_NOT_FOUND;
131
132 for (Index = 0; Index < HandleCount; ++Index) {
133 if ((ParentDevicePath != NULL) && (PrefixLength > 0)) {
134 Status2 = gBS->HandleProtocol (
135 HandleBuffer[Index],
137 (VOID **)&ChildDevicePath
138 );
139 if (EFI_ERROR (Status2)) {
140 DEBUG ((DEBUG_INFO, "OCJS: No child device path - %r\n", Status2));
141 continue;
142 }
143
144 if (CompareMem (ParentDevicePath, ChildDevicePath, PrefixLength) == 0) {
145 DEBUG ((DEBUG_INFO, "OCJS: Matched device path\n"));
146 } else {
147 continue;
148 }
149 }
150
151 Status2 = OcApfsConnectHandle (
152 HandleBuffer[Index],
153 VerifyPolicy
154 );
155 if (!EFI_ERROR (Status2)) {
156 Status = Status2;
157 }
158 }
159
160 FreePool (HandleBuffer);
161 } else {
162 DEBUG ((DEBUG_INFO, "OCJS: BlockIo buffer error - %r\n", Status));
163 }
164
165 return Status;
166}
167
168EFI_STATUS
170 IN BOOLEAN Monitor
171 )
172{
173 EFI_STATUS Status;
174 VOID *PartitionInfoInterface;
175
176 DEBUG_CODE_BEGIN ();
177 Status = gBS->LocateProtocol (
178 &gEfiPartitionInfoProtocolGuid,
179 NULL,
180 &PartitionInfoInterface
181 );
182 DEBUG ((DEBUG_INFO, "OCJS: PartitionInfo is %r\n", Status));
183 DEBUG_CODE_END ();
184
185 if (Monitor) {
186 Status = ApfsMonitorNewPartitions ();
187 if (EFI_ERROR (Status)) {
188 DEBUG ((DEBUG_INFO, "OCJS: Failed to setup drive monitoring - %r\n", Status));
189 }
190 }
191
192 return OcApfsConnectParentDevice (NULL, TRUE);
193}
STATIC EFI_STATUS ApfsMonitorNewPartitions(VOID)
Definition OcApfsLib.c:59
STATIC VOID * mApfsNewPartitionsEventKey
Definition OcApfsLib.c:26
EFI_STATUS OcApfsConnectDevices(IN BOOLEAN Monitor)
Definition OcApfsLib.c:169
EFI_STATUS OcApfsConnectParentDevice(IN EFI_HANDLE Handle OPTIONAL, IN BOOLEAN VerifyPolicy)
Definition OcApfsLib.c:90
STATIC VOID EFIAPI ApfsNewPartitionArrived(IN EFI_EVENT Event, IN VOID *Context)
Definition OcApfsLib.c:31
EFI_STATUS OcApfsConnectHandle(IN EFI_HANDLE Handle, IN BOOLEAN VerifyPolicy)
EFI_BOOT_SERVICES * gBS
APPLE_EVENT_HANDLE Handle
Definition OcTypingLib.h:45
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
EFI_GUID gEfiBlockIoProtocolGuid
EFI_GUID gEfiDevicePathProtocolGuid