]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/Include/Library/EfiFileLib.h
Update the copyright notice format
[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
60274cca
HT
5 Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>\r
6 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
2ef2b01e 7\r
60274cca 8 This program and the accompanying materials\r
2ef2b01e
A
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
60428d00 90 UINTN FvSize; \r
91 UINTN FvHeaderSize;\r
2ef2b01e
A
92\r
93 EFI_FILE *FsFileHandle; // Information valid for Fs#:\r
94 EFI_FILE_SYSTEM_INFO *FsInfo;\r
95 EFI_FILE_INFO *FsFileInfo;\r
96 EFI_BLOCK_IO_MEDIA FsBlockIoMedia; // Information valid for Fs#: or B#:\r
97\r
98 UINTN DiskOffset; // Information valid for B#:\r
99\r
100 EFI_LOAD_FILE_PROTOCOL *LoadFile; // Information valid for l#:\r
101 \r
102 EFI_IP_ADDRESS ServerIp; // Information valid for t:\r
103 BOOLEAN IsDirty;\r
104 BOOLEAN IsBufferValid;\r
105 \r
106} EFI_OPEN_FILE;\r
107\r
108\r
109/// Type of Seek to perform\r
110typedef enum {\r
111 EfiSeekStart,\r
112 EfiSeekCurrent,\r
113 EfiSeekEnd,\r
114 EfiSeekMax\r
115} EFI_SEEK_TYPE;\r
116\r
117\r
118/**\r
119 Open a device named by PathName. The PathName includes a device name and \r
120 path seperated by a :. See file header for more details on the PathName \r
121 syntax. There is no checking to prevent a file from being opened more than\r
122 one type. \r
123\r
124 SectionType is only used to open an FV. Each file in an FV contains multiple\r
125 secitons and only the SectionType section is opened. \r
126\r
127 For any file that is opened with EfiOpen() must be closed with EfiClose().\r
128\r
129 @param PathName Path to parse to open \r
130 @param OpenMode Same as EFI_FILE.Open()\r
131 @param SectionType Section in FV to open.\r
132\r
133 @return NULL Open failed\r
134 @return Valid EFI_OPEN_FILE handle\r
135\r
136**/\r
137EFI_OPEN_FILE *\r
138EfiOpen (\r
139 IN CHAR8 *PathName,\r
140 IN CONST UINT64 OpenMode,\r
141 IN CONST EFI_SECTION_TYPE SectionType\r
142 );\r
143\r
144EFI_STATUS\r
145EfiCopyFile (\r
146 IN CHAR8 *DestinationFile,\r
147 IN CHAR8 *SourceFile\r
148 );\r
149\r
150/**\r
151 Use DeviceType and Index to form a valid PathName and try and open it.\r
152\r
153 @param DeviceType Device type to open\r
154 @param Index Device Index to use. Zero relative.\r
155\r
156 @return NULL Open failed\r
157 @return Valid EFI_OPEN_FILE handle\r
158\r
159**/\r
160EFI_OPEN_FILE *\r
161EfiDeviceOpenByType (\r
162 IN EFI_OPEN_FILE_TYPE DeviceType,\r
163 IN UINTN Index\r
164 );\r
165\r
166\r
167/**\r
168 Close a file handle opened by EfiOpen() and free all resources allocated by\r
169 EfiOpen().\r
170\r
171 @param Stream Open File Handle\r
172\r
173 @return EFI_INVALID_PARAMETER Stream is not an Open File\r
174 @return EFI_SUCCESS Steam closed\r
175\r
176**/\r
177EFI_STATUS\r
178EfiClose (\r
179 IN EFI_OPEN_FILE *Stream\r
180 );\r
181\r
182\r
183/**\r
184 Return the size of the file represented by Stream. Also return the current \r
185 Seek position. Opening a file will enable a valid file size to be returned.\r
186 LoadFile is an exception as a load file size is set to zero. \r
187\r
188 @param Stream Open File Handle\r
189\r
190 @return 0 Stream is not an Open File or a valid LoadFile handle\r
191\r
192**/\r
193UINTN\r
194EfiTell (\r
195 IN EFI_OPEN_FILE *Stream,\r
196 OUT UINT64 *CurrentPosition OPTIONAL\r
197 );\r
198\r
199\r
200/**\r
201 Seek to the Offset locaiton in the file. LoadFile and FV device types do\r
202 not support EfiSeek(). It is not possible to grow the file size using \r
203 EfiSeek().\r
204 \r
205 SeekType defines how use Offset to calculate the new file position:\r
206 EfiSeekStart : Position = Offset\r
207 EfiSeekCurrent: Position is Offset bytes from the current position\r
208 EfiSeekEnd : Only supported if Offset is zero to seek to end of file.\r
209\r
210 @param Stream Open File Handle\r
211 @param Offset Offset to seek too. \r
212 @param SeekType Type of seek to perform\r
213\r
214\r
215 @return EFI_INVALID_PARAMETER Stream is not an Open File\r
216 @return EFI_UNSUPPORTED LoadFile and FV doe not support Seek\r
217 @return EFI_NOT_FOUND Seek past the end of the file.\r
218 @return EFI_SUCCESS Steam closed\r
219\r
220**/\r
221EFI_STATUS\r
222EfiSeek (\r
223 IN EFI_OPEN_FILE *Stream,\r
224 IN EFI_LBA Offset,\r
225 IN EFI_SEEK_TYPE SeekType\r
226 );\r
227\r
228\r
229/**\r
230 Read BufferSize bytes from the current locaiton in the file. For load file\r
231 and FV case you must read the entire file. \r
232\r
233 @param Stream Open File Handle\r
234 @param Buffer Caller allocated buffer. \r
235 @param BufferSize Size of buffer in bytes.\r
236\r
237\r
238 @return EFI_SUCCESS Stream is not an Open File\r
239 @return EFI_END_OF_FILE Tried to read past the end of the file\r
240 @return EFI_INVALID_PARAMETER Stream is not an open file handle\r
241 @return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read\r
242 @return "other" Error returned from device read\r
243\r
244**/\r
245EFI_STATUS\r
246EfiRead (\r
247 IN EFI_OPEN_FILE *Stream,\r
248 OUT VOID *Buffer,\r
249 OUT UINTN *BufferSize\r
250 );\r
251\r
252\r
253/**\r
254 Read the entire file into a buffer. This routine allocates the buffer and\r
255 returns it to the user full of the read data. \r
256\r
257 This is very useful for load flie where it's hard to know how big the buffer\r
258 must be.\r
259\r
260 @param Stream Open File Handle\r
261 @param Buffer Pointer to buffer to return. \r
262 @param BufferSize Pointer to Size of buffer return..\r
263\r
264\r
265 @return EFI_SUCCESS Stream is not an Open File\r
266 @return EFI_END_OF_FILE Tried to read past the end of the file\r
267 @return EFI_INVALID_PARAMETER Stream is not an open file handle\r
268 @return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read\r
269 @return "other" Error returned from device read\r
270\r
271**/\r
272EFI_STATUS\r
273EfiReadAllocatePool (\r
274 IN EFI_OPEN_FILE *Stream,\r
275 OUT VOID **Buffer,\r
276 OUT UINTN *BufferSize\r
277 );\r
278\r
279\r
280/**\r
281 Write data back to the file. \r
282\r
283 @param Stream Open File Handle\r
284 @param Buffer Pointer to buffer to return. \r
285 @param BufferSize Pointer to Size of buffer return..\r
286\r
287\r
288 @return EFI_SUCCESS Stream is not an Open File\r
289 @return EFI_END_OF_FILE Tried to read past the end of the file\r
290 @return EFI_INVALID_PARAMETER Stream is not an open file handle\r
291 @return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read\r
292 @return "other" Error returned from device write\r
293\r
294**/\r
295EFI_STATUS\r
296EfiWrite (\r
297 IN EFI_OPEN_FILE *Stream,\r
298 OUT VOID *Buffer,\r
299 OUT UINTN *BufferSize\r
300 );\r
301\r
302\r
303/**\r
304 Return the number of devices of the current type active in the system\r
305\r
306 @param Type Device type to check\r
307\r
308 @return 0 Invalid type\r
309\r
310**/\r
311UINTN\r
312EfiGetDeviceCounts (\r
313 IN EFI_OPEN_FILE_TYPE Type\r
314 );\r
85e385f4 315 \r
316\r
317/**\r
318 Set the Curent Working Directory (CWD). If a call is made to EfiOpen () and \r
319 the path does not contain a device name, The CWD is prepended to the path.\r
320 \r
321 @param Cwd Current Working Directory to set\r
322\r
323\r
324 @return EFI_SUCCESS CWD is set\r
325 @return EFI_INVALID_PARAMETER Cwd is not a valid device:path\r
326\r
327**/\r
328EFI_STATUS\r
329EfiSetCwd (\r
330 IN CHAR8 *Cwd\r
331 ); \r
332\r
333/**\r
334 Set the Curent Working Directory (CWD). If a call is made to EfiOpen () and \r
335 the path does not contain a device name, The CWD is prepended to the path.\r
336 \r
337 @param Cwd Current Working Directory \r
338\r
339\r
340 @return NULL No CWD set\r
341 @return 'other' malloc'ed buffer contains CWD.\r
342 \r
343**/\r
344CHAR8 *\r
16ccac42 345EfiGetCwd (\r
85e385f4 346 VOID\r
347 ); \r
2ef2b01e
A
348\r
349#endif\r