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