current mounted device concept of current working directory concept implement
by this library.
-Device names are case insensative and only check the leading characters for
+Device names are case insensitive and only check the leading characters for
unique matches. Thus the following are all the same:
LoadFile0:
l0:
**/
BOOLEAN
FileHandleValid (
- IN EFI_OPEN_FILE *File
- )
+ IN EFI_OPEN_FILE *File
+ )
{
EFI_OPEN_FILE_GUARD *GuardFile;
**/
VOID
EblFreePool (
- IN VOID *Buffer
- )
+ IN VOID *Buffer
+ )
{
if (Buffer != NULL) {
FreePool (Buffer);
**/
VOID
EblUpdateDeviceLists (
- VOID
- )
+ VOID
+ )
{
EFI_STATUS Status;
UINTN Size;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Fs;
- EFI_BLOCK_IO_PROTOCOL *BlkIo;
EFI_FILE_HANDLE Root;
UINTN Index;
- BOOLEAN Update;
if (mBlkIo != NULL) {
FreePool (mBlkIo);
}
gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &mBlkIoCount, &mBlkIo);
- //
- // This is a trick to trigger the gBS->ReinstallProtocolInterface () in a removable media
- // device to make a filesystem layer on. Probing devices will detect if media has been
- // inserted and create
- //
- for (Index =0, Update = FALSE; Index < mBlkIoCount; Index++) {
- Status = gBS->HandleProtocol (mBlkIo[Index], &gEfiBlockIoProtocolGuid, (VOID **)&BlkIo);
- if (!EFI_ERROR (Status)) {
- if (BlkIo->Media->RemovableMedia) {
- gBS->DisconnectController (mBlkIo[Index], NULL, NULL);
- gBS->ConnectController (mBlkIo[Index], NULL, NULL, TRUE);
- Update = TRUE;
- }
- }
- }
-
- if (Update) {
- // In case we caused media to be detected that contains a partition (SD Card, ...) rescan
- if (mBlkIo != NULL) {
- FreePool (mBlkIo);
- }
- gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &mBlkIoCount, &mBlkIo);
- }
if (mFv != NULL) {
}
if (&mFsInfo[0] != NULL) {
- // Need to Free the mFsInfo prior to reclaculating mFsCount so don't move this code
+ // Need to Free the mFsInfo prior to recalculating mFsCount so don't move this code
for (Index = 0; Index < mFsCount; Index++) {
if (mFsInfo[Index] != NULL) {
FreePool (mFsInfo[Index]);
**/
BOOLEAN
EblMatchVolumeName (
- IN CHAR8 *PathName,
- IN UINTN FileStart,
- OUT UINTN *MatchIndex
- )
+ IN CHAR8 *PathName,
+ IN UINTN FileStart,
+ OUT UINTN *MatchIndex
+ )
{
UINTN Index;
UINTN Compare;
**/
UINTN
EfiGetDeviceCounts (
- IN EFI_OPEN_FILE_TYPE DeviceType
- )
+ IN EFI_OPEN_FILE_TYPE DeviceType
+ )
{
switch (DeviceType) {
case EfiOpenLoadFile:
EFI_STATUS
ConvertIpStringToEfiIp (
- IN CHAR8 *PathName,
- OUT EFI_IP_ADDRESS *ServerIp
- )
+ IN CHAR8 *PathName,
+ OUT EFI_IP_ADDRESS *ServerIp
+ )
{
CHAR8 *Str;
**/
UINTN
EblConvertDevStringToNumber (
- IN CHAR8 *Str
- )
+ IN CHAR8 *Str
+ )
{
UINTN Max;
UINTN Index;
**/
EFI_STATUS
EblFileDevicePath (
- IN OUT EFI_OPEN_FILE *File,
- IN CHAR8 *FileName,
- IN CONST UINT64 OpenMode
- )
+ IN OUT EFI_OPEN_FILE *File,
+ IN CHAR8 *FileName,
+ IN CONST UINT64 OpenMode
+ )
{
EFI_STATUS Status;
UINTN Size;
Status = gBS->HandleProtocol (File->EfiHandle, &gEfiBlockIoProtocolGuid, (VOID **)&BlkIo);
if (!EFI_ERROR (Status)) {
File->FsBlockIoMedia = BlkIo->Media;
+ File->FsBlockIo = BlkIo;
// If we are not opening the device this will get over written with file info
File->MaxPosition = MultU64x32 (BlkIo->Media->LastBlock + 1, BlkIo->Media->BlockSize);
EFI_STATUS
CompareGuidToString (
- IN EFI_GUID *Guid,
- IN CHAR8 *String
- )
+ IN EFI_GUID *Guid,
+ IN CHAR8 *String
+ )
{
CHAR8 AsciiGuid[64];
CHAR8 *StringPtr;
**/
EFI_STATUS
EblFvFileDevicePath (
- IN OUT EFI_OPEN_FILE *File,
- IN CHAR8 *FileName,
- IN CONST UINT64 OpenMode
- )
+ IN OUT EFI_OPEN_FILE *File,
+ IN CHAR8 *FileName,
+ IN CONST UINT64 OpenMode
+ )
{
EFI_STATUS Status;
EFI_STATUS GetNextFileStatus;
/**
Open a device named by PathName. The PathName includes a device name and
-path seperated by a :. See file header for more details on the PathName
+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
-secitons and only the SectionType section is opened.
+sections and only the SectionType section is opened.
For any file that is opened with EfiOpen() must be closed with EfiClose().
**/
EFI_OPEN_FILE *
EfiOpen (
- IN CHAR8 *PathName,
- IN CONST UINT64 OpenMode,
- IN CONST EFI_SECTION_TYPE SectionType
- )
+ IN CHAR8 *PathName,
+ IN CONST UINT64 OpenMode,
+ IN CONST EFI_SECTION_TYPE SectionType
+ )
{
EFI_STATUS Status;
EFI_OPEN_FILE *File;
return NULL;
}
- // We could add a current working diretory concept
+ // We could add a current working directory concept
CwdPlusPathName = AllocatePool (AsciiStrSize (gCwd) + AsciiStrSize (PathName));
if (CwdPlusPathName == NULL) {
return NULL;
AsciiStrCat (CwdPlusPathName, PathName);
if (AsciiStrStr (CwdPlusPathName, ":") == NULL) {
- // Extra error check to make sure we don't recusre and blow stack
+ // Extra error check to make sure we don't recurse and blow stack
return NULL;
}
EFI_STATUS
EfiCopyFile (
- IN CHAR8 *DestinationFile,
- IN CHAR8 *SourceFile
- )
+ IN CHAR8 *DestinationFile,
+ IN CHAR8 *SourceFile
+ )
{
EFI_OPEN_FILE *Source = NULL;
EFI_OPEN_FILE *Destination = NULL;
Status = EfiRead(Source, Buffer, &Chunk);
if (EFI_ERROR(Status)) {
- AsciiPrint("Read file error\n");
+ AsciiPrint("Read file error %r\n", Status);
goto Exit;
}
Status = EfiWrite(Destination, Buffer, &Chunk);
if (EFI_ERROR(Status)) {
- AsciiPrint("Write file error\n");
+ AsciiPrint("Write file error %r\n", Status);
goto Exit;
}
}
**/
EFI_OPEN_FILE *
EfiDeviceOpenByType (
- IN EFI_OPEN_FILE_TYPE DeviceType,
- IN UINTN Index
- )
+ IN EFI_OPEN_FILE_TYPE DeviceType,
+ IN UINTN Index
+ )
{
CHAR8 *DevStr;
CHAR8 Path[MAX_CMD_LINE];
**/
EFI_STATUS
EfiClose (
- IN EFI_OPEN_FILE *File
- )
+ IN EFI_OPEN_FILE *File
+ )
{
EFI_STATUS Status;
UINT64 TftpBufferSize;
if ((File->Type == EfiOpenLoadFile) ||
((File->Type == EfiOpenTftp) && (File->IsBufferValid == TRUE)) ||
((File->Type == EfiOpenFirmwareVolume) && (File->IsBufferValid == TRUE))) {
- EblFreePool(File->Buffer);
- }
+ EblFreePool(File->Buffer);
+ }
- EblFreePool (File->DevicePath);
- EblFreePool (File->DeviceName);
- EblFreePool (File->FsFileInfo);
- EblFreePool (File->FsInfo);
+ EblFreePool (File->DevicePath);
+ EblFreePool (File->DeviceName);
+ EblFreePool (File->FsFileInfo);
+ EblFreePool (File->FsInfo);
- if (File->FsFileHandle != NULL) {
- File->FsFileHandle->Close (File->FsFileHandle);
- }
+ if (File->FsFileHandle != NULL) {
+ File->FsFileHandle->Close (File->FsFileHandle);
+ }
- // Need to free File and it's Guard structures
- EblFreePool (BASE_CR (File, EFI_OPEN_FILE_GUARD, File));
- return EFI_SUCCESS;
+ // Need to free File and it's Guard structures
+ EblFreePool (BASE_CR (File, EFI_OPEN_FILE_GUARD, File));
+ return EFI_SUCCESS;
}
**/
UINTN
EfiTell (
- IN EFI_OPEN_FILE *File,
- OUT EFI_LBA *CurrentPosition OPTIONAL
- )
+ IN EFI_OPEN_FILE *File,
+ OUT EFI_LBA *CurrentPosition OPTIONAL
+ )
{
EFI_STATUS Status;
UINT64 BufferSize = 0;
/**
-Seek to the Offset locaiton in the file. LoadFile and FV device types do
+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().
@return EFI_INVALID_PARAMETER Stream is not an Open File
-@return EFI_UNSUPPORTED LoadFile and FV doe not support Seek
+@return EFI_UNSUPPORTED LoadFile and FV do not support Seek
@return EFI_NOT_FOUND Seek past the end of the file.
@return EFI_SUCCESS Steam closed
**/
EFI_STATUS
EfiSeek (
- IN EFI_OPEN_FILE *File,
- IN EFI_LBA Offset,
- IN EFI_SEEK_TYPE SeekType
- )
+ IN EFI_OPEN_FILE *File,
+ IN EFI_LBA Offset,
+ IN EFI_SEEK_TYPE SeekType
+ )
{
EFI_STATUS Status;
UINT64 CurrentPosition;
EFI_STATUS
CacheTftpFile (
- IN OUT EFI_OPEN_FILE *File
- )
+ IN OUT EFI_OPEN_FILE *File
+ )
{
EFI_STATUS Status;
UINT64 TftpBufferSize;
}
/**
-Read BufferSize bytes from the current locaiton in the file. For load file,
+Read BufferSize bytes from the current location in the file. For load file,
FV, and TFTP case you must read the entire file.
@param Stream Open File Handle
**/
EFI_STATUS
EfiRead (
- IN EFI_OPEN_FILE *File,
- OUT VOID *Buffer,
- OUT UINTN *BufferSize
- )
+ IN EFI_OPEN_FILE *File,
+ OUT VOID *Buffer,
+ OUT UINTN *BufferSize
+ )
{
EFI_STATUS Status;
UINT32 AuthenticationStatus;
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 flie where it's hard to know how big the buffer
+This is very useful for load file where it's hard to know how big the buffer
must be.
@param Stream Open File Handle
**/
EFI_STATUS
EfiReadAllocatePool (
- IN EFI_OPEN_FILE *File,
- OUT VOID **Buffer,
- OUT UINTN *BufferSize
- )
+ IN EFI_OPEN_FILE *File,
+ OUT VOID **Buffer,
+ OUT UINTN *BufferSize
+ )
{
if (!FileHandleValid (File)) {
return EFI_INVALID_PARAMETER;
**/
EFI_STATUS
EfiWrite (
- IN EFI_OPEN_FILE *File,
- OUT VOID *Buffer,
- OUT UINTN *BufferSize
- )
+ IN EFI_OPEN_FILE *File,
+ OUT VOID *Buffer,
+ OUT UINTN *BufferSize
+ )
{
EFI_STATUS Status;
EFI_FV_WRITE_FILE_DATA FileData;
**/
CHAR8 *
ExpandPath (
- IN CHAR8 *Cwd,
- IN CHAR8 *Path
- )
+ IN CHAR8 *Cwd,
+ IN CHAR8 *Path
+ )
{
CHAR8 *NewPath;
CHAR8 *Work, *Start, *End;
/**
-Set the Curent Working Directory (CWD). If a call is made to EfiOpen () and
+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.
@param Cwd Current Working Directory to set
**/
EFI_STATUS
EfiSetCwd (
- IN CHAR8 *Cwd
- )
+ IN CHAR8 *Cwd
+ )
{
EFI_OPEN_FILE *File;
UINTN Len;
return EFI_INVALID_PARAMETER;
}
+ AsciiStrCpy (gCwd, File->DeviceName);
+ if (File->FileName == NULL) {
+ AsciiStrCat (gCwd, ":\\");
+ } else {
+ AsciiStrCat (gCwd, ":");
+ AsciiStrCat (gCwd, File->FileName);
+ }
+
+
EfiClose (File);
if (Path != Cwd) {
FreePool (Path);
/**
-Set the Curent Working Directory (CWD). If a call is made to EfiOpen () and
+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.
The CWD buffer is only valid until a new call is made to EfiSetCwd(). After
a call to EfiSetCwd() it is not legal to use the pointer returned by
-this funciton.
+this function.
@param Cwd Current Working Directory
**/
CHAR8 *
EfiGetCwd (
- VOID
- )
+ VOID
+ )
{
if (gCwd == NULL) {
return "";