]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Include/Library/FileHandleLib.h
udk2010.up2.shell initial release.
[mirror_edk2.git] / ShellPkg / Include / Library / FileHandleLib.h
CommitLineData
d2b4564b 1/** @file\r
2 Provides interface to EFI_FILE_HANDLE functionality.\r
3\r
3a888f2a 4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
1e6e84c7 5 This program and the accompanying materials\r
b3011f40 6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
d2b4564b 9\r
b3011f40 10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
d2b4564b 12\r
13**/\r
14\r
a405b86d 15#ifndef _FILE_HANDLE_LIBRARY_HEADER_\r
b3011f40 16#define _FILE_HANDLE_LIBRARY_HEADER_\r
17\r
a405b86d 18#include <Protocol/SimpleFileSystem.h>\r
19\r
20/// The tag for use in identifying UNICODE files.\r
21/// If the file is UNICODE, the first 16 bits of the file will equal this value.\r
b3011f40 22enum {\r
23 UnicodeFileTag = 0xFEFF\r
24};\r
25\r
d2b4564b 26/**\r
a405b86d 27 This function retrieves information about the file for the handle\r
28 specified and stores it in the allocated pool memory.\r
d2b4564b 29\r
1e6e84c7 30 This function allocates a buffer to store the file's information. It is the\r
125c2cf4 31 caller's responsibility to free the buffer.\r
d2b4564b 32\r
a405b86d 33 @param[in] FileHandle The file handle of the file for which information is\r
34 being requested.\r
d2b4564b 35\r
a405b86d 36 @retval NULL Information could not be retrieved.\r
37 @retval !NULL The information about the file.\r
d2b4564b 38**/\r
39EFI_FILE_INFO*\r
40EFIAPI\r
41FileHandleGetInfo (\r
42 IN EFI_FILE_HANDLE FileHandle\r
43 );\r
44\r
45/**\r
a405b86d 46 This function sets the information about the file for the opened handle\r
d2b4564b 47 specified.\r
48\r
a405b86d 49 @param[in] FileHandle The file handle of the file for which information\r
125c2cf4 50 is being set.\r
d2b4564b 51\r
a405b86d 52 @param[in] FileInfo The information to set.\r
d2b4564b 53\r
125c2cf4 54 @retval EFI_SUCCESS The information was set.\r
a405b86d 55 @retval EFI_INVALID_PARAMETER A parameter was out of range or invalid.\r
125c2cf4 56 @retval EFI_UNSUPPORTED The FileHandle does not support FileInfo.\r
57 @retval EFI_NO_MEDIA The device has no medium.\r
58 @retval EFI_DEVICE_ERROR The device reported an error.\r
d2b4564b 59 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
125c2cf4 60 @retval EFI_WRITE_PROTECTED The file or medium is write protected.\r
a405b86d 61 @retval EFI_ACCESS_DENIED The file was opened read only.\r
62 @retval EFI_VOLUME_FULL The volume is full.\r
d2b4564b 63**/\r
64EFI_STATUS\r
65EFIAPI\r
66FileHandleSetInfo (\r
67 IN EFI_FILE_HANDLE FileHandle,\r
68 IN CONST EFI_FILE_INFO *FileInfo\r
69 );\r
70\r
71/**\r
72 This function reads information from an opened file.\r
73\r
1e6e84c7 74 If FileHandle is not a directory, the function reads the requested number of\r
75 bytes from the file at the file's current position and returns them in Buffer.\r
d2b4564b 76 If the read goes beyond the end of the file, the read length is truncated to the\r
1e6e84c7 77 end of the file. The file's current position is increased by the number of bytes\r
78 returned. If FileHandle is a directory, the function reads the directory entry\r
79 at the file's current position and returns the entry in Buffer. If the Buffer\r
80 is not large enough to hold the current directory entry, then\r
81 EFI_BUFFER_TOO_SMALL is returned and the current file position is not updated.\r
82 BufferSize is set to be the size of the buffer needed to read the entry. On\r
83 success, the current position is updated to the next directory entry. If there\r
84 are no more directory entries, the read returns a zero-length buffer.\r
d2b4564b 85 EFI_FILE_INFO is the structure returned as the directory entry.\r
86\r
a405b86d 87 @param[in] FileHandle The opened file handle.\r
88 @param[in,out] BufferSize On input, the size of buffer in bytes. On return,\r
d2b4564b 89 the number of bytes written.\r
a405b86d 90 @param[out] Buffer The buffer to put read data into.\r
d2b4564b 91\r
a405b86d 92 @retval EFI_SUCCESS Data was read.\r
d2b4564b 93 @retval EFI_NO_MEDIA The device has no media.\r
a405b86d 94 @retval EFI_DEVICE_ERROR The device reported an error.\r
d2b4564b 95 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
a405b86d 96 @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required\r
d2b4564b 97 size.\r
98\r
99**/\r
100EFI_STATUS\r
101EFIAPI\r
102FileHandleRead(\r
103 IN EFI_FILE_HANDLE FileHandle,\r
104 IN OUT UINTN *BufferSize,\r
105 OUT VOID *Buffer\r
106 );\r
107\r
108/**\r
109 Write data to a file.\r
110\r
1e6e84c7 111 This function writes the specified number of bytes to the file at the current\r
112 file position. The current file position is advanced the actual number of bytes\r
113 written, which is returned in BufferSize. Partial writes only occur when there\r
114 has been a data error during the write attempt (such as "volume space full").\r
115 The file is automatically grown to hold the data if required. Direct writes to\r
d2b4564b 116 opened directories are not supported.\r
117\r
a405b86d 118 @param[in] FileHandle The opened file for writing.\r
119 @param[in,out] BufferSize On input, the number of bytes in Buffer. On output,\r
a31bd33c 120 the number of bytes written.\r
a405b86d 121 @param[in] Buffer The buffer containing data to write is stored.\r
125c2cf4 122\r
a405b86d 123 @retval EFI_SUCCESS Data was written.\r
124 @retval EFI_UNSUPPORTED Writes to an open directory are not supported.\r
125c2cf4 125 @retval EFI_NO_MEDIA The device has no media.\r
a405b86d 126 @retval EFI_DEVICE_ERROR The device reported an error.\r
125c2cf4 127 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
a405b86d 128 @retval EFI_WRITE_PROTECTED The device is write-protected.\r
129 @retval EFI_ACCESS_DENIED The file was opened for read only.\r
130 @retval EFI_VOLUME_FULL The volume is full.\r
d2b4564b 131**/\r
132EFI_STATUS\r
133EFIAPI\r
134FileHandleWrite(\r
135 IN EFI_FILE_HANDLE FileHandle,\r
136 IN OUT UINTN *BufferSize,\r
137 IN VOID *Buffer\r
138 );\r
139\r
1e6e84c7 140/**\r
d2b4564b 141 Close an open file handle.\r
142\r
1e6e84c7 143 This function closes a specified file handle. All "dirty" cached file data is\r
144 flushed to the device, and the file is closed. In all cases the handle is\r
d2b4564b 145 closed.\r
146\r
a405b86d 147 @param[in] FileHandle The file handle to close.\r
d2b4564b 148\r
a405b86d 149 @retval EFI_SUCCESS The file handle was closed successfully.\r
d2b4564b 150**/\r
151EFI_STATUS\r
152EFIAPI\r
153FileHandleClose (\r
154 IN EFI_FILE_HANDLE FileHandle\r
155 );\r
156\r
157/**\r
125c2cf4 158 Delete a file and close the handle.\r
d2b4564b 159\r
160 This function closes and deletes a file. In all cases the file handle is closed.\r
1e6e84c7 161 If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is\r
d2b4564b 162 returned, but the handle is still closed.\r
163\r
a405b86d 164 @param[in] FileHandle The file handle to delete.\r
d2b4564b 165\r
a405b86d 166 @retval EFI_SUCCESS The file was closed successfully.\r
167 @retval EFI_WARN_DELETE_FAILURE The handle was closed, but the file was not\r
168 deleted.\r
125c2cf4 169 @retval INVALID_PARAMETER One of the parameters has an invalid value.\r
d2b4564b 170**/\r
171EFI_STATUS\r
172EFIAPI\r
173FileHandleDelete (\r
174 IN EFI_FILE_HANDLE FileHandle\r
175 );\r
176\r
177/**\r
178 Set the current position in a file.\r
179\r
1e6e84c7 180 This function sets the current file position for the handle to the position\r
a405b86d 181 supplied. With the exception of moving to position 0xFFFFFFFFFFFFFFFF, only\r
182 absolute positioning is supported, and moving past the end of the file is\r
183 allowed (a subsequent write would grow the file). Moving to position\r
d2b4564b 184 0xFFFFFFFFFFFFFFFF causes the current position to be set to the end of the file.\r
1e6e84c7 185 If FileHandle is a directory, the only position that may be set is zero. This\r
a405b86d 186 has the effect of starting the read process of the directory entries over again.\r
d2b4564b 187\r
a405b86d 188 @param[in] FileHandle The file handle on which the position is being set.\r
189 @param[in] Position The byte position from the begining of the file.\r
d2b4564b 190\r
a405b86d 191 @retval EFI_SUCCESS The operation completed sucessfully.\r
192 @retval EFI_UNSUPPORTED The request for non-zero is not valid on\r
d2b4564b 193 directories.\r
194 @retval INVALID_PARAMETER One of the parameters has an invalid value.\r
195**/\r
196EFI_STATUS\r
197EFIAPI\r
198FileHandleSetPosition (\r
199 IN EFI_FILE_HANDLE FileHandle,\r
200 IN UINT64 Position\r
201 );\r
202\r
1e6e84c7 203/**\r
125c2cf4 204 Gets a file's current position.\r
d2b4564b 205\r
1e6e84c7 206 This function retrieves the current file position for the file handle. For\r
207 directories, the current file position has no meaning outside of the file\r
a405b86d 208 system driver. As such, the operation is not supported. An error is returned\r
d2b4564b 209 if FileHandle is a directory.\r
210\r
a405b86d 211 @param[in] FileHandle The open file handle on which to get the position.\r
212 @param[out] Position The byte position from begining of file.\r
d2b4564b 213\r
a405b86d 214 @retval EFI_SUCCESS The operation completed successfully.\r
d2b4564b 215 @retval INVALID_PARAMETER One of the parameters has an invalid value.\r
a405b86d 216 @retval EFI_UNSUPPORTED The request is not valid on directories.\r
d2b4564b 217**/\r
218EFI_STATUS\r
219EFIAPI\r
220FileHandleGetPosition (\r
221 IN EFI_FILE_HANDLE FileHandle,\r
222 OUT UINT64 *Position\r
223 );\r
224/**\r
125c2cf4 225 Flushes data on a file.\r
1e6e84c7 226\r
d2b4564b 227 This function flushes all modified data associated with a file to a device.\r
228\r
a405b86d 229 @param[in] FileHandle The file handle on which to flush data.\r
d2b4564b 230\r
231 @retval EFI_SUCCESS The data was flushed.\r
232 @retval EFI_NO_MEDIA The device has no media.\r
233 @retval EFI_DEVICE_ERROR The device reported an error.\r
234 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
235 @retval EFI_WRITE_PROTECTED The file or medium is write protected.\r
236 @retval EFI_ACCESS_DENIED The file was opened for read only.\r
237**/\r
238EFI_STATUS\r
239EFIAPI\r
240FileHandleFlush (\r
241 IN EFI_FILE_HANDLE FileHandle\r
242 );\r
243\r
244/**\r
125c2cf4 245 Function to determine if a given handle is a directory handle.\r
d2b4564b 246\r
a405b86d 247 If DirHandle is NULL, then ASSERT().\r
d2b4564b 248\r
a405b86d 249 Open the file information on the DirHandle, and verify that the Attribute\r
d2b4564b 250 includes EFI_FILE_DIRECTORY bit set.\r
251\r
a405b86d 252 @param[in] DirHandle The handle to open the file.\r
d2b4564b 253\r
a405b86d 254 @retval EFI_SUCCESS DirHandle is a directory.\r
255 @retval EFI_INVALID_PARAMETER DirHandle did not have EFI_FILE_INFO available.\r
256 @retval EFI_NOT_FOUND DirHandle is not a directory.\r
d2b4564b 257**/\r
258EFI_STATUS\r
259EFIAPI\r
260FileHandleIsDirectory (\r
261 IN EFI_FILE_HANDLE DirHandle\r
262 );\r
263\r
264/**\r
125c2cf4 265 Retrieves the first file from a directory.\r
d2b4564b 266\r
a405b86d 267 This function opens a directory and gets the first file's information in the\r
268 directory. The caller the uses FileHandleFindNextFile() to get other files. When\r
269 complete, the caller is responsible for calling FreePool() on *Buffer.\r
d2b4564b 270\r
a405b86d 271 @param[in] DirHandle The file handle of the directory to search.\r
272 @param[out] Buffer The pointer to pointer to buffer for file's information.\r
d2b4564b 273\r
274 @retval EFI_SUCCESS Found the first file.\r
275 @retval EFI_NOT_FOUND Cannot find the directory.\r
276 @retval EFI_NO_MEDIA The device has no media.\r
277 @retval EFI_DEVICE_ERROR The device reported an error.\r
278 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
a405b86d 279 @return Others The status of FileHandleGetInfo, FileHandleSetPosition,\r
280 or FileHandleRead.\r
d2b4564b 281**/\r
282EFI_STATUS\r
283EFIAPI\r
284FileHandleFindFirstFile (\r
285 IN EFI_FILE_HANDLE DirHandle,\r
286 OUT EFI_FILE_INFO **Buffer\r
287 );\r
288/**\r
289 Retrieves the next file in a directory.\r
290\r
1e6e84c7 291 To use this function, caller must call the FileHandleFindFirstFile() to get the\r
292 first file, and then use this function get other files. This function can be\r
293 called for several times to get each file's information in the directory. If\r
294 the call of FileHandleFindNextFile() got the last file in the directory, the next\r
295 call of this function has no file to get. *NoFile will be set to TRUE and the\r
296 Buffer memory will be automatically freed.\r
d2b4564b 297\r
a405b86d 298 @param[in] DirHandle The file handle of the directory.\r
299 @param[out] Buffer The pointer to buffer for file's information.\r
300 @param[out] NoFile The pointer to boolean when last file is found.\r
d2b4564b 301\r
a405b86d 302 @retval EFI_SUCCESS Found the next file, or reached last file.\r
d2b4564b 303 @retval EFI_NO_MEDIA The device has no media.\r
304 @retval EFI_DEVICE_ERROR The device reported an error.\r
305 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
306**/\r
307EFI_STATUS\r
308EFIAPI\r
309FileHandleFindNextFile(\r
310 IN EFI_FILE_HANDLE DirHandle,\r
311 OUT EFI_FILE_INFO *Buffer,\r
312 OUT BOOLEAN *NoFile\r
313 );\r
314\r
315/**\r
316 Retrieve the size of a file.\r
317\r
a405b86d 318 If FileHandle is NULL then ASSERT().\r
319 If Size is NULL then ASSERT().\r
d2b4564b 320\r
1e6e84c7 321 This function extracts the file size info from the FileHandle's EFI_FILE_INFO\r
d2b4564b 322 data.\r
323\r
a405b86d 324 @param[in] FileHandle The file handle from which size is retrieved.\r
325 @param[out] Size The pointer to size.\r
d2b4564b 326\r
a405b86d 327 @retval EFI_SUCCESS The operation completed successfully.\r
328 @retval EFI_DEVICE_ERROR Cannot access the file.\r
d2b4564b 329**/\r
330EFI_STATUS\r
331EFIAPI\r
332FileHandleGetSize (\r
333 IN EFI_FILE_HANDLE FileHandle,\r
334 OUT UINT64 *Size\r
b1f95a06 335 );\r
336\r
a405b86d 337/**\r
338 Set the size of a file.\r
339\r
340 If FileHandle is NULL then ASSERT().\r
341\r
342 This function changes the file size info from the FileHandle's EFI_FILE_INFO\r
343 data.\r
344\r
345 @param[in] FileHandle The file handle whose size is to be changed.\r
346 @param[in] Size The new size.\r
347\r
348 @retval EFI_SUCCESS The operation completed successfully.\r
349 @retval EFI_DEVICE_ERROR Cannot access the file.\r
350**/\r
351EFI_STATUS\r
352EFIAPI\r
353FileHandleSetSize (\r
354 IN EFI_FILE_HANDLE FileHandle,\r
355 IN UINT64 Size\r
356 );\r
357\r
b1f95a06 358/**\r
1e6e84c7 359 Function to get a full filename given a EFI_FILE_HANDLE somewhere lower on the\r
b1f95a06 360 directory 'stack'.\r
361\r
b1f95a06 362 @param[in] Handle Handle to the Directory or File to create path to.\r
1e6e84c7 363 @param[out] FullFileName Pointer to pointer to generated full file name. It\r
b1f95a06 364 is the responsibility of the caller to free this memory\r
365 with a call to FreePool().\r
a405b86d 366 @retval EFI_SUCCESS The operation was successful and FullFileName is valid.\r
b1f95a06 367 @retval EFI_INVALID_PARAMETER Handle was NULL.\r
368 @retval EFI_INVALID_PARAMETER FullFileName was NULL.\r
a405b86d 369 @retval EFI_OUT_OF_MEMORY A memory allocation failed.\r
b1f95a06 370**/\r
371EFI_STATUS\r
372EFIAPI\r
373FileHandleGetFileName (\r
374 IN CONST EFI_FILE_HANDLE Handle,\r
375 OUT CHAR16 **FullFileName\r
376 );\r
377\r
378/**\r
b3011f40 379 Function to read a single line (up to but not including the \n) from a file.\r
b1f95a06 380\r
1e6e84c7 381 If the position upon start is 0, then the Ascii Boolean will be set. This should be\r
b3011f40 382 maintained and not changed for all operations with the same file.\r
383\r
a405b86d 384 @param[in] Handle FileHandle to read from.\r
385 @param[in,out] Buffer The pointer to buffer to read into.\r
386 @param[in,out] Size The pointer to number of bytes in Buffer.\r
387 @param[in] Truncate If the buffer is large enough, this has no effect.\r
388 If the buffer is is too small and Truncate is TRUE,\r
389 the line will be truncated.\r
390 If the buffer is is too small and Truncate is FALSE,\r
391 then no read will occur.\r
392\r
1e6e84c7 393 @param[in,out] Ascii Boolean value for indicating whether the file is\r
a405b86d 394 Ascii (TRUE) or UCS2 (FALSE).\r
b1f95a06 395\r
a405b86d 396 @retval EFI_SUCCESS The operation was successful. The line is stored in\r
b3011f40 397 Buffer.\r
b1f95a06 398 @retval EFI_INVALID_PARAMETER Handle was NULL.\r
b1f95a06 399 @retval EFI_INVALID_PARAMETER Size was NULL.\r
a405b86d 400 @retval EFI_BUFFER_TOO_SMALL Size was not large enough to store the line.\r
401 Size was updated to the minimum space required.\r
b1f95a06 402 @sa FileHandleRead\r
403**/\r
404EFI_STATUS\r
405EFIAPI\r
406FileHandleReadLine(\r
407 IN EFI_FILE_HANDLE Handle,\r
125c2cf4 408 IN OUT CHAR16 *Buffer,\r
b1f95a06 409 IN OUT UINTN *Size,\r
b3011f40 410 IN BOOLEAN Truncate,\r
411 IN OUT BOOLEAN *Ascii\r
412 );\r
413\r
414/**\r
1e6e84c7 415 Function to read a single line from a file. The \n is not included in the returned\r
b3011f40 416 buffer. The returned buffer must be callee freed.\r
417\r
1e6e84c7 418 If the position upon start is 0, then the Ascii Boolean will be set. This should be\r
b3011f40 419 maintained and not changed for all operations with the same file.\r
420\r
421 @param[in] Handle FileHandle to read from.\r
a405b86d 422 @param[in,out] Ascii Boolean value for indicating whether the file is\r
423 Ascii (TRUE) or UCS2 (FALSE).\r
b3011f40 424\r
425 @return The line of text from the file.\r
426\r
427 @sa FileHandleReadLine\r
428**/\r
429CHAR16*\r
430EFIAPI\r
431FileHandleReturnLine(\r
432 IN EFI_FILE_HANDLE Handle,\r
433 IN OUT BOOLEAN *Ascii\r
b1f95a06 434 );\r
435\r
436/**\r
125c2cf4 437 Function to write a line of unicode text to a file.\r
b1f95a06 438\r
125c2cf4 439 If Handle is NULL, ASSERT.\r
b1f95a06 440\r
a405b86d 441 @param[in] Handle FileHandle to write to.\r
1e6e84c7 442 @param[in] Buffer Buffer to write, if NULL the function will\r
125c2cf4 443 take no action and return EFI_SUCCESS.\r
b1f95a06 444\r
a405b86d 445 @retval EFI_SUCCESS The data was written.\r
446 @retval other Failure.\r
b1f95a06 447\r
448 @sa FileHandleWrite\r
449**/\r
450EFI_STATUS\r
451EFIAPI\r
452FileHandleWriteLine(\r
453 IN EFI_FILE_HANDLE Handle,\r
454 IN CHAR16 *Buffer\r
e9880e25 455 );\r
125c2cf4 456\r
457/**\r
a405b86d 458 Function to take a formatted argument and print it to a file.\r
125c2cf4 459\r
a405b86d 460 @param[in] Handle The file handle for the file to write to.\r
461 @param[in] Format The format argument (see printlib for the format specifier).\r
462 @param[in] ... The variable arguments for the format.\r
125c2cf4 463\r
a405b86d 464 @retval EFI_SUCCESS The operation was successful.\r
465 @retval other A return value from FileHandleWriteLine.\r
125c2cf4 466\r
467 @sa FileHandleWriteLine\r
468**/\r
469EFI_STATUS\r
470EFIAPI\r
471FileHandlePrintLine(\r
472 IN EFI_FILE_HANDLE Handle,\r
473 IN CONST CHAR16 *Format,\r
474 ...\r
475 );\r
476\r
477/**\r
478 Function to determine if a FILE_HANDLE is at the end of the file.\r
479\r
480 This will NOT work on directories.\r
481\r
a405b86d 482 If Handle is NULL, then ASSERT().\r
b3011f40 483\r
a405b86d 484 @param[in] Handle The file handle.\r
125c2cf4 485\r
a405b86d 486 @retval TRUE The position is at the end of the file.\r
487 @retval FALSE The position is not at the end of the file.\r
125c2cf4 488**/\r
489BOOLEAN\r
490EFIAPI\r
491FileHandleEof(\r
492 IN EFI_FILE_HANDLE Handle\r
493 );\r
b3011f40 494\r
495#endif //_FILE_HANDLE_LIBRARY_HEADER_\r
496\r