Add Current working directory support to the library
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10333 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@ -1,36 +1,36 @@
|
|||||||
/** @file
|
/** @file
|
||||||
File IO routines inspired by Streams with an EFI flavor
|
File IO routines inspired by Streams with an EFI flavor
|
||||||
|
|
||||||
Copyright (c) 2007, Intel Corporation<BR>
|
Copyright (c) 2007, Intel Corporation<BR>
|
||||||
Portions copyright (c) 2008-2009, Apple Inc. All rights reserved.
|
Portions copyright (c) 2008-2009, Apple Inc. All rights reserved.
|
||||||
|
|
||||||
All rights reserved. This program and the accompanying materials
|
All rights reserved. This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
http://opensource.org/licenses/bsd-license.php
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
Basic support for opening files on different device types. The device string
|
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
|
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
|
current mounted device concept of current working directory concept implement
|
||||||
by this library.
|
by this library.
|
||||||
|
|
||||||
Device names are case insensative and only check the leading characters for
|
Device names are case insensative and only check the leading characters for
|
||||||
unique matches. Thus the following are all the same:
|
unique matches. Thus the following are all the same:
|
||||||
LoadFile0:
|
LoadFile0:
|
||||||
l0:
|
l0:
|
||||||
L0:
|
L0:
|
||||||
Lo0:
|
Lo0:
|
||||||
|
|
||||||
Supported Device Names:
|
Supported Device Names:
|
||||||
A0x1234:0x12 - A memory buffer starting at address 0x1234 for 0x12 bytes
|
A0x1234:0x12 - A memory buffer starting at address 0x1234 for 0x12 bytes
|
||||||
l1: - EFI LoadFile device one.
|
l1: - EFI LoadFile device one.
|
||||||
B0: - EFI BlockIo zero.
|
B0: - EFI BlockIo zero.
|
||||||
fs3: - EFI Simple File System device 3
|
fs3: - EFI Simple File System device 3
|
||||||
Fv2: - EFI Firmware VOlume device 2
|
Fv2: - EFI Firmware VOlume device 2
|
||||||
10.0.1.102: - TFTP service IP followed by the file name
|
10.0.1.102: - TFTP service IP followed by the file name
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include <PiDxe.h>
|
#include <PiDxe.h>
|
||||||
@ -89,42 +89,42 @@ UINTN mLoadFileCount = 0;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Internal worker function to validate a File handle.
|
Internal worker function to validate a File handle.
|
||||||
|
|
||||||
@param File Open File Handle
|
@param File Open File Handle
|
||||||
|
|
||||||
@return TRUE File is valid
|
@return TRUE File is valid
|
||||||
@return FALSE File is not valid
|
@return FALSE File is not valid
|
||||||
|
|
||||||
|
|
||||||
**/
|
**/
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
FileHandleValid (
|
FileHandleValid (
|
||||||
IN EFI_OPEN_FILE *File
|
IN EFI_OPEN_FILE *File
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_OPEN_FILE_GUARD *GuardFile;
|
EFI_OPEN_FILE_GUARD *GuardFile;
|
||||||
|
|
||||||
// Look right before and after file structure for the correct signatures
|
// Look right before and after file structure for the correct signatures
|
||||||
GuardFile = BASE_CR (File, EFI_OPEN_FILE_GUARD, File);
|
GuardFile = BASE_CR (File, EFI_OPEN_FILE_GUARD, File);
|
||||||
if ((GuardFile->Header != EFI_OPEN_FILE_GUARD_HEADER) ||
|
if ((GuardFile->Header != EFI_OPEN_FILE_GUARD_HEADER) ||
|
||||||
(GuardFile->Footer != EFI_OPEN_FILE_GUARD_FOOTER) ) {
|
(GuardFile->Footer != EFI_OPEN_FILE_GUARD_FOOTER) ) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Internal worker function. If Buffer is not NULL free it.
|
Internal worker function. If Buffer is not NULL free it.
|
||||||
|
|
||||||
@param Buffer Buffer to FreePool()
|
@param Buffer Buffer to FreePool()
|
||||||
|
|
||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
EblFreePool (
|
EblFreePool (
|
||||||
IN VOID *Buffer
|
IN VOID *Buffer
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (Buffer != NULL) {
|
if (Buffer != NULL) {
|
||||||
FreePool (Buffer);
|
FreePool (Buffer);
|
||||||
@ -132,13 +132,13 @@ EblFreePool (
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Update Device List Global Variables
|
Update Device List Global Variables
|
||||||
|
|
||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
EblUpdateDeviceLists (
|
EblUpdateDeviceLists (
|
||||||
VOID
|
VOID
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINTN Size;
|
UINTN Size;
|
||||||
@ -206,25 +206,25 @@ EblUpdateDeviceLists (
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
PathName is in the form <device name>:<path> for example fs1:\ or ROOT:\.
|
PathName is in the form <device name>:<path> for example fs1:\ or ROOT:\.
|
||||||
Return TRUE if the <devce name> prefix of PathName matches a file system
|
Return TRUE if the <devce name> prefix of PathName matches a file system
|
||||||
Volume Name. MatchIndex is the array index in mFsInfo[] of the match,
|
Volume Name. MatchIndex is the array index in mFsInfo[] of the match,
|
||||||
and it can be used with mFs[] to find the handle that needs to be opened
|
and it can be used with mFs[] to find the handle that needs to be opened
|
||||||
|
|
||||||
@param PathName PathName to check
|
@param PathName PathName to check
|
||||||
@param FileStart Index of the first character of the <path>
|
@param FileStart Index of the first character of the <path>
|
||||||
@param MatchIndex Index in mFsInfo[] that matches
|
@param MatchIndex Index in mFsInfo[] that matches
|
||||||
|
|
||||||
@return TRUE PathName matches a Volume Label and MatchIndex is valid
|
@return TRUE PathName matches a Volume Label and MatchIndex is valid
|
||||||
@return FALSE PathName does not match a Volume Label MatchIndex undefined
|
@return FALSE PathName does not match a Volume Label MatchIndex undefined
|
||||||
|
|
||||||
**/
|
**/
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
EblMatchVolumeName (
|
EblMatchVolumeName (
|
||||||
IN CHAR8 *PathName,
|
IN CHAR8 *PathName,
|
||||||
IN UINTN FileStart,
|
IN UINTN FileStart,
|
||||||
OUT UINTN *MatchIndex
|
OUT UINTN *MatchIndex
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN Index;
|
UINTN Index;
|
||||||
UINTN Compare;
|
UINTN Compare;
|
||||||
@ -261,17 +261,17 @@ EblMatchVolumeName (
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Return the number of devices of the current type active in the system
|
Return the number of devices of the current type active in the system
|
||||||
|
|
||||||
@param Type Device type to check
|
@param Type Device type to check
|
||||||
|
|
||||||
@return 0 Invalid type
|
@return 0 Invalid type
|
||||||
|
|
||||||
**/
|
**/
|
||||||
UINTN
|
UINTN
|
||||||
EfiGetDeviceCounts (
|
EfiGetDeviceCounts (
|
||||||
IN EFI_OPEN_FILE_TYPE DeviceType
|
IN EFI_OPEN_FILE_TYPE DeviceType
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
switch (DeviceType) {
|
switch (DeviceType) {
|
||||||
case EfiOpenLoadFile:
|
case EfiOpenLoadFile:
|
||||||
@ -289,9 +289,9 @@ EfiGetDeviceCounts (
|
|||||||
|
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
ConvertIpStringToEfiIp (
|
ConvertIpStringToEfiIp (
|
||||||
IN CHAR8 *PathName,
|
IN CHAR8 *PathName,
|
||||||
OUT EFI_IP_ADDRESS *ServerIp
|
OUT EFI_IP_ADDRESS *ServerIp
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
CHAR8 *Str;
|
CHAR8 *Str;
|
||||||
|
|
||||||
@ -324,19 +324,19 @@ ConvertIpStringToEfiIp (
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Internal work function to extract a device number from a string skipping
|
Internal work function to extract a device number from a string skipping
|
||||||
text. Easy way to extract numbers from strings like blk7:.
|
text. Easy way to extract numbers from strings like blk7:.
|
||||||
|
|
||||||
@param Str String to extract device number form
|
@param Str String to extract device number form
|
||||||
|
|
||||||
@return -1 Device string is not valid
|
@return -1 Device string is not valid
|
||||||
@return Device #
|
@return Device #
|
||||||
|
|
||||||
**/
|
**/
|
||||||
UINTN
|
UINTN
|
||||||
EblConvertDevStringToNumber (
|
EblConvertDevStringToNumber (
|
||||||
IN CHAR8 *Str
|
IN CHAR8 *Str
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN Max;
|
UINTN Max;
|
||||||
UINTN Index;
|
UINTN Index;
|
||||||
@ -356,19 +356,19 @@ EblConvertDevStringToNumber (
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Internal work function to fill in EFI_OPEN_FILE information for the Fs and BlkIo
|
Internal work function to fill in EFI_OPEN_FILE information for the Fs and BlkIo
|
||||||
|
|
||||||
@param File Open file handle
|
@param File Open file handle
|
||||||
@param FileName Name of file after device stripped off
|
@param FileName Name of file after device stripped off
|
||||||
|
|
||||||
|
|
||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EblFileDevicePath (
|
EblFileDevicePath (
|
||||||
IN OUT EFI_OPEN_FILE *File,
|
IN OUT EFI_OPEN_FILE *File,
|
||||||
IN CHAR8 *FileName,
|
IN CHAR8 *FileName,
|
||||||
IN CONST UINT64 OpenMode
|
IN CONST UINT64 OpenMode
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINTN Size;
|
UINTN Size;
|
||||||
@ -454,9 +454,9 @@ EblFileDevicePath (
|
|||||||
|
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
CompareGuidToString (
|
CompareGuidToString (
|
||||||
IN EFI_GUID *Guid,
|
IN EFI_GUID *Guid,
|
||||||
IN CHAR8 *String
|
IN CHAR8 *String
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
CHAR8 AsciiGuid[64];
|
CHAR8 AsciiGuid[64];
|
||||||
CHAR8 *StringPtr;
|
CHAR8 *StringPtr;
|
||||||
@ -492,19 +492,19 @@ CompareGuidToString (
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Internal work function to fill in EFI_OPEN_FILE information for the FV
|
Internal work function to fill in EFI_OPEN_FILE information for the FV
|
||||||
|
|
||||||
@param File Open file handle
|
@param File Open file handle
|
||||||
@param FileName Name of file after device stripped off
|
@param FileName Name of file after device stripped off
|
||||||
|
|
||||||
|
|
||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EblFvFileDevicePath (
|
EblFvFileDevicePath (
|
||||||
IN OUT EFI_OPEN_FILE *File,
|
IN OUT EFI_OPEN_FILE *File,
|
||||||
IN CHAR8 *FileName,
|
IN CHAR8 *FileName,
|
||||||
IN CONST UINT64 OpenMode
|
IN CONST UINT64 OpenMode
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
EFI_STATUS GetNextFileStatus;
|
EFI_STATUS GetNextFileStatus;
|
||||||
@ -560,13 +560,13 @@ EblFvFileDevicePath (
|
|||||||
do {
|
do {
|
||||||
File->FvType = EFI_FV_FILETYPE_ALL;
|
File->FvType = EFI_FV_FILETYPE_ALL;
|
||||||
GetNextFileStatus = File->Fv->GetNextFile (
|
GetNextFileStatus = File->Fv->GetNextFile (
|
||||||
File->Fv,
|
File->Fv,
|
||||||
&Key,
|
&Key,
|
||||||
&File->FvType,
|
&File->FvType,
|
||||||
&File->FvNameGuid,
|
&File->FvNameGuid,
|
||||||
&File->FvAttributes,
|
&File->FvAttributes,
|
||||||
&File->Size
|
&File->Size
|
||||||
);
|
);
|
||||||
if (!EFI_ERROR (GetNextFileStatus)) {
|
if (!EFI_ERROR (GetNextFileStatus)) {
|
||||||
// Compare GUID first
|
// Compare GUID first
|
||||||
Status = CompareGuidToString (&File->FvNameGuid, FileName);
|
Status = CompareGuidToString (&File->FvNameGuid, FileName);
|
||||||
@ -576,14 +576,14 @@ EblFvFileDevicePath (
|
|||||||
|
|
||||||
Section = NULL;
|
Section = NULL;
|
||||||
Status = File->Fv->ReadSection (
|
Status = File->Fv->ReadSection (
|
||||||
File->Fv,
|
File->Fv,
|
||||||
&File->FvNameGuid,
|
&File->FvNameGuid,
|
||||||
EFI_SECTION_USER_INTERFACE,
|
EFI_SECTION_USER_INTERFACE,
|
||||||
0,
|
0,
|
||||||
&Section,
|
&Section,
|
||||||
&SectionSize,
|
&SectionSize,
|
||||||
&AuthenticationStatus
|
&AuthenticationStatus
|
||||||
);
|
);
|
||||||
if (!EFI_ERROR (Status)) {
|
if (!EFI_ERROR (Status)) {
|
||||||
UnicodeStrToAsciiStr (Section, AsciiSection);
|
UnicodeStrToAsciiStr (Section, AsciiSection);
|
||||||
if (AsciiStriCmp (FileName, AsciiSection) == 0) {
|
if (AsciiStriCmp (FileName, AsciiSection) == 0) {
|
||||||
@ -604,14 +604,14 @@ EblFvFileDevicePath (
|
|||||||
Section = NULL;
|
Section = NULL;
|
||||||
File->Size = 0;
|
File->Size = 0;
|
||||||
Status = File->Fv->ReadSection (
|
Status = File->Fv->ReadSection (
|
||||||
File->Fv,
|
File->Fv,
|
||||||
&File->FvNameGuid,
|
&File->FvNameGuid,
|
||||||
OpenMode,
|
(EFI_SECTION_TYPE)OpenMode,
|
||||||
0,
|
0,
|
||||||
&Section,
|
&Section,
|
||||||
&File->Size,
|
&File->Size,
|
||||||
&AuthenticationStatus
|
&AuthenticationStatus
|
||||||
);
|
);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
@ -631,30 +631,30 @@ EblFvFileDevicePath (
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Open a device named by PathName. The PathName includes a device name and
|
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 seperated 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
|
syntax. There is no checking to prevent a file from being opened more than
|
||||||
one type.
|
one type.
|
||||||
|
|
||||||
SectionType is only used to open an FV. Each file in an FV contains multiple
|
SectionType is only used to open an FV. Each file in an FV contains multiple
|
||||||
secitons and only the SectionType section is opened.
|
secitons and only the SectionType section is opened.
|
||||||
|
|
||||||
For any file that is opened with EfiOpen() must be closed with EfiClose().
|
For any file that is opened with EfiOpen() must be closed with EfiClose().
|
||||||
|
|
||||||
@param PathName Path to parse to open
|
@param PathName Path to parse to open
|
||||||
@param OpenMode Same as EFI_FILE.Open()
|
@param OpenMode Same as EFI_FILE.Open()
|
||||||
@param SectionType Section in FV to open.
|
@param SectionType Section in FV to open.
|
||||||
|
|
||||||
@return NULL Open failed
|
@return NULL Open failed
|
||||||
@return Valid EFI_OPEN_FILE handle
|
@return Valid EFI_OPEN_FILE handle
|
||||||
|
|
||||||
**/
|
**/
|
||||||
EFI_OPEN_FILE *
|
EFI_OPEN_FILE *
|
||||||
EfiOpen (
|
EfiOpen (
|
||||||
IN CHAR8 *PathName,
|
IN CHAR8 *PathName,
|
||||||
IN CONST UINT64 OpenMode,
|
IN CONST UINT64 OpenMode,
|
||||||
IN CONST EFI_SECTION_TYPE SectionType
|
IN CONST EFI_SECTION_TYPE SectionType
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
EFI_OPEN_FILE *File;
|
EFI_OPEN_FILE *File;
|
||||||
@ -782,7 +782,7 @@ EfiOpen (
|
|||||||
if (PathName[Index] == ':') {
|
if (PathName[Index] == ':') {
|
||||||
// Support fv0:\DxeCore:0x10
|
// Support fv0:\DxeCore:0x10
|
||||||
// This means open the PE32 Section of the file
|
// This means open the PE32 Section of the file
|
||||||
ModifiedSectionType = AsciiStrHexToUintn (&PathName[Index + 1]);
|
ModifiedSectionType = (EFI_SECTION_TYPE)AsciiStrHexToUintn (&PathName[Index + 1]);
|
||||||
PathName[Index] = '\0';
|
PathName[Index] = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -910,9 +910,9 @@ ErrorExit:
|
|||||||
|
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EfiCopyFile (
|
EfiCopyFile (
|
||||||
IN CHAR8 *DestinationFile,
|
IN CHAR8 *DestinationFile,
|
||||||
IN CHAR8 *SourceFile
|
IN CHAR8 *SourceFile
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_OPEN_FILE *Source = NULL;
|
EFI_OPEN_FILE *Source = NULL;
|
||||||
EFI_OPEN_FILE *Destination = NULL;
|
EFI_OPEN_FILE *Destination = NULL;
|
||||||
@ -1000,20 +1000,20 @@ Exit:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Use DeviceType and Index to form a valid PathName and try and open it.
|
Use DeviceType and Index to form a valid PathName and try and open it.
|
||||||
|
|
||||||
@param DeviceType Device type to open
|
@param DeviceType Device type to open
|
||||||
@param Index Device Index to use. Zero relative.
|
@param Index Device Index to use. Zero relative.
|
||||||
|
|
||||||
@return NULL Open failed
|
@return NULL Open failed
|
||||||
@return Valid EFI_OPEN_FILE handle
|
@return Valid EFI_OPEN_FILE handle
|
||||||
|
|
||||||
**/
|
**/
|
||||||
EFI_OPEN_FILE *
|
EFI_OPEN_FILE *
|
||||||
EfiDeviceOpenByType (
|
EfiDeviceOpenByType (
|
||||||
IN EFI_OPEN_FILE_TYPE DeviceType,
|
IN EFI_OPEN_FILE_TYPE DeviceType,
|
||||||
IN UINTN Index
|
IN UINTN Index
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
CHAR8 *DevStr;
|
CHAR8 *DevStr;
|
||||||
CHAR8 Path[MAX_CMD_LINE];
|
CHAR8 Path[MAX_CMD_LINE];
|
||||||
@ -1045,19 +1045,19 @@ EfiDeviceOpenByType (
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Close a file handle opened by EfiOpen() and free all resources allocated by
|
Close a file handle opened by EfiOpen() and free all resources allocated by
|
||||||
EfiOpen().
|
EfiOpen().
|
||||||
|
|
||||||
@param Stream Open File Handle
|
@param Stream Open File Handle
|
||||||
|
|
||||||
@return EFI_INVALID_PARAMETER Stream is not an Open File
|
@return EFI_INVALID_PARAMETER Stream is not an Open File
|
||||||
@return EFI_SUCCESS Steam closed
|
@return EFI_SUCCESS Steam closed
|
||||||
|
|
||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EfiClose (
|
EfiClose (
|
||||||
IN EFI_OPEN_FILE *File
|
IN EFI_OPEN_FILE *File
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINT64 TftpBufferSize;
|
UINT64 TftpBufferSize;
|
||||||
@ -1071,16 +1071,16 @@ EfiClose (
|
|||||||
|
|
||||||
TftpBufferSize = File->Size;
|
TftpBufferSize = File->Size;
|
||||||
Status = EblMtftp (
|
Status = EblMtftp (
|
||||||
EFI_PXE_BASE_CODE_TFTP_WRITE_FILE,
|
EFI_PXE_BASE_CODE_TFTP_WRITE_FILE,
|
||||||
File->Buffer,
|
File->Buffer,
|
||||||
TRUE,
|
TRUE,
|
||||||
&TftpBufferSize,
|
&TftpBufferSize,
|
||||||
NULL,
|
NULL,
|
||||||
&File->ServerIp,
|
&File->ServerIp,
|
||||||
(UINT8 *)File->FileName,
|
(UINT8 *)File->FileName,
|
||||||
NULL,
|
NULL,
|
||||||
FALSE
|
FALSE
|
||||||
);
|
);
|
||||||
if (EFI_ERROR(Status)) {
|
if (EFI_ERROR(Status)) {
|
||||||
AsciiPrint("TFTP error during APPLE_NSP_TFTP_WRITE_FILE: %r\n", Status);
|
AsciiPrint("TFTP error during APPLE_NSP_TFTP_WRITE_FILE: %r\n", Status);
|
||||||
return Status;
|
return Status;
|
||||||
@ -1088,41 +1088,41 @@ EfiClose (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((File->Type == EfiOpenLoadFile) ||
|
if ((File->Type == EfiOpenLoadFile) ||
|
||||||
((File->Type == EfiOpenTftp) && (File->IsBufferValid == TRUE)) ||
|
((File->Type == EfiOpenTftp) && (File->IsBufferValid == TRUE)) ||
|
||||||
((File->Type == EfiOpenFirmwareVolume) && (File->IsBufferValid == TRUE))) {
|
((File->Type == EfiOpenFirmwareVolume) && (File->IsBufferValid == TRUE))) {
|
||||||
EblFreePool(File->Buffer);
|
EblFreePool(File->Buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
EblFreePool (File->DevicePath);
|
EblFreePool (File->DevicePath);
|
||||||
EblFreePool (File->DeviceName);
|
EblFreePool (File->DeviceName);
|
||||||
EblFreePool (File->FsFileInfo);
|
EblFreePool (File->FsFileInfo);
|
||||||
EblFreePool (File->FsInfo);
|
EblFreePool (File->FsInfo);
|
||||||
|
|
||||||
if (File->FsFileHandle != NULL) {
|
if (File->FsFileHandle != NULL) {
|
||||||
File->FsFileHandle->Close (File->FsFileHandle);
|
File->FsFileHandle->Close (File->FsFileHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to free File and it's Guard structures
|
// Need to free File and it's Guard structures
|
||||||
EblFreePool (BASE_CR (File, EFI_OPEN_FILE_GUARD, File));
|
EblFreePool (BASE_CR (File, EFI_OPEN_FILE_GUARD, File));
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Return the size of the file represented by Stream. Also return the current
|
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.
|
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.
|
LoadFile is an exception as a load file size is set to zero.
|
||||||
|
|
||||||
@param Stream Open File Handle
|
@param Stream Open File Handle
|
||||||
|
|
||||||
@return 0 Stream is not an Open File or a valid LoadFile handle
|
@return 0 Stream is not an Open File or a valid LoadFile handle
|
||||||
|
|
||||||
**/
|
**/
|
||||||
UINTN
|
UINTN
|
||||||
EfiTell (
|
EfiTell (
|
||||||
IN EFI_OPEN_FILE *File,
|
IN EFI_OPEN_FILE *File,
|
||||||
OUT EFI_LBA *CurrentPosition OPTIONAL
|
OUT EFI_LBA *CurrentPosition OPTIONAL
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINT64 BufferSize = 0;
|
UINT64 BufferSize = 0;
|
||||||
@ -1148,16 +1148,16 @@ EfiTell (
|
|||||||
} else if (File->Type == EfiOpenTftp) {
|
} else if (File->Type == EfiOpenTftp) {
|
||||||
|
|
||||||
Status = EblMtftp (
|
Status = EblMtftp (
|
||||||
EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE,
|
EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE,
|
||||||
NULL,
|
NULL,
|
||||||
FALSE,
|
FALSE,
|
||||||
&BufferSize,
|
&BufferSize,
|
||||||
NULL,
|
NULL,
|
||||||
&File->ServerIp,
|
&File->ServerIp,
|
||||||
(UINT8 *)File->FileName,
|
(UINT8 *)File->FileName,
|
||||||
NULL,
|
NULL,
|
||||||
TRUE
|
TRUE
|
||||||
);
|
);
|
||||||
if (EFI_ERROR(Status)) {
|
if (EFI_ERROR(Status)) {
|
||||||
AsciiPrint("TFTP error during APPLE_NSP_TFTP_GET_FILE_SIZE: %r\n", Status);
|
AsciiPrint("TFTP error during APPLE_NSP_TFTP_GET_FILE_SIZE: %r\n", Status);
|
||||||
return 0;
|
return 0;
|
||||||
@ -1172,32 +1172,32 @@ EfiTell (
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Seek to the Offset locaiton in the file. LoadFile and FV device types do
|
Seek to the Offset locaiton in the file. LoadFile and FV device types do
|
||||||
not support EfiSeek(). It is not possible to grow the file size using
|
not support EfiSeek(). It is not possible to grow the file size using
|
||||||
EfiSeek().
|
EfiSeek().
|
||||||
|
|
||||||
SeekType defines how use Offset to calculate the new file position:
|
SeekType defines how use Offset to calculate the new file position:
|
||||||
EfiSeekStart : Position = Offset
|
EfiSeekStart : Position = Offset
|
||||||
EfiSeekCurrent: Position is Offset bytes from the current position
|
EfiSeekCurrent: Position is Offset bytes from the current position
|
||||||
EfiSeekEnd : Only supported if Offset is zero to seek to end of file.
|
EfiSeekEnd : Only supported if Offset is zero to seek to end of file.
|
||||||
|
|
||||||
@param Stream Open File Handle
|
@param Stream Open File Handle
|
||||||
@param Offset Offset to seek too.
|
@param Offset Offset to seek too.
|
||||||
@param SeekType Type of seek to perform
|
@param SeekType Type of seek to perform
|
||||||
|
|
||||||
|
|
||||||
@return EFI_INVALID_PARAMETER Stream is not an Open File
|
@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 doe not support Seek
|
||||||
@return EFI_NOT_FOUND Seek past the end of the file.
|
@return EFI_NOT_FOUND Seek past the end of the file.
|
||||||
@return EFI_SUCCESS Steam closed
|
@return EFI_SUCCESS Steam closed
|
||||||
|
|
||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EfiSeek (
|
EfiSeek (
|
||||||
IN EFI_OPEN_FILE *File,
|
IN EFI_OPEN_FILE *File,
|
||||||
IN EFI_LBA Offset,
|
IN EFI_LBA Offset,
|
||||||
IN EFI_SEEK_TYPE SeekType
|
IN EFI_SEEK_TYPE SeekType
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINT64 CurrentPosition;
|
UINT64 CurrentPosition;
|
||||||
@ -1253,8 +1253,8 @@ EfiSeek (
|
|||||||
|
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
CacheTftpFile (
|
CacheTftpFile (
|
||||||
IN OUT EFI_OPEN_FILE *File
|
IN OUT EFI_OPEN_FILE *File
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINT64 TftpBufferSize;
|
UINT64 TftpBufferSize;
|
||||||
@ -1275,15 +1275,15 @@ CacheTftpFile (
|
|||||||
TftpBufferSize = File->Size;
|
TftpBufferSize = File->Size;
|
||||||
|
|
||||||
Status = EblMtftp (
|
Status = EblMtftp (
|
||||||
EFI_PXE_BASE_CODE_TFTP_READ_FILE,
|
EFI_PXE_BASE_CODE_TFTP_READ_FILE,
|
||||||
File->Buffer,
|
File->Buffer,
|
||||||
FALSE,
|
FALSE,
|
||||||
&TftpBufferSize,
|
&TftpBufferSize,
|
||||||
NULL,
|
NULL,
|
||||||
&File->ServerIp,
|
&File->ServerIp,
|
||||||
(UINT8 *)File->FileName,
|
(UINT8 *)File->FileName,
|
||||||
NULL,
|
NULL,
|
||||||
FALSE);
|
FALSE);
|
||||||
if (EFI_ERROR(Status)) {
|
if (EFI_ERROR(Status)) {
|
||||||
AsciiPrint("TFTP error during APPLE_NSP_TFTP_READ_FILE: %r\n", Status);
|
AsciiPrint("TFTP error during APPLE_NSP_TFTP_READ_FILE: %r\n", Status);
|
||||||
FreePool(File->Buffer);
|
FreePool(File->Buffer);
|
||||||
@ -1297,27 +1297,27 @@ CacheTftpFile (
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Read BufferSize bytes from the current locaiton in the file. For load file,
|
Read BufferSize bytes from the current locaiton in the file. For load file,
|
||||||
FV, and TFTP case you must read the entire file.
|
FV, and TFTP case you must read the entire file.
|
||||||
|
|
||||||
@param Stream Open File Handle
|
@param Stream Open File Handle
|
||||||
@param Buffer Caller allocated buffer.
|
@param Buffer Caller allocated buffer.
|
||||||
@param BufferSize Size of buffer in bytes.
|
@param BufferSize Size of buffer in bytes.
|
||||||
|
|
||||||
|
|
||||||
@return EFI_SUCCESS Stream is not an Open File
|
@return EFI_SUCCESS Stream is not an Open File
|
||||||
@return EFI_END_OF_FILE Tried to read past the end of the file
|
@return EFI_END_OF_FILE Tried to read past the end of the file
|
||||||
@return EFI_INVALID_PARAMETER Stream is not an open file handle
|
@return EFI_INVALID_PARAMETER Stream is not an open file handle
|
||||||
@return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read
|
@return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read
|
||||||
@return "other" Error returned from device read
|
@return "other" Error returned from device read
|
||||||
|
|
||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EfiRead (
|
EfiRead (
|
||||||
IN EFI_OPEN_FILE *File,
|
IN EFI_OPEN_FILE *File,
|
||||||
OUT VOID *Buffer,
|
OUT VOID *Buffer,
|
||||||
OUT UINTN *BufferSize
|
OUT UINTN *BufferSize
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINT32 AuthenticationStatus;
|
UINT32 AuthenticationStatus;
|
||||||
@ -1350,24 +1350,24 @@ EfiRead (
|
|||||||
if (File->Buffer == NULL) {
|
if (File->Buffer == NULL) {
|
||||||
if (File->FvSectionType == EFI_SECTION_ALL) {
|
if (File->FvSectionType == EFI_SECTION_ALL) {
|
||||||
Status = File->Fv->ReadFile (
|
Status = File->Fv->ReadFile (
|
||||||
File->Fv,
|
File->Fv,
|
||||||
&File->FvNameGuid,
|
&File->FvNameGuid,
|
||||||
(VOID **)&File->Buffer,
|
(VOID **)&File->Buffer,
|
||||||
&File->Size,
|
&File->Size,
|
||||||
&File->FvType,
|
&File->FvType,
|
||||||
&File->FvAttributes,
|
&File->FvAttributes,
|
||||||
&AuthenticationStatus
|
&AuthenticationStatus
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
Status = File->Fv->ReadSection (
|
Status = File->Fv->ReadSection (
|
||||||
File->Fv,
|
File->Fv,
|
||||||
&File->FvNameGuid,
|
&File->FvNameGuid,
|
||||||
File->FvSectionType,
|
File->FvSectionType,
|
||||||
0,
|
0,
|
||||||
(VOID **)&File->Buffer,
|
(VOID **)&File->Buffer,
|
||||||
&File->Size,
|
&File->Size,
|
||||||
&AuthenticationStatus
|
&AuthenticationStatus
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
return Status;
|
||||||
@ -1425,30 +1425,30 @@ EfiRead (
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Read the entire file into a buffer. This routine allocates the buffer and
|
Read the entire file into a buffer. This routine allocates the buffer and
|
||||||
returns it to the user full of the read data.
|
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 flie where it's hard to know how big the buffer
|
||||||
must be.
|
must be.
|
||||||
|
|
||||||
@param Stream Open File Handle
|
@param Stream Open File Handle
|
||||||
@param Buffer Pointer to buffer to return.
|
@param Buffer Pointer to buffer to return.
|
||||||
@param BufferSize Pointer to Size of buffer return..
|
@param BufferSize Pointer to Size of buffer return..
|
||||||
|
|
||||||
|
|
||||||
@return EFI_SUCCESS Stream is not an Open File
|
@return EFI_SUCCESS Stream is not an Open File
|
||||||
@return EFI_END_OF_FILE Tried to read past the end of the file
|
@return EFI_END_OF_FILE Tried to read past the end of the file
|
||||||
@return EFI_INVALID_PARAMETER Stream is not an open file handle
|
@return EFI_INVALID_PARAMETER Stream is not an open file handle
|
||||||
@return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read
|
@return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read
|
||||||
@return "other" Error returned from device read
|
@return "other" Error returned from device read
|
||||||
|
|
||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EfiReadAllocatePool (
|
EfiReadAllocatePool (
|
||||||
IN EFI_OPEN_FILE *File,
|
IN EFI_OPEN_FILE *File,
|
||||||
OUT VOID **Buffer,
|
OUT VOID **Buffer,
|
||||||
OUT UINTN *BufferSize
|
OUT UINTN *BufferSize
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (!FileHandleValid (File)) {
|
if (!FileHandleValid (File)) {
|
||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
@ -1468,26 +1468,26 @@ EfiReadAllocatePool (
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Write data back to the file. For TFTP case you must write the entire file.
|
Write data back to the file. For TFTP case you must write the entire file.
|
||||||
|
|
||||||
@param Stream Open File Handle
|
@param Stream Open File Handle
|
||||||
@param Buffer Pointer to buffer to return.
|
@param Buffer Pointer to buffer to return.
|
||||||
@param BufferSize Pointer to Size of buffer return..
|
@param BufferSize Pointer to Size of buffer return..
|
||||||
|
|
||||||
|
|
||||||
@return EFI_SUCCESS Stream is not an Open File
|
@return EFI_SUCCESS Stream is not an Open File
|
||||||
@return EFI_END_OF_FILE Tried to read past the end of the file
|
@return EFI_END_OF_FILE Tried to read past the end of the file
|
||||||
@return EFI_INVALID_PARAMETER Stream is not an open file handle
|
@return EFI_INVALID_PARAMETER Stream is not an open file handle
|
||||||
@return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read
|
@return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read
|
||||||
@return "other" Error returned from device write
|
@return "other" Error returned from device write
|
||||||
|
|
||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EfiWrite (
|
EfiWrite (
|
||||||
IN EFI_OPEN_FILE *File,
|
IN EFI_OPEN_FILE *File,
|
||||||
OUT VOID *Buffer,
|
OUT VOID *Buffer,
|
||||||
OUT UINTN *BufferSize
|
OUT UINTN *BufferSize
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
EFI_FV_WRITE_FILE_DATA FileData;
|
EFI_FV_WRITE_FILE_DATA FileData;
|
||||||
@ -1589,21 +1589,21 @@ EfiWrite (
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Given Cwd expand Path to remove .. and replace them with real
|
Given Cwd expand Path to remove .. and replace them with real
|
||||||
directory names.
|
directory names.
|
||||||
|
|
||||||
@param Cwd Current Working Directory
|
@param Cwd Current Working Directory
|
||||||
@param Path Path to expand
|
@param Path Path to expand
|
||||||
|
|
||||||
@return NULL Cwd or Path are not valid
|
@return NULL Cwd or Path are not valid
|
||||||
@return 'other' Path with .. expanded
|
@return 'other' Path with .. expanded
|
||||||
|
|
||||||
**/
|
**/
|
||||||
CHAR8 *
|
CHAR8 *
|
||||||
ExpandPath (
|
ExpandPath (
|
||||||
IN CHAR8 *Cwd,
|
IN CHAR8 *Cwd,
|
||||||
IN CHAR8 *Path
|
IN CHAR8 *Path
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
CHAR8 *NewPath;
|
CHAR8 *NewPath;
|
||||||
CHAR8 *Work, *Start, *End;
|
CHAR8 *Work, *Start, *End;
|
||||||
@ -1666,20 +1666,20 @@ ExpandPath (
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set the Curent Working Directory (CWD). If a call is made to EfiOpen () and
|
Set the Curent 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 path does not contain a device name, The CWD is prepended to the path.
|
||||||
|
|
||||||
@param Cwd Current Working Directory to set
|
@param Cwd Current Working Directory to set
|
||||||
|
|
||||||
|
|
||||||
@return EFI_SUCCESS CWD is set
|
@return EFI_SUCCESS CWD is set
|
||||||
@return EFI_INVALID_PARAMETER Cwd is not a valid device:path
|
@return EFI_INVALID_PARAMETER Cwd is not a valid device:path
|
||||||
|
|
||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EfiSetCwd (
|
EfiSetCwd (
|
||||||
IN CHAR8 *Cwd
|
IN CHAR8 *Cwd
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_OPEN_FILE *File;
|
EFI_OPEN_FILE *File;
|
||||||
UINTN Len;
|
UINTN Len;
|
||||||
@ -1729,13 +1729,6 @@ EfiSetCwd (
|
|||||||
if (gCwd == NULL) {
|
if (gCwd == NULL) {
|
||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
AsciiStrCpy (gCwd, File->DeviceName);
|
|
||||||
if (File->FileName == NULL) {
|
|
||||||
AsciiStrCat (gCwd, ":\\");
|
|
||||||
} else {
|
|
||||||
AsciiStrCat (gCwd, ":");
|
|
||||||
AsciiStrCat (gCwd, File->FileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
EfiClose (File);
|
EfiClose (File);
|
||||||
if (Path != Cwd) {
|
if (Path != Cwd) {
|
||||||
@ -1746,23 +1739,23 @@ EfiSetCwd (
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set the Curent Working Directory (CWD). If a call is made to EfiOpen () and
|
Set the Curent 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 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
|
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
|
a call to EfiSetCwd() it is not legal to use the pointer returned by
|
||||||
this funciton.
|
this funciton.
|
||||||
|
|
||||||
@param Cwd Current Working Directory
|
@param Cwd Current Working Directory
|
||||||
|
|
||||||
|
|
||||||
@return "" No CWD set
|
@return "" No CWD set
|
||||||
@return 'other' Returns buffer that contains CWD.
|
@return 'other' Returns buffer that contains CWD.
|
||||||
|
|
||||||
**/
|
**/
|
||||||
CHAR8 *
|
CHAR8 *
|
||||||
EfiGetCwd (
|
EfiGetCwd (
|
||||||
VOID
|
VOID
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (gCwd == NULL) {
|
if (gCwd == NULL) {
|
||||||
return "";
|
return "";
|
||||||
|
Reference in New Issue
Block a user