2 Utility routines used by boot maintenance modules.
4 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
13 Function opens and returns a file handle to the root directory of a volume.
15 @param DeviceHandle A handle for a device
17 @return A valid file handle or NULL is returned
22 IN EFI_HANDLE DeviceHandle
26 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*Volume
;
32 // File the file system interface to the device
34 Status
= gBS
->HandleProtocol (
36 &gEfiSimpleFileSystemProtocolGuid
,
41 // Open the root directory of the volume
43 if (!EFI_ERROR (Status
)) {
44 Status
= Volume
->OpenVolume (
52 return EFI_ERROR (Status
) ? NULL
: File
;
57 Helper function called as part of the code needed
58 to allocate the proper sized buffer for various
62 @param Status Current status
63 @param Buffer Current allocated buffer, or NULL
64 @param BufferSize Current buffer size needed
66 @retval TRUE if the buffer was reallocated and the caller
67 should try the API again.
68 @retval FALSE The caller should not call this function again.
73 IN OUT EFI_STATUS
*Status
,
81 // If this is an initial request, buffer will be null with a new buffer size
83 if ((*Buffer
== NULL
) && (BufferSize
!= 0)) {
84 *Status
= EFI_BUFFER_TOO_SMALL
;
87 // If the status code is "buffer too small", resize the buffer
90 if (*Status
== EFI_BUFFER_TOO_SMALL
) {
92 if (*Buffer
!= NULL
) {
96 *Buffer
= AllocateZeroPool (BufferSize
);
98 if (*Buffer
!= NULL
) {
101 *Status
= EFI_OUT_OF_RESOURCES
;
105 // If there's an error, free the buffer
107 if (!TryAgain
&& EFI_ERROR (*Status
) && (*Buffer
!= NULL
)) {
116 Function returns the value of the specified variable.
119 @param Name A Null-terminated Unicode string that is
120 the name of the vendor's variable.
121 @param VendorGuid A unique identifier for the vendor.
123 @return The payload of the variable.
124 @retval NULL If the variable can't be read.
130 IN EFI_GUID
*VendorGuid
135 return BdsLibGetVariableAndSize (Name
, VendorGuid
, &VarSize
);
139 Function deletes the variable specified by VarName and VarGuid.
141 @param VarName A Null-terminated Unicode string that is
142 the name of the vendor's variable.
144 @param VarGuid A unique identifier for the vendor.
146 @retval EFI_SUCCESS The variable was found and removed
147 @retval EFI_UNSUPPORTED The variable store was inaccessible
148 @retval EFI_OUT_OF_RESOURCES The temporary buffer was not available
149 @retval EFI_NOT_FOUND The variable was not found
153 EfiLibDeleteVariable (
161 VarBuf
= EfiLibGetVariable (VarName
, VarGuid
);
162 Status
= EFI_NOT_FOUND
;
164 if (VarBuf
!= NULL
) {
166 // Delete variable from Storage
168 Status
= gRT
->SetVariable (
171 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
176 // Deleting variable with current variable implementation shouldn't fail.
178 ASSERT_EFI_ERROR (Status
);
187 Function gets the file system information from an open file descriptor,
188 and stores it in a buffer allocated from pool.
191 @param FHand The file handle.
193 @return A pointer to a buffer with file information.
194 @retval NULL is returned if failed to get Vaolume Label Info.
197 EFI_FILE_SYSTEM_VOLUME_LABEL
*
198 EfiLibFileSystemVolumeLabelInfo (
199 IN EFI_FILE_HANDLE FHand
203 EFI_FILE_SYSTEM_VOLUME_LABEL
*Buffer
;
206 // Initialize for GrowBuffer loop
209 BufferSize
= SIZE_OF_EFI_FILE_SYSTEM_VOLUME_LABEL
+ 200;
212 // Call the real function
214 while (EfiGrowBuffer (&Status
, (VOID
**) &Buffer
, BufferSize
)) {
215 Status
= FHand
->GetInfo (
217 &gEfiFileSystemVolumeLabelInfoIdGuid
,
229 @param Src The source.
231 @return A new string which is duplicated copy of the source.
232 @retval NULL If there is not enough memory.
243 Size
= StrSize (Src
);
244 Dest
= AllocateZeroPool (Size
);
245 ASSERT (Dest
!= NULL
);
247 CopyMem (Dest
, Src
, Size
);
255 Function gets the file information from an open file descriptor, and stores it
256 in a buffer allocated from pool.
258 @param FHand File Handle.
260 @return A pointer to a buffer with file information or NULL is returned
265 IN EFI_FILE_HANDLE FHand
269 EFI_FILE_INFO
*Buffer
;
273 // Initialize for GrowBuffer loop
276 BufferSize
= SIZE_OF_EFI_FILE_INFO
+ 200;
279 // Call the real function
281 while (EfiGrowBuffer (&Status
, (VOID
**) &Buffer
, BufferSize
)) {
282 Status
= FHand
->GetInfo (
294 Function is used to determine the number of device path instances
295 that exist in a device path.
298 @param DevicePath A pointer to a device path data structure.
300 @return This function counts and returns the number of device path instances
305 EfiDevicePathInstanceCount (
306 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
313 while (GetNextDevicePathInstance (&DevicePath
, &Size
) != NULL
) {
322 Get a string from the Data Hub record based on
325 @param DevPath The device Path.
327 @return A string located from the Data Hub records based on
329 @retval NULL If failed to get the String from Data Hub.
333 EfiLibStrFromDatahub (
334 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
342 Find the first instance of this Protocol
343 in the system and return it's interface.
346 @param ProtocolGuid Provides the protocol to search for
347 @param Interface On return, a pointer to the first interface
348 that matches ProtocolGuid
350 @retval EFI_SUCCESS A protocol instance matching ProtocolGuid was found
351 @retval EFI_NOT_FOUND No protocol instances were found that match ProtocolGuid
355 EfiLibLocateProtocol (
356 IN EFI_GUID
*ProtocolGuid
,
362 Status
= gBS
->LocateProtocol (