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.
18 Find the first instance of this Protocol
19 in the system and return it's interface.
22 @param ProtocolGuid Provides the protocol to search for
23 @param Interface On return, a pointer to the first interface
24 that matches ProtocolGuid
26 @retval EFI_SUCCESS A protocol instance matching ProtocolGuid was found
27 @retval EFI_NOT_FOUND No protocol instances were found that match ProtocolGuid
31 EfiLibLocateProtocol (
32 IN EFI_GUID
*ProtocolGuid
,
38 Status
= gBS
->LocateProtocol (
48 Function opens and returns a file handle to the root directory of a volume.
50 @param DeviceHandle A handle for a device
52 @return A valid file handle or NULL is returned
57 IN EFI_HANDLE DeviceHandle
61 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*Volume
;
67 // File the file system interface to the device
69 Status
= gBS
->HandleProtocol (
71 &gEfiSimpleFileSystemProtocolGuid
,
76 // Open the root directory of the volume
78 if (!EFI_ERROR (Status
)) {
79 Status
= Volume
->OpenVolume (
87 return EFI_ERROR (Status
) ? NULL
: File
;
92 Function gets the file system information from an open file descriptor,
93 and stores it in a buffer allocated from pool.
96 @param FHand The file handle.
98 @return A pointer to a buffer with file information.
99 @retval NULL is returned if failed to get Volume Label Info.
102 EFI_FILE_SYSTEM_VOLUME_LABEL
*
103 EfiLibFileSystemVolumeLabelInfo (
104 IN EFI_FILE_HANDLE FHand
108 EFI_FILE_SYSTEM_VOLUME_LABEL
*VolumeInfo
= NULL
;
111 Status
= FHand
->GetInfo (FHand
, &gEfiFileSystemVolumeLabelInfoIdGuid
, &Size
, VolumeInfo
);
112 if (Status
== EFI_BUFFER_TOO_SMALL
) {
113 VolumeInfo
= AllocateZeroPool (Size
);
114 Status
= FHand
->GetInfo (FHand
, &gEfiFileSystemVolumeLabelInfoIdGuid
, &Size
, VolumeInfo
);
117 return EFI_ERROR(Status
)?NULL
:VolumeInfo
;
123 @param Src The source.
125 @return A new string which is duplicated copy of the source.
126 @retval NULL If there is not enough memory.
137 Size
= StrSize (Src
); //at least 2bytes
138 Dest
= AllocateZeroPool (Size
);
139 // ASSERT (Dest != NULL);
141 CopyMem (Dest
, Src
, Size
);
146 //Compare strings case insensitive
150 IN CONST CHAR16
*FirstString
,
151 IN CONST CHAR16
*SecondString
155 while ((*FirstString
!= L
'\0') && ((*FirstString
& ~0x20) == (*SecondString
& ~0x20))) {
159 return *FirstString
- *SecondString
;
165 Function gets the file information from an open file descriptor, and stores it
166 in a buffer allocated from pool.
168 @param FHand File Handle.
170 @return A pointer to a buffer with file information or NULL is returned
175 IN EFI_FILE_HANDLE FHand
179 EFI_FILE_INFO
*FileInfo
= NULL
;
182 Status
= FHand
->GetInfo (FHand
, &gEfiFileInfoGuid
, &Size
, FileInfo
);
183 if (Status
== EFI_BUFFER_TOO_SMALL
) {
184 FileInfo
= AllocateZeroPool (Size
);
185 Status
= FHand
->GetInfo (FHand
, &gEfiFileInfoGuid
, &Size
, FileInfo
);
188 return EFI_ERROR(Status
)?NULL
:FileInfo
;
191 EFI_FILE_SYSTEM_INFO
*
192 EfiLibFileSystemInfo (
193 IN EFI_FILE_HANDLE FHand
197 EFI_FILE_SYSTEM_INFO
*FileSystemInfo
= NULL
;
200 Status
= FHand
->GetInfo (FHand
, &gEfiFileSystemInfoGuid
, &Size
, FileSystemInfo
);
201 if (Status
== EFI_BUFFER_TOO_SMALL
) {
202 FileSystemInfo
= AllocateZeroPool (Size
);
203 Status
= FHand
->GetInfo (FHand
, &gEfiFileSystemInfoGuid
, &Size
, FileSystemInfo
);
206 return EFI_ERROR(Status
)?NULL
:FileSystemInfo
;
210 Function is used to determine the number of device path instances
211 that exist in a device path.
214 @param DevicePath A pointer to a device path data structure.
216 @return This function counts and returns the number of device path instances
221 EfiDevicePathInstanceCount (
222 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
229 while (GetNextDevicePathInstance (&DevicePath
, &Size
) != NULL
) {
237 Adjusts the size of a previously allocated buffer.
240 @param OldPool - A pointer to the buffer whose size is being adjusted.
241 @param OldSize - The size of the current buffer.
242 @param NewSize - The size of the new buffer.
244 @return The newly allocated buffer.
245 @retval NULL Allocation failed.
259 NewPool
= AllocateZeroPool (NewSize
);
262 if (OldPool
!= NULL
) {
263 if (NewPool
!= NULL
) {
264 CopyMem (NewPool
, OldPool
, OldSize
< NewSize
? OldSize
: NewSize
);
274 Compare two EFI_TIME data.
277 @param FirstTime - A pointer to the first EFI_TIME data.
278 @param SecondTime - A pointer to the second EFI_TIME data.
280 @retval TRUE The FirstTime is not later than the SecondTime.
281 @retval FALSE The FirstTime is later than the SecondTime.
286 IN EFI_TIME
*FirstTime
,
287 IN EFI_TIME
*SecondTime
290 if (FirstTime
->Year
!= SecondTime
->Year
) {
291 return (BOOLEAN
) (FirstTime
->Year
< SecondTime
->Year
);
292 } else if (FirstTime
->Month
!= SecondTime
->Month
) {
293 return (BOOLEAN
) (FirstTime
->Month
< SecondTime
->Month
);
294 } else if (FirstTime
->Day
!= SecondTime
->Day
) {
295 return (BOOLEAN
) (FirstTime
->Day
< SecondTime
->Day
);
296 } else if (FirstTime
->Hour
!= SecondTime
->Hour
) {
297 return (BOOLEAN
) (FirstTime
->Hour
< SecondTime
->Hour
);
298 } else if (FirstTime
->Minute
!= SecondTime
->Minute
) {
299 return (BOOLEAN
) (FirstTime
->Minute
< FirstTime
->Minute
);
300 } else if (FirstTime
->Second
!= SecondTime
->Second
) {
301 return (BOOLEAN
) (FirstTime
->Second
< SecondTime
->Second
);
304 return (BOOLEAN
) (FirstTime
->Nanosecond
<= SecondTime
->Nanosecond
);
308 Get a string from the Data Hub record based on
311 @param DevPath The device Path.
313 @return A string located from the Data Hub records based on
315 @retval NULL If failed to get the String from Data Hub.
320 EfiLibStrFromDatahub (
321 IN EFI_DEVICE_PATH_PROTOCOL *DevPath