EmbeddedPkg[all]  0.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
EfiFileLib.h File Reference

Data Structures

struct  EFI_OPEN_FILE
 Public information about the open file. More...
 

Macros

#define MAX_PATHNAME   0x200
 

Enumerations

enum  EFI_OPEN_FILE_TYPE {
  EfiOpenLoadFile, EfiOpenMemoryBuffer, EfiOpenFirmwareVolume, EfiOpenFileSystem,
  EfiOpenBlockIo, EfiOpenTftp, EfiOpenMaxValue
}
 Type of the file that has been opened. More...
 
enum  EFI_SEEK_TYPE { EfiSeekStart, EfiSeekCurrent, EfiSeekEnd, EfiSeekMax }
 Type of Seek to perform. More...
 

Functions

EFI_OPEN_FILEEfiOpen (IN CHAR8 *PathName, IN CONST UINT64 OpenMode, IN CONST EFI_SECTION_TYPE SectionType)
 
EFI_STATUS EfiCopyFile (IN CHAR8 *DestinationFile, IN CHAR8 *SourceFile)
 
EFI_OPEN_FILEEfiDeviceOpenByType (IN EFI_OPEN_FILE_TYPE DeviceType, IN UINTN Index)
 
EFI_STATUS EfiClose (IN EFI_OPEN_FILE *Stream)
 
UINTN EfiTell (IN EFI_OPEN_FILE *Stream, OUT UINT64 *CurrentPosition)
 
EFI_STATUS EfiSeek (IN EFI_OPEN_FILE *Stream, IN EFI_LBA Offset, IN EFI_SEEK_TYPE SeekType)
 
EFI_STATUS EfiRead (IN EFI_OPEN_FILE *Stream, OUT VOID *Buffer, OUT UINTN *BufferSize)
 
EFI_STATUS EfiReadAllocatePool (IN EFI_OPEN_FILE *Stream, OUT VOID **Buffer, OUT UINTN *BufferSize)
 
EFI_STATUS EfiWrite (IN EFI_OPEN_FILE *Stream, OUT VOID *Buffer, OUT UINTN *BufferSize)
 
UINTN EfiGetDeviceCounts (IN EFI_OPEN_FILE_TYPE Type)
 
EFI_STATUS EfiSetCwd (IN CHAR8 *Cwd)
 
CHAR8 * EfiGetCwd (VOID)
 

Detailed Description

Library functions that perform file IO. Memory buffer, file system, and firmware volume operations are supported.

Copyright (c) 2007, Intel Corporation. All rights reserved.
Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.

SPDX-License-Identifier: BSD-2-Clause-Patent

Basic support for opening files on different device types. The device string is in the form of DevType:Path. Current DevType is required as there is no current mounted device concept of current working directory concept implement by this library.

Device names are case insensitive and only check the leading characters for unique matches. Thus the following are all the same: LoadFile0: l0: L0: Lo0:

Supported Device Names: A0x1234:0x12 - A memory buffer starting at address 0x1234 for 0x12 bytes l1: - EFI LoadFile device one. B0: - EFI BlockIo zero. fs3: - EFI Simple File System device 3 Fv2: - EFI Firmware Volume device 2 1.2.3.4:name - TFTP IP and file name

Macro Definition Documentation

#define MAX_PATHNAME   0x200

Enumeration Type Documentation

Type of the file that has been opened.

Enumerator
EfiOpenLoadFile 
EfiOpenMemoryBuffer 
EfiOpenFirmwareVolume 
EfiOpenFileSystem 
EfiOpenBlockIo 
EfiOpenTftp 
EfiOpenMaxValue 

Type of Seek to perform.

Enumerator
EfiSeekStart 
EfiSeekCurrent 
EfiSeekEnd 
EfiSeekMax 

Function Documentation

EFI_STATUS EfiClose ( IN EFI_OPEN_FILE Stream)

Close a file handle opened by EfiOpen() and free all resources allocated by EfiOpen().

Parameters
StreamOpen File Handle
Returns
EFI_INVALID_PARAMETER Stream is not an Open File
EFI_SUCCESS Steam closed
EFI_STATUS EfiCopyFile ( IN CHAR8 *  DestinationFile,
IN CHAR8 *  SourceFile 
)
EFI_OPEN_FILE* EfiDeviceOpenByType ( IN EFI_OPEN_FILE_TYPE  DeviceType,
IN UINTN  Index 
)

Use DeviceType and Index to form a valid PathName and try and open it.

Parameters
DeviceTypeDevice type to open
IndexDevice Index to use. Zero relative.
Returns
NULL Open failed
Valid EFI_OPEN_FILE handle
CHAR8* EfiGetCwd ( VOID  )

Set the Current Working Directory (CWD). If a call is made to EfiOpen () and the path does not contain a device name, The CWD is prepended to the path.

Parameters
CwdCurrent Working Directory
Returns
NULL No CWD set
'other' malloc'ed buffer contains CWD.
UINTN EfiGetDeviceCounts ( IN EFI_OPEN_FILE_TYPE  Type)

Return the number of devices of the current type active in the system

Parameters
TypeDevice type to check
Returns
0 Invalid type
EFI_OPEN_FILE* EfiOpen ( IN CHAR8 *  PathName,
IN CONST UINT64  OpenMode,
IN CONST EFI_SECTION_TYPE  SectionType 
)

Open a device named by PathName. The PathName includes a device name and path separated by a :. See file header for more details on the PathName syntax. There is no checking to prevent a file from being opened more than one type.

SectionType is only used to open an FV. Each file in an FV contains multiple sections and only the SectionType section is opened.

For any file that is opened with EfiOpen() must be closed with EfiClose().

Parameters
PathNamePath to parse to open
OpenModeSame as EFI_FILE.Open()
SectionTypeSection in FV to open.
Returns
NULL Open failed
Valid EFI_OPEN_FILE handle
EFI_STATUS EfiRead ( IN EFI_OPEN_FILE Stream,
OUT VOID Buffer,
OUT UINTN *  BufferSize 
)

Read BufferSize bytes from the current location in the file. For load file and FV case you must read the entire file.

Parameters
StreamOpen File Handle
BufferCaller allocated buffer.
BufferSizeSize of buffer in bytes.
Returns
EFI_SUCCESS Stream is not an Open File
EFI_END_OF_FILE Tried to read past the end of the file
EFI_INVALID_PARAMETER Stream is not an open file handle
EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read
"other" Error returned from device read
EFI_STATUS EfiReadAllocatePool ( IN EFI_OPEN_FILE Stream,
OUT VOID **  Buffer,
OUT UINTN *  BufferSize 
)

Read the entire file into a buffer. This routine allocates the buffer and returns it to the user full of the read data.

This is very useful for load file where it's hard to know how big the buffer must be.

Parameters
StreamOpen File Handle
BufferPointer to buffer to return.
BufferSizePointer to Size of buffer return..
Returns
EFI_SUCCESS Stream is not an Open File
EFI_END_OF_FILE Tried to read past the end of the file
EFI_INVALID_PARAMETER Stream is not an open file handle
EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read
"other" Error returned from device read
EFI_STATUS EfiSeek ( IN EFI_OPEN_FILE Stream,
IN EFI_LBA  Offset,
IN EFI_SEEK_TYPE  SeekType 
)

Seek to the Offset location in the file. LoadFile and FV device types do not support EfiSeek(). It is not possible to grow the file size using EfiSeek().

SeekType defines how use Offset to calculate the new file position: EfiSeekStart : Position = Offset EfiSeekCurrent: Position is Offset bytes from the current position EfiSeekEnd : Only supported if Offset is zero to seek to end of file.

Parameters
StreamOpen File Handle
OffsetOffset to seek too.
SeekTypeType of seek to perform
Returns
EFI_INVALID_PARAMETER Stream is not an Open File
EFI_UNSUPPORTED LoadFile and FV does not support Seek
EFI_NOT_FOUND Seek past the end of the file.
EFI_SUCCESS Steam closed
EFI_STATUS EfiSetCwd ( IN CHAR8 *  Cwd)

Set the Current Working Directory (CWD). If a call is made to EfiOpen () and the path does not contain a device name, The CWD is prepended to the path.

Parameters
CwdCurrent Working Directory to set
Returns
EFI_SUCCESS CWD is set
EFI_INVALID_PARAMETER Cwd is not a valid device:path
UINTN EfiTell ( IN EFI_OPEN_FILE Stream,
OUT UINT64 *  CurrentPosition 
)

Return the size of the file represented by Stream. Also return the current Seek position. Opening a file will enable a valid file size to be returned. LoadFile is an exception as a load file size is set to zero.

Parameters
StreamOpen File Handle
Returns
0 Stream is not an Open File or a valid LoadFile handle
EFI_STATUS EfiWrite ( IN EFI_OPEN_FILE Stream,
OUT VOID Buffer,
OUT UINTN *  BufferSize 
)

Write data back to the file.

Parameters
StreamOpen File Handle
BufferPointer to buffer to return.
BufferSizePointer to Size of buffer return..
Returns
EFI_SUCCESS Stream is not an Open File
EFI_END_OF_FILE Tried to read past the end of the file
EFI_INVALID_PARAMETER Stream is not an open file handle
EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read
"other" Error returned from device write