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