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