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