2 Provides interface to EFI_FILE_HANDLE functionality.
4 Copyright (c) 2009, Intel Corporation<BR>
5 All rights reserved. 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 #if !defined (_FILE_HANDLE_LIBRARY_HEADER_)
16 #define _FILE_HANDLE_LIBRARY_HEADER_
18 /// Tag for use in identifying UNICODE files.
19 /// If the file is UNICODE the first 16 bits of the file will equal this value.
21 UnicodeFileTag
= 0xFEFF
25 This function will retrieve the information about the file for the handle
26 specified and store it in allocated pool memory.
28 This function allocates a buffer to store the file's information. It is the
29 caller's responsibility to free the buffer.
31 @param FileHandle The file handle of the file for which information is
34 @retval NULL information could not be retrieved.
36 @retval !NULL the information about the file
41 IN EFI_FILE_HANDLE FileHandle
45 This function will set the information about the file for the opened handle
48 @param FileHandle The file handle of the file for which information
51 @param FileInfo The information to set.
53 @retval EFI_SUCCESS The information was set.
54 @retval EFI_UNSUPPORTED The FileHandle does not support FileInfo.
55 @retval EFI_NO_MEDIA The device has no medium.
56 @retval EFI_DEVICE_ERROR The device reported an error.
57 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
58 @retval EFI_WRITE_PROTECTED The file or medium is write protected.
59 @retval EFI_ACCESS_DENIED The file was opened read only.
60 @retval EFI_VOLUME_FULL The volume is full.
65 IN EFI_FILE_HANDLE FileHandle
,
66 IN CONST EFI_FILE_INFO
*FileInfo
70 This function reads information from an opened file.
72 If FileHandle is not a directory, the function reads the requested number of
73 bytes from the file at the file's current position and returns them in Buffer.
74 If the read goes beyond the end of the file, the read length is truncated to the
75 end of the file. The file's current position is increased by the number of bytes
76 returned. If FileHandle is a directory, the function reads the directory entry
77 at the file's current position and returns the entry in Buffer. If the Buffer
78 is not large enough to hold the current directory entry, then
79 EFI_BUFFER_TOO_SMALL is returned and the current file position is not updated.
80 BufferSize is set to be the size of the buffer needed to read the entry. On
81 success, the current position is updated to the next directory entry. If there
82 are no more directory entries, the read returns a zero-length buffer.
83 EFI_FILE_INFO is the structure returned as the directory entry.
85 @param FileHandle The opened file handle.
86 @param BufferSize On input the size of buffer in bytes. On return
87 the number of bytes written.
88 @param Buffer The buffer to put read data into.
90 @retval EFI_SUCCESS Data was read.
91 @retval EFI_NO_MEDIA The device has no media.
92 @retval EFI_DEVICE_ERROR The device reported an error.
93 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
94 @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required
101 IN EFI_FILE_HANDLE FileHandle
,
102 IN OUT UINTN
*BufferSize
,
107 Write data to a file.
109 This function writes the specified number of bytes to the file at the current
110 file position. The current file position is advanced the actual number of bytes
111 written, which is returned in BufferSize. Partial writes only occur when there
112 has been a data error during the write attempt (such as "volume space full").
113 The file is automatically grown to hold the data if required. Direct writes to
114 opened directories are not supported.
116 @param FileHandle The opened file for writing
117 @param BufferSize On input the number of bytes in Buffer. On output
118 the number of bytes written.
119 @param Buffer The buffer containing data to write is stored.
121 @retval EFI_SUCCESS Data was written.
122 @retval EFI_UNSUPPORTED Writes to an open directory are not supported.
123 @retval EFI_NO_MEDIA The device has no media.
124 @retval EFI_DEVICE_ERROR The device reported an error.
125 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
126 @retval EFI_WRITE_PROTECTED The device is write-protected.
127 @retval EFI_ACCESS_DENIED The file was open for read only.
128 @retval EFI_VOLUME_FULL The volume is full.
133 IN EFI_FILE_HANDLE FileHandle
,
134 IN OUT UINTN
*BufferSize
,
139 Close an open file handle.
141 This function closes a specified file handle. All "dirty" cached file data is
142 flushed to the device, and the file is closed. In all cases the handle is
145 @param FileHandle The file handle to close.
147 @retval EFI_SUCCESS The file handle was closed sucessfully.
152 IN EFI_FILE_HANDLE FileHandle
156 Delete a file and close the handle.
158 This function closes and deletes a file. In all cases the file handle is closed.
159 If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is
160 returned, but the handle is still closed.
162 @param FileHandle The file handle to delete.
164 @retval EFI_SUCCESS The file was closed sucessfully.
165 @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not
167 @retval INVALID_PARAMETER One of the parameters has an invalid value.
172 IN EFI_FILE_HANDLE FileHandle
176 Set the current position in a file.
178 This function sets the current file position for the handle to the position
179 supplied. With the exception of seeking to position 0xFFFFFFFFFFFFFFFF, only
180 absolute positioning is supported, and seeking past the end of the file is
181 allowed (a subsequent write would grow the file). Seeking to position
182 0xFFFFFFFFFFFFFFFF causes the current position to be set to the end of the file.
183 If FileHandle is a directory, the only position that may be set is zero. This
184 has the effect of starting the read process of the directory entries over.
186 @param FileHandle The file handle on which the position is being set
187 @param Position Byte position from begining of file
189 @retval EFI_SUCCESS Operation completed sucessfully.
190 @retval EFI_UNSUPPORTED the seek request for non-zero is not valid on
192 @retval INVALID_PARAMETER One of the parameters has an invalid value.
196 FileHandleSetPosition (
197 IN EFI_FILE_HANDLE FileHandle
,
202 Gets a file's current position.
204 This function retrieves the current file position for the file handle. For
205 directories, the current file position has no meaning outside of the file
206 system driver and as such the operation is not supported. An error is returned
207 if FileHandle is a directory.
209 @param FileHandle The open file handle on which to get the position.
210 @param Position Byte position from begining of file.
212 @retval EFI_SUCCESS the operation completed sucessfully.
213 @retval INVALID_PARAMETER One of the parameters has an invalid value.
214 @retval EFI_UNSUPPORTED the request is not valid on directories.
218 FileHandleGetPosition (
219 IN EFI_FILE_HANDLE FileHandle
,
223 Flushes data on a file.
225 This function flushes all modified data associated with a file to a device.
227 @param FileHandle The file handle on which to flush data.
229 @retval EFI_SUCCESS The data was flushed.
230 @retval EFI_NO_MEDIA The device has no media.
231 @retval EFI_DEVICE_ERROR The device reported an error.
232 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
233 @retval EFI_WRITE_PROTECTED The file or medium is write protected.
234 @retval EFI_ACCESS_DENIED The file was opened for read only.
239 IN EFI_FILE_HANDLE FileHandle
243 Function to determine if a given handle is a directory handle.
245 If DirHandle is NULL then ASSERT().
247 Open the file information on the DirHandle and verify that the Attribute
248 includes EFI_FILE_DIRECTORY bit set.
250 @param DirHandle Handle to open file.
252 @retval EFI_SUCCESS DirHandle is a directory
253 @retval EFI_INVALID_PARAMETER DirHandle did not have EFI_FILE_INFO available
254 @retval EFI_NOT_FOUND DirHandle is not a directory
258 FileHandleIsDirectory (
259 IN EFI_FILE_HANDLE DirHandle
263 Retrieves the first file from a directory.
265 This function opens a directory and gets the first file's info in the
266 directory. Caller can use FileHandleFindNextFile() to get other files. When
267 complete the caller is responsible for calling FreePool() on *Buffer.
269 @param DirHandle The file handle of the directory to search
270 @param Buffer Pointer to pointer to buffer for file's information
272 @retval EFI_SUCCESS Found the first file.
273 @retval EFI_NOT_FOUND Cannot find the directory.
274 @retval EFI_NO_MEDIA The device has no media.
275 @retval EFI_DEVICE_ERROR The device reported an error.
276 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
277 @return Others status of FileHandleGetInfo, FileHandleSetPosition,
282 FileHandleFindFirstFile (
283 IN EFI_FILE_HANDLE DirHandle
,
284 OUT EFI_FILE_INFO
**Buffer
287 Retrieves the next file in a directory.
289 To use this function, caller must call the FileHandleFindFirstFile() to get the
290 first file, and then use this function get other files. This function can be
291 called for several times to get each file's information in the directory. If
292 the call of FileHandleFindNextFile() got the last file in the directory, the next
293 call of this function has no file to get. *NoFile will be set to TRUE and the
294 Buffer memory will be automatically freed.
296 @param DirHandle the file handle of the directory
297 @param Buffer pointer to buffer for file's information
298 @param NoFile pointer to boolean when last file is found
300 @retval EFI_SUCCESS Found the next file, or reached last file
301 @retval EFI_NO_MEDIA The device has no media.
302 @retval EFI_DEVICE_ERROR The device reported an error.
303 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
307 FileHandleFindNextFile(
308 IN EFI_FILE_HANDLE DirHandle
,
309 OUT EFI_FILE_INFO
*Buffer
,
314 Retrieve the size of a file.
316 If FileHandle is NULL then ASSERT()
317 If Size is NULL then ASSERT()
319 This function extracts the file size info from the FileHandle's EFI_FILE_INFO
322 @param FileHandle The file handle from which size is retrieved.
323 @param Size pointer to size.
325 @retval EFI_SUCCESS operation was completed sucessfully
326 @retval EFI_DEVICE_ERROR cannot access the file
331 IN EFI_FILE_HANDLE FileHandle
,
336 Function to get a full filename given a EFI_FILE_HANDLE somewhere lower on the
339 @param[in] Handle Handle to the Directory or File to create path to.
340 @param[out] FullFileName Pointer to pointer to generated full file name. It
341 is the responsibility of the caller to free this memory
342 with a call to FreePool().
343 @retval EFI_SUCCESS the operation was sucessful and the FullFileName is valid.
344 @retval EFI_INVALID_PARAMETER Handle was NULL.
345 @retval EFI_INVALID_PARAMETER FullFileName was NULL.
346 @retval EFI_OUT_OF_MEMORY a memory allocation failed.
350 FileHandleGetFileName (
351 IN CONST EFI_FILE_HANDLE Handle
,
352 OUT CHAR16
**FullFileName
356 Function to read a single line (up to but not including the \n) from a file.
358 If the position upon start is 0, then the Ascii Boolean will be set. This should be
359 maintained and not changed for all operations with the same file.
361 @param[in] Handle FileHandle to read from
362 @param[in,out] Buffer pointer to buffer to read into
363 @param[in,out] Size pointer to number of bytes in buffer
364 @param[in] Truncate if TRUE then allows for truncation of the line to fit.
365 if FALSE will reset the position to the begining of the
366 line if the buffer is not large enough.
367 @param[in,out] Ascii Boolean value for indicating whether the file is
368 Ascii (TRUE) or UCS2 (FALSE);
370 @retval EFI_SUCCESS the operation was sucessful. the line is stored in
372 @retval EFI_INVALID_PARAMETER Handle was NULL.
373 @retval EFI_INVALID_PARAMETER Size was NULL.
374 @retval EFI_BUFFER_TOO_SMALL Size was not enough space to store the line.
375 Size was updated to minimum space required.
381 IN EFI_FILE_HANDLE Handle
,
382 IN OUT CHAR16
*Buffer
,
385 IN OUT BOOLEAN
*Ascii
389 Function to read a single line from a file. The \n is not included in the returned
390 buffer. The returned buffer must be callee freed.
392 If the position upon start is 0, then the Ascii Boolean will be set. This should be
393 maintained and not changed for all operations with the same file.
395 @param[in] Handle FileHandle to read from.
396 @param[in,out] Ascii Boolean value for indicating whether the file is Ascii (TRUE) or UCS2 (FALSE);
398 @return The line of text from the file.
400 @sa FileHandleReadLine
404 FileHandleReturnLine(
405 IN EFI_FILE_HANDLE Handle
,
406 IN OUT BOOLEAN
*Ascii
410 Function to write a line of unicode text to a file.
412 If Handle is NULL, ASSERT.
414 @param[in] Handle FileHandle to write to
415 @param[in] Buffer Buffer to write, if NULL the function will
416 take no action and return EFI_SUCCESS.
418 @retval EFI_SUCCESS the data was written.
419 @retval other failure.
426 IN EFI_FILE_HANDLE Handle
,
431 function to take a formatted argument and print it to a file.
433 @param[in] Handle the file handle for the file to write to
434 @param[in] Format the format argument (see printlib for format specifier)
435 @param[in] ... the variable arguments for the format
437 @retval EFI_SUCCESS the operation was sucessful
438 @return other a return value from FileHandleWriteLine
440 @sa FileHandleWriteLine
445 IN EFI_FILE_HANDLE Handle
,
446 IN CONST CHAR16
*Format
,
451 Function to determine if a FILE_HANDLE is at the end of the file.
453 This will NOT work on directories.
455 If Handle is NULL, then ASSERT.
457 @param[in] Handle the file handle
459 @retval TRUE the position is at the end of the file
460 @retval FALSE the position is not at the end of the file
465 IN EFI_FILE_HANDLE Handle
468 #endif //_FILE_HANDLE_LIBRARY_HEADER_