]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Include/Library/FileHandleLib.h
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8633 6f19259b...
[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
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
23 being requested.\r
24\r
25 @retval NULL information could not be retrieved.\r
26\r
27 @return the information about the file\r
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
40 is being set\r
41\r
42 @param FileInfo The infotmation to set.\r
43\r
44 @retval EFI_SUCCESS The information was set.\r
45 @retval EFI_UNSUPPORTED The InformationType is not known.\r
46 @retval EFI_NO_MEDIA The device has no medium.\r
47 @retval EFI_DEVICE_ERROR The device reported an error.\r
48 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
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
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
76 @param FileHandle the opened file handle\r
77 @param BufferSize on input the size of buffer in bytes. on return \r
78 the number of bytes written.\r
79 @param Buffer the buffer to put read data into.\r
80\r
81 @retval EFI_SUCCESS Data was read.\r
82 @retval EFI_NO_MEDIA The device has no media.\r
83 @retval EFI_DEVICE_ERROR The device reported an error.\r
84 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
85 @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required \r
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
108 @param BufferSize on input the number of bytes in Buffer. On output\r
109 the number of bytes written.\r
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
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
136@param FileHandle the file handle to close.\r
137\r
138@retval EFI_SUCCESS the file handle was closed sucessfully.\r
139**/\r
140EFI_STATUS\r
141EFIAPI\r
142FileHandleClose (\r
143 IN EFI_FILE_HANDLE FileHandle\r
144 );\r
145\r
146/**\r
147 Delete a file and close the handle\r
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
153 @param FileHandle the file handle to delete\r
154\r
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
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
193 Gets a file's current position\r
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
214 Flushes data on a file\r
215 \r
216 This function flushes all modified data associated with a file to a device.\r
217\r
218 @param FileHandle The file handle on which to flush data\r
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
234 function to determine if a given handle is a directory handle\r
235\r
236 if DirHandle is NULL then ASSERT()\r
237\r
238 open the file information on the DirHandle and verify that the Attribute\r
239 includes EFI_FILE_DIRECTORY bit set.\r
240\r
241 @param DirHandle Handle to open file\r
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
254 Retrieves the first file from a directory\r
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
307 if FileHandle is NULL then ASSERT()\r
308 if Size is NULL then ASSERT()\r
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
313 @param FileHandle file handle from which size is retrieved\r
314 @param Size pointer to size\r
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
330 if Handle is NULL, return EFI_INVALID_PARAMETER\r
331\r
332 @param[in] Handle Handle to the Directory or File to create path to.\r
333 @param[out] FullFileName pointer to pointer to generated full file name. It \r
334 is the responsibility of the caller to free this memory\r
335 with a call to FreePool().\r
336 @retval EFI_SUCCESS the operation was sucessful and the FullFileName is valid.\r
337 @retval EFI_INVALID_PARAMETER Handle was NULL.\r
338 @retval EFI_INVALID_PARAMETER FullFileName was NULL.\r
339 @retval EFI_OUT_OF_MEMORY a memory allocation failed.\r
340**/\r
341EFI_STATUS\r
342EFIAPI\r
343FileHandleGetFileName (\r
344 IN CONST EFI_FILE_HANDLE Handle,\r
345 OUT CHAR16 **FullFileName\r
346 );\r
347\r
348/**\r
349 Function to read a single line (up to but not including the \n) from a file.\r
350\r
351 @param[in] Handle FileHandle to read from\r
352 @param[in][out] Buffer pointer to buffer to read into\r
353 @param[in][out] Size pointer to number of bytes in buffer\r
354 @param[in[ Truncate if TRUE then allows for truncation of the line to fit.\r
355 if FALSE will reset the position to the begining of the \r
356 line if the buffer is not large enough.\r
357\r
358 @retval EFI_SUCCESS the operation was sucessful. the line is stored in \r
359 Buffer. (Size was NOT updated)\r
360 @retval EFI_INVALID_PARAMETER Handle was NULL.\r
361 @retval EFI_INVALID_PARAMETER Buffer was NULL.\r
362 @retval EFI_INVALID_PARAMETER Size was NULL.\r
363 @retval EFI_BUFFER_TOO_SMALL Size was not enough space to store the line. \r
364 Size was updated to minimum space required.\r
365 @sa FileHandleRead\r
366**/\r
367EFI_STATUS\r
368EFIAPI\r
369FileHandleReadLine(\r
370 IN EFI_FILE_HANDLE Handle,\r
371 IN OUT VOID *Buffer,\r
372 IN OUT UINTN *Size,\r
373 IN BOOLEAN Truncate\r
374 );\r
375\r
376/**\r
377 function to write a line of unicode text to a file.\r
378\r
379 if Handle is NULL, ASSERT.\r
380 if Buffer is NULL, do nothing. (return SUCCESS)\r
381\r
382 @param[in] Handle FileHandle to write to\r
383 @param[in] Buffer Buffer to write\r
384\r
385 @retval EFI_SUCCESS the data was written.\r
386 @retval other failure.\r
387\r
388 @sa FileHandleWrite\r
389**/\r
390EFI_STATUS\r
391EFIAPI\r
392FileHandleWriteLine(\r
393 IN EFI_FILE_HANDLE Handle,\r
394 IN CHAR16 *Buffer\r
d2b4564b 395 );