hand.c revision 1.1.1.1.4.2 1 1.1.1.1.4.2 rmind /* $NetBSD: hand.c,v 1.1.1.1.4.2 2014/05/18 17:46:03 rmind Exp $ */
2 1.1.1.1.4.2 rmind
3 1.1.1.1.4.2 rmind /*++
4 1.1.1.1.4.2 rmind
5 1.1.1.1.4.2 rmind Copyright (c) 1998 Intel Corporation
6 1.1.1.1.4.2 rmind
7 1.1.1.1.4.2 rmind Module Name:
8 1.1.1.1.4.2 rmind
9 1.1.1.1.4.2 rmind hand.c
10 1.1.1.1.4.2 rmind
11 1.1.1.1.4.2 rmind Abstract:
12 1.1.1.1.4.2 rmind
13 1.1.1.1.4.2 rmind
14 1.1.1.1.4.2 rmind
15 1.1.1.1.4.2 rmind
16 1.1.1.1.4.2 rmind Revision History
17 1.1.1.1.4.2 rmind
18 1.1.1.1.4.2 rmind --*/
19 1.1.1.1.4.2 rmind
20 1.1.1.1.4.2 rmind #include "lib.h"
21 1.1.1.1.4.2 rmind #include "efistdarg.h" // !!!
22 1.1.1.1.4.2 rmind
23 1.1.1.1.4.2 rmind
24 1.1.1.1.4.2 rmind EFI_STATUS
25 1.1.1.1.4.2 rmind LibLocateProtocol (
26 1.1.1.1.4.2 rmind IN EFI_GUID *ProtocolGuid,
27 1.1.1.1.4.2 rmind OUT VOID **Interface
28 1.1.1.1.4.2 rmind )
29 1.1.1.1.4.2 rmind //
30 1.1.1.1.4.2 rmind // Find the first instance of this Protocol in the system and return it's interface
31 1.1.1.1.4.2 rmind //
32 1.1.1.1.4.2 rmind {
33 1.1.1.1.4.2 rmind EFI_STATUS Status;
34 1.1.1.1.4.2 rmind UINTN NumberHandles, Index;
35 1.1.1.1.4.2 rmind EFI_HANDLE *Handles;
36 1.1.1.1.4.2 rmind
37 1.1.1.1.4.2 rmind
38 1.1.1.1.4.2 rmind *Interface = NULL;
39 1.1.1.1.4.2 rmind Status = LibLocateHandle (ByProtocol, ProtocolGuid, NULL, &NumberHandles, &Handles);
40 1.1.1.1.4.2 rmind if (EFI_ERROR(Status)) {
41 1.1.1.1.4.2 rmind DEBUG((D_INFO, "LibLocateProtocol: Handle not found\n"));
42 1.1.1.1.4.2 rmind return Status;
43 1.1.1.1.4.2 rmind }
44 1.1.1.1.4.2 rmind
45 1.1.1.1.4.2 rmind for (Index=0; Index < NumberHandles; Index++) {
46 1.1.1.1.4.2 rmind Status = uefi_call_wrapper(BS->HandleProtocol, 3, Handles[Index], ProtocolGuid, Interface);
47 1.1.1.1.4.2 rmind if (!EFI_ERROR(Status)) {
48 1.1.1.1.4.2 rmind break;
49 1.1.1.1.4.2 rmind }
50 1.1.1.1.4.2 rmind }
51 1.1.1.1.4.2 rmind
52 1.1.1.1.4.2 rmind if (Handles) {
53 1.1.1.1.4.2 rmind FreePool (Handles);
54 1.1.1.1.4.2 rmind }
55 1.1.1.1.4.2 rmind
56 1.1.1.1.4.2 rmind return Status;
57 1.1.1.1.4.2 rmind }
58 1.1.1.1.4.2 rmind
59 1.1.1.1.4.2 rmind EFI_STATUS
60 1.1.1.1.4.2 rmind LibLocateHandle (
61 1.1.1.1.4.2 rmind IN EFI_LOCATE_SEARCH_TYPE SearchType,
62 1.1.1.1.4.2 rmind IN EFI_GUID *Protocol OPTIONAL,
63 1.1.1.1.4.2 rmind IN VOID *SearchKey OPTIONAL,
64 1.1.1.1.4.2 rmind IN OUT UINTN *NoHandles,
65 1.1.1.1.4.2 rmind OUT EFI_HANDLE **Buffer
66 1.1.1.1.4.2 rmind )
67 1.1.1.1.4.2 rmind
68 1.1.1.1.4.2 rmind {
69 1.1.1.1.4.2 rmind EFI_STATUS Status;
70 1.1.1.1.4.2 rmind UINTN BufferSize;
71 1.1.1.1.4.2 rmind
72 1.1.1.1.4.2 rmind //
73 1.1.1.1.4.2 rmind // Initialize for GrowBuffer loop
74 1.1.1.1.4.2 rmind //
75 1.1.1.1.4.2 rmind
76 1.1.1.1.4.2 rmind Status = EFI_SUCCESS;
77 1.1.1.1.4.2 rmind *Buffer = NULL;
78 1.1.1.1.4.2 rmind BufferSize = 50 * sizeof(EFI_HANDLE);
79 1.1.1.1.4.2 rmind
80 1.1.1.1.4.2 rmind //
81 1.1.1.1.4.2 rmind // Call the real function
82 1.1.1.1.4.2 rmind //
83 1.1.1.1.4.2 rmind
84 1.1.1.1.4.2 rmind while (GrowBuffer (&Status, (VOID **) Buffer, BufferSize)) {
85 1.1.1.1.4.2 rmind
86 1.1.1.1.4.2 rmind Status = uefi_call_wrapper(
87 1.1.1.1.4.2 rmind BS->LocateHandle,
88 1.1.1.1.4.2 rmind 5,
89 1.1.1.1.4.2 rmind SearchType,
90 1.1.1.1.4.2 rmind Protocol,
91 1.1.1.1.4.2 rmind SearchKey,
92 1.1.1.1.4.2 rmind &BufferSize,
93 1.1.1.1.4.2 rmind *Buffer
94 1.1.1.1.4.2 rmind );
95 1.1.1.1.4.2 rmind
96 1.1.1.1.4.2 rmind }
97 1.1.1.1.4.2 rmind
98 1.1.1.1.4.2 rmind *NoHandles = BufferSize / sizeof (EFI_HANDLE);
99 1.1.1.1.4.2 rmind if (EFI_ERROR(Status)) {
100 1.1.1.1.4.2 rmind *NoHandles = 0;
101 1.1.1.1.4.2 rmind }
102 1.1.1.1.4.2 rmind
103 1.1.1.1.4.2 rmind return Status;
104 1.1.1.1.4.2 rmind }
105 1.1.1.1.4.2 rmind
106 1.1.1.1.4.2 rmind EFI_STATUS
107 1.1.1.1.4.2 rmind LibLocateHandleByDiskSignature (
108 1.1.1.1.4.2 rmind IN UINT8 MBRType,
109 1.1.1.1.4.2 rmind IN UINT8 SignatureType,
110 1.1.1.1.4.2 rmind IN VOID *Signature,
111 1.1.1.1.4.2 rmind IN OUT UINTN *NoHandles,
112 1.1.1.1.4.2 rmind OUT EFI_HANDLE **Buffer
113 1.1.1.1.4.2 rmind )
114 1.1.1.1.4.2 rmind
115 1.1.1.1.4.2 rmind {
116 1.1.1.1.4.2 rmind EFI_STATUS Status;
117 1.1.1.1.4.2 rmind UINTN BufferSize;
118 1.1.1.1.4.2 rmind UINTN NoBlockIoHandles;
119 1.1.1.1.4.2 rmind EFI_HANDLE *BlockIoBuffer;
120 1.1.1.1.4.2 rmind EFI_DEVICE_PATH *DevicePath;
121 1.1.1.1.4.2 rmind UINTN Index;
122 1.1.1.1.4.2 rmind EFI_DEVICE_PATH *Start, *Next, *DevPath;
123 1.1.1.1.4.2 rmind HARDDRIVE_DEVICE_PATH *HardDriveDevicePath;
124 1.1.1.1.4.2 rmind BOOLEAN Match;
125 1.1.1.1.4.2 rmind BOOLEAN PreviousNodeIsHardDriveDevicePath;
126 1.1.1.1.4.2 rmind
127 1.1.1.1.4.2 rmind //
128 1.1.1.1.4.2 rmind // Initialize for GrowBuffer loop
129 1.1.1.1.4.2 rmind //
130 1.1.1.1.4.2 rmind
131 1.1.1.1.4.2 rmind BlockIoBuffer = NULL;
132 1.1.1.1.4.2 rmind BufferSize = 50 * sizeof(EFI_HANDLE);
133 1.1.1.1.4.2 rmind
134 1.1.1.1.4.2 rmind //
135 1.1.1.1.4.2 rmind // Call the real function
136 1.1.1.1.4.2 rmind //
137 1.1.1.1.4.2 rmind
138 1.1.1.1.4.2 rmind while (GrowBuffer (&Status, (VOID **)&BlockIoBuffer, BufferSize)) {
139 1.1.1.1.4.2 rmind
140 1.1.1.1.4.2 rmind //
141 1.1.1.1.4.2 rmind // Get list of device handles that support the BLOCK_IO Protocol.
142 1.1.1.1.4.2 rmind //
143 1.1.1.1.4.2 rmind
144 1.1.1.1.4.2 rmind Status = uefi_call_wrapper(
145 1.1.1.1.4.2 rmind BS->LocateHandle,
146 1.1.1.1.4.2 rmind 5,
147 1.1.1.1.4.2 rmind ByProtocol,
148 1.1.1.1.4.2 rmind &BlockIoProtocol,
149 1.1.1.1.4.2 rmind NULL,
150 1.1.1.1.4.2 rmind &BufferSize,
151 1.1.1.1.4.2 rmind BlockIoBuffer
152 1.1.1.1.4.2 rmind );
153 1.1.1.1.4.2 rmind
154 1.1.1.1.4.2 rmind }
155 1.1.1.1.4.2 rmind
156 1.1.1.1.4.2 rmind NoBlockIoHandles = BufferSize / sizeof (EFI_HANDLE);
157 1.1.1.1.4.2 rmind if (EFI_ERROR(Status)) {
158 1.1.1.1.4.2 rmind NoBlockIoHandles = 0;
159 1.1.1.1.4.2 rmind }
160 1.1.1.1.4.2 rmind
161 1.1.1.1.4.2 rmind //
162 1.1.1.1.4.2 rmind // If there was an error or there are no device handles that support
163 1.1.1.1.4.2 rmind // the BLOCK_IO Protocol, then return.
164 1.1.1.1.4.2 rmind //
165 1.1.1.1.4.2 rmind
166 1.1.1.1.4.2 rmind if (NoBlockIoHandles == 0) {
167 1.1.1.1.4.2 rmind FreePool(BlockIoBuffer);
168 1.1.1.1.4.2 rmind *NoHandles = 0;
169 1.1.1.1.4.2 rmind *Buffer = NULL;
170 1.1.1.1.4.2 rmind return Status;
171 1.1.1.1.4.2 rmind }
172 1.1.1.1.4.2 rmind
173 1.1.1.1.4.2 rmind //
174 1.1.1.1.4.2 rmind // Loop through all the device handles that support the BLOCK_IO Protocol
175 1.1.1.1.4.2 rmind //
176 1.1.1.1.4.2 rmind
177 1.1.1.1.4.2 rmind *NoHandles = 0;
178 1.1.1.1.4.2 rmind
179 1.1.1.1.4.2 rmind for(Index=0;Index<NoBlockIoHandles;Index++) {
180 1.1.1.1.4.2 rmind
181 1.1.1.1.4.2 rmind Status = uefi_call_wrapper(
182 1.1.1.1.4.2 rmind BS->HandleProtocol,
183 1.1.1.1.4.2 rmind 3,
184 1.1.1.1.4.2 rmind BlockIoBuffer[Index],
185 1.1.1.1.4.2 rmind &DevicePathProtocol,
186 1.1.1.1.4.2 rmind (VOID*)&DevicePath
187 1.1.1.1.4.2 rmind );
188 1.1.1.1.4.2 rmind
189 1.1.1.1.4.2 rmind //
190 1.1.1.1.4.2 rmind // Search DevicePath for a Hard Drive Media Device Path node.
191 1.1.1.1.4.2 rmind // If one is found, then see if it matches the signature that was
192 1.1.1.1.4.2 rmind // passed in. If it does match, and the next node is the End of the
193 1.1.1.1.4.2 rmind // device path, and the previous node is not a Hard Drive Media Device
194 1.1.1.1.4.2 rmind // Path, then we have found a match.
195 1.1.1.1.4.2 rmind //
196 1.1.1.1.4.2 rmind
197 1.1.1.1.4.2 rmind Match = FALSE;
198 1.1.1.1.4.2 rmind
199 1.1.1.1.4.2 rmind if (DevicePath != NULL) {
200 1.1.1.1.4.2 rmind
201 1.1.1.1.4.2 rmind PreviousNodeIsHardDriveDevicePath = FALSE;
202 1.1.1.1.4.2 rmind
203 1.1.1.1.4.2 rmind DevPath = DevicePath;
204 1.1.1.1.4.2 rmind Start = DevPath;
205 1.1.1.1.4.2 rmind
206 1.1.1.1.4.2 rmind //
207 1.1.1.1.4.2 rmind // Check for end of device path type
208 1.1.1.1.4.2 rmind //
209 1.1.1.1.4.2 rmind
210 1.1.1.1.4.2 rmind for (; ;) {
211 1.1.1.1.4.2 rmind
212 1.1.1.1.4.2 rmind if ((DevicePathType(DevPath) == MEDIA_DEVICE_PATH) &&
213 1.1.1.1.4.2 rmind (DevicePathSubType(DevPath) == MEDIA_HARDDRIVE_DP)) {
214 1.1.1.1.4.2 rmind
215 1.1.1.1.4.2 rmind HardDriveDevicePath = (HARDDRIVE_DEVICE_PATH *)(DevPath);
216 1.1.1.1.4.2 rmind
217 1.1.1.1.4.2 rmind if (PreviousNodeIsHardDriveDevicePath == FALSE) {
218 1.1.1.1.4.2 rmind
219 1.1.1.1.4.2 rmind Next = NextDevicePathNode(DevPath);
220 1.1.1.1.4.2 rmind if (IsDevicePathEndType(Next)) {
221 1.1.1.1.4.2 rmind if ((HardDriveDevicePath->MBRType == MBRType) &&
222 1.1.1.1.4.2 rmind (HardDriveDevicePath->SignatureType == SignatureType)) {
223 1.1.1.1.4.2 rmind switch(SignatureType) {
224 1.1.1.1.4.2 rmind case SIGNATURE_TYPE_MBR:
225 1.1.1.1.4.2 rmind if (*((UINT32 *)(Signature)) == *(UINT32 *)(&(HardDriveDevicePath->Signature[0]))) {
226 1.1.1.1.4.2 rmind Match = TRUE;
227 1.1.1.1.4.2 rmind }
228 1.1.1.1.4.2 rmind break;
229 1.1.1.1.4.2 rmind case SIGNATURE_TYPE_GUID:
230 1.1.1.1.4.2 rmind if (CompareGuid((EFI_GUID *)Signature,(EFI_GUID *)(&(HardDriveDevicePath->Signature[0]))) == 0) {
231 1.1.1.1.4.2 rmind Match = TRUE;
232 1.1.1.1.4.2 rmind }
233 1.1.1.1.4.2 rmind break;
234 1.1.1.1.4.2 rmind }
235 1.1.1.1.4.2 rmind }
236 1.1.1.1.4.2 rmind }
237 1.1.1.1.4.2 rmind }
238 1.1.1.1.4.2 rmind PreviousNodeIsHardDriveDevicePath = TRUE;
239 1.1.1.1.4.2 rmind } else {
240 1.1.1.1.4.2 rmind PreviousNodeIsHardDriveDevicePath = FALSE;
241 1.1.1.1.4.2 rmind }
242 1.1.1.1.4.2 rmind
243 1.1.1.1.4.2 rmind if (IsDevicePathEnd(DevPath)) {
244 1.1.1.1.4.2 rmind break;
245 1.1.1.1.4.2 rmind }
246 1.1.1.1.4.2 rmind
247 1.1.1.1.4.2 rmind DevPath = NextDevicePathNode(DevPath);
248 1.1.1.1.4.2 rmind }
249 1.1.1.1.4.2 rmind
250 1.1.1.1.4.2 rmind }
251 1.1.1.1.4.2 rmind
252 1.1.1.1.4.2 rmind if (Match == FALSE) {
253 1.1.1.1.4.2 rmind BlockIoBuffer[Index] = NULL;
254 1.1.1.1.4.2 rmind } else {
255 1.1.1.1.4.2 rmind *NoHandles = *NoHandles + 1;
256 1.1.1.1.4.2 rmind }
257 1.1.1.1.4.2 rmind }
258 1.1.1.1.4.2 rmind
259 1.1.1.1.4.2 rmind //
260 1.1.1.1.4.2 rmind // If there are no matches, then return
261 1.1.1.1.4.2 rmind //
262 1.1.1.1.4.2 rmind
263 1.1.1.1.4.2 rmind if (*NoHandles == 0) {
264 1.1.1.1.4.2 rmind FreePool(BlockIoBuffer);
265 1.1.1.1.4.2 rmind *NoHandles = 0;
266 1.1.1.1.4.2 rmind *Buffer = NULL;
267 1.1.1.1.4.2 rmind return EFI_SUCCESS;
268 1.1.1.1.4.2 rmind }
269 1.1.1.1.4.2 rmind
270 1.1.1.1.4.2 rmind //
271 1.1.1.1.4.2 rmind // Allocate space for the return buffer of device handles.
272 1.1.1.1.4.2 rmind //
273 1.1.1.1.4.2 rmind
274 1.1.1.1.4.2 rmind *Buffer = AllocatePool(*NoHandles * sizeof(EFI_HANDLE));
275 1.1.1.1.4.2 rmind
276 1.1.1.1.4.2 rmind if (*Buffer == NULL) {
277 1.1.1.1.4.2 rmind FreePool(BlockIoBuffer);
278 1.1.1.1.4.2 rmind *NoHandles = 0;
279 1.1.1.1.4.2 rmind *Buffer = NULL;
280 1.1.1.1.4.2 rmind return EFI_OUT_OF_RESOURCES;
281 1.1.1.1.4.2 rmind }
282 1.1.1.1.4.2 rmind
283 1.1.1.1.4.2 rmind //
284 1.1.1.1.4.2 rmind // Build list of matching device handles.
285 1.1.1.1.4.2 rmind //
286 1.1.1.1.4.2 rmind
287 1.1.1.1.4.2 rmind *NoHandles = 0;
288 1.1.1.1.4.2 rmind for(Index=0;Index<NoBlockIoHandles;Index++) {
289 1.1.1.1.4.2 rmind if (BlockIoBuffer[Index] != NULL) {
290 1.1.1.1.4.2 rmind (*Buffer)[*NoHandles] = BlockIoBuffer[Index];
291 1.1.1.1.4.2 rmind *NoHandles = *NoHandles + 1;
292 1.1.1.1.4.2 rmind }
293 1.1.1.1.4.2 rmind }
294 1.1.1.1.4.2 rmind
295 1.1.1.1.4.2 rmind FreePool(BlockIoBuffer);
296 1.1.1.1.4.2 rmind
297 1.1.1.1.4.2 rmind return EFI_SUCCESS;
298 1.1.1.1.4.2 rmind }
299 1.1.1.1.4.2 rmind
300 1.1.1.1.4.2 rmind EFI_FILE_HANDLE
301 1.1.1.1.4.2 rmind LibOpenRoot (
302 1.1.1.1.4.2 rmind IN EFI_HANDLE DeviceHandle
303 1.1.1.1.4.2 rmind )
304 1.1.1.1.4.2 rmind {
305 1.1.1.1.4.2 rmind EFI_STATUS Status;
306 1.1.1.1.4.2 rmind EFI_FILE_IO_INTERFACE *Volume;
307 1.1.1.1.4.2 rmind EFI_FILE_HANDLE File;
308 1.1.1.1.4.2 rmind
309 1.1.1.1.4.2 rmind
310 1.1.1.1.4.2 rmind //
311 1.1.1.1.4.2 rmind // File the file system interface to the device
312 1.1.1.1.4.2 rmind //
313 1.1.1.1.4.2 rmind
314 1.1.1.1.4.2 rmind Status = uefi_call_wrapper(BS->HandleProtocol, 3, DeviceHandle, &FileSystemProtocol, (VOID*)&Volume);
315 1.1.1.1.4.2 rmind
316 1.1.1.1.4.2 rmind //
317 1.1.1.1.4.2 rmind // Open the root directory of the volume
318 1.1.1.1.4.2 rmind //
319 1.1.1.1.4.2 rmind
320 1.1.1.1.4.2 rmind if (!EFI_ERROR(Status)) {
321 1.1.1.1.4.2 rmind Status = uefi_call_wrapper(Volume->OpenVolume, 2, Volume, &File);
322 1.1.1.1.4.2 rmind }
323 1.1.1.1.4.2 rmind
324 1.1.1.1.4.2 rmind //
325 1.1.1.1.4.2 rmind // Done
326 1.1.1.1.4.2 rmind //
327 1.1.1.1.4.2 rmind
328 1.1.1.1.4.2 rmind return EFI_ERROR(Status) ? NULL : File;
329 1.1.1.1.4.2 rmind }
330 1.1.1.1.4.2 rmind
331 1.1.1.1.4.2 rmind EFI_FILE_INFO *
332 1.1.1.1.4.2 rmind LibFileInfo (
333 1.1.1.1.4.2 rmind IN EFI_FILE_HANDLE FHand
334 1.1.1.1.4.2 rmind )
335 1.1.1.1.4.2 rmind {
336 1.1.1.1.4.2 rmind EFI_STATUS Status;
337 1.1.1.1.4.2 rmind EFI_FILE_INFO *Buffer;
338 1.1.1.1.4.2 rmind UINTN BufferSize;
339 1.1.1.1.4.2 rmind
340 1.1.1.1.4.2 rmind //
341 1.1.1.1.4.2 rmind // Initialize for GrowBuffer loop
342 1.1.1.1.4.2 rmind //
343 1.1.1.1.4.2 rmind
344 1.1.1.1.4.2 rmind Buffer = NULL;
345 1.1.1.1.4.2 rmind BufferSize = SIZE_OF_EFI_FILE_INFO + 200;
346 1.1.1.1.4.2 rmind
347 1.1.1.1.4.2 rmind //
348 1.1.1.1.4.2 rmind // Call the real function
349 1.1.1.1.4.2 rmind //
350 1.1.1.1.4.2 rmind
351 1.1.1.1.4.2 rmind while (GrowBuffer (&Status, (VOID **) &Buffer, BufferSize)) {
352 1.1.1.1.4.2 rmind Status = uefi_call_wrapper(
353 1.1.1.1.4.2 rmind FHand->GetInfo,
354 1.1.1.1.4.2 rmind 4,
355 1.1.1.1.4.2 rmind FHand,
356 1.1.1.1.4.2 rmind &GenericFileInfo,
357 1.1.1.1.4.2 rmind &BufferSize,
358 1.1.1.1.4.2 rmind Buffer
359 1.1.1.1.4.2 rmind );
360 1.1.1.1.4.2 rmind }
361 1.1.1.1.4.2 rmind
362 1.1.1.1.4.2 rmind return Buffer;
363 1.1.1.1.4.2 rmind }
364 1.1.1.1.4.2 rmind
365 1.1.1.1.4.2 rmind
366 1.1.1.1.4.2 rmind EFI_FILE_SYSTEM_INFO *
367 1.1.1.1.4.2 rmind LibFileSystemInfo (
368 1.1.1.1.4.2 rmind IN EFI_FILE_HANDLE FHand
369 1.1.1.1.4.2 rmind )
370 1.1.1.1.4.2 rmind {
371 1.1.1.1.4.2 rmind EFI_STATUS Status;
372 1.1.1.1.4.2 rmind EFI_FILE_SYSTEM_INFO *Buffer;
373 1.1.1.1.4.2 rmind UINTN BufferSize;
374 1.1.1.1.4.2 rmind
375 1.1.1.1.4.2 rmind //
376 1.1.1.1.4.2 rmind // Initialize for GrowBuffer loop
377 1.1.1.1.4.2 rmind //
378 1.1.1.1.4.2 rmind
379 1.1.1.1.4.2 rmind Buffer = NULL;
380 1.1.1.1.4.2 rmind BufferSize = SIZE_OF_EFI_FILE_SYSTEM_INFO + 200;
381 1.1.1.1.4.2 rmind
382 1.1.1.1.4.2 rmind //
383 1.1.1.1.4.2 rmind // Call the real function
384 1.1.1.1.4.2 rmind //
385 1.1.1.1.4.2 rmind
386 1.1.1.1.4.2 rmind while (GrowBuffer (&Status, (VOID **) &Buffer, BufferSize)) {
387 1.1.1.1.4.2 rmind Status = uefi_call_wrapper(
388 1.1.1.1.4.2 rmind FHand->GetInfo,
389 1.1.1.1.4.2 rmind 4,
390 1.1.1.1.4.2 rmind FHand,
391 1.1.1.1.4.2 rmind &FileSystemInfo,
392 1.1.1.1.4.2 rmind &BufferSize,
393 1.1.1.1.4.2 rmind Buffer
394 1.1.1.1.4.2 rmind );
395 1.1.1.1.4.2 rmind }
396 1.1.1.1.4.2 rmind
397 1.1.1.1.4.2 rmind return Buffer;
398 1.1.1.1.4.2 rmind }
399 1.1.1.1.4.2 rmind
400 1.1.1.1.4.2 rmind EFI_FILE_SYSTEM_VOLUME_LABEL_INFO *
401 1.1.1.1.4.2 rmind LibFileSystemVolumeLabelInfo (
402 1.1.1.1.4.2 rmind IN EFI_FILE_HANDLE FHand
403 1.1.1.1.4.2 rmind )
404 1.1.1.1.4.2 rmind {
405 1.1.1.1.4.2 rmind EFI_STATUS Status;
406 1.1.1.1.4.2 rmind EFI_FILE_SYSTEM_VOLUME_LABEL_INFO *Buffer;
407 1.1.1.1.4.2 rmind UINTN BufferSize;
408 1.1.1.1.4.2 rmind
409 1.1.1.1.4.2 rmind //
410 1.1.1.1.4.2 rmind // Initialize for GrowBuffer loop
411 1.1.1.1.4.2 rmind //
412 1.1.1.1.4.2 rmind
413 1.1.1.1.4.2 rmind Buffer = NULL;
414 1.1.1.1.4.2 rmind BufferSize = SIZE_OF_EFI_FILE_SYSTEM_VOLUME_LABEL_INFO + 200;
415 1.1.1.1.4.2 rmind
416 1.1.1.1.4.2 rmind //
417 1.1.1.1.4.2 rmind // Call the real function
418 1.1.1.1.4.2 rmind //
419 1.1.1.1.4.2 rmind
420 1.1.1.1.4.2 rmind while (GrowBuffer (&Status, (VOID **) &Buffer, BufferSize)) {
421 1.1.1.1.4.2 rmind Status = uefi_call_wrapper(
422 1.1.1.1.4.2 rmind FHand->GetInfo,
423 1.1.1.1.4.2 rmind 4,
424 1.1.1.1.4.2 rmind FHand,
425 1.1.1.1.4.2 rmind &FileSystemVolumeLabelInfo,
426 1.1.1.1.4.2 rmind &BufferSize,
427 1.1.1.1.4.2 rmind Buffer
428 1.1.1.1.4.2 rmind );
429 1.1.1.1.4.2 rmind }
430 1.1.1.1.4.2 rmind
431 1.1.1.1.4.2 rmind return Buffer;
432 1.1.1.1.4.2 rmind }
433 1.1.1.1.4.2 rmind
434 1.1.1.1.4.2 rmind
435 1.1.1.1.4.2 rmind
436 1.1.1.1.4.2 rmind EFI_STATUS
437 1.1.1.1.4.2 rmind LibInstallProtocolInterfaces (
438 1.1.1.1.4.2 rmind IN OUT EFI_HANDLE *Handle,
439 1.1.1.1.4.2 rmind ...
440 1.1.1.1.4.2 rmind )
441 1.1.1.1.4.2 rmind {
442 1.1.1.1.4.2 rmind va_list args;
443 1.1.1.1.4.2 rmind EFI_STATUS Status;
444 1.1.1.1.4.2 rmind EFI_GUID *Protocol;
445 1.1.1.1.4.2 rmind VOID *Interface;
446 1.1.1.1.4.2 rmind EFI_TPL OldTpl;
447 1.1.1.1.4.2 rmind UINTN Index;
448 1.1.1.1.4.2 rmind EFI_HANDLE OldHandle;
449 1.1.1.1.4.2 rmind
450 1.1.1.1.4.2 rmind //
451 1.1.1.1.4.2 rmind // Syncronize with notifcations
452 1.1.1.1.4.2 rmind //
453 1.1.1.1.4.2 rmind
454 1.1.1.1.4.2 rmind OldTpl = uefi_call_wrapper(BS->RaiseTPL, 1, TPL_NOTIFY);
455 1.1.1.1.4.2 rmind OldHandle = *Handle;
456 1.1.1.1.4.2 rmind
457 1.1.1.1.4.2 rmind //
458 1.1.1.1.4.2 rmind // Install the protocol interfaces
459 1.1.1.1.4.2 rmind //
460 1.1.1.1.4.2 rmind
461 1.1.1.1.4.2 rmind Index = 0;
462 1.1.1.1.4.2 rmind Status = EFI_SUCCESS;
463 1.1.1.1.4.2 rmind va_start (args, Handle);
464 1.1.1.1.4.2 rmind
465 1.1.1.1.4.2 rmind while (!EFI_ERROR(Status)) {
466 1.1.1.1.4.2 rmind
467 1.1.1.1.4.2 rmind //
468 1.1.1.1.4.2 rmind // If protocol is NULL, then it's the end of the list
469 1.1.1.1.4.2 rmind //
470 1.1.1.1.4.2 rmind
471 1.1.1.1.4.2 rmind Protocol = va_arg(args, EFI_GUID *);
472 1.1.1.1.4.2 rmind if (!Protocol) {
473 1.1.1.1.4.2 rmind break;
474 1.1.1.1.4.2 rmind }
475 1.1.1.1.4.2 rmind
476 1.1.1.1.4.2 rmind Interface = va_arg(args, VOID *);
477 1.1.1.1.4.2 rmind
478 1.1.1.1.4.2 rmind //
479 1.1.1.1.4.2 rmind // Install it
480 1.1.1.1.4.2 rmind //
481 1.1.1.1.4.2 rmind
482 1.1.1.1.4.2 rmind DEBUG((D_INFO, "LibInstallProtocolInterface: %d %x\n", Protocol, Interface));
483 1.1.1.1.4.2 rmind Status = uefi_call_wrapper(BS->InstallProtocolInterface, 4, Handle, Protocol, EFI_NATIVE_INTERFACE, Interface);
484 1.1.1.1.4.2 rmind if (EFI_ERROR(Status)) {
485 1.1.1.1.4.2 rmind break;
486 1.1.1.1.4.2 rmind }
487 1.1.1.1.4.2 rmind
488 1.1.1.1.4.2 rmind Index += 1;
489 1.1.1.1.4.2 rmind }
490 1.1.1.1.4.2 rmind
491 1.1.1.1.4.2 rmind //
492 1.1.1.1.4.2 rmind // If there was an error, remove all the interfaces that were
493 1.1.1.1.4.2 rmind // installed without any errors
494 1.1.1.1.4.2 rmind //
495 1.1.1.1.4.2 rmind
496 1.1.1.1.4.2 rmind if (EFI_ERROR(Status)) {
497 1.1.1.1.4.2 rmind va_start (args, Handle);
498 1.1.1.1.4.2 rmind while (Index) {
499 1.1.1.1.4.2 rmind
500 1.1.1.1.4.2 rmind Protocol = va_arg(args, EFI_GUID *);
501 1.1.1.1.4.2 rmind Interface = va_arg(args, VOID *);
502 1.1.1.1.4.2 rmind uefi_call_wrapper(BS->UninstallProtocolInterface, 3, *Handle, Protocol, Interface);
503 1.1.1.1.4.2 rmind
504 1.1.1.1.4.2 rmind Index -= 1;
505 1.1.1.1.4.2 rmind }
506 1.1.1.1.4.2 rmind
507 1.1.1.1.4.2 rmind *Handle = OldHandle;
508 1.1.1.1.4.2 rmind }
509 1.1.1.1.4.2 rmind
510 1.1.1.1.4.2 rmind //
511 1.1.1.1.4.2 rmind // Done
512 1.1.1.1.4.2 rmind //
513 1.1.1.1.4.2 rmind
514 1.1.1.1.4.2 rmind uefi_call_wrapper(BS->RestoreTPL, 1, OldTpl);
515 1.1.1.1.4.2 rmind return Status;
516 1.1.1.1.4.2 rmind }
517 1.1.1.1.4.2 rmind
518 1.1.1.1.4.2 rmind
519 1.1.1.1.4.2 rmind VOID
520 1.1.1.1.4.2 rmind LibUninstallProtocolInterfaces (
521 1.1.1.1.4.2 rmind IN EFI_HANDLE Handle,
522 1.1.1.1.4.2 rmind ...
523 1.1.1.1.4.2 rmind )
524 1.1.1.1.4.2 rmind {
525 1.1.1.1.4.2 rmind va_list args;
526 1.1.1.1.4.2 rmind EFI_STATUS Status;
527 1.1.1.1.4.2 rmind EFI_GUID *Protocol;
528 1.1.1.1.4.2 rmind VOID *Interface;
529 1.1.1.1.4.2 rmind
530 1.1.1.1.4.2 rmind
531 1.1.1.1.4.2 rmind va_start (args, Handle);
532 1.1.1.1.4.2 rmind for (; ;) {
533 1.1.1.1.4.2 rmind
534 1.1.1.1.4.2 rmind //
535 1.1.1.1.4.2 rmind // If protocol is NULL, then it's the end of the list
536 1.1.1.1.4.2 rmind //
537 1.1.1.1.4.2 rmind
538 1.1.1.1.4.2 rmind Protocol = va_arg(args, EFI_GUID *);
539 1.1.1.1.4.2 rmind if (!Protocol) {
540 1.1.1.1.4.2 rmind break;
541 1.1.1.1.4.2 rmind }
542 1.1.1.1.4.2 rmind
543 1.1.1.1.4.2 rmind Interface = va_arg(args, VOID *);
544 1.1.1.1.4.2 rmind
545 1.1.1.1.4.2 rmind //
546 1.1.1.1.4.2 rmind // Uninstall it
547 1.1.1.1.4.2 rmind //
548 1.1.1.1.4.2 rmind
549 1.1.1.1.4.2 rmind Status = uefi_call_wrapper(BS->UninstallProtocolInterface, 3, Handle, Protocol, Interface);
550 1.1.1.1.4.2 rmind if (EFI_ERROR(Status)) {
551 1.1.1.1.4.2 rmind DEBUG((D_ERROR, "LibUninstallProtocolInterfaces: failed %g, %r\n", Protocol, Handle));
552 1.1.1.1.4.2 rmind }
553 1.1.1.1.4.2 rmind }
554 1.1.1.1.4.2 rmind }
555 1.1.1.1.4.2 rmind
556 1.1.1.1.4.2 rmind
557 1.1.1.1.4.2 rmind EFI_STATUS
558 1.1.1.1.4.2 rmind LibReinstallProtocolInterfaces (
559 1.1.1.1.4.2 rmind IN OUT EFI_HANDLE *Handle,
560 1.1.1.1.4.2 rmind ...
561 1.1.1.1.4.2 rmind )
562 1.1.1.1.4.2 rmind {
563 1.1.1.1.4.2 rmind va_list args;
564 1.1.1.1.4.2 rmind EFI_STATUS Status;
565 1.1.1.1.4.2 rmind EFI_GUID *Protocol;
566 1.1.1.1.4.2 rmind VOID *OldInterface, *NewInterface;
567 1.1.1.1.4.2 rmind EFI_TPL OldTpl;
568 1.1.1.1.4.2 rmind UINTN Index;
569 1.1.1.1.4.2 rmind
570 1.1.1.1.4.2 rmind //
571 1.1.1.1.4.2 rmind // Syncronize with notifcations
572 1.1.1.1.4.2 rmind //
573 1.1.1.1.4.2 rmind
574 1.1.1.1.4.2 rmind OldTpl = uefi_call_wrapper(BS->RaiseTPL, 1, TPL_NOTIFY);
575 1.1.1.1.4.2 rmind
576 1.1.1.1.4.2 rmind //
577 1.1.1.1.4.2 rmind // Install the protocol interfaces
578 1.1.1.1.4.2 rmind //
579 1.1.1.1.4.2 rmind
580 1.1.1.1.4.2 rmind Index = 0;
581 1.1.1.1.4.2 rmind Status = EFI_SUCCESS;
582 1.1.1.1.4.2 rmind va_start (args, Handle);
583 1.1.1.1.4.2 rmind
584 1.1.1.1.4.2 rmind while (!EFI_ERROR(Status)) {
585 1.1.1.1.4.2 rmind
586 1.1.1.1.4.2 rmind //
587 1.1.1.1.4.2 rmind // If protocol is NULL, then it's the end of the list
588 1.1.1.1.4.2 rmind //
589 1.1.1.1.4.2 rmind
590 1.1.1.1.4.2 rmind Protocol = va_arg(args, EFI_GUID *);
591 1.1.1.1.4.2 rmind if (!Protocol) {
592 1.1.1.1.4.2 rmind break;
593 1.1.1.1.4.2 rmind }
594 1.1.1.1.4.2 rmind
595 1.1.1.1.4.2 rmind OldInterface = va_arg(args, VOID *);
596 1.1.1.1.4.2 rmind NewInterface = va_arg(args, VOID *);
597 1.1.1.1.4.2 rmind
598 1.1.1.1.4.2 rmind //
599 1.1.1.1.4.2 rmind // Reinstall it
600 1.1.1.1.4.2 rmind //
601 1.1.1.1.4.2 rmind
602 1.1.1.1.4.2 rmind Status = uefi_call_wrapper(BS->ReinstallProtocolInterface, 4, Handle, Protocol, OldInterface, NewInterface);
603 1.1.1.1.4.2 rmind if (EFI_ERROR(Status)) {
604 1.1.1.1.4.2 rmind break;
605 1.1.1.1.4.2 rmind }
606 1.1.1.1.4.2 rmind
607 1.1.1.1.4.2 rmind Index += 1;
608 1.1.1.1.4.2 rmind }
609 1.1.1.1.4.2 rmind
610 1.1.1.1.4.2 rmind //
611 1.1.1.1.4.2 rmind // If there was an error, undo all the interfaces that were
612 1.1.1.1.4.2 rmind // reinstalled without any errors
613 1.1.1.1.4.2 rmind //
614 1.1.1.1.4.2 rmind
615 1.1.1.1.4.2 rmind if (EFI_ERROR(Status)) {
616 1.1.1.1.4.2 rmind va_start (args, Handle);
617 1.1.1.1.4.2 rmind while (Index) {
618 1.1.1.1.4.2 rmind
619 1.1.1.1.4.2 rmind Protocol = va_arg(args, EFI_GUID *);
620 1.1.1.1.4.2 rmind OldInterface = va_arg(args, VOID *);
621 1.1.1.1.4.2 rmind NewInterface = va_arg(args, VOID *);
622 1.1.1.1.4.2 rmind
623 1.1.1.1.4.2 rmind uefi_call_wrapper(BS->ReinstallProtocolInterface, 4, Handle, Protocol, NewInterface, OldInterface);
624 1.1.1.1.4.2 rmind
625 1.1.1.1.4.2 rmind Index -= 1;
626 1.1.1.1.4.2 rmind }
627 1.1.1.1.4.2 rmind }
628 1.1.1.1.4.2 rmind
629 1.1.1.1.4.2 rmind //
630 1.1.1.1.4.2 rmind // Done
631 1.1.1.1.4.2 rmind //
632 1.1.1.1.4.2 rmind
633 1.1.1.1.4.2 rmind uefi_call_wrapper(BS->RestoreTPL, 1, OldTpl);
634 1.1.1.1.4.2 rmind return Status;
635 1.1.1.1.4.2 rmind }
636