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
);
124 Function gets the file information from an open file descriptor, and stores it
125 in a buffer allocated from pool.
127 @param FHand File Handle.
129 @return A pointer to a buffer with file information or NULL is returned
134 IN EFI_FILE_HANDLE FHand
138 EFI_FILE_INFO
*FileInfo
= NULL
;
141 Status
= FHand
->GetInfo (FHand
, &gEfiFileInfoGuid
, &Size
, FileInfo
);
142 if (Status
== EFI_BUFFER_TOO_SMALL
) {
143 FileInfo
= AllocateZeroPool (Size
);
144 Status
= FHand
->GetInfo (FHand
, &gEfiFileInfoGuid
, &Size
, FileInfo
);
147 return EFI_ERROR(Status
)?NULL
:FileInfo
;
150 EFI_FILE_SYSTEM_INFO
*
151 EfiLibFileSystemInfo (
152 IN EFI_FILE_HANDLE FHand
156 EFI_FILE_SYSTEM_INFO
*FileSystemInfo
= NULL
;
159 Status
= FHand
->GetInfo (FHand
, &gEfiFileSystemInfoGuid
, &Size
, FileSystemInfo
);
160 if (Status
== EFI_BUFFER_TOO_SMALL
) {
161 FileSystemInfo
= AllocateZeroPool (Size
);
162 Status
= FHand
->GetInfo (FHand
, &gEfiFileSystemInfoGuid
, &Size
, FileSystemInfo
);
165 return EFI_ERROR(Status
)?NULL
:FileSystemInfo
;
169 Adjusts the size of a previously allocated buffer.
172 @param OldPool - A pointer to the buffer whose size is being adjusted.
173 @param OldSize - The size of the current buffer.
174 @param NewSize - The size of the new buffer.
176 @return The newly allocated buffer.
177 @retval NULL Allocation failed.
191 NewPool
= AllocateZeroPool (NewSize
);
194 if (OldPool
!= NULL
) {
195 if (NewPool
!= NULL
) {
196 CopyMem (NewPool
, OldPool
, OldSize
< NewSize
? OldSize
: NewSize
);