jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 1 | /** @file
|
| 2 | Provides interface to EFI_FILE_HANDLE functionality.
|
| 3 |
|
rsun3 | 3bbe68a | 2012-02-01 06:06:08 +0000 | [diff] [blame] | 4 | Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved. <BR>
|
jcarsey | ac255da | 2010-01-25 20:06:10 +0000 | [diff] [blame] | 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
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 9 |
|
jcarsey | ac255da | 2010-01-25 20:06:10 +0000 | [diff] [blame] | 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.
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 12 |
|
| 13 | **/
|
| 14 |
|
| 15 | #include <Uefi.h>
|
| 16 |
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 17 | #include <Protocol/SimpleFileSystem.h>
|
jcarsey | 4eb59be | 2011-03-25 20:43:54 +0000 | [diff] [blame] | 18 | #include <Protocol/UnicodeCollation.h>
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 19 |
|
| 20 | #include <Guid/FileInfo.h>
|
| 21 |
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 22 | #include <Library/DebugLib.h>
|
| 23 | #include <Library/MemoryAllocationLib.h>
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 24 | #include <Library/BaseLib.h>
|
| 25 | #include <Library/BaseMemoryLib.h>
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 26 | #include <Library/FileHandleLib.h>
|
| 27 | #include <Library/PcdLib.h>
|
| 28 | #include <Library/PrintLib.h>
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 29 |
|
jcarsey | 4eb59be | 2011-03-25 20:43:54 +0000 | [diff] [blame] | 30 | CONST UINT16 gUnicodeFileTag = EFI_UNICODE_BYTE_ORDER_MARK;
|
| 31 |
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 32 | #define MAX_FILE_NAME_LEN 522 // (20 * (6+5+2))+1) unicode characters from EFI FAT spec (doubled for bytes)
|
| 33 | #define FIND_XXXXX_FILE_BUFFER_SIZE (SIZE_OF_EFI_FILE_INFO + MAX_FILE_NAME_LEN)
|
| 34 |
|
| 35 | /**
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 36 | This function will retrieve the information about the file for the handle
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 37 | specified and store it in allocated pool memory.
|
| 38 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 39 | This function allocates a buffer to store the file's information. It is the
|
qhuang8 | 69817bf | 2009-05-20 14:42:48 +0000 | [diff] [blame] | 40 | caller's responsibility to free the buffer
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 41 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 42 | @param FileHandle The file handle of the file for which information is
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 43 | being requested.
|
| 44 |
|
| 45 | @retval NULL information could not be retrieved.
|
| 46 |
|
| 47 | @return the information about the file
|
| 48 | **/
|
| 49 | EFI_FILE_INFO*
|
| 50 | EFIAPI
|
| 51 | FileHandleGetInfo (
|
| 52 | IN EFI_FILE_HANDLE FileHandle
|
| 53 | )
|
| 54 | {
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 55 | EFI_FILE_INFO *FileInfo;
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 56 | UINTN FileInfoSize;
|
| 57 | EFI_STATUS Status;
|
| 58 |
|
jcarsey | 4eb59be | 2011-03-25 20:43:54 +0000 | [diff] [blame] | 59 | if (FileHandle == NULL) {
|
| 60 | return (NULL);
|
| 61 | }
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 62 |
|
| 63 | //
|
| 64 | // Get the required size to allocate
|
| 65 | //
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 66 | FileInfoSize = 0;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 67 | FileInfo = NULL;
|
| 68 | Status = FileHandle->GetInfo(FileHandle,
|
| 69 | &gEfiFileInfoGuid,
|
| 70 | &FileInfoSize,
|
jcarsey | 4eb59be | 2011-03-25 20:43:54 +0000 | [diff] [blame] | 71 | NULL);
|
| 72 | if (Status == EFI_BUFFER_TOO_SMALL){
|
| 73 | //
|
| 74 | // error is expected. getting size to allocate
|
| 75 | //
|
| 76 | FileInfo = AllocateZeroPool(FileInfoSize);
|
| 77 | //
|
| 78 | // now get the information
|
| 79 | //
|
| 80 | Status = FileHandle->GetInfo(FileHandle,
|
| 81 | &gEfiFileInfoGuid,
|
| 82 | &FileInfoSize,
|
| 83 | FileInfo);
|
| 84 | //
|
| 85 | // if we got an error free the memory and return NULL
|
| 86 | //
|
Sergei Antonov | 037ca23 | 2013-09-20 20:10:17 +0000 | [diff] [blame] | 87 | if (EFI_ERROR(Status) && (FileInfo != NULL)) {
|
jcarsey | 4eb59be | 2011-03-25 20:43:54 +0000 | [diff] [blame] | 88 | FreePool(FileInfo);
|
Sergei Antonov | 037ca23 | 2013-09-20 20:10:17 +0000 | [diff] [blame] | 89 | FileInfo = NULL;
|
jcarsey | 4eb59be | 2011-03-25 20:43:54 +0000 | [diff] [blame] | 90 | }
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 91 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 92 | return (FileInfo);
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 93 | }
|
| 94 |
|
| 95 | /**
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 96 | This function sets the information about the file for the opened handle
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 97 | specified.
|
| 98 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 99 | @param[in] FileHandle The file handle of the file for which information
|
| 100 | is being set.
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 101 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 102 | @param[in] FileInfo The information to set.
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 103 |
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 104 | @retval EFI_SUCCESS The information was set.
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 105 | @retval EFI_INVALID_PARAMETER A parameter was out of range or invalid.
|
| 106 | @retval EFI_UNSUPPORTED The FileHandle does not support FileInfo.
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 107 | @retval EFI_NO_MEDIA The device has no medium.
|
| 108 | @retval EFI_DEVICE_ERROR The device reported an error.
|
| 109 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
|
| 110 | @retval EFI_WRITE_PROTECTED The file or medium is write protected.
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 111 | @retval EFI_ACCESS_DENIED The file was opened read only.
|
| 112 | @retval EFI_VOLUME_FULL The volume is full.
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 113 | **/
|
| 114 | EFI_STATUS
|
| 115 | EFIAPI
|
| 116 | FileHandleSetInfo (
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 117 | IN EFI_FILE_HANDLE FileHandle,
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 118 | IN CONST EFI_FILE_INFO *FileInfo
|
| 119 | )
|
| 120 | {
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 121 |
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 122 | //
|
| 123 | // ASSERT if the FileHandle or FileInfo is NULL
|
| 124 | //
|
| 125 | ASSERT (FileHandle != NULL);
|
| 126 | ASSERT (FileInfo != NULL);
|
| 127 |
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 128 | //
|
| 129 | // Set the info
|
| 130 | //
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 131 | return (FileHandle->SetInfo(FileHandle,
|
qhuang8 | 3d34202 | 2009-11-18 06:01:35 +0000 | [diff] [blame] | 132 | &gEfiFileInfoGuid,
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 133 | (UINTN)FileInfo->Size,
|
| 134 | (EFI_FILE_INFO*)FileInfo));
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 135 | }
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 136 |
|
| 137 | /**
|
| 138 | This function reads information from an opened file.
|
| 139 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 140 | If FileHandle is not a directory, the function reads the requested number of
|
| 141 | bytes from the file at the file's current position and returns them in Buffer.
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 142 | If the read goes beyond the end of the file, the read length is truncated to the
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 143 | end of the file. The file's current position is increased by the number of bytes
|
| 144 | returned. If FileHandle is a directory, the function reads the directory entry
|
| 145 | at the file's current position and returns the entry in Buffer. If the Buffer
|
| 146 | is not large enough to hold the current directory entry, then
|
| 147 | EFI_BUFFER_TOO_SMALL is returned and the current file position is not updated.
|
| 148 | BufferSize is set to be the size of the buffer needed to read the entry. On
|
| 149 | success, the current position is updated to the next directory entry. If there
|
| 150 | are no more directory entries, the read returns a zero-length buffer.
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 151 | EFI_FILE_INFO is the structure returned as the directory entry.
|
| 152 |
|
| 153 | @param FileHandle the opened file handle
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 154 | @param BufferSize on input the size of buffer in bytes. on return
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 155 | the number of bytes written.
|
| 156 | @param Buffer the buffer to put read data into.
|
| 157 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 158 | @retval EFI_SUCCESS Data was read.
|
| 159 | @retval EFI_NO_MEDIA The device has no media.
|
| 160 | @retval EFI_DEVICE_ERROR The device reported an error.
|
| 161 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
|
| 162 | @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 163 | size.
|
| 164 |
|
| 165 | **/
|
| 166 | EFI_STATUS
|
| 167 | EFIAPI
|
| 168 | FileHandleRead(
|
| 169 | IN EFI_FILE_HANDLE FileHandle,
|
| 170 | IN OUT UINTN *BufferSize,
|
| 171 | OUT VOID *Buffer
|
| 172 | )
|
| 173 | {
|
| 174 | //
|
| 175 | // ASSERT if FileHandle is NULL
|
| 176 | //
|
| 177 | ASSERT (FileHandle != NULL);
|
| 178 |
|
| 179 | //
|
| 180 | // Perform the read based on EFI_FILE_PROTOCOL
|
| 181 | //
|
| 182 | return (FileHandle->Read(FileHandle, BufferSize, Buffer));
|
| 183 | }
|
| 184 |
|
| 185 |
|
| 186 | /**
|
| 187 | Write data to a file.
|
| 188 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 189 | This function writes the specified number of bytes to the file at the current
|
| 190 | file position. The current file position is advanced the actual number of bytes
|
| 191 | written, which is returned in BufferSize. Partial writes only occur when there
|
| 192 | has been a data error during the write attempt (such as "volume space full").
|
| 193 | The file is automatically grown to hold the data if required. Direct writes to
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 194 | opened directories are not supported.
|
| 195 |
|
| 196 | @param FileHandle The opened file for writing
|
| 197 | @param BufferSize on input the number of bytes in Buffer. On output
|
| 198 | the number of bytes written.
|
| 199 | @param Buffer the buffer containing data to write is stored.
|
| 200 |
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 201 | @retval EFI_SUCCESS Data was written.
|
| 202 | @retval EFI_UNSUPPORTED Writes to an open directory are not supported.
|
| 203 | @retval EFI_NO_MEDIA The device has no media.
|
| 204 | @retval EFI_DEVICE_ERROR The device reported an error.
|
| 205 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
|
| 206 | @retval EFI_WRITE_PROTECTED The device is write-protected.
|
| 207 | @retval EFI_ACCESS_DENIED The file was open for read only.
|
| 208 | @retval EFI_VOLUME_FULL The volume is full.
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 209 | **/
|
| 210 | EFI_STATUS
|
| 211 | EFIAPI
|
| 212 | FileHandleWrite(
|
| 213 | IN EFI_FILE_HANDLE FileHandle,
|
| 214 | IN OUT UINTN *BufferSize,
|
| 215 | IN VOID *Buffer
|
| 216 | )
|
| 217 | {
|
| 218 | //
|
| 219 | // ASSERT if FileHandle is NULL
|
| 220 | //
|
| 221 | ASSERT (FileHandle != NULL);
|
| 222 | //
|
| 223 | // Perform the write based on EFI_FILE_PROTOCOL
|
| 224 | //
|
| 225 | return (FileHandle->Write(FileHandle, BufferSize, Buffer));
|
| 226 | }
|
| 227 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 228 | /**
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 229 | Close an open file handle.
|
| 230 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 231 | This function closes a specified file handle. All "dirty" cached file data is
|
| 232 | flushed to the device, and the file is closed. In all cases the handle is
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 233 | closed.
|
| 234 |
|
| 235 | @param FileHandle the file handle to close.
|
| 236 |
|
| 237 | @retval EFI_SUCCESS the file handle was closed sucessfully.
|
| 238 | **/
|
| 239 | EFI_STATUS
|
| 240 | EFIAPI
|
| 241 | FileHandleClose (
|
| 242 | IN EFI_FILE_HANDLE FileHandle
|
| 243 | )
|
| 244 | {
|
| 245 | EFI_STATUS Status;
|
| 246 | //
|
| 247 | // ASSERT if FileHandle is NULL
|
| 248 | //
|
| 249 | ASSERT (FileHandle != NULL);
|
| 250 | //
|
| 251 | // Perform the Close based on EFI_FILE_PROTOCOL
|
| 252 | //
|
| 253 | Status = FileHandle->Close(FileHandle);
|
| 254 | return Status;
|
| 255 | }
|
| 256 |
|
| 257 | /**
|
| 258 | Delete a file and close the handle
|
| 259 |
|
| 260 | This function closes and deletes a file. In all cases the file handle is closed.
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 261 | If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 262 | returned, but the handle is still closed.
|
| 263 |
|
| 264 | @param FileHandle the file handle to delete
|
| 265 |
|
| 266 | @retval EFI_SUCCESS the file was closed sucessfully
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 267 | @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 268 | deleted
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 269 | @retval INVALID_PARAMETER One of the parameters has an invalid value.
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 270 | **/
|
| 271 | EFI_STATUS
|
| 272 | EFIAPI
|
| 273 | FileHandleDelete (
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 274 | IN EFI_FILE_HANDLE FileHandle
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 275 | )
|
| 276 | {
|
| 277 | EFI_STATUS Status;
|
| 278 | //
|
| 279 | // ASSERT if FileHandle is NULL
|
| 280 | //
|
| 281 | ASSERT (FileHandle != NULL);
|
| 282 | //
|
| 283 | // Perform the Delete based on EFI_FILE_PROTOCOL
|
| 284 | //
|
| 285 | Status = FileHandle->Delete(FileHandle);
|
| 286 | return Status;
|
| 287 | }
|
| 288 |
|
| 289 | /**
|
| 290 | Set the current position in a file.
|
| 291 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 292 | This function sets the current file position for the handle to the position
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 293 | supplied. With the exception of seeking to position 0xFFFFFFFFFFFFFFFF, only
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 294 | absolute positioning is supported, and seeking past the end of the file is
|
| 295 | allowed (a subsequent write would grow the file). Seeking to position
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 296 | 0xFFFFFFFFFFFFFFFF causes the current position to be set to the end of the file.
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 297 | If FileHandle is a directory, the only position that may be set is zero. This
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 298 | has the effect of starting the read process of the directory entries over.
|
| 299 |
|
| 300 | @param FileHandle The file handle on which the position is being set
|
| 301 | @param Position Byte position from begining of file
|
| 302 |
|
| 303 | @retval EFI_SUCCESS Operation completed sucessfully.
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 304 | @retval EFI_UNSUPPORTED the seek request for non-zero is not valid on
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 305 | directories.
|
| 306 | @retval INVALID_PARAMETER One of the parameters has an invalid value.
|
| 307 | **/
|
| 308 | EFI_STATUS
|
| 309 | EFIAPI
|
| 310 | FileHandleSetPosition (
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 311 | IN EFI_FILE_HANDLE FileHandle,
|
| 312 | IN UINT64 Position
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 313 | )
|
| 314 | {
|
| 315 | //
|
| 316 | // ASSERT if FileHandle is NULL
|
| 317 | //
|
| 318 | ASSERT (FileHandle != NULL);
|
| 319 | //
|
| 320 | // Perform the SetPosition based on EFI_FILE_PROTOCOL
|
| 321 | //
|
| 322 | return (FileHandle->SetPosition(FileHandle, Position));
|
| 323 | }
|
| 324 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 325 | /**
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 326 | Gets a file's current position
|
| 327 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 328 | This function retrieves the current file position for the file handle. For
|
| 329 | directories, the current file position has no meaning outside of the file
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 330 | system driver and as such the operation is not supported. An error is returned
|
| 331 | if FileHandle is a directory.
|
| 332 |
|
| 333 | @param FileHandle The open file handle on which to get the position.
|
| 334 | @param Position Byte position from begining of file.
|
| 335 |
|
| 336 | @retval EFI_SUCCESS the operation completed sucessfully.
|
| 337 | @retval INVALID_PARAMETER One of the parameters has an invalid value.
|
| 338 | @retval EFI_UNSUPPORTED the request is not valid on directories.
|
| 339 | **/
|
| 340 | EFI_STATUS
|
| 341 | EFIAPI
|
| 342 | FileHandleGetPosition (
|
| 343 | IN EFI_FILE_HANDLE FileHandle,
|
| 344 | OUT UINT64 *Position
|
| 345 | )
|
| 346 | {
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 347 | if (Position == NULL) {
|
| 348 | return (EFI_INVALID_PARAMETER);
|
| 349 | }
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 350 | //
|
| 351 | // ASSERT if FileHandle is NULL
|
| 352 | //
|
| 353 | ASSERT (FileHandle != NULL);
|
| 354 | //
|
| 355 | // Perform the GetPosition based on EFI_FILE_PROTOCOL
|
| 356 | //
|
| 357 | return (FileHandle->GetPosition(FileHandle, Position));
|
| 358 | }
|
| 359 | /**
|
| 360 | Flushes data on a file
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 361 |
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 362 | This function flushes all modified data associated with a file to a device.
|
| 363 |
|
| 364 | @param FileHandle The file handle on which to flush data
|
| 365 |
|
| 366 | @retval EFI_SUCCESS The data was flushed.
|
| 367 | @retval EFI_NO_MEDIA The device has no media.
|
| 368 | @retval EFI_DEVICE_ERROR The device reported an error.
|
| 369 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
|
| 370 | @retval EFI_WRITE_PROTECTED The file or medium is write protected.
|
| 371 | @retval EFI_ACCESS_DENIED The file was opened for read only.
|
| 372 | **/
|
| 373 | EFI_STATUS
|
| 374 | EFIAPI
|
| 375 | FileHandleFlush (
|
| 376 | IN EFI_FILE_HANDLE FileHandle
|
| 377 | )
|
| 378 | {
|
| 379 | //
|
| 380 | // ASSERT if FileHandle is NULL
|
| 381 | //
|
| 382 | ASSERT (FileHandle != NULL);
|
| 383 | //
|
| 384 | // Perform the Flush based on EFI_FILE_PROTOCOL
|
| 385 | //
|
| 386 | return (FileHandle->Flush(FileHandle));
|
| 387 | }
|
| 388 |
|
| 389 | /**
|
| 390 | function to determine if a given handle is a directory handle
|
| 391 |
|
| 392 | if DirHandle is NULL then ASSERT()
|
| 393 |
|
| 394 | open the file information on the DirHandle and verify that the Attribute
|
| 395 | includes EFI_FILE_DIRECTORY bit set.
|
| 396 |
|
| 397 | @param DirHandle Handle to open file
|
| 398 |
|
| 399 | @retval EFI_SUCCESS DirHandle is a directory
|
| 400 | @retval EFI_INVALID_PARAMETER DirHandle did not have EFI_FILE_INFO available
|
| 401 | @retval EFI_NOT_FOUND DirHandle is not a directory
|
| 402 | **/
|
| 403 | EFI_STATUS
|
| 404 | EFIAPI
|
| 405 | FileHandleIsDirectory (
|
| 406 | IN EFI_FILE_HANDLE DirHandle
|
| 407 | )
|
| 408 | {
|
| 409 | EFI_FILE_INFO *DirInfo;
|
| 410 |
|
| 411 | //
|
| 412 | // ASSERT if DirHandle is NULL
|
| 413 | //
|
| 414 | ASSERT(DirHandle != NULL);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 415 |
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 416 | //
|
| 417 | // get the file information for DirHandle
|
| 418 | //
|
| 419 | DirInfo = FileHandleGetInfo (DirHandle);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 420 |
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 421 | //
|
| 422 | // Parse DirInfo
|
| 423 | //
|
| 424 | if (DirInfo == NULL) {
|
| 425 | //
|
| 426 | // We got nothing...
|
| 427 | //
|
| 428 | return (EFI_INVALID_PARAMETER);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 429 | }
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 430 | if ((DirInfo->Attribute & EFI_FILE_DIRECTORY) == 0) {
|
| 431 | //
|
| 432 | // Attributes say this is not a directory
|
| 433 | //
|
| 434 | FreePool (DirInfo);
|
| 435 | return (EFI_NOT_FOUND);
|
| 436 | }
|
| 437 | //
|
| 438 | // all good...
|
| 439 | //
|
| 440 | FreePool (DirInfo);
|
| 441 | return (EFI_SUCCESS);
|
| 442 | }
|
| 443 |
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 444 | /** Retrieve first entry from a directory.
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 445 |
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 446 | This function takes an open directory handle and gets information from the
|
| 447 | first entry in the directory. A buffer is allocated to contain
|
| 448 | the information and a pointer to the buffer is returned in *Buffer. The
|
| 449 | caller can use FileHandleFindNextFile() to get subsequent directory entries.
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 450 |
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 451 | The buffer will be freed by FileHandleFindNextFile() when the last directory
|
| 452 | entry is read. Otherwise, the caller must free the buffer, using FreePool,
|
| 453 | when finished with it.
|
| 454 |
|
| 455 | @param[in] DirHandle The file handle of the directory to search.
|
| 456 | @param[out] Buffer The pointer to pointer to buffer for file's information.
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 457 |
|
| 458 | @retval EFI_SUCCESS Found the first file.
|
| 459 | @retval EFI_NOT_FOUND Cannot find the directory.
|
| 460 | @retval EFI_NO_MEDIA The device has no media.
|
| 461 | @retval EFI_DEVICE_ERROR The device reported an error.
|
| 462 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
|
| 463 | @return Others status of FileHandleGetInfo, FileHandleSetPosition,
|
| 464 | or FileHandleRead
|
| 465 | **/
|
| 466 | EFI_STATUS
|
| 467 | EFIAPI
|
| 468 | FileHandleFindFirstFile (
|
| 469 | IN EFI_FILE_HANDLE DirHandle,
|
| 470 | OUT EFI_FILE_INFO **Buffer
|
| 471 | )
|
| 472 | {
|
| 473 | EFI_STATUS Status;
|
| 474 | UINTN BufferSize;
|
| 475 |
|
jcarsey | 4eb59be | 2011-03-25 20:43:54 +0000 | [diff] [blame] | 476 | if (Buffer == NULL || DirHandle == NULL) {
|
| 477 | return (EFI_INVALID_PARAMETER);
|
| 478 | }
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 479 |
|
| 480 | //
|
| 481 | // verify that DirHandle is a directory
|
| 482 | //
|
| 483 | Status = FileHandleIsDirectory(DirHandle);
|
| 484 | if (EFI_ERROR(Status)) {
|
| 485 | return (Status);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 486 | }
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 487 |
|
| 488 | //
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 489 | // Allocate a buffer sized to struct size + enough for the string at the end
|
| 490 | //
|
| 491 | BufferSize = FIND_XXXXX_FILE_BUFFER_SIZE;
|
| 492 | *Buffer = AllocateZeroPool(BufferSize);
|
jcarsey | 4eb59be | 2011-03-25 20:43:54 +0000 | [diff] [blame] | 493 | if (*Buffer == NULL){
|
| 494 | return (EFI_OUT_OF_RESOURCES);
|
| 495 | }
|
| 496 |
|
| 497 | //
|
| 498 | // reset to the begining of the directory
|
| 499 | //
|
| 500 | Status = FileHandleSetPosition(DirHandle, 0);
|
| 501 | if (EFI_ERROR(Status)) {
|
| 502 | FreePool(*Buffer);
|
| 503 | *Buffer = NULL;
|
| 504 | return (Status);
|
| 505 | }
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 506 |
|
| 507 | //
|
| 508 | // read in the info about the first file
|
| 509 | //
|
| 510 | Status = FileHandleRead (DirHandle, &BufferSize, *Buffer);
|
| 511 | ASSERT(Status != EFI_BUFFER_TOO_SMALL);
|
jcarsey | 74fa83f | 2012-02-02 16:55:30 +0000 | [diff] [blame] | 512 | if (EFI_ERROR(Status) || BufferSize == 0) {
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 513 | FreePool(*Buffer);
|
| 514 | *Buffer = NULL;
|
jcarsey | 74fa83f | 2012-02-02 16:55:30 +0000 | [diff] [blame] | 515 | if (BufferSize == 0) {
|
| 516 | return (EFI_NOT_FOUND);
|
| 517 | }
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 518 | return (Status);
|
| 519 | }
|
| 520 | return (EFI_SUCCESS);
|
| 521 | }
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 522 |
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 523 | /** Retrieve next entries from a directory.
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 524 |
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 525 | To use this function, the caller must first call the FileHandleFindFirstFile()
|
| 526 | function to get the first directory entry. Subsequent directory entries are
|
| 527 | retrieved by using the FileHandleFindNextFile() function. This function can
|
| 528 | be called several times to get each entry from the directory. If the call of
|
| 529 | FileHandleFindNextFile() retrieved the last directory entry, the next call of
|
| 530 | this function will set *NoFile to TRUE and free the buffer.
|
| 531 |
|
| 532 | @param[in] DirHandle The file handle of the directory.
|
| 533 | @param[out] Buffer The pointer to buffer for file's information.
|
| 534 | @param[out] NoFile The pointer to boolean when last file is found.
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 535 |
|
| 536 | @retval EFI_SUCCESS Found the next file, or reached last file
|
| 537 | @retval EFI_NO_MEDIA The device has no media.
|
| 538 | @retval EFI_DEVICE_ERROR The device reported an error.
|
| 539 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
|
| 540 | **/
|
| 541 | EFI_STATUS
|
| 542 | EFIAPI
|
| 543 | FileHandleFindNextFile(
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 544 | IN EFI_FILE_HANDLE DirHandle,
|
| 545 | OUT EFI_FILE_INFO *Buffer,
|
| 546 | OUT BOOLEAN *NoFile
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 547 | )
|
| 548 | {
|
| 549 | EFI_STATUS Status;
|
| 550 | UINTN BufferSize;
|
| 551 |
|
| 552 | //
|
| 553 | // ASSERTs for DirHandle or Buffer or NoFile poitners being NULL
|
| 554 | //
|
| 555 | ASSERT (DirHandle != NULL);
|
| 556 | ASSERT (Buffer != NULL);
|
| 557 | ASSERT (NoFile != NULL);
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 558 |
|
| 559 | //
|
| 560 | // This BufferSize MUST stay equal to the originally allocated one in GetFirstFile
|
| 561 | //
|
| 562 | BufferSize = FIND_XXXXX_FILE_BUFFER_SIZE;
|
| 563 |
|
| 564 | //
|
| 565 | // read in the info about the next file
|
| 566 | //
|
| 567 | Status = FileHandleRead (DirHandle, &BufferSize, Buffer);
|
| 568 | ASSERT(Status != EFI_BUFFER_TOO_SMALL);
|
| 569 | if (EFI_ERROR(Status)) {
|
| 570 | return (Status);
|
| 571 | }
|
| 572 |
|
| 573 | //
|
| 574 | // If we read 0 bytes (but did not have erros) we already read in the last file.
|
| 575 | //
|
| 576 | if (BufferSize == 0) {
|
| 577 | FreePool(Buffer);
|
| 578 | *NoFile = TRUE;
|
| 579 | }
|
| 580 |
|
| 581 | return (EFI_SUCCESS);
|
| 582 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 583 |
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 584 | /**
|
| 585 | Retrieve the size of a file.
|
| 586 |
|
| 587 | if FileHandle is NULL then ASSERT()
|
| 588 | if Size is NULL then ASSERT()
|
| 589 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 590 | This function extracts the file size info from the FileHandle's EFI_FILE_INFO
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 591 | data.
|
| 592 |
|
| 593 | @param FileHandle file handle from which size is retrieved
|
| 594 | @param Size pointer to size
|
| 595 |
|
| 596 | @retval EFI_SUCCESS operation was completed sucessfully
|
| 597 | @retval EFI_DEVICE_ERROR cannot access the file
|
| 598 | **/
|
| 599 | EFI_STATUS
|
| 600 | EFIAPI
|
| 601 | FileHandleGetSize (
|
| 602 | IN EFI_FILE_HANDLE FileHandle,
|
| 603 | OUT UINT64 *Size
|
| 604 | )
|
| 605 | {
|
| 606 | EFI_FILE_INFO *FileInfo;
|
| 607 |
|
| 608 | //
|
| 609 | // ASSERT for FileHandle or Size being NULL
|
| 610 | //
|
| 611 | ASSERT (FileHandle != NULL);
|
| 612 | ASSERT (Size != NULL);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 613 |
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 614 | //
|
| 615 | // get the FileInfo structure
|
| 616 | //
|
| 617 | FileInfo = FileHandleGetInfo(FileHandle);
|
| 618 | if (FileInfo == NULL) {
|
| 619 | return (EFI_DEVICE_ERROR);
|
| 620 | }
|
| 621 |
|
| 622 | //
|
| 623 | // Assign the Size pointer to the correct value
|
| 624 | //
|
| 625 | *Size = FileInfo->FileSize;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 626 |
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 627 | //
|
| 628 | // free the FileInfo memory
|
| 629 | //
|
| 630 | FreePool(FileInfo);
|
| 631 |
|
| 632 | return (EFI_SUCCESS);
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 633 | }
|
| 634 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 635 | /**
|
| 636 | Set the size of a file.
|
| 637 |
|
| 638 | If FileHandle is NULL then ASSERT().
|
| 639 |
|
| 640 | This function changes the file size info from the FileHandle's EFI_FILE_INFO
|
| 641 | data.
|
| 642 |
|
| 643 | @param FileHandle File handle whose size is to be changed.
|
| 644 | @param Size New size.
|
| 645 |
|
| 646 | @retval EFI_SUCCESS operation was completed sucessfully.
|
| 647 | @retval EFI_DEVICE_ERROR cannot access the file.
|
| 648 | **/
|
| 649 | EFI_STATUS
|
| 650 | EFIAPI
|
| 651 | FileHandleSetSize (
|
| 652 | IN EFI_FILE_HANDLE FileHandle,
|
| 653 | IN UINT64 Size
|
| 654 | )
|
| 655 | {
|
| 656 | EFI_FILE_INFO *FileInfo;
|
| 657 | EFI_STATUS Status;
|
| 658 |
|
| 659 | //
|
| 660 | // ASSERT for FileHandle or Size being NULL
|
| 661 | //
|
| 662 | ASSERT (FileHandle != NULL);
|
| 663 |
|
| 664 | //
|
| 665 | // get the FileInfo structure
|
| 666 | //
|
| 667 | FileInfo = FileHandleGetInfo(FileHandle);
|
| 668 | if (FileInfo == NULL) {
|
| 669 | return (EFI_DEVICE_ERROR);
|
| 670 | }
|
| 671 |
|
| 672 | //
|
| 673 | // Assign the FileSize pointer to the new value
|
| 674 | //
|
| 675 | FileInfo->FileSize = Size;
|
| 676 |
|
| 677 | Status = FileHandleSetInfo(FileHandle, FileInfo);
|
| 678 | //
|
| 679 | // free the FileInfo memory
|
| 680 | //
|
| 681 | FreePool(FileInfo);
|
| 682 |
|
| 683 | return (Status);
|
| 684 | }
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 685 |
|
| 686 | /**
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 687 | Safely append (on the left) with automatic string resizing given length of Destination and
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 688 | desired length of copy from Source.
|
| 689 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 690 | append the first D characters of Source to the end of Destination, where D is
|
| 691 | the lesser of Count and the StrLen() of Source. If appending those D characters
|
| 692 | will fit within Destination (whose Size is given as CurrentSize) and
|
| 693 | still leave room for a NULL terminator, then those characters are appended,
|
| 694 | starting at the original terminating NULL of Destination, and a new terminating
|
jcarsey | ac255da | 2010-01-25 20:06:10 +0000 | [diff] [blame] | 695 | NULL is appended.
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 696 |
|
| 697 | If appending D characters onto Destination will result in a overflow of the size
|
| 698 | given in CurrentSize the string will be grown such that the copy can be performed
|
| 699 | and CurrentSize will be updated to the new size.
|
| 700 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 701 | If Source is NULL, there is nothing to append, just return the current buffer in
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 702 | Destination.
|
| 703 |
|
| 704 | if Destination is NULL, then ASSERT()
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 705 | if Destination's current length (including NULL terminator) is already more then
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 706 | CurrentSize, then ASSERT()
|
| 707 |
|
ydong10 | 4ff7e37 | 2011-09-02 08:05:34 +0000 | [diff] [blame] | 708 | @param[in, out] Destination The String to append onto
|
| 709 | @param[in, out] CurrentSize on call the number of bytes in Destination. On
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 710 | return possibly the new size (still in bytes). if NULL
|
| 711 | then allocate whatever is needed.
|
| 712 | @param[in] Source The String to append from
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 713 | @param[in] Count Maximum number of characters to append. if 0 then
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 714 | all are appended.
|
| 715 |
|
| 716 | @return Destination return the resultant string.
|
| 717 | **/
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 718 | CHAR16*
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 719 | EFIAPI
|
| 720 | StrnCatGrowLeft (
|
| 721 | IN OUT CHAR16 **Destination,
|
| 722 | IN OUT UINTN *CurrentSize,
|
| 723 | IN CONST CHAR16 *Source,
|
| 724 | IN UINTN Count
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 725 | )
|
| 726 | {
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 727 | UINTN DestinationStartSize;
|
| 728 | UINTN NewSize;
|
jcarsey | 727a4c7 | 2009-07-09 17:36:06 +0000 | [diff] [blame] | 729 | UINTN CopySize;
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 730 |
|
| 731 | //
|
| 732 | // ASSERTs
|
| 733 | //
|
| 734 | ASSERT(Destination != NULL);
|
| 735 |
|
| 736 | //
|
| 737 | // If there's nothing to do then just return Destination
|
| 738 | //
|
| 739 | if (Source == NULL) {
|
| 740 | return (*Destination);
|
| 741 | }
|
| 742 |
|
| 743 | //
|
| 744 | // allow for NULL pointers address as Destination
|
| 745 | //
|
| 746 | if (*Destination != NULL) {
|
| 747 | ASSERT(CurrentSize != 0);
|
| 748 | DestinationStartSize = StrSize(*Destination);
|
| 749 | ASSERT(DestinationStartSize <= *CurrentSize);
|
| 750 | } else {
|
| 751 | DestinationStartSize = 0;
|
| 752 | // ASSERT(*CurrentSize == 0);
|
| 753 | }
|
| 754 |
|
| 755 | //
|
| 756 | // Append all of Source?
|
| 757 | //
|
| 758 | if (Count == 0) {
|
jcarsey | d595d4b | 2009-07-16 17:24:16 +0000 | [diff] [blame] | 759 | Count = StrSize(Source);
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 760 | }
|
| 761 |
|
| 762 | //
|
| 763 | // Test and grow if required
|
| 764 | //
|
| 765 | if (CurrentSize != NULL) {
|
| 766 | NewSize = *CurrentSize;
|
jcarsey | d595d4b | 2009-07-16 17:24:16 +0000 | [diff] [blame] | 767 | while (NewSize < (DestinationStartSize + Count)) {
|
| 768 | NewSize += 2 * Count;
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 769 | }
|
| 770 | *Destination = ReallocatePool(*CurrentSize, NewSize, *Destination);
|
| 771 | *CurrentSize = NewSize;
|
| 772 | } else {
|
jcarsey | d595d4b | 2009-07-16 17:24:16 +0000 | [diff] [blame] | 773 | *Destination = AllocateZeroPool(Count+sizeof(CHAR16));
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 774 | }
|
sfu5 | 02a758c | 2011-10-08 02:55:30 +0000 | [diff] [blame] | 775 | if (*Destination == NULL) {
|
| 776 | return NULL;
|
| 777 | }
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 778 |
|
jcarsey | 727a4c7 | 2009-07-09 17:36:06 +0000 | [diff] [blame] | 779 | CopySize = StrSize(*Destination);
|
jcarsey | 46f43bc | 2009-07-24 21:32:00 +0000 | [diff] [blame] | 780 | CopyMem((*Destination)+((Count-2)/sizeof(CHAR16)), *Destination, CopySize);
|
| 781 | CopyMem(*Destination, Source, Count-2);
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 782 | return (*Destination);
|
| 783 | }
|
| 784 |
|
| 785 | /**
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 786 | Function to get a full filename given a EFI_FILE_HANDLE somewhere lower on the
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 787 | directory 'stack'.
|
| 788 |
|
| 789 | if Handle is NULL, return EFI_INVALID_PARAMETER
|
| 790 |
|
| 791 | @param[in] Handle Handle to the Directory or File to create path to.
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 792 | @param[out] FullFileName pointer to pointer to generated full file name. It
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 793 | is the responsibility of the caller to free this memory
|
| 794 | with a call to FreePool().
|
| 795 | @retval EFI_SUCCESS the operation was sucessful and the FullFileName is valid.
|
| 796 | @retval EFI_INVALID_PARAMETER Handle was NULL.
|
| 797 | @retval EFI_INVALID_PARAMETER FullFileName was NULL.
|
| 798 | @retval EFI_OUT_OF_RESOURCES a memory allocation failed.
|
| 799 | **/
|
| 800 | EFI_STATUS
|
| 801 | EFIAPI
|
| 802 | FileHandleGetFileName (
|
| 803 | IN CONST EFI_FILE_HANDLE Handle,
|
| 804 | OUT CHAR16 **FullFileName
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 805 | )
|
| 806 | {
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 807 | EFI_STATUS Status;
|
| 808 | UINTN Size;
|
| 809 | EFI_FILE_HANDLE CurrentHandle;
|
| 810 | EFI_FILE_HANDLE NextHigherHandle;
|
| 811 | EFI_FILE_INFO *FileInfo;
|
| 812 |
|
| 813 | Size = 0;
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 814 |
|
| 815 | //
|
| 816 | // Check our parameters
|
| 817 | //
|
| 818 | if (FullFileName == NULL || Handle == NULL) {
|
| 819 | return (EFI_INVALID_PARAMETER);
|
| 820 | }
|
| 821 |
|
jcarsey | d595d4b | 2009-07-16 17:24:16 +0000 | [diff] [blame] | 822 | *FullFileName = NULL;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 823 | CurrentHandle = NULL;
|
jcarsey | d595d4b | 2009-07-16 17:24:16 +0000 | [diff] [blame] | 824 |
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 825 | Status = Handle->Open(Handle, &CurrentHandle, L".", EFI_FILE_MODE_READ, 0);
|
| 826 | if (!EFI_ERROR(Status)) {
|
| 827 | //
|
| 828 | // Reverse out the current directory on the device
|
| 829 | //
|
| 830 | for (;;) {
|
| 831 | FileInfo = FileHandleGetInfo(CurrentHandle);
|
| 832 | if (FileInfo == NULL) {
|
| 833 | Status = EFI_OUT_OF_RESOURCES;
|
| 834 | break;
|
| 835 | } else {
|
| 836 | //
|
| 837 | // We got info... do we have a name? if yes preceed the current path with it...
|
| 838 | //
|
| 839 | if (StrLen (FileInfo->FileName) == 0) {
|
jcarsey | 46f43bc | 2009-07-24 21:32:00 +0000 | [diff] [blame] | 840 | if (*FullFileName == NULL) {
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 841 | ASSERT((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));
|
jcarsey | 46f43bc | 2009-07-24 21:32:00 +0000 | [diff] [blame] | 842 | *FullFileName = StrnCatGrowLeft(FullFileName, &Size, L"\\", 0);
|
| 843 | }
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 844 | FreePool(FileInfo);
|
| 845 | break;
|
| 846 | } else {
|
jcarsey | 46f43bc | 2009-07-24 21:32:00 +0000 | [diff] [blame] | 847 | if (*FullFileName == NULL) {
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 848 | ASSERT((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));
|
jcarsey | 46f43bc | 2009-07-24 21:32:00 +0000 | [diff] [blame] | 849 | *FullFileName = StrnCatGrowLeft(FullFileName, &Size, L"\\", 0);
|
| 850 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 851 | ASSERT((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 852 | *FullFileName = StrnCatGrowLeft(FullFileName, &Size, FileInfo->FileName, 0);
|
jcarsey | 46f43bc | 2009-07-24 21:32:00 +0000 | [diff] [blame] | 853 | *FullFileName = StrnCatGrowLeft(FullFileName, &Size, L"\\", 0);
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 854 | FreePool(FileInfo);
|
| 855 | }
|
| 856 | }
|
| 857 | //
|
| 858 | // Move to the parent directory
|
| 859 | //
|
| 860 | Status = CurrentHandle->Open (CurrentHandle, &NextHigherHandle, L"..", EFI_FILE_MODE_READ, 0);
|
| 861 | if (EFI_ERROR (Status)) {
|
| 862 | break;
|
| 863 | }
|
| 864 |
|
| 865 | FileHandleClose(CurrentHandle);
|
| 866 | CurrentHandle = NextHigherHandle;
|
| 867 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 868 | } else if (Status == EFI_NOT_FOUND) {
|
| 869 | Status = EFI_SUCCESS;
|
| 870 | ASSERT((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));
|
| 871 | *FullFileName = StrnCatGrowLeft(FullFileName, &Size, L"\\", 0);
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 872 | }
|
| 873 |
|
| 874 | if (CurrentHandle != NULL) {
|
| 875 | CurrentHandle->Close (CurrentHandle);
|
| 876 | }
|
| 877 |
|
| 878 | if (EFI_ERROR(Status) && *FullFileName != NULL) {
|
jcarsey | 9eb53ac | 2009-07-08 17:26:58 +0000 | [diff] [blame] | 879 | FreePool(*FullFileName);
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 880 | }
|
| 881 |
|
| 882 | return (Status);
|
| 883 | }
|
| 884 |
|
| 885 | /**
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 886 | Function to read a single line from a file. The \n is not included in the returned
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 887 | buffer. The returned buffer must be callee freed.
|
| 888 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 889 | If the position upon start is 0, then the Ascii Boolean will be set. This should be
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 890 | maintained and not changed for all operations with the same file.
|
| 891 |
|
ydong10 | 4ff7e37 | 2011-09-02 08:05:34 +0000 | [diff] [blame] | 892 | @param[in] Handle FileHandle to read from.
|
| 893 | @param[in, out] Ascii Boolean value for indicating whether the file is Ascii (TRUE) or UCS2 (FALSE);
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 894 |
|
| 895 | @return The line of text from the file.
|
| 896 |
|
| 897 | @sa FileHandleReadLine
|
| 898 | **/
|
| 899 | CHAR16*
|
| 900 | EFIAPI
|
| 901 | FileHandleReturnLine(
|
| 902 | IN EFI_FILE_HANDLE Handle,
|
| 903 | IN OUT BOOLEAN *Ascii
|
| 904 | )
|
| 905 | {
|
| 906 | CHAR16 *RetVal;
|
| 907 | UINTN Size;
|
| 908 | EFI_STATUS Status;
|
| 909 |
|
| 910 | Size = 0;
|
| 911 | RetVal = NULL;
|
| 912 |
|
| 913 | Status = FileHandleReadLine(Handle, RetVal, &Size, FALSE, Ascii);
|
| 914 | if (Status == EFI_BUFFER_TOO_SMALL) {
|
jcarsey | 4eb59be | 2011-03-25 20:43:54 +0000 | [diff] [blame] | 915 | RetVal = AllocateZeroPool(Size);
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 916 | Status = FileHandleReadLine(Handle, RetVal, &Size, FALSE, Ascii);
|
| 917 | }
|
| 918 | ASSERT_EFI_ERROR(Status);
|
| 919 | if (EFI_ERROR(Status) && (RetVal != NULL)) {
|
| 920 | FreePool(RetVal);
|
| 921 | RetVal = NULL;
|
| 922 | }
|
| 923 | return (RetVal);
|
| 924 | }
|
| 925 |
|
| 926 | /**
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 927 | Function to read a single line (up to but not including the \n) from a EFI_FILE_HANDLE.
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 928 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 929 | If the position upon start is 0, then the Ascii Boolean will be set. This should be
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 930 | maintained and not changed for all operations with the same file.
|
| 931 |
|
ydong10 | 4ff7e37 | 2011-09-02 08:05:34 +0000 | [diff] [blame] | 932 | @param[in] Handle FileHandle to read from
|
| 933 | @param[in, out] Buffer pointer to buffer to read into
|
| 934 | @param[in, out] Size pointer to number of bytes in buffer
|
| 935 | @param[in] Truncate if TRUE then allows for truncation of the line to fit.
|
| 936 | if FALSE will reset the position to the begining of the
|
| 937 | line if the buffer is not large enough.
|
| 938 | @param[in, out] Ascii Boolean value for indicating whether the file is Ascii (TRUE) or UCS2 (FALSE);
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 939 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 940 | @retval EFI_SUCCESS the operation was sucessful. the line is stored in
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 941 | Buffer.
|
| 942 | @retval EFI_INVALID_PARAMETER Handle was NULL.
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 943 | @retval EFI_INVALID_PARAMETER Size was NULL.
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 944 | @retval EFI_BUFFER_TOO_SMALL Size was not enough space to store the line.
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 945 | Size was updated to minimum space required.
|
| 946 | @sa FileHandleRead
|
| 947 | **/
|
| 948 | EFI_STATUS
|
| 949 | EFIAPI
|
| 950 | FileHandleReadLine(
|
| 951 | IN EFI_FILE_HANDLE Handle,
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 952 | IN OUT CHAR16 *Buffer,
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 953 | IN OUT UINTN *Size,
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 954 | IN BOOLEAN Truncate,
|
| 955 | IN OUT BOOLEAN *Ascii
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 956 | )
|
| 957 | {
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 958 | EFI_STATUS Status;
|
| 959 | CHAR16 CharBuffer;
|
| 960 | UINTN CharSize;
|
| 961 | UINTN CountSoFar;
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 962 | UINT64 OriginalFilePosition;
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 963 |
|
| 964 |
|
| 965 | if (Handle == NULL
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 966 | ||Size == NULL
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 967 | ){
|
| 968 | return (EFI_INVALID_PARAMETER);
|
| 969 | }
|
| 970 | if (Buffer == NULL) {
|
| 971 | ASSERT(*Size == 0);
|
| 972 | } else {
|
| 973 | *Buffer = CHAR_NULL;
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 974 | }
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 975 | FileHandleGetPosition(Handle, &OriginalFilePosition);
|
| 976 | if (OriginalFilePosition == 0) {
|
| 977 | CharSize = sizeof(CHAR16);
|
| 978 | Status = FileHandleRead(Handle, &CharSize, &CharBuffer);
|
| 979 | ASSERT_EFI_ERROR(Status);
|
jcarsey | 4eb59be | 2011-03-25 20:43:54 +0000 | [diff] [blame] | 980 | if (CharBuffer == gUnicodeFileTag) {
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 981 | *Ascii = FALSE;
|
| 982 | } else {
|
| 983 | *Ascii = TRUE;
|
| 984 | FileHandleSetPosition(Handle, OriginalFilePosition);
|
| 985 | }
|
| 986 | }
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 987 |
|
| 988 | for (CountSoFar = 0;;CountSoFar++){
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 989 | CharBuffer = 0;
|
| 990 | if (*Ascii) {
|
| 991 | CharSize = sizeof(CHAR8);
|
| 992 | } else {
|
| 993 | CharSize = sizeof(CHAR16);
|
| 994 | }
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 995 | Status = FileHandleRead(Handle, &CharSize, &CharBuffer);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 996 | if ( EFI_ERROR(Status)
|
| 997 | || CharSize == 0
|
| 998 | || (CharBuffer == L'\n' && !(*Ascii))
|
| 999 | || (CharBuffer == '\n' && *Ascii)
|
| 1000 | ){
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 1001 | break;
|
| 1002 | }
|
| 1003 | //
|
| 1004 | // if we have space save it...
|
| 1005 | //
|
| 1006 | if ((CountSoFar+1)*sizeof(CHAR16) < *Size){
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 1007 | ASSERT(Buffer != NULL);
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 1008 | ((CHAR16*)Buffer)[CountSoFar] = CharBuffer;
|
jcarsey | 46f43bc | 2009-07-24 21:32:00 +0000 | [diff] [blame] | 1009 | ((CHAR16*)Buffer)[CountSoFar+1] = CHAR_NULL;
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 1010 | }
|
| 1011 | }
|
| 1012 |
|
| 1013 | //
|
| 1014 | // if we ran out of space tell when...
|
| 1015 | //
|
| 1016 | if ((CountSoFar+1)*sizeof(CHAR16) > *Size){
|
| 1017 | *Size = (CountSoFar+1)*sizeof(CHAR16);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1018 | if (!Truncate) {
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 1019 | FileHandleSetPosition(Handle, OriginalFilePosition);
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 1020 | } else {
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 1021 | DEBUG((DEBUG_WARN, "The line was truncated in FileHandleReadLine"));
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 1022 | }
|
| 1023 | return (EFI_BUFFER_TOO_SMALL);
|
| 1024 | }
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 1025 | while(Buffer[StrLen(Buffer)-1] == L'\r') {
|
| 1026 | Buffer[StrLen(Buffer)-1] = CHAR_NULL;
|
| 1027 | }
|
| 1028 |
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 1029 | return (Status);
|
| 1030 | }
|
| 1031 |
|
| 1032 | /**
|
| 1033 | function to write a line of unicode text to a file.
|
| 1034 |
|
| 1035 | if Handle is NULL, ASSERT.
|
| 1036 | if Buffer is NULL, do nothing. (return SUCCESS)
|
| 1037 |
|
| 1038 | @param[in] Handle FileHandle to write to
|
| 1039 | @param[in] Buffer Buffer to write
|
| 1040 |
|
| 1041 | @retval EFI_SUCCESS the data was written.
|
| 1042 | @retval other failure.
|
| 1043 |
|
| 1044 | @sa FileHandleWrite
|
| 1045 | **/
|
| 1046 | EFI_STATUS
|
| 1047 | EFIAPI
|
| 1048 | FileHandleWriteLine(
|
| 1049 | IN EFI_FILE_HANDLE Handle,
|
| 1050 | IN CHAR16 *Buffer
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1051 | )
|
| 1052 | {
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 1053 | EFI_STATUS Status;
|
| 1054 | UINTN Size;
|
| 1055 |
|
| 1056 | ASSERT(Handle != NULL);
|
| 1057 |
|
| 1058 | if (Buffer == NULL) {
|
| 1059 | return (EFI_SUCCESS);
|
| 1060 | }
|
| 1061 |
|
jcarsey | ac255da | 2010-01-25 20:06:10 +0000 | [diff] [blame] | 1062 | Size = StrSize(Buffer) - sizeof(Buffer[0]);
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 1063 | Status = FileHandleWrite(Handle, &Size, Buffer);
|
| 1064 | if (EFI_ERROR(Status)) {
|
| 1065 | return (Status);
|
| 1066 | }
|
jcarsey | ac255da | 2010-01-25 20:06:10 +0000 | [diff] [blame] | 1067 | Size = StrSize(L"\r\n") - sizeof(CHAR16);
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 1068 | return FileHandleWrite(Handle, &Size, L"\r\n");
|
| 1069 | }
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 1070 |
|
| 1071 | /**
|
| 1072 | function to take a formatted argument and print it to a file.
|
| 1073 |
|
| 1074 | @param[in] Handle the file handle for the file to write to
|
| 1075 | @param[in] Format the format argument (see printlib for format specifier)
|
| 1076 | @param[in] ... the variable arguments for the format
|
| 1077 |
|
| 1078 | @retval EFI_SUCCESS the operation was sucessful
|
| 1079 | @return other a return value from FileHandleWriteLine
|
| 1080 |
|
| 1081 | @sa FileHandleWriteLine
|
| 1082 | **/
|
| 1083 | EFI_STATUS
|
| 1084 | EFIAPI
|
| 1085 | FileHandlePrintLine(
|
| 1086 | IN EFI_FILE_HANDLE Handle,
|
| 1087 | IN CONST CHAR16 *Format,
|
| 1088 | ...
|
| 1089 | )
|
| 1090 | {
|
| 1091 | VA_LIST Marker;
|
| 1092 | CHAR16 *Buffer;
|
| 1093 | EFI_STATUS Status;
|
| 1094 |
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 1095 | //
|
| 1096 | // Get a buffer to print into
|
| 1097 | //
|
| 1098 | Buffer = AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize));
|
| 1099 | ASSERT (Buffer != NULL);
|
| 1100 |
|
| 1101 | //
|
| 1102 | // Print into our buffer
|
| 1103 | //
|
rsun3 | 3bbe68a | 2012-02-01 06:06:08 +0000 | [diff] [blame] | 1104 | VA_START (Marker, Format);
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 1105 | UnicodeVSPrint (Buffer, PcdGet16 (PcdShellPrintBufferSize), Format, Marker);
|
rsun3 | 3bbe68a | 2012-02-01 06:06:08 +0000 | [diff] [blame] | 1106 | VA_END (Marker);
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 1107 |
|
| 1108 | //
|
| 1109 | // Print buffer into file
|
| 1110 | //
|
| 1111 | Status = FileHandleWriteLine(Handle, Buffer);
|
| 1112 |
|
| 1113 | //
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1114 | // Cleanup and return
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 1115 | //
|
| 1116 | FreePool(Buffer);
|
| 1117 | return (Status);
|
| 1118 | }
|
| 1119 |
|
| 1120 | /**
|
| 1121 | Function to determine if a FILE_HANDLE is at the end of the file.
|
| 1122 |
|
| 1123 | This will NOT work on directories.
|
| 1124 |
|
| 1125 | If Handle is NULL, then ASSERT.
|
| 1126 |
|
| 1127 | @param[in] Handle the file handle
|
| 1128 |
|
| 1129 | @retval TRUE the position is at the end of the file
|
| 1130 | @retval FALSE the position is not at the end of the file
|
| 1131 | **/
|
| 1132 | BOOLEAN
|
| 1133 | EFIAPI
|
| 1134 | FileHandleEof(
|
| 1135 | IN EFI_FILE_HANDLE Handle
|
| 1136 | )
|
| 1137 | {
|
| 1138 | EFI_FILE_INFO *Info;
|
| 1139 | UINT64 Pos;
|
| 1140 | BOOLEAN RetVal;
|
| 1141 |
|
| 1142 | //
|
| 1143 | // ASSERT if Handle is NULL
|
| 1144 | //
|
| 1145 | ASSERT(Handle != NULL);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1146 |
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 1147 | FileHandleGetPosition(Handle, &Pos);
|
| 1148 | Info = FileHandleGetInfo (Handle);
|
| 1149 | ASSERT(Info != NULL);
|
| 1150 | FileHandleSetPosition(Handle, Pos);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1151 |
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 1152 | if (Info == NULL) {
|
| 1153 | return (FALSE);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1154 | }
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 1155 |
|
jcarsey | d54744c | 2010-01-12 19:04:06 +0000 | [diff] [blame] | 1156 | if (Pos == Info->FileSize) {
|
| 1157 | RetVal = TRUE;
|
| 1158 | } else {
|
| 1159 | RetVal = FALSE;
|
| 1160 | }
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 1161 |
|
| 1162 | FreePool (Info);
|
| 1163 |
|
| 1164 | return (RetVal);
|
jcarsey | 22d1195 | 2010-01-13 19:07:58 +0000 | [diff] [blame] | 1165 | }
|