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