3
Copyright (c) 1998 Intel Corporation
19
#include "efistdarg.h" // !!!
24
IN EFI_GUID *ProtocolGuid,
28
// Find the first instance of this Protocol in the system and return it's interface
32
UINTN NumberHandles, Index;
37
Status = LibLocateHandle (ByProtocol, ProtocolGuid, NULL, &NumberHandles, &Handles);
38
if (EFI_ERROR(Status)) {
39
DEBUG((D_INFO, "LibLocateProtocol: Handle not found\n"));
43
for (Index=0; Index < NumberHandles; Index++) {
44
Status = BS->HandleProtocol (Handles[Index], ProtocolGuid, Interface);
45
if (!EFI_ERROR(Status)) {
59
IN EFI_LOCATE_SEARCH_TYPE SearchType,
60
IN EFI_GUID *Protocol OPTIONAL,
61
IN VOID *SearchKey OPTIONAL,
62
IN OUT UINTN *NoHandles,
63
OUT EFI_HANDLE **Buffer
71
// Initialize for GrowBuffer loop
76
BufferSize = 50 * sizeof(EFI_HANDLE);
79
// Call the real function
82
while (GrowBuffer (&Status, (VOID **) Buffer, BufferSize)) {
84
Status = BS->LocateHandle (
94
*NoHandles = BufferSize / sizeof (EFI_HANDLE);
95
if (EFI_ERROR(Status)) {
103
LibLocateHandleByDiskSignature (
105
IN UINT8 SignatureType,
107
IN OUT UINTN *NoHandles,
108
OUT EFI_HANDLE **Buffer
114
UINTN NoBlockIoHandles;
115
EFI_HANDLE *BlockIoBuffer;
116
EFI_DEVICE_PATH *DevicePath;
118
EFI_DEVICE_PATH *Start, *Next, *DevPath;
119
HARDDRIVE_DEVICE_PATH *HardDriveDevicePath;
121
BOOLEAN PreviousNodeIsHardDriveDevicePath;
124
// Initialize for GrowBuffer loop
127
BlockIoBuffer = NULL;
128
BufferSize = 50 * sizeof(EFI_HANDLE);
131
// Call the real function
134
while (GrowBuffer (&Status, (VOID **)&BlockIoBuffer, BufferSize)) {
137
// Get list of device handles that support the BLOCK_IO Protocol.
140
Status = BS->LocateHandle (
150
NoBlockIoHandles = BufferSize / sizeof (EFI_HANDLE);
151
if (EFI_ERROR(Status)) {
152
NoBlockIoHandles = 0;
156
// If there was an error or there are no device handles that support
157
// the BLOCK_IO Protocol, then return.
160
if (NoBlockIoHandles == 0) {
161
FreePool(BlockIoBuffer);
168
// Loop through all the device handles that support the BLOCK_IO Protocol
173
for(Index=0;Index<NoBlockIoHandles;Index++) {
175
Status = BS->HandleProtocol (BlockIoBuffer[Index],
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
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
185
// Path, then we have found a match.
190
if (DevicePath != NULL) {
192
PreviousNodeIsHardDriveDevicePath = FALSE;
194
DevPath = DevicePath;
198
// Check for end of device path type
203
if ((DevicePathType(DevPath) == MEDIA_DEVICE_PATH) &&
204
(DevicePathSubType(DevPath) == MEDIA_HARDDRIVE_DP)) {
206
HardDriveDevicePath = (HARDDRIVE_DEVICE_PATH *)(DevPath);
208
if (PreviousNodeIsHardDriveDevicePath == FALSE) {
210
Next = NextDevicePathNode(DevPath);
211
if (IsDevicePathEndType(Next)) {
212
if ((HardDriveDevicePath->MBRType == MBRType) &&
213
(HardDriveDevicePath->SignatureType == SignatureType)) {
214
switch(SignatureType) {
215
case SIGNATURE_TYPE_MBR:
216
if (*((UINT32 *)(Signature)) == *(UINT32 *)(&(HardDriveDevicePath->Signature[0]))) {
220
case SIGNATURE_TYPE_GUID:
221
if (CompareGuid((EFI_GUID *)Signature,(EFI_GUID *)(&(HardDriveDevicePath->Signature[0]))) == 0) {
229
PreviousNodeIsHardDriveDevicePath = TRUE;
231
PreviousNodeIsHardDriveDevicePath = FALSE;
234
if (IsDevicePathEnd(DevPath)) {
238
DevPath = NextDevicePathNode(DevPath);
243
if (Match == FALSE) {
244
BlockIoBuffer[Index] = NULL;
246
*NoHandles = *NoHandles + 1;
251
// If there are no matches, then return
254
if (*NoHandles == 0) {
255
FreePool(BlockIoBuffer);
262
// Allocate space for the return buffer of device handles.
265
*Buffer = AllocatePool(*NoHandles * sizeof(EFI_HANDLE));
267
if (*Buffer == NULL) {
268
FreePool(BlockIoBuffer);
271
return EFI_OUT_OF_RESOURCES;
275
// Build list of matching device handles.
279
for(Index=0;Index<NoBlockIoHandles;Index++) {
280
if (BlockIoBuffer[Index] != NULL) {
281
(*Buffer)[*NoHandles] = BlockIoBuffer[Index];
282
*NoHandles = *NoHandles + 1;
286
FreePool(BlockIoBuffer);
293
IN EFI_HANDLE DeviceHandle
297
EFI_FILE_IO_INTERFACE *Volume;
298
EFI_FILE_HANDLE File;
302
// File the file system interface to the device
305
Status = BS->HandleProtocol (DeviceHandle, &FileSystemProtocol, (VOID*)&Volume);
308
// Open the root directory of the volume
311
if (!EFI_ERROR(Status)) {
312
Status = Volume->OpenVolume(Volume, &File);
319
return EFI_ERROR(Status) ? NULL : File;
324
IN EFI_FILE_HANDLE FHand
328
EFI_FILE_INFO *Buffer;
332
// Initialize for GrowBuffer loop
336
BufferSize = SIZE_OF_EFI_FILE_INFO + 200;
339
// Call the real function
342
while (GrowBuffer (&Status, (VOID **) &Buffer, BufferSize)) {
343
Status = FHand->GetInfo (
355
EFI_FILE_SYSTEM_INFO *
357
IN EFI_FILE_HANDLE FHand
361
EFI_FILE_SYSTEM_INFO *Buffer;
365
// Initialize for GrowBuffer loop
369
BufferSize = SIZE_OF_EFI_FILE_SYSTEM_INFO + 200;
372
// Call the real function
375
while (GrowBuffer (&Status, (VOID **) &Buffer, BufferSize)) {
376
Status = FHand->GetInfo (
387
EFI_FILE_SYSTEM_VOLUME_LABEL_INFO *
388
LibFileSystemVolumeLabelInfo (
389
IN EFI_FILE_HANDLE FHand
393
EFI_FILE_SYSTEM_VOLUME_LABEL_INFO *Buffer;
397
// Initialize for GrowBuffer loop
401
BufferSize = SIZE_OF_EFI_FILE_SYSTEM_VOLUME_LABEL_INFO + 200;
404
// Call the real function
407
while (GrowBuffer (&Status, (VOID **) &Buffer, BufferSize)) {
408
Status = FHand->GetInfo (
410
&FileSystemVolumeLabelInfo,
422
LibInstallProtocolInterfaces (
423
IN OUT EFI_HANDLE *Handle,
433
EFI_HANDLE OldHandle;
436
// Syncronize with notifcations
439
OldTpl = BS->RaiseTPL(TPL_NOTIFY);
443
// Install the protocol interfaces
447
Status = EFI_SUCCESS;
448
va_start (args, Handle);
450
while (!EFI_ERROR(Status)) {
453
// If protocol is NULL, then it's the end of the list
456
Protocol = va_arg(args, EFI_GUID *);
461
Interface = va_arg(args, VOID *);
467
DEBUG((D_INFO, "LibInstallProtocolInterface: %d %x\n", Protocol, Interface));
468
Status = BS->InstallProtocolInterface (Handle, Protocol, EFI_NATIVE_INTERFACE, Interface);
469
if (EFI_ERROR(Status)) {
477
// If there was an error, remove all the interfaces that were
478
// installed without any errors
481
if (EFI_ERROR(Status)) {
482
va_start (args, Handle);
485
Protocol = va_arg(args, EFI_GUID *);
486
Interface = va_arg(args, VOID *);
487
BS->UninstallProtocolInterface (*Handle, Protocol, Interface);
499
BS->RestoreTPL(OldTpl);
505
LibUninstallProtocolInterfaces (
506
IN EFI_HANDLE Handle,
516
va_start (args, Handle);
520
// If protocol is NULL, then it's the end of the list
523
Protocol = va_arg(args, EFI_GUID *);
528
Interface = va_arg(args, VOID *);
534
Status = BS->UninstallProtocolInterface (Handle, Protocol, Interface);
535
if (EFI_ERROR(Status)) {
536
DEBUG((D_ERROR, "LibUninstallProtocolInterfaces: failed %g, %r\n", Protocol, Handle));
543
LibReinstallProtocolInterfaces (
544
IN OUT EFI_HANDLE *Handle,
551
VOID *OldInterface, *NewInterface;
556
// Syncronize with notifcations
559
OldTpl = BS->RaiseTPL(TPL_NOTIFY);
562
// Install the protocol interfaces
566
Status = EFI_SUCCESS;
567
va_start (args, Handle);
569
while (!EFI_ERROR(Status)) {
572
// If protocol is NULL, then it's the end of the list
575
Protocol = va_arg(args, EFI_GUID *);
580
OldInterface = va_arg(args, VOID *);
581
NewInterface = va_arg(args, VOID *);
587
Status = BS->ReinstallProtocolInterface (Handle, Protocol, OldInterface, NewInterface);
588
if (EFI_ERROR(Status)) {
596
// If there was an error, undo all the interfaces that were
597
// reinstalled without any errors
600
if (EFI_ERROR(Status)) {
601
va_start (args, Handle);
604
Protocol = va_arg(args, EFI_GUID *);
605
OldInterface = va_arg(args, VOID *);
606
NewInterface = va_arg(args, VOID *);
608
BS->ReinstallProtocolInterface (Handle, Protocol, NewInterface, OldInterface);
618
BS->RestoreTPL(OldTpl);