2 Utility routines used by boot maintenance modules.
4 Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #ifdef __MAKEWITH_TIANO
18 #include "gnuefi-helper.h"
20 #include "../include/refit_call_wrapper.h"
24 Find the first instance of this Protocol
25 in the system and return it's interface.
28 @param ProtocolGuid Provides the protocol to search for
29 @param Interface On return, a pointer to the first interface
30 that matches ProtocolGuid
32 @retval EFI_SUCCESS A protocol instance matching ProtocolGuid was found
33 @retval EFI_NOT_FOUND No protocol instances were found that match ProtocolGuid
37 EfiLibLocateProtocol (
38 IN EFI_GUID
*ProtocolGuid
,
44 Status
= refit_call3_wrapper(gBS
->LocateProtocol
,
54 Function opens and returns a file handle to the root directory of a volume.
56 @param DeviceHandle A handle for a device
58 @return A valid file handle or NULL is returned
63 IN EFI_HANDLE DeviceHandle
67 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*Volume
;
73 // File the file system interface to the device
75 Status
= refit_call3_wrapper(gBS
->HandleProtocol
,
77 &gEfiSimpleFileSystemProtocolGuid
,
82 // Open the root directory of the volume
84 if (!EFI_ERROR (Status
)) {
85 Status
= Volume
->OpenVolume (
93 return EFI_ERROR (Status
) ? NULL
: File
;
99 @param Src The source.
101 @return A new string which is duplicated copy of the source.
102 @retval NULL If there is not enough memory.
113 Size
= StrSize (Src
); //at least 2bytes
114 Dest
= AllocateZeroPool (Size
);
116 CopyMem (Dest
, Src
, Size
);
122 //Compare strings case insensitive
126 IN CONST CHAR16
*FirstString
,
127 IN CONST CHAR16
*SecondString
131 while ((*FirstString
!= L
'\0') && ((*FirstString
& ~0x20) == (*SecondString
& ~0x20))) {
135 return *FirstString
- *SecondString
;
140 Function gets the file information from an open file descriptor, and stores it
141 in a buffer allocated from pool.
143 @param FHand File Handle.
145 @return A pointer to a buffer with file information or NULL is returned
150 IN EFI_FILE_HANDLE FHand
154 EFI_FILE_INFO
*FileInfo
= NULL
;
157 Status
= FHand
->GetInfo (FHand
, &gEfiFileInfoGuid
, &Size
, FileInfo
);
158 if (Status
== EFI_BUFFER_TOO_SMALL
) {
159 FileInfo
= AllocateZeroPool (Size
);
160 Status
= FHand
->GetInfo (FHand
, &gEfiFileInfoGuid
, &Size
, FileInfo
);
163 return EFI_ERROR(Status
)?NULL
:FileInfo
;
166 EFI_FILE_SYSTEM_INFO
*
167 EfiLibFileSystemInfo (
168 IN EFI_FILE_HANDLE FHand
172 EFI_FILE_SYSTEM_INFO
*FileSystemInfo
= NULL
;
175 Status
= FHand
->GetInfo (FHand
, &gEfiFileSystemInfoGuid
, &Size
, FileSystemInfo
);
176 if (Status
== EFI_BUFFER_TOO_SMALL
) {
177 FileSystemInfo
= AllocateZeroPool (Size
);
178 Status
= FHand
->GetInfo (FHand
, &gEfiFileSystemInfoGuid
, &Size
, FileSystemInfo
);
181 return EFI_ERROR(Status
)?NULL
:FileSystemInfo
;
185 Adjusts the size of a previously allocated buffer.
188 @param OldPool - A pointer to the buffer whose size is being adjusted.
189 @param OldSize - The size of the current buffer.
190 @param NewSize - The size of the new buffer.
192 @return The newly allocated buffer.
193 @retval NULL Allocation failed.
207 NewPool
= AllocateZeroPool (NewSize
);
210 if (OldPool
!= NULL
) {
211 if (NewPool
!= NULL
) {
212 CopyMem (NewPool
, OldPool
, OldSize
< NewSize
? OldSize
: NewSize
);