Revert incompatible change:
[mirror_edk2.git] / EmbeddedPkg / Include / Library / EfiFileLib.h
CommitLineData
2ef2b01e
A
1/** @file\r
2 Library functions that perform file IO. Memory buffer, file system, and \r
3 fimrware volume operations are supproted. \r
4\r
5 Copyright (c) 2007, Intel Corporation<BR>\r
6 Portions copyright (c) 2008-2009 Apple Inc. All rights reserved.<BR>\r
7\r
8 All rights reserved. This program and the accompanying materials\r
9 are licensed and made available under the terms and conditions of the BSD License\r
10 which accompanies this distribution. The full text of the license may be found at\r
11 http://opensource.org/licenses/bsd-license.php\r
12\r
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
15\r
16 Basic support for opening files on different device types. The device string\r
17 is in the form of DevType:Path. Current DevType is required as there is no\r
18 current mounted device concept of current working directory concept implement\r
19 by this library.\r
20\r
21 Device names are case insensative and only check the leading characters for \r
22 unique matches. Thus the following are all the same:\r
23 LoadFile0:\r
24 l0:\r
25 L0:\r
26 Lo0:\r
27\r
28 Supported Device Names:\r
29 A0x1234:0x12 - A memory buffer starting at address 0x1234 for 0x12 bytes\r
30 l1: - EFI LoadFile device one.\r
31 B0: - EFI BlockIo zero.\r
32 fs3: - EFI Simple File System device 3\r
33 Fv2: - EFI Firmware VOlume device 2\r
34 1.2.3.4:name - TFTP IP and file name\r
35 \r
36**/\r
37\r
38#ifndef __EFI_FILE_LIB_H__\r
39#define __EFI_FILE_LIB_H__\r
40\r
41#include <PiDxe.h>\r
42#include <Protocol/FirmwareVolume2.h>\r
43#include <Protocol/FirmwareVolumeBlock.h>\r
44#include <Protocol/BlockIo.h>\r
45#include <Protocol/LoadFile.h>\r
46#include <Protocol/LoadFile.h>\r
47#include <Protocol/SimpleFileSystem.h>\r
48#include <Guid/FileInfo.h>\r
49#include <Guid/FileSystemInfo.h>\r
50\r
51#define MAX_PATHNAME 0x200\r
52\r
53/// Type of the file that has been opened \r
54typedef enum {\r
55 EfiOpenLoadFile,\r
56 EfiOpenMemoryBuffer,\r
57 EfiOpenFirmwareVolume,\r
58 EfiOpenFileSystem,\r
59 EfiOpenBlockIo,\r
60 EfiOpenTftp,\r
61 EfiOpenMaxValue\r
62} EFI_OPEN_FILE_TYPE;\r
63\r
64\r
65/// Public information about the open file\r
66typedef struct {\r
67 UINTN Version; // Common information \r
68 EFI_OPEN_FILE_TYPE Type;\r
69 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
70 EFI_STATUS LastError;\r
71 EFI_HANDLE EfiHandle; \r
72 CHAR8 *DeviceName;\r
73 CHAR8 *FileName;\r
74\r
75 UINT64 CurrentPosition; // Information for Seek\r
76 UINT64 MaxPosition;\r
77\r
78 UINTN BaseOffset; // Base offset for hexdump command\r
79 \r
80 UINTN Size; // Valid for all types other than l#:\r
81 UINT8 *Buffer; // Information valid for A#:\r
82\r
83 EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv; // Information valid for Fv#: \r
84 EFI_GUID FvNameGuid; \r
85 EFI_SECTION_TYPE FvSectionType; \r
86 EFI_FV_FILETYPE FvType; \r
87 EFI_FV_FILE_ATTRIBUTES FvAttributes; \r
88\r
89 EFI_PHYSICAL_ADDRESS FvStart; \r
90 UINTN FvSize; \r
91\r
92 EFI_FILE *FsFileHandle; // Information valid for Fs#:\r
93 EFI_FILE_SYSTEM_INFO *FsInfo;\r
94 EFI_FILE_INFO *FsFileInfo;\r
95 EFI_BLOCK_IO_MEDIA FsBlockIoMedia; // Information valid for Fs#: or B#:\r
96\r
97 UINTN DiskOffset; // Information valid for B#:\r
98\r
99 EFI_LOAD_FILE_PROTOCOL *LoadFile; // Information valid for l#:\r
100 \r
101 EFI_IP_ADDRESS ServerIp; // Information valid for t:\r
102 BOOLEAN IsDirty;\r
103 BOOLEAN IsBufferValid;\r
104 \r
105} EFI_OPEN_FILE;\r
106\r
107\r
108/// Type of Seek to perform\r
109typedef enum {\r
110 EfiSeekStart,\r
111 EfiSeekCurrent,\r
112 EfiSeekEnd,\r
113 EfiSeekMax\r
114} EFI_SEEK_TYPE;\r
115\r
116\r
117/**\r
118 Open a device named by PathName. The PathName includes a device name and \r
119 path seperated by a :. See file header for more details on the PathName \r
120 syntax. There is no checking to prevent a file from being opened more than\r
121 one type. \r
122\r
123 SectionType is only used to open an FV. Each file in an FV contains multiple\r
124 secitons and only the SectionType section is opened. \r
125\r
126 For any file that is opened with EfiOpen() must be closed with EfiClose().\r
127\r
128 @param PathName Path to parse to open \r
129 @param OpenMode Same as EFI_FILE.Open()\r
130 @param SectionType Section in FV to open.\r
131\r
132 @return NULL Open failed\r
133 @return Valid EFI_OPEN_FILE handle\r
134\r
135**/\r
136EFI_OPEN_FILE *\r
137EfiOpen (\r
138 IN CHAR8 *PathName,\r
139 IN CONST UINT64 OpenMode,\r
140 IN CONST EFI_SECTION_TYPE SectionType\r
141 );\r
142\r
143EFI_STATUS\r
144EfiCopyFile (\r
145 IN CHAR8 *DestinationFile,\r
146 IN CHAR8 *SourceFile\r
147 );\r
148\r
149/**\r
150 Use DeviceType and Index to form a valid PathName and try and open it.\r
151\r
152 @param DeviceType Device type to open\r
153 @param Index Device Index to use. Zero relative.\r
154\r
155 @return NULL Open failed\r
156 @return Valid EFI_OPEN_FILE handle\r
157\r
158**/\r
159EFI_OPEN_FILE *\r
160EfiDeviceOpenByType (\r
161 IN EFI_OPEN_FILE_TYPE DeviceType,\r
162 IN UINTN Index\r
163 );\r
164\r
165\r
166/**\r
167 Close a file handle opened by EfiOpen() and free all resources allocated by\r
168 EfiOpen().\r
169\r
170 @param Stream Open File Handle\r
171\r
172 @return EFI_INVALID_PARAMETER Stream is not an Open File\r
173 @return EFI_SUCCESS Steam closed\r
174\r
175**/\r
176EFI_STATUS\r
177EfiClose (\r
178 IN EFI_OPEN_FILE *Stream\r
179 );\r
180\r
181\r
182/**\r
183 Return the size of the file represented by Stream. Also return the current \r
184 Seek position. Opening a file will enable a valid file size to be returned.\r
185 LoadFile is an exception as a load file size is set to zero. \r
186\r
187 @param Stream Open File Handle\r
188\r
189 @return 0 Stream is not an Open File or a valid LoadFile handle\r
190\r
191**/\r
192UINTN\r
193EfiTell (\r
194 IN EFI_OPEN_FILE *Stream,\r
195 OUT UINT64 *CurrentPosition OPTIONAL\r
196 );\r
197\r
198\r
199/**\r
200 Seek to the Offset locaiton in the file. LoadFile and FV device types do\r
201 not support EfiSeek(). It is not possible to grow the file size using \r
202 EfiSeek().\r
203 \r
204 SeekType defines how use Offset to calculate the new file position:\r
205 EfiSeekStart : Position = Offset\r
206 EfiSeekCurrent: Position is Offset bytes from the current position\r
207 EfiSeekEnd : Only supported if Offset is zero to seek to end of file.\r
208\r
209 @param Stream Open File Handle\r
210 @param Offset Offset to seek too. \r
211 @param SeekType Type of seek to perform\r
212\r
213\r
214 @return EFI_INVALID_PARAMETER Stream is not an Open File\r
215 @return EFI_UNSUPPORTED LoadFile and FV doe not support Seek\r
216 @return EFI_NOT_FOUND Seek past the end of the file.\r
217 @return EFI_SUCCESS Steam closed\r
218\r
219**/\r
220EFI_STATUS\r
221EfiSeek (\r
222 IN EFI_OPEN_FILE *Stream,\r
223 IN EFI_LBA Offset,\r
224 IN EFI_SEEK_TYPE SeekType\r
225 );\r
226\r
227\r
228/**\r
229 Read BufferSize bytes from the current locaiton in the file. For load file\r
230 and FV case you must read the entire file. \r
231\r
232 @param Stream Open File Handle\r
233 @param Buffer Caller allocated buffer. \r
234 @param BufferSize Size of buffer in bytes.\r
235\r
236\r
237 @return EFI_SUCCESS Stream is not an Open File\r
238 @return EFI_END_OF_FILE Tried to read past the end of the file\r
239 @return EFI_INVALID_PARAMETER Stream is not an open file handle\r
240 @return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read\r
241 @return "other" Error returned from device read\r
242\r
243**/\r
244EFI_STATUS\r
245EfiRead (\r
246 IN EFI_OPEN_FILE *Stream,\r
247 OUT VOID *Buffer,\r
248 OUT UINTN *BufferSize\r
249 );\r
250\r
251\r
252/**\r
253 Read the entire file into a buffer. This routine allocates the buffer and\r
254 returns it to the user full of the read data. \r
255\r
256 This is very useful for load flie where it's hard to know how big the buffer\r
257 must be.\r
258\r
259 @param Stream Open File Handle\r
260 @param Buffer Pointer to buffer to return. \r
261 @param BufferSize Pointer to Size of buffer return..\r
262\r
263\r
264 @return EFI_SUCCESS Stream is not an Open File\r
265 @return EFI_END_OF_FILE Tried to read past the end of the file\r
266 @return EFI_INVALID_PARAMETER Stream is not an open file handle\r
267 @return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read\r
268 @return "other" Error returned from device read\r
269\r
270**/\r
271EFI_STATUS\r
272EfiReadAllocatePool (\r
273 IN EFI_OPEN_FILE *Stream,\r
274 OUT VOID **Buffer,\r
275 OUT UINTN *BufferSize\r
276 );\r
277\r
278\r
279/**\r
280 Write data back to the file. \r
281\r
282 @param Stream Open File Handle\r
283 @param Buffer Pointer to buffer to return. \r
284 @param BufferSize Pointer to Size of buffer return..\r
285\r
286\r
287 @return EFI_SUCCESS Stream is not an Open File\r
288 @return EFI_END_OF_FILE Tried to read past the end of the file\r
289 @return EFI_INVALID_PARAMETER Stream is not an open file handle\r
290 @return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read\r
291 @return "other" Error returned from device write\r
292\r
293**/\r
294EFI_STATUS\r
295EfiWrite (\r
296 IN EFI_OPEN_FILE *Stream,\r
297 OUT VOID *Buffer,\r
298 OUT UINTN *BufferSize\r
299 );\r
300\r
301\r
302/**\r
303 Return the number of devices of the current type active in the system\r
304\r
305 @param Type Device type to check\r
306\r
307 @return 0 Invalid type\r
308\r
309**/\r
310UINTN\r
311EfiGetDeviceCounts (\r
312 IN EFI_OPEN_FILE_TYPE Type\r
313 );\r
314\r
315#endif\r