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