]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - ShellPkg/Include/Library/FileHandleLib.h
udk2010.up2.shell initial release.
[mirror_edk2.git] / ShellPkg / Include / Library / FileHandleLib.h
... / ...
CommitLineData
1/** @file\r
2 Provides interface to EFI_FILE_HANDLE functionality.\r
3\r
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
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
9\r
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
12\r
13**/\r
14\r
15#ifndef _FILE_HANDLE_LIBRARY_HEADER_\r
16#define _FILE_HANDLE_LIBRARY_HEADER_\r
17\r
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
22enum {\r
23 UnicodeFileTag = 0xFEFF\r
24};\r
25\r
26/**\r
27 This function retrieves information about the file for the handle\r
28 specified and stores it in the allocated pool memory.\r
29\r
30 This function allocates a buffer to store the file's information. It is the\r
31 caller's responsibility to free the buffer.\r
32\r
33 @param[in] FileHandle The file handle of the file for which information is\r
34 being requested.\r
35\r
36 @retval NULL Information could not be retrieved.\r
37 @retval !NULL The information about the file.\r
38**/\r
39EFI_FILE_INFO*\r
40EFIAPI\r
41FileHandleGetInfo (\r
42 IN EFI_FILE_HANDLE FileHandle\r
43 );\r
44\r
45/**\r
46 This function sets the information about the file for the opened handle\r
47 specified.\r
48\r
49 @param[in] FileHandle The file handle of the file for which information\r
50 is being set.\r
51\r
52 @param[in] FileInfo The information to set.\r
53\r
54 @retval EFI_SUCCESS The information was set.\r
55 @retval EFI_INVALID_PARAMETER A parameter was out of range or invalid.\r
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
59 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
60 @retval EFI_WRITE_PROTECTED The file or medium is write protected.\r
61 @retval EFI_ACCESS_DENIED The file was opened read only.\r
62 @retval EFI_VOLUME_FULL The volume is full.\r
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
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
76 If the read goes beyond the end of the file, the read length is truncated to the\r
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
85 EFI_FILE_INFO is the structure returned as the directory entry.\r
86\r
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
89 the number of bytes written.\r
90 @param[out] Buffer The buffer to put read data into.\r
91\r
92 @retval EFI_SUCCESS Data was read.\r
93 @retval EFI_NO_MEDIA The device has no media.\r
94 @retval EFI_DEVICE_ERROR The device reported an error.\r
95 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
96 @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required\r
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
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
116 opened directories are not supported.\r
117\r
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
120 the number of bytes written.\r
121 @param[in] Buffer The buffer containing data to write is stored.\r
122\r
123 @retval EFI_SUCCESS Data was written.\r
124 @retval EFI_UNSUPPORTED Writes to an open directory are not supported.\r
125 @retval EFI_NO_MEDIA The device has no media.\r
126 @retval EFI_DEVICE_ERROR The device reported an error.\r
127 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
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
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
140/**\r
141 Close an open file handle.\r
142\r
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
145 closed.\r
146\r
147 @param[in] FileHandle The file handle to close.\r
148\r
149 @retval EFI_SUCCESS The file handle was closed successfully.\r
150**/\r
151EFI_STATUS\r
152EFIAPI\r
153FileHandleClose (\r
154 IN EFI_FILE_HANDLE FileHandle\r
155 );\r
156\r
157/**\r
158 Delete a file and close the handle.\r
159\r
160 This function closes and deletes a file. In all cases the file handle is closed.\r
161 If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is\r
162 returned, but the handle is still closed.\r
163\r
164 @param[in] FileHandle The file handle to delete.\r
165\r
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
169 @retval INVALID_PARAMETER One of the parameters has an invalid value.\r
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
180 This function sets the current file position for the handle to the position\r
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
184 0xFFFFFFFFFFFFFFFF causes the current position to be set to the end of the file.\r
185 If FileHandle is a directory, the only position that may be set is zero. This\r
186 has the effect of starting the read process of the directory entries over again.\r
187\r
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
190\r
191 @retval EFI_SUCCESS The operation completed sucessfully.\r
192 @retval EFI_UNSUPPORTED The request for non-zero is not valid on\r
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
203/**\r
204 Gets a file's current position.\r
205\r
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
208 system driver. As such, the operation is not supported. An error is returned\r
209 if FileHandle is a directory.\r
210\r
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
213\r
214 @retval EFI_SUCCESS The operation completed successfully.\r
215 @retval INVALID_PARAMETER One of the parameters has an invalid value.\r
216 @retval EFI_UNSUPPORTED The request is not valid on directories.\r
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
225 Flushes data on a file.\r
226\r
227 This function flushes all modified data associated with a file to a device.\r
228\r
229 @param[in] FileHandle The file handle on which to flush data.\r
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
245 Function to determine if a given handle is a directory handle.\r
246\r
247 If DirHandle is NULL, then ASSERT().\r
248\r
249 Open the file information on the DirHandle, and verify that the Attribute\r
250 includes EFI_FILE_DIRECTORY bit set.\r
251\r
252 @param[in] DirHandle The handle to open the file.\r
253\r
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
257**/\r
258EFI_STATUS\r
259EFIAPI\r
260FileHandleIsDirectory (\r
261 IN EFI_FILE_HANDLE DirHandle\r
262 );\r
263\r
264/**\r
265 Retrieves the first file from a directory.\r
266\r
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
270\r
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
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
279 @return Others The status of FileHandleGetInfo, FileHandleSetPosition,\r
280 or FileHandleRead.\r
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
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
297\r
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
301\r
302 @retval EFI_SUCCESS Found the next file, or reached last file.\r
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
318 If FileHandle is NULL then ASSERT().\r
319 If Size is NULL then ASSERT().\r
320\r
321 This function extracts the file size info from the FileHandle's EFI_FILE_INFO\r
322 data.\r
323\r
324 @param[in] FileHandle The file handle from which size is retrieved.\r
325 @param[out] Size The pointer to size.\r
326\r
327 @retval EFI_SUCCESS The operation completed successfully.\r
328 @retval EFI_DEVICE_ERROR Cannot access the file.\r
329**/\r
330EFI_STATUS\r
331EFIAPI\r
332FileHandleGetSize (\r
333 IN EFI_FILE_HANDLE FileHandle,\r
334 OUT UINT64 *Size\r
335 );\r
336\r
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
358/**\r
359 Function to get a full filename given a EFI_FILE_HANDLE somewhere lower on the\r
360 directory 'stack'.\r
361\r
362 @param[in] Handle Handle to the Directory or File to create path to.\r
363 @param[out] FullFileName Pointer to pointer to generated full file name. It\r
364 is the responsibility of the caller to free this memory\r
365 with a call to FreePool().\r
366 @retval EFI_SUCCESS The operation was successful and FullFileName is valid.\r
367 @retval EFI_INVALID_PARAMETER Handle was NULL.\r
368 @retval EFI_INVALID_PARAMETER FullFileName was NULL.\r
369 @retval EFI_OUT_OF_MEMORY A memory allocation failed.\r
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
379 Function to read a single line (up to but not including the \n) from a file.\r
380\r
381 If the position upon start is 0, then the Ascii Boolean will be set. This should be\r
382 maintained and not changed for all operations with the same file.\r
383\r
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
393 @param[in,out] Ascii Boolean value for indicating whether the file is\r
394 Ascii (TRUE) or UCS2 (FALSE).\r
395\r
396 @retval EFI_SUCCESS The operation was successful. The line is stored in\r
397 Buffer.\r
398 @retval EFI_INVALID_PARAMETER Handle was NULL.\r
399 @retval EFI_INVALID_PARAMETER Size was NULL.\r
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
402 @sa FileHandleRead\r
403**/\r
404EFI_STATUS\r
405EFIAPI\r
406FileHandleReadLine(\r
407 IN EFI_FILE_HANDLE Handle,\r
408 IN OUT CHAR16 *Buffer,\r
409 IN OUT UINTN *Size,\r
410 IN BOOLEAN Truncate,\r
411 IN OUT BOOLEAN *Ascii\r
412 );\r
413\r
414/**\r
415 Function to read a single line from a file. The \n is not included in the returned\r
416 buffer. The returned buffer must be callee freed.\r
417\r
418 If the position upon start is 0, then the Ascii Boolean will be set. This should be\r
419 maintained and not changed for all operations with the same file.\r
420\r
421 @param[in] Handle FileHandle to read from.\r
422 @param[in,out] Ascii Boolean value for indicating whether the file is\r
423 Ascii (TRUE) or UCS2 (FALSE).\r
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
434 );\r
435\r
436/**\r
437 Function to write a line of unicode text to a file.\r
438\r
439 If Handle is NULL, ASSERT.\r
440\r
441 @param[in] Handle FileHandle to write to.\r
442 @param[in] Buffer Buffer to write, if NULL the function will\r
443 take no action and return EFI_SUCCESS.\r
444\r
445 @retval EFI_SUCCESS The data was written.\r
446 @retval other Failure.\r
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
455 );\r
456\r
457/**\r
458 Function to take a formatted argument and print it to a file.\r
459\r
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
463\r
464 @retval EFI_SUCCESS The operation was successful.\r
465 @retval other A return value from FileHandleWriteLine.\r
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
482 If Handle is NULL, then ASSERT().\r
483\r
484 @param[in] Handle The file handle.\r
485\r
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
488**/\r
489BOOLEAN\r
490EFIAPI\r
491FileHandleEof(\r
492 IN EFI_FILE_HANDLE Handle\r
493 );\r
494\r
495#endif //_FILE_HANDLE_LIBRARY_HEADER_\r
496\r