]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/Include/Library/EfiFileLib.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / EmbeddedPkg / Include / Library / EfiFileLib.h
CommitLineData
2ef2b01e 1/** @file\r
3402aac7 2 Library functions that perform file IO. Memory buffer, file system, and\r
c6a72cd7 3 firmware volume operations are supported.\r
2ef2b01e 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
878b807a 8 SPDX-License-Identifier: BSD-2-Clause-Patent\r
2ef2b01e
A
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
c6a72cd7 15 Device names are case insensitive and only check the leading characters for\r
2ef2b01e
A
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
c6a72cd7 27 Fv2: - EFI Firmware Volume device 2\r
2ef2b01e 28 1.2.3.4:name - TFTP IP and file name\r
3402aac7 29\r
2ef2b01e
A
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
e7108d0e 45#define MAX_PATHNAME 0x200\r
2ef2b01e 46\r
3402aac7 47/// Type of the file that has been opened\r
2ef2b01e
A
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
2ef2b01e
A
58/// Public information about the open file\r
59typedef struct {\r
e7108d0e
MK
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
2ef2b01e 67\r
e7108d0e
MK
68 UINT64 CurrentPosition; // Information for Seek\r
69 UINT64 MaxPosition;\r
3402aac7 70\r
e7108d0e 71 UINTN BaseOffset; // Base offset for hexdump command\r
2ef2b01e 72\r
e7108d0e
MK
73 UINTN Size; // Valid for all types other than l#:\r
74 UINT8 *Buffer; // Information valid for A#:\r
2ef2b01e 75\r
e7108d0e
MK
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
2ef2b01e 81\r
e7108d0e
MK
82 EFI_PHYSICAL_ADDRESS FvStart;\r
83 UINTN FvSize;\r
84 UINTN FvHeaderSize;\r
2ef2b01e 85\r
e7108d0e
MK
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
2ef2b01e 91\r
e7108d0e 92 UINTN DiskOffset; // Information valid for B#:\r
3402aac7 93\r
e7108d0e 94 EFI_LOAD_FILE_PROTOCOL *LoadFile; // Information valid for l#:\r
3402aac7 95\r
e7108d0e
MK
96 EFI_IP_ADDRESS ServerIp; // Information valid for t:\r
97 BOOLEAN IsDirty;\r
98 BOOLEAN IsBufferValid;\r
2ef2b01e
A
99} EFI_OPEN_FILE;\r
100\r
2ef2b01e
A
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
2ef2b01e 109/**\r
3402aac7 110 Open a device named by PathName. The PathName includes a device name and\r
7ca9e5a4 111 path separated by a :. See file header for more details on the PathName\r
2ef2b01e 112 syntax. There is no checking to prevent a file from being opened more than\r
3402aac7 113 one type.\r
2ef2b01e
A
114\r
115 SectionType is only used to open an FV. Each file in an FV contains multiple\r
7ca9e5a4 116 sections and only the SectionType section is opened.\r
2ef2b01e
A
117\r
118 For any file that is opened with EfiOpen() must be closed with EfiClose().\r
119\r
3402aac7 120 @param PathName Path to parse to open\r
2ef2b01e
A
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
e7108d0e
MK
130 IN CHAR8 *PathName,\r
131 IN CONST UINT64 OpenMode,\r
132 IN CONST EFI_SECTION_TYPE SectionType\r
2ef2b01e
A
133 );\r
134\r
135EFI_STATUS\r
136EfiCopyFile (\r
e7108d0e
MK
137 IN CHAR8 *DestinationFile,\r
138 IN CHAR8 *SourceFile\r
2ef2b01e
A
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
e7108d0e
MK
153 IN EFI_OPEN_FILE_TYPE DeviceType,\r
154 IN UINTN Index\r
2ef2b01e
A
155 );\r
156\r
2ef2b01e
A
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
e7108d0e 169 IN EFI_OPEN_FILE *Stream\r
2ef2b01e
A
170 );\r
171\r
2ef2b01e 172/**\r
3402aac7 173 Return the size of the file represented by Stream. Also return the current\r
2ef2b01e 174 Seek position. Opening a file will enable a valid file size to be returned.\r
3402aac7 175 LoadFile is an exception as a load file size is set to zero.\r
2ef2b01e
A
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
e7108d0e
MK
184 IN EFI_OPEN_FILE *Stream,\r
185 OUT UINT64 *CurrentPosition OPTIONAL\r
2ef2b01e
A
186 );\r
187\r
2ef2b01e 188/**\r
7ca9e5a4 189 Seek to the Offset location in the file. LoadFile and FV device types do\r
3402aac7 190 not support EfiSeek(). It is not possible to grow the file size using\r
2ef2b01e 191 EfiSeek().\r
3402aac7 192\r
2ef2b01e
A
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
3402aac7 199 @param Offset Offset to seek too.\r
2ef2b01e
A
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
7ca9e5a4 204 @return EFI_UNSUPPORTED LoadFile and FV does not support Seek\r
2ef2b01e
A
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
e7108d0e
MK
211 IN EFI_OPEN_FILE *Stream,\r
212 IN EFI_LBA Offset,\r
213 IN EFI_SEEK_TYPE SeekType\r
2ef2b01e
A
214 );\r
215\r
2ef2b01e 216/**\r
7ca9e5a4 217 Read BufferSize bytes from the current location in the file. For load file\r
3402aac7 218 and FV case you must read the entire file.\r
2ef2b01e
A
219\r
220 @param Stream Open File Handle\r
3402aac7 221 @param Buffer Caller allocated buffer.\r
2ef2b01e
A
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
e7108d0e
MK
234 IN EFI_OPEN_FILE *Stream,\r
235 OUT VOID *Buffer,\r
236 OUT UINTN *BufferSize\r
2ef2b01e
A
237 );\r
238\r
2ef2b01e
A
239/**\r
240 Read the entire file into a buffer. This routine allocates the buffer and\r
3402aac7 241 returns it to the user full of the read data.\r
2ef2b01e 242\r
7ca9e5a4 243 This is very useful for load file where it's hard to know how big the buffer\r
2ef2b01e
A
244 must be.\r
245\r
246 @param Stream Open File Handle\r
3402aac7 247 @param Buffer Pointer to buffer to return.\r
2ef2b01e
A
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
e7108d0e
MK
260 IN EFI_OPEN_FILE *Stream,\r
261 OUT VOID **Buffer,\r
262 OUT UINTN *BufferSize\r
2ef2b01e
A
263 );\r
264\r
2ef2b01e 265/**\r
3402aac7 266 Write data back to the file.\r
2ef2b01e
A
267\r
268 @param Stream Open File Handle\r
3402aac7 269 @param Buffer Pointer to buffer to return.\r
2ef2b01e
A
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
e7108d0e
MK
282 IN EFI_OPEN_FILE *Stream,\r
283 OUT VOID *Buffer,\r
284 OUT UINTN *BufferSize\r
2ef2b01e
A
285 );\r
286\r
2ef2b01e
A
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
e7108d0e 297 IN EFI_OPEN_FILE_TYPE Type\r
2ef2b01e 298 );\r
3402aac7 299\r
85e385f4 300/**\r
7ca9e5a4 301 Set the Current Working Directory (CWD). If a call is made to EfiOpen () and\r
85e385f4 302 the path does not contain a device name, The CWD is prepended to the path.\r
3402aac7 303\r
85e385f4 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
e7108d0e 313 IN CHAR8 *Cwd\r
3402aac7 314 );\r
85e385f4 315\r
316/**\r
7ca9e5a4 317 Set the Current Working Directory (CWD). If a call is made to EfiOpen () and\r
85e385f4 318 the path does not contain a device name, The CWD is prepended to the path.\r
3402aac7
RC
319\r
320 @param Cwd Current Working Directory\r
85e385f4 321\r
322\r
323 @return NULL No CWD set\r
324 @return 'other' malloc'ed buffer contains CWD.\r
3402aac7 325\r
85e385f4 326**/\r
327CHAR8 *\r
16ccac42 328EfiGetCwd (\r
85e385f4 329 VOID\r
3402aac7 330 );\r
2ef2b01e
A
331\r
332#endif\r