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