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