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