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