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