3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #ifndef _FILE_HANDLE_LIBRARY_HEADER_
12 #define _FILE_HANDLE_LIBRARY_HEADER_
14 #include <Protocol/SimpleFileSystem.h>
17 // The tag for use in identifying UNICODE files.
18 // If the file is UNICODE, the first 16 bits of the file will equal this value.
20 extern CONST UINT16 gUnicodeFileTag
;
23 This function retrieves information about the file for the handle
24 specified and stores it in the allocated pool memory.
26 This function allocates a buffer to store the file's information. It is the
27 caller's responsibility to free the buffer.
29 @param[in] FileHandle The file handle of the file for which information is
32 @retval NULL Information could not be retrieved.
33 @retval !NULL The information about the file.
38 IN EFI_FILE_HANDLE FileHandle
42 This function sets the information about the file for the opened handle
45 @param[in] FileHandle The file handle of the file for which information
48 @param[in] FileInfo The information to set.
50 @retval EFI_SUCCESS The information was set.
51 @retval EFI_INVALID_PARAMETER A parameter was out of range or invalid.
52 @retval EFI_UNSUPPORTED The FileHandle does not support FileInfo.
53 @retval EFI_NO_MEDIA The device has no medium.
54 @retval EFI_DEVICE_ERROR The device reported an error.
55 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
56 @retval EFI_WRITE_PROTECTED The file or medium is write protected.
57 @retval EFI_ACCESS_DENIED The file was opened read only.
58 @retval EFI_VOLUME_FULL The volume is full.
63 IN EFI_FILE_HANDLE FileHandle
,
64 IN CONST EFI_FILE_INFO
*FileInfo
68 This function reads information from an opened file.
70 If FileHandle is not a directory, the function reads the requested number of
71 bytes from the file at the file's current position and returns them in Buffer.
72 If the read goes beyond the end of the file, the read length is truncated to the
73 end of the file. The file's current position is increased by the number of bytes
74 returned. If FileHandle is a directory, the function reads the directory entry
75 at the file's current position and returns the entry in Buffer. If the Buffer
76 is not large enough to hold the current directory entry, then
77 EFI_BUFFER_TOO_SMALL is returned and the current file position is not updated.
78 BufferSize is set to be the size of the buffer needed to read the entry. On
79 success, the current position is updated to the next directory entry. If there
80 are no more directory entries, the read returns a zero-length buffer.
81 EFI_FILE_INFO is the structure returned as the directory entry.
83 @param[in] FileHandle The opened file handle.
84 @param[in, out] BufferSize On input, the size of buffer in bytes. On return,
85 the number of bytes written.
86 @param[out] Buffer The buffer to put read data into.
88 @retval EFI_SUCCESS Data was read.
89 @retval EFI_NO_MEDIA The device has no media.
90 @retval EFI_DEVICE_ERROR The device reported an error.
91 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
92 @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required
99 IN EFI_FILE_HANDLE FileHandle
,
100 IN OUT UINTN
*BufferSize
,
105 Write data to a file.
107 This function writes the specified number of bytes to the file at the current
108 file position. The current file position is advanced the actual number of bytes
109 written, which is returned in BufferSize. Partial writes only occur when there
110 has been a data error during the write attempt (such as "volume space full").
111 The file is automatically grown to hold the data if required. Direct writes to
112 opened directories are not supported.
114 @param[in] FileHandle The opened file for writing.
115 @param[in, out] BufferSize On input, the number of bytes in Buffer. On output,
116 the number of bytes written.
117 @param[in] Buffer The buffer containing data to write is stored.
119 @retval EFI_SUCCESS Data was written.
120 @retval EFI_UNSUPPORTED Writes to an open directory are not supported.
121 @retval EFI_NO_MEDIA The device has no media.
122 @retval EFI_DEVICE_ERROR The device reported an error.
123 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
124 @retval EFI_WRITE_PROTECTED The device is write-protected.
125 @retval EFI_ACCESS_DENIED The file was opened for read only.
126 @retval EFI_VOLUME_FULL The volume is full.
131 IN EFI_FILE_HANDLE FileHandle
,
132 IN OUT UINTN
*BufferSize
,
137 Close an open file handle.
139 This function closes a specified file handle. All "dirty" cached file data is
140 flushed to the device, and the file is closed. In all cases the handle is
143 @param[in] FileHandle The file handle to close.
145 @retval EFI_SUCCESS The file handle was closed successfully.
150 IN EFI_FILE_HANDLE FileHandle
154 Delete a file and close the handle.
156 This function closes and deletes a file. In all cases the file handle is closed.
157 If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is
158 returned, but the handle is still closed.
160 @param[in] FileHandle The file handle to delete.
162 @retval EFI_SUCCESS The file was closed successfully.
163 @retval EFI_WARN_DELETE_FAILURE The handle was closed, but the file was not
165 @retval INVALID_PARAMETER One of the parameters has an invalid value.
170 IN EFI_FILE_HANDLE FileHandle
174 Set the current position in a file.
176 This function sets the current file position for the handle to the position
177 supplied. With the exception of moving to position 0xFFFFFFFFFFFFFFFF, only
178 absolute positioning is supported, and moving past the end of the file is
179 allowed (a subsequent write would grow the file). Moving to position
180 0xFFFFFFFFFFFFFFFF causes the current position to be set to the end of the file.
181 If FileHandle is a directory, the only position that may be set is zero. This
182 has the effect of starting the read process of the directory entries over again.
184 @param[in] FileHandle The file handle on which the position is being set.
185 @param[in] Position The byte position from the begining of the file.
187 @retval EFI_SUCCESS The operation completed sucessfully.
188 @retval EFI_UNSUPPORTED The request for non-zero is not valid on
190 @retval INVALID_PARAMETER One of the parameters has an invalid value.
194 FileHandleSetPosition (
195 IN EFI_FILE_HANDLE FileHandle
,
200 Gets a file's current position.
202 This function retrieves the current file position for the file handle. For
203 directories, the current file position has no meaning outside of the file
204 system driver. As such, the operation is not supported. An error is returned
205 if FileHandle is a directory.
207 @param[in] FileHandle The open file handle on which to get the position.
208 @param[out] Position The byte position from begining of file.
210 @retval EFI_SUCCESS The operation completed successfully.
211 @retval INVALID_PARAMETER One of the parameters has an invalid value.
212 @retval EFI_UNSUPPORTED The request is not valid on directories.
216 FileHandleGetPosition (
217 IN EFI_FILE_HANDLE FileHandle
,
222 Flushes data on a file.
224 This function flushes all modified data associated with a file to a device.
226 @param[in] FileHandle The file handle on which to flush data.
228 @retval EFI_SUCCESS The data was flushed.
229 @retval EFI_NO_MEDIA The device has no media.
230 @retval EFI_DEVICE_ERROR The device reported an error.
231 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
232 @retval EFI_WRITE_PROTECTED The file or medium is write protected.
233 @retval EFI_ACCESS_DENIED The file was opened for read only.
238 IN EFI_FILE_HANDLE FileHandle
242 Function to determine if a given handle is a directory handle.
244 If DirHandle is NULL, then ASSERT().
246 Open the file information on the DirHandle, and verify that the Attribute
247 includes EFI_FILE_DIRECTORY bit set.
249 @param[in] DirHandle The handle to open the file.
251 @retval EFI_SUCCESS DirHandle is a directory.
252 @retval EFI_INVALID_PARAMETER DirHandle did not have EFI_FILE_INFO available.
253 @retval EFI_NOT_FOUND DirHandle is not a directory.
257 FileHandleIsDirectory (
258 IN EFI_FILE_HANDLE DirHandle
262 Retrieve first entry from a directory.
264 This function takes an open directory handle and gets information from the
265 first entry in the directory. A buffer is allocated to contain
266 the information and a pointer to the buffer is returned in *Buffer. The
267 caller can use FileHandleFindNextFile() to get subsequent directory entries.
269 The buffer will be freed by FileHandleFindNextFile() when the last directory
270 entry is read. Otherwise, the caller must free the buffer, using FreePool,
271 when finished with it.
273 @param[in] DirHandle The file handle of the directory to search.
274 @param[out] Buffer The pointer to pointer to buffer for file's information.
276 @retval EFI_SUCCESS Found the first file.
277 @retval EFI_NOT_FOUND Cannot find the directory.
278 @retval EFI_NO_MEDIA The device has no media.
279 @retval EFI_DEVICE_ERROR The device reported an error.
280 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
281 @return Others The status of FileHandleGetInfo, FileHandleSetPosition,
286 FileHandleFindFirstFile (
287 IN EFI_FILE_HANDLE DirHandle
,
288 OUT EFI_FILE_INFO
**Buffer
292 Retrieve next entries from a directory.
294 To use this function, the caller must first call the FileHandleFindFirstFile()
295 function to get the first directory entry. Subsequent directory entries are
296 retrieved by using the FileHandleFindNextFile() function. This function can
297 be called several times to get each entry from the directory. If the call of
298 FileHandleFindNextFile() retrieved the last directory entry, the next call of
299 this function will set *NoFile to TRUE and free the buffer.
301 @param[in] DirHandle The file handle of the directory.
302 @param[out] Buffer The pointer to buffer for file's information.
303 @param[out] NoFile The pointer to boolean when last file is found.
305 @retval EFI_SUCCESS Found the next file, or reached last file.
306 @retval EFI_NO_MEDIA The device has no media.
307 @retval EFI_DEVICE_ERROR The device reported an error.
308 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
312 FileHandleFindNextFile(
313 IN EFI_FILE_HANDLE DirHandle
,
314 OUT EFI_FILE_INFO
*Buffer
,
319 Retrieve the size of a file.
321 If FileHandle is NULL then ASSERT().
322 If Size is NULL then ASSERT().
324 This function extracts the file size info from the FileHandle's EFI_FILE_INFO
327 @param[in] FileHandle The file handle from which size is retrieved.
328 @param[out] Size The pointer to size.
330 @retval EFI_SUCCESS The operation completed successfully.
331 @retval EFI_DEVICE_ERROR Cannot access the file.
336 IN EFI_FILE_HANDLE FileHandle
,
341 Set the size of a file.
343 If FileHandle is NULL then ASSERT().
345 This function changes the file size info from the FileHandle's EFI_FILE_INFO
348 @param[in] FileHandle The file handle whose size is to be changed.
349 @param[in] Size The new size.
351 @retval EFI_SUCCESS The operation completed successfully.
352 @retval EFI_DEVICE_ERROR Cannot access the file.
357 IN EFI_FILE_HANDLE FileHandle
,
362 Function to get a full filename given a EFI_FILE_HANDLE somewhere lower on the
365 @param[in] Handle Handle to the Directory or File to create path to.
366 @param[out] FullFileName Pointer to pointer to generated full file name. It
367 is the responsibility of the caller to free this memory
368 with a call to FreePool().
369 @retval EFI_SUCCESS The operation was successful and FullFileName is valid.
370 @retval EFI_INVALID_PARAMETER Handle was NULL.
371 @retval EFI_INVALID_PARAMETER FullFileName was NULL.
372 @retval EFI_OUT_OF_MEMORY A memory allocation failed.
376 FileHandleGetFileName (
377 IN CONST EFI_FILE_HANDLE Handle
,
378 OUT CHAR16
**FullFileName
382 Function to read a single line (up to but not including the \n) from a file.
384 If the position upon start is 0, then the Ascii Boolean will be set. This should be
385 maintained and not changed for all operations with the same file.
387 @param[in] Handle FileHandle to read from.
388 @param[in, out] Buffer The pointer to buffer to read into.
389 @param[in, out] Size The pointer to number of bytes in Buffer.
390 @param[in] Truncate If the buffer is large enough, this has no effect.
391 If the buffer is is too small and Truncate is TRUE,
392 the line will be truncated.
393 If the buffer is is too small and Truncate is FALSE,
394 then no read will occur.
396 @param[in, out] Ascii Boolean value for indicating whether the file is
397 Ascii (TRUE) or UCS2 (FALSE).
399 @retval EFI_SUCCESS The operation was successful. The line is stored in
401 @retval EFI_INVALID_PARAMETER Handle was NULL.
402 @retval EFI_INVALID_PARAMETER Size was NULL.
403 @retval EFI_BUFFER_TOO_SMALL Size was not large enough to store the line.
404 Size was updated to the minimum space required.
410 IN EFI_FILE_HANDLE Handle
,
411 IN OUT CHAR16
*Buffer
,
414 IN OUT BOOLEAN
*Ascii
418 Function to read a single line from a file. The \n is not included in the returned
419 buffer. The returned buffer must be callee freed.
421 If the position upon start is 0, then the Ascii Boolean will be set. This should be
422 maintained and not changed for all operations with the same file.
424 @param[in] Handle FileHandle to read from.
425 @param[in, out] Ascii Boolean value for indicating whether the file is
426 Ascii (TRUE) or UCS2 (FALSE).
428 @return The line of text from the file.
430 @sa FileHandleReadLine
434 FileHandleReturnLine(
435 IN EFI_FILE_HANDLE Handle
,
436 IN OUT BOOLEAN
*Ascii
440 Function to write a line of unicode text to a file.
442 If Handle is NULL, ASSERT.
444 @param[in] Handle FileHandle to write to.
445 @param[in] Buffer Buffer to write, if NULL the function will
446 take no action and return EFI_SUCCESS.
448 @retval EFI_SUCCESS The data was written.
449 @retval other Failure.
456 IN EFI_FILE_HANDLE Handle
,
461 Function to take a formatted argument and print it to a file.
463 @param[in] Handle The file handle for the file to write to.
464 @param[in] Format The format argument (see printlib for the format specifier).
465 @param[in] ... The variable arguments for the format.
467 @retval EFI_SUCCESS The operation was successful.
468 @retval other A return value from FileHandleWriteLine.
470 @sa FileHandleWriteLine
475 IN EFI_FILE_HANDLE Handle
,
476 IN CONST CHAR16
*Format
,
481 Function to determine if a FILE_HANDLE is at the end of the file.
483 This will NOT work on directories.
485 If Handle is NULL, then ASSERT().
487 @param[in] Handle The file handle.
489 @retval TRUE The position is at the end of the file.
490 @retval FALSE The position is not at the end of the file.
495 IN EFI_FILE_HANDLE Handle
498 #endif //_FILE_HANDLE_LIBRARY_HEADER_