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