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