]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Include/Library/FileHandleLib.h
MdePkg: fix comment typo in DebugLib.h
[mirror_edk2.git] / MdePkg / Include / Library / FileHandleLib.h
... / ...
CommitLineData
1/** @file\r
2 Provides interface to EFI_FILE_HANDLE functionality.\r
3\r
4 Copyright (c) 2009 - 2015, 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
22extern CONST UINT16 gUnicodeFileTag;\r
23\r
24/**\r
25 This function retrieves information about the file for the handle\r
26 specified and stores it in the 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[in] 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 @retval !NULL The information about the file.\r
36**/\r
37EFI_FILE_INFO*\r
38EFIAPI\r
39FileHandleGetInfo (\r
40 IN EFI_FILE_HANDLE FileHandle\r
41 );\r
42\r
43/**\r
44 This function sets the information about the file for the opened handle\r
45 specified.\r
46\r
47 @param[in] FileHandle The file handle of the file for which information\r
48 is being set.\r
49\r
50 @param[in] FileInfo The information to set.\r
51\r
52 @retval EFI_SUCCESS The information was set.\r
53 @retval EFI_INVALID_PARAMETER A parameter was out of range or invalid.\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[in] FileHandle The opened file handle.\r
86 @param[in, out] BufferSize On input, the size of buffer in bytes. On return,\r
87 the number of bytes written.\r
88 @param[out] 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[in] FileHandle The opened file for writing.\r
117 @param[in, out] BufferSize On input, the number of bytes in Buffer. On output,\r
118 the number of bytes written.\r
119 @param[in] 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 opened 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[in] FileHandle The file handle to close.\r
146\r
147 @retval EFI_SUCCESS The file handle was closed successfully.\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[in] FileHandle The file handle to delete.\r
163\r
164 @retval EFI_SUCCESS The file was closed successfully.\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 moving to position 0xFFFFFFFFFFFFFFFF, only\r
180 absolute positioning is supported, and moving past the end of the file is\r
181 allowed (a subsequent write would grow the file). Moving 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 again.\r
185\r
186 @param[in] FileHandle The file handle on which the position is being set.\r
187 @param[in] Position The byte position from the begining of the file.\r
188\r
189 @retval EFI_SUCCESS The operation completed sucessfully.\r
190 @retval EFI_UNSUPPORTED The 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. As such, the operation is not supported. An error is returned\r
207 if FileHandle is a directory.\r
208\r
209 @param[in] FileHandle The open file handle on which to get the position.\r
210 @param[out] Position The byte position from begining of file.\r
211\r
212 @retval EFI_SUCCESS The operation completed successfully.\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[in] 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 Open the file information on the DirHandle and verify that the Attribute\r
246 includes EFI_FILE_DIRECTORY bit set.\r
247\r
248 @param[in] DirHandle Handle to open file.\r
249\r
250 @retval EFI_SUCCESS DirHandle is a directory.\r
251 @retval EFI_INVALID_PARAMETER DirHandle is NULL. \r
252 The file information returns from FileHandleGetInfo is NULL. \r
253 @retval EFI_NOT_FOUND DirHandle is not a directory.\r
254**/\r
255EFI_STATUS\r
256EFIAPI\r
257FileHandleIsDirectory (\r
258 IN EFI_FILE_HANDLE DirHandle\r
259 );\r
260\r
261/** Retrieve first entry from a directory.\r
262\r
263 This function takes an open directory handle and gets information from the\r
264 first entry in the directory. A buffer is allocated to contain\r
265 the information and a pointer to the buffer is returned in *Buffer. The\r
266 caller can use FileHandleFindNextFile() to get subsequent directory entries.\r
267\r
268 The buffer will be freed by FileHandleFindNextFile() when the last directory\r
269 entry is read. Otherwise, the caller must free the buffer, using FreePool,\r
270 when finished with it.\r
271\r
272 @param[in] DirHandle The file handle of the directory to search.\r
273 @param[out] Buffer The pointer to pointer to buffer for file's information.\r
274\r
275 @retval EFI_SUCCESS Found the first file.\r
276 @retval EFI_NOT_FOUND Cannot find the directory.\r
277 @retval EFI_NO_MEDIA The device has no media.\r
278 @retval EFI_DEVICE_ERROR The device reported an error.\r
279 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
280 @return Others The status of FileHandleGetInfo, FileHandleSetPosition,\r
281 or FileHandleRead.\r
282**/\r
283EFI_STATUS\r
284EFIAPI\r
285FileHandleFindFirstFile (\r
286 IN EFI_FILE_HANDLE DirHandle,\r
287 OUT EFI_FILE_INFO **Buffer\r
288 );\r
289\r
290/** Retrieve next entries from a directory.\r
291\r
292 To use this function, the caller must first call the FileHandleFindFirstFile()\r
293 function to get the first directory entry. Subsequent directory entries are\r
294 retrieved by using the FileHandleFindNextFile() function. This function can\r
295 be called several times to get each entry from the directory. If the call of\r
296 FileHandleFindNextFile() retrieved the last directory entry, the next call of\r
297 this function will set *NoFile to TRUE and free the buffer.\r
298\r
299 @param[in] DirHandle The file handle of the directory.\r
300 @param[out] Buffer The pointer to buffer for file's information.\r
301 @param[out] NoFile The pointer to boolean when last file is found.\r
302\r
303 @retval EFI_SUCCESS Found the next file, or reached last file.\r
304 @retval EFI_NO_MEDIA The device has no media.\r
305 @retval EFI_DEVICE_ERROR The device reported an error.\r
306 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
307**/\r
308EFI_STATUS\r
309EFIAPI\r
310FileHandleFindNextFile(\r
311 IN EFI_FILE_HANDLE DirHandle,\r
312 OUT EFI_FILE_INFO *Buffer,\r
313 OUT BOOLEAN *NoFile\r
314 );\r
315\r
316/**\r
317 Retrieve the size of a file.\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[in] FileHandle The file handle from which size is retrieved.\r
323 @param[out] Size The 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 @retval EFI_INVALID_PARAMETER FileHandle is NULL.\r
328 Size is NULL.\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 This function changes the file size info from the FileHandle's EFI_FILE_INFO\r
341 data.\r
342\r
343 @param[in] FileHandle The file handle whose size is to be changed.\r
344 @param[in] Size The new size.\r
345\r
346 @retval EFI_SUCCESS The operation completed successfully.\r
347 @retval EFI_DEVICE_ERROR Cannot access the file.\r
348 @retval EFI_INVALID_PARAMETER FileHandle is NULL.\r
349**/\r
350EFI_STATUS\r
351EFIAPI\r
352FileHandleSetSize (\r
353 IN EFI_FILE_HANDLE FileHandle,\r
354 IN UINT64 Size\r
355 );\r
356\r
357/**\r
358 Function to get a full filename given a EFI_FILE_HANDLE somewhere lower on the\r
359 directory 'stack'. If the file is a directory, then append the '\' char at the \r
360 end of name string. If it's not a directory, then the last '\' should not be \r
361 added.\r
362\r
363 @param[in] Handle Handle to the Directory or File to create path to.\r
364 @param[out] FullFileName Pointer to pointer to generated full file name. It\r
365 is the responsibility of the caller to free this memory\r
366 with a call to FreePool().\r
367 @retval EFI_SUCCESS The operation was successful and FullFileName is valid.\r
368 @retval EFI_INVALID_PARAMETER Handle was NULL.\r
369 @retval EFI_INVALID_PARAMETER FullFileName was NULL.\r
370 @retval EFI_OUT_OF_MEMORY A memory allocation failed.\r
371**/\r
372EFI_STATUS\r
373EFIAPI\r
374FileHandleGetFileName (\r
375 IN CONST EFI_FILE_HANDLE Handle,\r
376 OUT CHAR16 **FullFileName\r
377 );\r
378\r
379/**\r
380 Function to read a single line (up to but not including the \n) from a file.\r
381\r
382 If the position upon start is 0, then the Ascii Boolean will be set. This should be\r
383 maintained and not changed for all operations with the same file.\r
384 The function will not return the \r and \n character in buffer. When an empty line is\r
385 read a CHAR_NULL character will be returned in buffer.\r
386\r
387 @param[in] Handle FileHandle to read from.\r
388 @param[in, out] Buffer The pointer to buffer to read into.\r
389 @param[in, out] Size The pointer to number of bytes in Buffer.\r
390 @param[in] Truncate If the buffer is large enough, this has no effect.\r
391 If the buffer is is too small and Truncate is TRUE,\r
392 the line will be truncated.\r
393 If the buffer is is too small and Truncate is FALSE,\r
394 then no read will occur.\r
395\r
396 @param[in, out] Ascii Boolean value for indicating whether the file is\r
397 Ascii (TRUE) or UCS2 (FALSE).\r
398\r
399 @retval EFI_SUCCESS The operation was successful. The line is stored in\r
400 Buffer.\r
401 @retval EFI_INVALID_PARAMETER Handle was NULL.\r
402 @retval EFI_INVALID_PARAMETER Size was NULL.\r
403 @retval EFI_BUFFER_TOO_SMALL Size was not large enough to store the line.\r
404 Size was updated to the minimum space required.\r
405 @sa FileHandleRead\r
406**/\r
407EFI_STATUS\r
408EFIAPI\r
409FileHandleReadLine(\r
410 IN EFI_FILE_HANDLE Handle,\r
411 IN OUT CHAR16 *Buffer,\r
412 IN OUT UINTN *Size,\r
413 IN BOOLEAN Truncate,\r
414 IN OUT BOOLEAN *Ascii\r
415 );\r
416\r
417/**\r
418 Function to read a single line from a file. The \n is not included in the returned\r
419 buffer. The returned buffer must be callee freed.\r
420\r
421 If the position upon start is 0, then the Ascii Boolean will be set. This should be\r
422 maintained and not changed for all operations with the same file.\r
423\r
424 @param[in] Handle FileHandle to read from.\r
425 @param[in, out] Ascii Boolean value for indicating whether the file is\r
426 Ascii (TRUE) or UCS2 (FALSE).\r
427\r
428 @return The line of text from the file.\r
429\r
430 @sa FileHandleReadLine\r
431**/\r
432CHAR16*\r
433EFIAPI\r
434FileHandleReturnLine(\r
435 IN EFI_FILE_HANDLE Handle,\r
436 IN OUT BOOLEAN *Ascii\r
437 );\r
438\r
439/**\r
440 Function to write a line of text to a file.\r
441 \r
442 If the file is a Unicode file (with UNICODE file tag) then write the unicode \r
443 text.\r
444 If the file is an ASCII file then write the ASCII text.\r
445 If the size of file is zero (without file tag at the beginning) then write \r
446 ASCII text as default.\r
447\r
448 @param[in] Handle FileHandle to write to.\r
449 @param[in] Buffer Buffer to write, if NULL the function will\r
450 take no action and return EFI_SUCCESS.\r
451\r
452 @retval EFI_SUCCESS The data was written.\r
453 Buffer is NULL.\r
454 @retval EFI_INVALID_PARAMETER Handle is NULL.\r
455 @retval EFI_OUT_OF_RESOURCES Unable to allocate temporary space for ASCII \r
456 string due to out of resources.\r
457\r
458 @sa FileHandleWrite\r
459**/\r
460EFI_STATUS\r
461EFIAPI\r
462FileHandleWriteLine(\r
463 IN EFI_FILE_HANDLE Handle,\r
464 IN CHAR16 *Buffer\r
465 );\r
466\r
467/**\r
468 Function to take a formatted argument and print it to a file.\r
469\r
470 @param[in] Handle The file handle for the file to write to.\r
471 @param[in] Format The format argument (see printlib for the format specifier).\r
472 @param[in] ... The variable arguments for the format.\r
473\r
474 @retval EFI_SUCCESS The operation was successful.\r
475 @retval other A return value from FileHandleWriteLine.\r
476\r
477 @sa FileHandleWriteLine\r
478**/\r
479EFI_STATUS\r
480EFIAPI\r
481FileHandlePrintLine(\r
482 IN EFI_FILE_HANDLE Handle,\r
483 IN CONST CHAR16 *Format,\r
484 ...\r
485 );\r
486\r
487/**\r
488 Function to determine if a FILE_HANDLE is at the end of the file.\r
489\r
490 This will NOT work on directories.\r
491\r
492 If Handle is NULL, then ASSERT().\r
493\r
494 @param[in] Handle The file handle.\r
495\r
496 @retval TRUE The position is at the end of the file.\r
497 @retval FALSE The position is not at the end of the file.\r
498**/\r
499BOOLEAN\r
500EFIAPI\r
501FileHandleEof(\r
502 IN EFI_FILE_HANDLE Handle\r
503 );\r
504\r
505#endif //_FILE_HANDLE_LIBRARY_HEADER_\r
506\r