]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Include/Library/FileHandleLib.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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/**\r
219 Flushes data on a file.\r
220\r
221 This function flushes all modified data associated with a file to a device.\r
222\r
223 @param[in] FileHandle The file handle on which to flush data.\r
224\r
225 @retval EFI_SUCCESS The data was flushed.\r
226 @retval EFI_NO_MEDIA The device has no media.\r
227 @retval EFI_DEVICE_ERROR The device reported an error.\r
228 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
229 @retval EFI_WRITE_PROTECTED The file or medium is write protected.\r
230 @retval EFI_ACCESS_DENIED The file was opened for read only.\r
231**/\r
232EFI_STATUS\r
233EFIAPI\r
234FileHandleFlush (\r
235 IN EFI_FILE_HANDLE FileHandle\r
236 );\r
237\r
238/**\r
239 Function to determine if a given handle is a directory handle.\r
240\r
241 Open the file information on the DirHandle and verify that the Attribute\r
242 includes EFI_FILE_DIRECTORY bit set.\r
243\r
244 @param[in] DirHandle Handle to open file.\r
245\r
246 @retval EFI_SUCCESS DirHandle is a directory.\r
247 @retval EFI_INVALID_PARAMETER DirHandle is NULL.\r
248 The file information returns from FileHandleGetInfo is NULL.\r
249 @retval EFI_NOT_FOUND DirHandle is not a directory.\r
250**/\r
251EFI_STATUS\r
252EFIAPI\r
253FileHandleIsDirectory (\r
254 IN EFI_FILE_HANDLE DirHandle\r
255 );\r
256\r
257/** Retrieve first entry from a directory.\r
258\r
259 This function takes an open directory handle and gets information from the\r
260 first entry in the directory. A buffer is allocated to contain\r
261 the information and a pointer to the buffer is returned in *Buffer. The\r
262 caller can use FileHandleFindNextFile() to get subsequent directory entries.\r
263\r
264 The buffer will be freed by FileHandleFindNextFile() when the last directory\r
265 entry is read. Otherwise, the caller must free the buffer, using FreePool,\r
266 when finished with it.\r
267\r
268 @param[in] DirHandle The file handle of the directory to search.\r
269 @param[out] Buffer The pointer to pointer to buffer for file's information.\r
270\r
271 @retval EFI_SUCCESS Found the first file.\r
272 @retval EFI_NOT_FOUND Cannot find the directory.\r
273 @retval EFI_NO_MEDIA The device has no media.\r
274 @retval EFI_DEVICE_ERROR The device reported an error.\r
275 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
276 @return Others The status of FileHandleGetInfo, FileHandleSetPosition,\r
277 or FileHandleRead.\r
278**/\r
279EFI_STATUS\r
280EFIAPI\r
281FileHandleFindFirstFile (\r
282 IN EFI_FILE_HANDLE DirHandle,\r
283 OUT EFI_FILE_INFO **Buffer\r
284 );\r
285\r
286/** Retrieve next entries from a directory.\r
287\r
288 To use this function, the caller must first call the FileHandleFindFirstFile()\r
289 function to get the first directory entry. Subsequent directory entries are\r
290 retrieved by using the FileHandleFindNextFile() function. This function can\r
291 be called several times to get each entry from the directory. If the call of\r
292 FileHandleFindNextFile() retrieved the last directory entry, the next call of\r
293 this function will set *NoFile to TRUE and free the buffer.\r
294\r
295 @param[in] DirHandle The file handle of the directory.\r
296 @param[out] Buffer The pointer to buffer for file's information.\r
297 @param[out] NoFile The pointer to boolean when last file is found.\r
298\r
299 @retval EFI_SUCCESS Found the next file, or reached last file.\r
300 @retval EFI_NO_MEDIA The device has no media.\r
301 @retval EFI_DEVICE_ERROR The device reported an error.\r
302 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
303**/\r
304EFI_STATUS\r
305EFIAPI\r
306FileHandleFindNextFile (\r
307 IN EFI_FILE_HANDLE DirHandle,\r
308 OUT EFI_FILE_INFO *Buffer,\r
309 OUT BOOLEAN *NoFile\r
310 );\r
311\r
312/**\r
313 Retrieve the size of a file.\r
314\r
315 This function extracts the file size info from the FileHandle's EFI_FILE_INFO\r
316 data.\r
317\r
318 @param[in] FileHandle The file handle from which size is retrieved.\r
319 @param[out] Size The pointer to size.\r
320\r
321 @retval EFI_SUCCESS Operation was completed successfully.\r
322 @retval EFI_DEVICE_ERROR Cannot access the file.\r
323 @retval EFI_INVALID_PARAMETER FileHandle is NULL.\r
324 Size is NULL.\r
325**/\r
326EFI_STATUS\r
327EFIAPI\r
328FileHandleGetSize (\r
329 IN EFI_FILE_HANDLE FileHandle,\r
330 OUT UINT64 *Size\r
331 );\r
332\r
333/**\r
334 Set the size of a file.\r
335\r
336 This function changes the file size info from the FileHandle's EFI_FILE_INFO\r
337 data.\r
338\r
339 @param[in] FileHandle The file handle whose size is to be changed.\r
340 @param[in] Size The new size.\r
341\r
342 @retval EFI_SUCCESS The operation completed successfully.\r
343 @retval EFI_DEVICE_ERROR Cannot access the file.\r
344 @retval EFI_INVALID_PARAMETER FileHandle is NULL.\r
345**/\r
346EFI_STATUS\r
347EFIAPI\r
348FileHandleSetSize (\r
349 IN EFI_FILE_HANDLE FileHandle,\r
350 IN UINT64 Size\r
351 );\r
352\r
353/**\r
354 Function to get a full filename given a EFI_FILE_HANDLE somewhere lower on the\r
355 directory 'stack'. If the file is a directory, then append the '\' char at the\r
356 end of name string. If it's not a directory, then the last '\' should not be\r
357 added.\r
358\r
359 @param[in] Handle Handle to the Directory or File to create path to.\r
360 @param[out] FullFileName Pointer to pointer to generated full file name. It\r
361 is the responsibility of the caller to free this memory\r
362 with a call to FreePool().\r
363 @retval EFI_SUCCESS The operation was successful and FullFileName is valid.\r
364 @retval EFI_INVALID_PARAMETER Handle was NULL.\r
365 @retval EFI_INVALID_PARAMETER FullFileName was NULL.\r
366 @retval EFI_OUT_OF_MEMORY A memory allocation failed.\r
367**/\r
368EFI_STATUS\r
369EFIAPI\r
370FileHandleGetFileName (\r
371 IN CONST EFI_FILE_HANDLE Handle,\r
372 OUT CHAR16 **FullFileName\r
373 );\r
374\r
375/**\r
376 Function to read a single line (up to but not including the \n) from a file.\r
377\r
378 If the position upon start is 0, then the Ascii Boolean will be set. This should be\r
379 maintained and not changed for all operations with the same file.\r
380 The function will not return the \r and \n character in buffer. When an empty line is\r
381 read a CHAR_NULL character will be returned in buffer.\r
382\r
383 @param[in] Handle FileHandle to read from.\r
384 @param[in, out] Buffer The pointer to buffer to read into.\r
385 @param[in, out] Size The pointer to number of bytes in Buffer.\r
386 @param[in] Truncate If the buffer is large enough, this has no effect.\r
387 If the buffer is is too small and Truncate is TRUE,\r
388 the line will be truncated.\r
389 If the buffer is is too small and Truncate is FALSE,\r
390 then no read will occur.\r
391\r
392 @param[in, out] Ascii Boolean value for indicating whether the file is\r
393 Ascii (TRUE) or UCS2 (FALSE).\r
394\r
395 @retval EFI_SUCCESS The operation was successful. The line is stored in\r
396 Buffer.\r
397 @retval EFI_INVALID_PARAMETER Handle was NULL.\r
398 @retval EFI_INVALID_PARAMETER Size was NULL.\r
399 @retval EFI_BUFFER_TOO_SMALL Size was not large enough to store the line.\r
400 Size was updated to the minimum space required.\r
401 @sa FileHandleRead\r
402**/\r
403EFI_STATUS\r
404EFIAPI\r
405FileHandleReadLine (\r
406 IN EFI_FILE_HANDLE Handle,\r
407 IN OUT CHAR16 *Buffer,\r
408 IN OUT UINTN *Size,\r
409 IN BOOLEAN Truncate,\r
410 IN OUT BOOLEAN *Ascii\r
411 );\r
412\r
413/**\r
414 Function to read a single line from a file. The \n is not included in the returned\r
415 buffer. The returned buffer must be callee freed.\r
416\r
417 If the position upon start is 0, then the Ascii Boolean will be set. This should be\r
418 maintained and not changed for all operations with the same file.\r
419\r
420 @param[in] Handle FileHandle to read from.\r
421 @param[in, out] Ascii Boolean value for indicating whether the file is\r
422 Ascii (TRUE) or UCS2 (FALSE).\r
423\r
424 @return The line of text from the file.\r
425\r
426 @sa FileHandleReadLine\r
427**/\r
428CHAR16 *\r
429EFIAPI\r
430FileHandleReturnLine (\r
431 IN EFI_FILE_HANDLE Handle,\r
432 IN OUT BOOLEAN *Ascii\r
433 );\r
434\r
435/**\r
436 Function to write a line of text to a file.\r
437\r
438 If the file is a Unicode file (with UNICODE file tag) then write the unicode\r
439 text.\r
440 If the file is an ASCII file then write the ASCII text.\r
441 If the size of file is zero (without file tag at the beginning) then write\r
442 ASCII text as default.\r
443\r
444 @param[in] Handle FileHandle to write to.\r
445 @param[in] Buffer Buffer to write, if NULL the function will\r
446 take no action and return EFI_SUCCESS.\r
447\r
448 @retval EFI_SUCCESS The data was written.\r
449 Buffer is NULL.\r
450 @retval EFI_INVALID_PARAMETER Handle is NULL.\r
451 @retval EFI_OUT_OF_RESOURCES Unable to allocate temporary space for ASCII\r
452 string due to out of resources.\r
453\r
454 @sa FileHandleWrite\r
455**/\r
456EFI_STATUS\r
457EFIAPI\r
458FileHandleWriteLine (\r
459 IN EFI_FILE_HANDLE Handle,\r
460 IN CHAR16 *Buffer\r
461 );\r
462\r
463/**\r
464 Function to take a formatted argument and print it to a file.\r
465\r
466 @param[in] Handle The file handle for the file to write to.\r
467 @param[in] Format The format argument (see printlib for the format specifier).\r
468 @param[in] ... The variable arguments for the format.\r
469\r
470 @retval EFI_SUCCESS The operation was successful.\r
471 @retval other A return value from FileHandleWriteLine.\r
472\r
473 @sa FileHandleWriteLine\r
474**/\r
475EFI_STATUS\r
476EFIAPI\r
477FileHandlePrintLine (\r
478 IN EFI_FILE_HANDLE Handle,\r
479 IN CONST CHAR16 *Format,\r
480 ...\r
481 );\r
482\r
483/**\r
484 Function to determine if a FILE_HANDLE is at the end of the file.\r
485\r
486 This will NOT work on directories.\r
487\r
488 If Handle is NULL, then ASSERT().\r
489\r
490 @param[in] Handle The file handle.\r
491\r
492 @retval TRUE The position is at the end of the file.\r
493 @retval FALSE The position is not at the end of the file.\r
494**/\r
495BOOLEAN\r
496EFIAPI\r
497FileHandleEof (\r
498 IN EFI_FILE_HANDLE Handle\r
499 );\r
500\r
501#endif //_FILE_HANDLE_LIBRARY_HEADER_\r