2 Provides interface to EFI_FILE_HANDLE functionality.
4 Copyright (c) 2009 - 2010, 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 #ifndef _FILE_HANDLE_LIBRARY_HEADER_
16 #define _FILE_HANDLE_LIBRARY_HEADER_
18 #include <Protocol/SimpleFileSystem.h>
20 /// The tag for use in identifying UNICODE files.
21 /// If the file is UNICODE, the first 16 bits of the file will equal this value.
23 UnicodeFileTag
= 0xFEFF
27 This function retrieves information about the file for the handle
28 specified and stores it in the allocated pool memory.
30 This function allocates a buffer to store the file's information. It is the
31 caller's responsibility to free the buffer.
33 @param[in] FileHandle The file handle of the file for which information is
36 @retval NULL Information could not be retrieved.
37 @retval !NULL The information about the file.
42 IN EFI_FILE_HANDLE FileHandle
46 This function sets the information about the file for the opened handle
49 @param[in] FileHandle The file handle of the file for which information
52 @param[in] FileInfo The information to set.
54 @retval EFI_SUCCESS The information was set.
55 @retval EFI_INVALID_PARAMETER A parameter was out of range or invalid.
56 @retval EFI_UNSUPPORTED The FileHandle does not support FileInfo.
57 @retval EFI_NO_MEDIA The device has no medium.
58 @retval EFI_DEVICE_ERROR The device reported an error.
59 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
60 @retval EFI_WRITE_PROTECTED The file or medium is write protected.
61 @retval EFI_ACCESS_DENIED The file was opened read only.
62 @retval EFI_VOLUME_FULL The volume is full.
67 IN EFI_FILE_HANDLE FileHandle
,
68 IN CONST EFI_FILE_INFO
*FileInfo
72 This function reads information from an opened file.
74 If FileHandle is not a directory, the function reads the requested number of
75 bytes from the file at the file's current position and returns them in Buffer.
76 If the read goes beyond the end of the file, the read length is truncated to the
77 end of the file. The file's current position is increased by the number of bytes
78 returned. If FileHandle is a directory, the function reads the directory entry
79 at the file's current position and returns the entry in Buffer. If the Buffer
80 is not large enough to hold the current directory entry, then
81 EFI_BUFFER_TOO_SMALL is returned and the current file position is not updated.
82 BufferSize is set to be the size of the buffer needed to read the entry. On
83 success, the current position is updated to the next directory entry. If there
84 are no more directory entries, the read returns a zero-length buffer.
85 EFI_FILE_INFO is the structure returned as the directory entry.
87 @param[in] FileHandle The opened file handle.
88 @param[in,out] BufferSize On input, the size of buffer in bytes. On return,
89 the number of bytes written.
90 @param[out] Buffer The buffer to put read data into.
92 @retval EFI_SUCCESS Data was read.
93 @retval EFI_NO_MEDIA The device has no media.
94 @retval EFI_DEVICE_ERROR The device reported an error.
95 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
96 @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required
103 IN EFI_FILE_HANDLE FileHandle
,
104 IN OUT UINTN
*BufferSize
,
109 Write data to a file.
111 This function writes the specified number of bytes to the file at the current
112 file position. The current file position is advanced the actual number of bytes
113 written, which is returned in BufferSize. Partial writes only occur when there
114 has been a data error during the write attempt (such as "volume space full").
115 The file is automatically grown to hold the data if required. Direct writes to
116 opened directories are not supported.
118 @param[in] FileHandle The opened file for writing.
119 @param[in,out] BufferSize On input, the number of bytes in Buffer. On output,
120 the number of bytes written.
121 @param[in] Buffer The buffer containing data to write is stored.
123 @retval EFI_SUCCESS Data was written.
124 @retval EFI_UNSUPPORTED Writes to an open directory are not supported.
125 @retval EFI_NO_MEDIA The device has no media.
126 @retval EFI_DEVICE_ERROR The device reported an error.
127 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
128 @retval EFI_WRITE_PROTECTED The device is write-protected.
129 @retval EFI_ACCESS_DENIED The file was opened for read only.
130 @retval EFI_VOLUME_FULL The volume is full.
135 IN EFI_FILE_HANDLE FileHandle
,
136 IN OUT UINTN
*BufferSize
,
141 Close an open file handle.
143 This function closes a specified file handle. All "dirty" cached file data is
144 flushed to the device, and the file is closed. In all cases the handle is
147 @param[in] FileHandle The file handle to close.
149 @retval EFI_SUCCESS The file handle was closed successfully.
154 IN EFI_FILE_HANDLE FileHandle
158 Delete a file and close the handle.
160 This function closes and deletes a file. In all cases the file handle is closed.
161 If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is
162 returned, but the handle is still closed.
164 @param[in] FileHandle The file handle to delete.
166 @retval EFI_SUCCESS The file was closed successfully.
167 @retval EFI_WARN_DELETE_FAILURE The handle was closed, but the file was not
169 @retval INVALID_PARAMETER One of the parameters has an invalid value.
174 IN EFI_FILE_HANDLE FileHandle
178 Set the current position in a file.
180 This function sets the current file position for the handle to the position
181 supplied. With the exception of moving to position 0xFFFFFFFFFFFFFFFF, only
182 absolute positioning is supported, and moving past the end of the file is
183 allowed (a subsequent write would grow the file). Moving to position
184 0xFFFFFFFFFFFFFFFF causes the current position to be set to the end of the file.
185 If FileHandle is a directory, the only position that may be set is zero. This
186 has the effect of starting the read process of the directory entries over again.
188 @param[in] FileHandle The file handle on which the position is being set.
189 @param[in] Position The byte position from the begining of the file.
191 @retval EFI_SUCCESS The operation completed sucessfully.
192 @retval EFI_UNSUPPORTED The request for non-zero is not valid on
194 @retval INVALID_PARAMETER One of the parameters has an invalid value.
198 FileHandleSetPosition (
199 IN EFI_FILE_HANDLE FileHandle
,
204 Gets a file's current position.
206 This function retrieves the current file position for the file handle. For
207 directories, the current file position has no meaning outside of the file
208 system driver. As such, the operation is not supported. An error is returned
209 if FileHandle is a directory.
211 @param[in] FileHandle The open file handle on which to get the position.
212 @param[out] Position The byte position from begining of file.
214 @retval EFI_SUCCESS The operation completed successfully.
215 @retval INVALID_PARAMETER One of the parameters has an invalid value.
216 @retval EFI_UNSUPPORTED The request is not valid on directories.
220 FileHandleGetPosition (
221 IN EFI_FILE_HANDLE FileHandle
,
225 Flushes data on a file.
227 This function flushes all modified data associated with a file to a device.
229 @param[in] FileHandle The file handle on which to flush data.
231 @retval EFI_SUCCESS The data was flushed.
232 @retval EFI_NO_MEDIA The device has no media.
233 @retval EFI_DEVICE_ERROR The device reported an error.
234 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
235 @retval EFI_WRITE_PROTECTED The file or medium is write protected.
236 @retval EFI_ACCESS_DENIED The file was opened for read only.
241 IN EFI_FILE_HANDLE FileHandle
245 Function to determine if a given handle is a directory handle.
247 If DirHandle is NULL, then ASSERT().
249 Open the file information on the DirHandle, and verify that the Attribute
250 includes EFI_FILE_DIRECTORY bit set.
252 @param[in] DirHandle The handle to open the file.
254 @retval EFI_SUCCESS DirHandle is a directory.
255 @retval EFI_INVALID_PARAMETER DirHandle did not have EFI_FILE_INFO available.
256 @retval EFI_NOT_FOUND DirHandle is not a directory.
260 FileHandleIsDirectory (
261 IN EFI_FILE_HANDLE DirHandle
265 Retrieves the first file from a directory.
267 This function opens a directory and gets the first file's information in the
268 directory. The caller the uses FileHandleFindNextFile() to get other files. When
269 complete, the caller is responsible for calling FreePool() on *Buffer.
271 @param[in] DirHandle The file handle of the directory to search.
272 @param[out] Buffer The pointer to pointer to buffer for file's information.
274 @retval EFI_SUCCESS Found the first file.
275 @retval EFI_NOT_FOUND Cannot find the directory.
276 @retval EFI_NO_MEDIA The device has no media.
277 @retval EFI_DEVICE_ERROR The device reported an error.
278 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
279 @return Others The status of FileHandleGetInfo, FileHandleSetPosition,
284 FileHandleFindFirstFile (
285 IN EFI_FILE_HANDLE DirHandle
,
286 OUT EFI_FILE_INFO
**Buffer
289 Retrieves the next file in a directory.
291 To use this function, caller must call the FileHandleFindFirstFile() to get the
292 first file, and then use this function get other files. This function can be
293 called for several times to get each file's information in the directory. If
294 the call of FileHandleFindNextFile() got the last file in the directory, the next
295 call of this function has no file to get. *NoFile will be set to TRUE and the
296 Buffer memory will be automatically freed.
298 @param[in] DirHandle The file handle of the directory.
299 @param[out] Buffer The pointer to buffer for file's information.
300 @param[out] NoFile The pointer to boolean when last file is found.
302 @retval EFI_SUCCESS Found the next file, or reached last file.
303 @retval EFI_NO_MEDIA The device has no media.
304 @retval EFI_DEVICE_ERROR The device reported an error.
305 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
309 FileHandleFindNextFile(
310 IN EFI_FILE_HANDLE DirHandle
,
311 OUT EFI_FILE_INFO
*Buffer
,
316 Retrieve the size of a file.
318 If FileHandle is NULL then ASSERT().
319 If Size is NULL then ASSERT().
321 This function extracts the file size info from the FileHandle's EFI_FILE_INFO
324 @param[in] FileHandle The file handle from which size is retrieved.
325 @param[out] Size The pointer to size.
327 @retval EFI_SUCCESS The operation completed successfully.
328 @retval EFI_DEVICE_ERROR Cannot access the file.
333 IN EFI_FILE_HANDLE FileHandle
,
338 Set the size of a file.
340 If FileHandle is NULL then ASSERT().
342 This function changes the file size info from the FileHandle's EFI_FILE_INFO
345 @param[in] FileHandle The file handle whose size is to be changed.
346 @param[in] Size The new size.
348 @retval EFI_SUCCESS The operation completed successfully.
349 @retval EFI_DEVICE_ERROR Cannot access the file.
354 IN EFI_FILE_HANDLE FileHandle
,
359 Function to get a full filename given a EFI_FILE_HANDLE somewhere lower on the
362 @param[in] Handle Handle to the Directory or File to create path to.
363 @param[out] FullFileName Pointer to pointer to generated full file name. It
364 is the responsibility of the caller to free this memory
365 with a call to FreePool().
366 @retval EFI_SUCCESS The operation was successful and FullFileName is valid.
367 @retval EFI_INVALID_PARAMETER Handle was NULL.
368 @retval EFI_INVALID_PARAMETER FullFileName was NULL.
369 @retval EFI_OUT_OF_MEMORY A memory allocation failed.
373 FileHandleGetFileName (
374 IN CONST EFI_FILE_HANDLE Handle
,
375 OUT CHAR16
**FullFileName
379 Function to read a single line (up to but not including the \n) from a file.
381 If the position upon start is 0, then the Ascii Boolean will be set. This should be
382 maintained and not changed for all operations with the same file.
384 @param[in] Handle FileHandle to read from.
385 @param[in,out] Buffer The pointer to buffer to read into.
386 @param[in,out] Size The pointer to number of bytes in Buffer.
387 @param[in] Truncate If the buffer is large enough, this has no effect.
388 If the buffer is is too small and Truncate is TRUE,
389 the line will be truncated.
390 If the buffer is is too small and Truncate is FALSE,
391 then no read will occur.
393 @param[in,out] Ascii Boolean value for indicating whether the file is
394 Ascii (TRUE) or UCS2 (FALSE).
396 @retval EFI_SUCCESS The operation was successful. The line is stored in
398 @retval EFI_INVALID_PARAMETER Handle was NULL.
399 @retval EFI_INVALID_PARAMETER Size was NULL.
400 @retval EFI_BUFFER_TOO_SMALL Size was not large enough to store the line.
401 Size was updated to the minimum space required.
407 IN EFI_FILE_HANDLE Handle
,
408 IN OUT CHAR16
*Buffer
,
411 IN OUT BOOLEAN
*Ascii
415 Function to read a single line from a file. The \n is not included in the returned
416 buffer. The returned buffer must be callee freed.
418 If the position upon start is 0, then the Ascii Boolean will be set. This should be
419 maintained and not changed for all operations with the same file.
421 @param[in] Handle FileHandle to read from.
422 @param[in,out] Ascii Boolean value for indicating whether the file is
423 Ascii (TRUE) or UCS2 (FALSE).
425 @return The line of text from the file.
427 @sa FileHandleReadLine
431 FileHandleReturnLine(
432 IN EFI_FILE_HANDLE Handle
,
433 IN OUT BOOLEAN
*Ascii
437 Function to write a line of unicode text to a file.
439 If Handle is NULL, ASSERT.
441 @param[in] Handle FileHandle to write to.
442 @param[in] Buffer Buffer to write, if NULL the function will
443 take no action and return EFI_SUCCESS.
445 @retval EFI_SUCCESS The data was written.
446 @retval other Failure.
453 IN EFI_FILE_HANDLE Handle
,
458 Function to take a formatted argument and print it to a file.
460 @param[in] Handle The file handle for the file to write to.
461 @param[in] Format The format argument (see printlib for the format specifier).
462 @param[in] ... The variable arguments for the format.
464 @retval EFI_SUCCESS The operation was successful.
465 @retval other A return value from FileHandleWriteLine.
467 @sa FileHandleWriteLine
472 IN EFI_FILE_HANDLE Handle
,
473 IN CONST CHAR16
*Format
,
478 Function to determine if a FILE_HANDLE is at the end of the file.
480 This will NOT work on directories.
482 If Handle is NULL, then ASSERT().
484 @param[in] Handle The file handle.
486 @retval TRUE The position is at the end of the file.
487 @retval FALSE The position is not at the end of the file.
492 IN EFI_FILE_HANDLE Handle
495 #endif //_FILE_HANDLE_LIBRARY_HEADER_