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:
andrewfish
2010-04-03 00:38:35 +00:00
parent 43263288dd
commit 66c0b4461a

View File

@ -1,36 +1,36 @@
/** @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>
Portions copyright (c) 2008-2009, Apple Inc. All rights reserved.
Copyright (c) 2007, Intel Corporation<BR>
Portions copyright (c) 2008-2009, Apple Inc. All rights reserved.
All rights reserved. This program and the accompanying materials
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
http://opensource.org/licenses/bsd-license.php
All rights reserved. This program and the accompanying materials
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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
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.
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 insensative and only check the leading characters for
unique matches. Thus the following are all the same:
LoadFile0:
l0:
L0:
Lo0:
Device names are case insensative 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
10.0.1.102: - TFTP service IP followed by the file name
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
10.0.1.102: - TFTP service IP followed by the file name
**/
#include <PiDxe.h>
@ -89,12 +89,12 @@ 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 FALSE File is not valid
@return TRUE File is valid
@return FALSE File is not valid
**/
@ -116,9 +116,9 @@ FileHandleValid (
}
/**
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
@ -132,7 +132,7 @@ EblFreePool (
}
/**
Update Device List Global Variables
Update Device List Global Variables
**/
VOID
@ -206,17 +206,17 @@ EblUpdateDeviceLists (
/**
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
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
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
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
@param PathName PathName to check
@param FileStart Index of the first character of the <path>
@param MatchIndex Index in mFsInfo[] that matches
@param PathName PathName to check
@param FileStart Index of the first character of the <path>
@param MatchIndex Index in mFsInfo[] that matches
@return TRUE PathName matches a Volume Label and MatchIndex is valid
@return FALSE PathName does not match a Volume Label MatchIndex undefined
@return TRUE PathName matches a Volume Label and MatchIndex is valid
@return FALSE PathName does not match a Volume Label MatchIndex undefined
**/
BOOLEAN
@ -261,11 +261,11 @@ 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
@ -324,13 +324,13 @@ ConvertIpStringToEfiIp (
/**
Internal work function to extract a device number from a string skipping
text. Easy way to extract numbers from strings like blk7:.
Internal work function to extract a device number from a string skipping
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 Device #
@return -1 Device string is not valid
@return Device #
**/
UINTN
@ -356,10 +356,10 @@ 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 FileName Name of file after device stripped off
@param File Open file handle
@param FileName Name of file after device stripped off
**/
@ -492,10 +492,10 @@ 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 FileName Name of file after device stripped off
@param File Open file handle
@param FileName Name of file after device stripped off
**/
@ -606,7 +606,7 @@ EblFvFileDevicePath (
Status = File->Fv->ReadSection (
File->Fv,
&File->FvNameGuid,
OpenMode,
(EFI_SECTION_TYPE)OpenMode,
0,
&Section,
&File->Size,
@ -631,22 +631,22 @@ EblFvFileDevicePath (
/**
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
syntax. There is no checking to prevent a file from being opened more than
one type.
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
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.
SectionType is only used to open an FV. Each file in an FV contains multiple
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 OpenMode Same as EFI_FILE.Open()
@param SectionType Section in FV to open.
@param PathName Path to parse to open
@param OpenMode Same as EFI_FILE.Open()
@param SectionType Section in FV to open.
@return NULL Open failed
@return Valid EFI_OPEN_FILE handle
@return NULL Open failed
@return Valid EFI_OPEN_FILE handle
**/
EFI_OPEN_FILE *
@ -782,7 +782,7 @@ EfiOpen (
if (PathName[Index] == ':') {
// Support fv0:\DxeCore:0x10
// 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';
}
}
@ -1000,13 +1000,13 @@ 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 Index Device Index to use. Zero relative.
@param DeviceType Device type to open
@param Index Device Index to use. Zero relative.
@return NULL Open failed
@return Valid EFI_OPEN_FILE handle
@return NULL Open failed
@return Valid EFI_OPEN_FILE handle
**/
EFI_OPEN_FILE *
@ -1045,13 +1045,13 @@ EfiDeviceOpenByType (
/**
Close a file handle opened by EfiOpen() and free all resources allocated by
EfiOpen().
Close a file handle opened by EfiOpen() and free all resources allocated by
EfiOpen().
@param Stream Open File Handle
@param Stream Open File Handle
@return EFI_INVALID_PARAMETER Stream is not an Open File
@return EFI_SUCCESS Steam closed
@return EFI_INVALID_PARAMETER Stream is not an Open File
@return EFI_SUCCESS Steam closed
**/
EFI_STATUS
@ -1109,13 +1109,13 @@ EfiClose (
/**
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.
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.
@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
@ -1172,24 +1172,24 @@ EfiTell (
/**
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
EfiSeek().
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
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.
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.
@param Stream Open File Handle
@param Offset Offset to seek too.
@param SeekType Type of seek to perform
@param Stream Open File Handle
@param Offset Offset to seek too.
@param SeekType Type of seek to perform
@return EFI_INVALID_PARAMETER Stream is not an Open File
@return EFI_UNSUPPORTED LoadFile and FV doe not support Seek
@return EFI_NOT_FOUND Seek past the end of the file.
@return EFI_SUCCESS Steam closed
@return EFI_INVALID_PARAMETER Stream is not an Open File
@return EFI_UNSUPPORTED LoadFile and FV doe not support Seek
@return EFI_NOT_FOUND Seek past the end of the file.
@return EFI_SUCCESS Steam closed
**/
EFI_STATUS
@ -1297,19 +1297,19 @@ CacheTftpFile (
}
/**
Read BufferSize bytes from the current locaiton in the file. For load file,
FV, and TFTP case you must read the entire file.
Read BufferSize bytes from the current locaiton in the file. For load file,
FV, and TFTP case you must read the entire file.
@param Stream Open File Handle
@param Buffer Caller allocated buffer.
@param BufferSize Size of buffer in bytes.
@param Stream Open File Handle
@param Buffer Caller allocated buffer.
@param BufferSize Size of buffer in bytes.
@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_INVALID_PARAMETER Stream is not an open file handle
@return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read
@return "other" Error returned from device read
@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_INVALID_PARAMETER Stream is not an open file handle
@return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read
@return "other" Error returned from device read
**/
EFI_STATUS
@ -1425,22 +1425,22 @@ EfiRead (
/**
Read the entire file into a buffer. This routine allocates the buffer and
returns it to the user full of the read data.
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
must be.
This is very useful for load flie where it's hard to know how big the buffer
must be.
@param Stream Open File Handle
@param Buffer Pointer to buffer to return.
@param BufferSize Pointer to Size of buffer return..
@param Stream Open File Handle
@param Buffer Pointer to buffer to return.
@param BufferSize Pointer to Size of buffer return..
@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_INVALID_PARAMETER Stream is not an open file handle
@return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read
@return "other" Error returned from device read
@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_INVALID_PARAMETER Stream is not an open file handle
@return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read
@return "other" Error returned from device read
**/
EFI_STATUS
@ -1468,18 +1468,18 @@ 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 Buffer Pointer to buffer to return.
@param BufferSize Pointer to Size of buffer return..
@param Stream Open File Handle
@param Buffer Pointer to buffer to return.
@param BufferSize Pointer to Size of buffer return..
@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_INVALID_PARAMETER Stream is not an open file handle
@return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read
@return "other" Error returned from device write
@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_INVALID_PARAMETER Stream is not an open file handle
@return EFI_BUFFER_TOO_SMALL Buffer is not big enough to do the read
@return "other" Error returned from device write
**/
EFI_STATUS
@ -1589,14 +1589,14 @@ EfiWrite (
/**
Given Cwd expand Path to remove .. and replace them with real
directory names.
Given Cwd expand Path to remove .. and replace them with real
directory names.
@param Cwd Current Working Directory
@param Path Path to expand
@param Cwd Current Working Directory
@param Path Path to expand
@return NULL Cwd or Path are not valid
@return 'other' Path with .. expanded
@return NULL Cwd or Path are not valid
@return 'other' Path with .. expanded
**/
CHAR8 *
@ -1666,14 +1666,14 @@ ExpandPath (
/**
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.
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.
@param Cwd Current Working Directory to set
@param Cwd Current Working Directory to set
@return EFI_SUCCESS CWD is set
@return EFI_INVALID_PARAMETER Cwd is not a valid device:path
@return EFI_SUCCESS CWD is set
@return EFI_INVALID_PARAMETER Cwd is not a valid device:path
**/
EFI_STATUS
@ -1729,13 +1729,6 @@ EfiSetCwd (
if (gCwd == NULL) {
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) {
@ -1746,17 +1739,17 @@ EfiSetCwd (
/**
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 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.
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 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.
@param Cwd Current Working Directory
@param Cwd Current Working Directory
@return "" No CWD set
@return 'other' Returns buffer that contains CWD.
@return "" No CWD set
@return 'other' Returns buffer that contains CWD.
**/
CHAR8 *