2 Library functions that perform file IO. Memory buffer, file system, and
3 firmware volume operations are supported.
5 Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
6 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
10 Basic support for opening files on different device types. The device string
11 is in the form of DevType:Path. Current DevType is required as there is no
12 current mounted device concept of current working directory concept implement
15 Device names are case insensitive and only check the leading characters for
16 unique matches. Thus the following are all the same:
22 Supported Device Names:
23 A0x1234:0x12 - A memory buffer starting at address 0x1234 for 0x12 bytes
24 l1: - EFI LoadFile device one.
25 B0: - EFI BlockIo zero.
26 fs3: - EFI Simple File System device 3
27 Fv2: - EFI Firmware Volume device 2
28 1.2.3.4:name - TFTP IP and file name
32 #ifndef __EFI_FILE_LIB_H__
33 #define __EFI_FILE_LIB_H__
36 #include <Protocol/FirmwareVolume2.h>
37 #include <Protocol/FirmwareVolumeBlock.h>
38 #include <Protocol/BlockIo.h>
39 #include <Protocol/LoadFile.h>
40 #include <Protocol/LoadFile.h>
41 #include <Protocol/SimpleFileSystem.h>
42 #include <Guid/FileInfo.h>
43 #include <Guid/FileSystemInfo.h>
45 #define MAX_PATHNAME 0x200
47 /// Type of the file that has been opened
51 EfiOpenFirmwareVolume
,
58 /// Public information about the open file
60 UINTN Version
; // Common information
61 EFI_OPEN_FILE_TYPE Type
;
62 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
68 UINT64 CurrentPosition
; // Information for Seek
71 UINTN BaseOffset
; // Base offset for hexdump command
73 UINTN Size
; // Valid for all types other than l#:
74 UINT8
*Buffer
; // Information valid for A#:
76 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
; // Information valid for Fv#:
78 EFI_SECTION_TYPE FvSectionType
;
79 EFI_FV_FILETYPE FvType
;
80 EFI_FV_FILE_ATTRIBUTES FvAttributes
;
82 EFI_PHYSICAL_ADDRESS FvStart
;
86 EFI_FILE
*FsFileHandle
; // Information valid for Fs#:
87 EFI_FILE_SYSTEM_INFO
*FsInfo
;
88 EFI_FILE_INFO
*FsFileInfo
;
89 EFI_BLOCK_IO_MEDIA
*FsBlockIoMedia
; // Information valid for Fs#: or B#:
90 EFI_BLOCK_IO_PROTOCOL
*FsBlockIo
; // Information valid for Fs#: or B#:
92 UINTN DiskOffset
; // Information valid for B#:
94 EFI_LOAD_FILE_PROTOCOL
*LoadFile
; // Information valid for l#:
96 EFI_IP_ADDRESS ServerIp
; // Information valid for t:
98 BOOLEAN IsBufferValid
;
101 /// Type of Seek to perform
110 Open a device named by PathName. The PathName includes a device name and
111 path separated by a :. See file header for more details on the PathName
112 syntax. There is no checking to prevent a file from being opened more than
115 SectionType is only used to open an FV. Each file in an FV contains multiple
116 sections and only the SectionType section is opened.
118 For any file that is opened with EfiOpen() must be closed with EfiClose().
120 @param PathName Path to parse to open
121 @param OpenMode Same as EFI_FILE.Open()
122 @param SectionType Section in FV to open.
124 @return NULL Open failed
125 @return Valid EFI_OPEN_FILE handle
131 IN CONST UINT64 OpenMode
,
132 IN CONST EFI_SECTION_TYPE SectionType
137 IN CHAR8
*DestinationFile
,
142 Use DeviceType and Index to form a valid PathName and try and open it.
144 @param DeviceType Device type to open
145 @param Index Device Index to use. Zero relative.
147 @return NULL Open failed
148 @return Valid EFI_OPEN_FILE handle
152 EfiDeviceOpenByType (
153 IN EFI_OPEN_FILE_TYPE DeviceType
,
158 Close a file handle opened by EfiOpen() and free all resources allocated by
161 @param Stream Open File Handle
163 @return EFI_INVALID_PARAMETER Stream is not an Open File
164 @return EFI_SUCCESS Steam closed
169 IN EFI_OPEN_FILE
*Stream
173 Return the size of the file represented by Stream. Also return the current
174 Seek position. Opening a file will enable a valid file size to be returned.
175 LoadFile is an exception as a load file size is set to zero.
177 @param Stream Open File Handle
179 @return 0 Stream is not an Open File or a valid LoadFile handle
184 IN EFI_OPEN_FILE
*Stream
,
185 OUT UINT64
*CurrentPosition OPTIONAL
189 Seek to the Offset location in the file. LoadFile and FV device types do
190 not support EfiSeek(). It is not possible to grow the file size using
193 SeekType defines how use Offset to calculate the new file position:
194 EfiSeekStart : Position = Offset
195 EfiSeekCurrent: Position is Offset bytes from the current position
196 EfiSeekEnd : Only supported if Offset is zero to seek to end of file.
198 @param Stream Open File Handle
199 @param Offset Offset to seek too.
200 @param SeekType Type of seek to perform
203 @return EFI_INVALID_PARAMETER Stream is not an Open File
204 @return EFI_UNSUPPORTED LoadFile and FV does not support Seek
205 @return EFI_NOT_FOUND Seek past the end of the file.
206 @return EFI_SUCCESS Steam closed
211 IN EFI_OPEN_FILE
*Stream
,
213 IN EFI_SEEK_TYPE SeekType
217 Read BufferSize bytes from the current location in the file. For load file
218 and FV case you must read the entire file.
220 @param Stream Open File Handle
221 @param Buffer Caller allocated buffer.
222 @param BufferSize Size of buffer in bytes.
225 @return EFI_SUCCESS Stream is not an Open File
226 @return EFI_END_OF_FILE Tried to read past the end of the file
227 @return EFI_INVALID_PARAMETER Stream is not an open file handle
228 @return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read
229 @return "other" Error returned from device read
234 IN EFI_OPEN_FILE
*Stream
,
236 OUT UINTN
*BufferSize
240 Read the entire file into a buffer. This routine allocates the buffer and
241 returns it to the user full of the read data.
243 This is very useful for load file where it's hard to know how big the buffer
246 @param Stream Open File Handle
247 @param Buffer Pointer to buffer to return.
248 @param BufferSize Pointer to Size of buffer return..
251 @return EFI_SUCCESS Stream is not an Open File
252 @return EFI_END_OF_FILE Tried to read past the end of the file
253 @return EFI_INVALID_PARAMETER Stream is not an open file handle
254 @return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read
255 @return "other" Error returned from device read
259 EfiReadAllocatePool (
260 IN EFI_OPEN_FILE
*Stream
,
262 OUT UINTN
*BufferSize
266 Write data back to the file.
268 @param Stream Open File Handle
269 @param Buffer Pointer to buffer to return.
270 @param BufferSize Pointer to Size of buffer return..
273 @return EFI_SUCCESS Stream is not an Open File
274 @return EFI_END_OF_FILE Tried to read past the end of the file
275 @return EFI_INVALID_PARAMETER Stream is not an open file handle
276 @return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read
277 @return "other" Error returned from device write
282 IN EFI_OPEN_FILE
*Stream
,
284 OUT UINTN
*BufferSize
288 Return the number of devices of the current type active in the system
290 @param Type Device type to check
292 @return 0 Invalid type
297 IN EFI_OPEN_FILE_TYPE Type
301 Set the Current Working Directory (CWD). If a call is made to EfiOpen () and
302 the path does not contain a device name, The CWD is prepended to the path.
304 @param Cwd Current Working Directory to set
307 @return EFI_SUCCESS CWD is set
308 @return EFI_INVALID_PARAMETER Cwd is not a valid device:path
317 Set the Current Working Directory (CWD). If a call is made to EfiOpen () and
318 the path does not contain a device name, The CWD is prepended to the path.
320 @param Cwd Current Working Directory
323 @return NULL No CWD set
324 @return 'other' malloc'ed buffer contains CWD.