summaryrefslogtreecommitdiff
path: root/ShellPkg/Library
diff options
context:
space:
mode:
authorjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>2009-05-11 18:02:16 +0000
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>2009-05-11 18:02:16 +0000
commitd2b4564ba50b095d5a5e00b9c7bebef004967d5e (patch)
treef646839a453fb83c6c094a876bcbbfac5916834a /ShellPkg/Library
parent446b94b0a1b98635d7db21d67fff158c6f153de4 (diff)
downloadedk2-platforms-d2b4564ba50b095d5a5e00b9c7bebef004967d5e.tar.xz
fixed to build under IPF.
Refactored some commands into FileHandleLib since they are used in many binaries. Added .h for GUID that was missing. Added PCD for initialization of shell apps and shell itself in shell library interaction. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8295 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ShellPkg/Library')
-rw-r--r--ShellPkg/Library/BaseFileHandleLib/BaseFileHandleLib.c623
-rw-r--r--ShellPkg/Library/BaseFileHandleLib/BaseFileHandleLib.inf49
-rw-r--r--ShellPkg/Library/BaseShellLib/BaseShellLib.c662
-rw-r--r--ShellPkg/Library/BaseShellLib/BaseShellLib.h26
-rw-r--r--ShellPkg/Library/BaseShellLib/BaseShellLib.inf4
5 files changed, 952 insertions, 412 deletions
diff --git a/ShellPkg/Library/BaseFileHandleLib/BaseFileHandleLib.c b/ShellPkg/Library/BaseFileHandleLib/BaseFileHandleLib.c
new file mode 100644
index 0000000000..6822b748b4
--- /dev/null
+++ b/ShellPkg/Library/BaseFileHandleLib/BaseFileHandleLib.c
@@ -0,0 +1,623 @@
+/** @file
+ Provides interface to EFI_FILE_HANDLE functionality.
+
+Copyright (c) 2006 - 2009, Intel Corporation
+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.
+
+**/
+
+#include <Uefi.h>
+
+#include <Library/ShellLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+
+#include <Protocol/SimpleFileSystem.h>
+
+#define MAX_FILE_NAME_LEN 522 // (20 * (6+5+2))+1) unicode characters from EFI FAT spec (doubled for bytes)
+#define FIND_XXXXX_FILE_BUFFER_SIZE (SIZE_OF_EFI_FILE_INFO + MAX_FILE_NAME_LEN)
+
+/**
+ This function will retrieve the information about the file for the handle
+ specified and store it in allocated pool memory.
+
+ This function allocates a buffer to store the file’s information. It is the
+ caller’s responsibility to free the buffer
+
+ @param FileHandle The file handle of the file for which information is
+ being requested.
+
+ @retval NULL information could not be retrieved.
+
+ @return the information about the file
+**/
+EFI_FILE_INFO*
+EFIAPI
+FileHandleGetInfo (
+ IN EFI_FILE_HANDLE FileHandle
+ )
+{
+ EFI_GUID FileInfoGuid;
+ EFI_FILE_INFO *pFileInfo;
+ UINTN FileInfoSize;
+ EFI_STATUS Status;
+
+ //
+ // ASSERT if FileHandle is NULL
+ //
+ ASSERT (FileHandle != NULL);
+
+ //
+ // Get the required size to allocate
+ //
+ FileInfoGuid = gEfiFileInfoGuid;
+ FileInfoSize = 0;
+ pFileInfo = NULL;
+ Status = FileHandle->GetInfo(FileHandle,
+ &FileInfoGuid,
+ &FileInfoSize,
+ pFileInfo);
+ //
+ // error is expected. getting size to allocate
+ //
+ ASSERT (Status == EFI_BUFFER_TOO_SMALL);
+ pFileInfo = AllocateZeroPool(FileInfoSize);
+ ASSERT (pFileInfo != NULL);
+ //
+ // now get the information
+ //
+ Status = FileHandle->GetInfo(FileHandle,
+ &FileInfoGuid,
+ &FileInfoSize,
+ pFileInfo);
+ //
+ // if we got an error free the memory and return NULL
+ //
+ if (EFI_ERROR(Status)) {
+ FreePool(pFileInfo);
+ return NULL;
+ }
+ return (pFileInfo);
+}
+
+/**
+ This function will set the information about the file for the opened handle
+ specified.
+
+ @param FileHandle The file handle of the file for which information
+ is being set
+
+ @param FileInfo The infotmation to set.
+
+ @retval EFI_SUCCESS The information was set.
+ @retval EFI_UNSUPPORTED The InformationType is not known.
+ @retval EFI_NO_MEDIA The device has no medium.
+ @retval EFI_DEVICE_ERROR The device reported an error.
+ @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
+ @retval EFI_WRITE_PROTECTED The file or medium is write protected.
+ @retval EFI_ACCESS_DENIED The file was opened read only.
+ @retval EFI_VOLUME_FULL The volume is full.
+**/
+EFI_STATUS
+EFIAPI
+FileHandleSetInfo (
+ IN EFI_FILE_HANDLE FileHandle,
+ IN CONST EFI_FILE_INFO *FileInfo
+ )
+{
+ EFI_GUID FileInfoGuid;
+
+ //
+ // ASSERT if the FileHandle or FileInfo is NULL
+ //
+ ASSERT (FileHandle != NULL);
+ ASSERT (FileInfo != NULL);
+
+ FileInfoGuid = gEfiFileInfoGuid;
+ //
+ // Set the info
+ //
+ return (FileHandle->SetInfo(FileHandle,
+ &FileInfoGuid,
+ (UINTN)FileInfo->Size,
+ (EFI_FILE_INFO*)FileInfo));
+}
+
+/**
+ This function reads information from an opened file.
+
+ If FileHandle is not a directory, the function reads the requested number of
+ bytes from the file at the file’s current position and returns them in Buffer.
+ If the read goes beyond the end of the file, the read length is truncated to the
+ end of the file. The file’s current position is increased by the number of bytes
+ returned. If FileHandle is a directory, the function reads the directory entry
+ at the file’s current position and returns the entry in Buffer. If the Buffer
+ is not large enough to hold the current directory entry, then
+ EFI_BUFFER_TOO_SMALL is returned and the current file position is not updated.
+ BufferSize is set to be the size of the buffer needed to read the entry. On
+ success, the current position is updated to the next directory entry. If there
+ are no more directory entries, the read returns a zero-length buffer.
+ EFI_FILE_INFO is the structure returned as the directory entry.
+
+ @param FileHandle the opened file handle
+ @param BufferSize on input the size of buffer in bytes. on return
+ the number of bytes written.
+ @param Buffer the buffer to put read data into.
+
+ @retval EFI_SUCCESS Data was read.
+ @retval EFI_NO_MEDIA The device has no media.
+ @retval EFI_DEVICE_ERROR The device reported an error.
+ @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
+ @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required
+ size.
+
+**/
+EFI_STATUS
+EFIAPI
+FileHandleRead(
+ IN EFI_FILE_HANDLE FileHandle,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
+ )
+{
+ //
+ // ASSERT if FileHandle is NULL
+ //
+ ASSERT (FileHandle != NULL);
+
+ //
+ // Perform the read based on EFI_FILE_PROTOCOL
+ //
+ return (FileHandle->Read(FileHandle, BufferSize, Buffer));
+}
+
+
+/**
+ Write data to a file.
+
+ This function writes the specified number of bytes to the file at the current
+ file position. The current file position is advanced the actual number of bytes
+ written, which is returned in BufferSize. Partial writes only occur when there
+ has been a data error during the write attempt (such as “volume space full”).
+ The file is automatically grown to hold the data if required. Direct writes to
+ opened directories are not supported.
+
+ @param FileHandle The opened file for writing
+ @param BufferSize on input the number of bytes in Buffer. On output
+ the number of bytes written.
+ @param Buffer the buffer containing data to write is stored.
+
+ @retval EFI_SUCCESS Data was written.
+ @retval EFI_UNSUPPORTED Writes to an open directory are not supported.
+ @retval EFI_NO_MEDIA The device has no media.
+ @retval EFI_DEVICE_ERROR The device reported an error.
+ @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
+ @retval EFI_WRITE_PROTECTED The device is write-protected.
+ @retval EFI_ACCESS_DENIED The file was open for read only.
+ @retval EFI_VOLUME_FULL The volume is full.
+**/
+EFI_STATUS
+EFIAPI
+FileHandleWrite(
+ IN EFI_FILE_HANDLE FileHandle,
+ IN OUT UINTN *BufferSize,
+ IN VOID *Buffer
+ )
+{
+ //
+ // ASSERT if FileHandle is NULL
+ //
+ ASSERT (FileHandle != NULL);
+ //
+ // Perform the write based on EFI_FILE_PROTOCOL
+ //
+ return (FileHandle->Write(FileHandle, BufferSize, Buffer));
+}
+
+/**
+ Close an open file handle.
+
+ This function closes a specified file handle. All “dirty” cached file data is
+ flushed to the device, and the file is closed. In all cases the handle is
+ closed.
+
+@param FileHandle the file handle to close.
+
+@retval EFI_SUCCESS the file handle was closed sucessfully.
+**/
+EFI_STATUS
+EFIAPI
+FileHandleClose (
+ IN EFI_FILE_HANDLE FileHandle
+ )
+{
+ EFI_STATUS Status;
+ //
+ // ASSERT if FileHandle is NULL
+ //
+ ASSERT (FileHandle != NULL);
+ //
+ // Perform the Close based on EFI_FILE_PROTOCOL
+ //
+ Status = FileHandle->Close(FileHandle);
+ return Status;
+}
+
+/**
+ Delete a file and close the handle
+
+ This function closes and deletes a file. In all cases the file handle is closed.
+ If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is
+ returned, but the handle is still closed.
+
+ @param FileHandle the file handle to delete
+
+ @retval EFI_SUCCESS the file was closed sucessfully
+ @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not
+ deleted
+ @retval INVALID_PARAMETER One of the parameters has an invalid value.
+**/
+EFI_STATUS
+EFIAPI
+FileHandleDelete (
+ IN EFI_FILE_HANDLE FileHandle
+ )
+{
+ EFI_STATUS Status;
+ //
+ // ASSERT if FileHandle is NULL
+ //
+ ASSERT (FileHandle != NULL);
+ //
+ // Perform the Delete based on EFI_FILE_PROTOCOL
+ //
+ Status = FileHandle->Delete(FileHandle);
+ return Status;
+}
+
+/**
+ Set the current position in a file.
+
+ This function sets the current file position for the handle to the position
+ supplied. With the exception of seeking to position 0xFFFFFFFFFFFFFFFF, only
+ absolute positioning is supported, and seeking past the end of the file is
+ allowed (a subsequent write would grow the file). Seeking to position
+ 0xFFFFFFFFFFFFFFFF causes the current position to be set to the end of the file.
+ If FileHandle is a directory, the only position that may be set is zero. This
+ has the effect of starting the read process of the directory entries over.
+
+ @param FileHandle The file handle on which the position is being set
+ @param Position Byte position from begining of file
+
+ @retval EFI_SUCCESS Operation completed sucessfully.
+ @retval EFI_UNSUPPORTED the seek request for non-zero is not valid on
+ directories.
+ @retval INVALID_PARAMETER One of the parameters has an invalid value.
+**/
+EFI_STATUS
+EFIAPI
+FileHandleSetPosition (
+ IN EFI_FILE_HANDLE FileHandle,
+ IN UINT64 Position
+ )
+{
+ //
+ // ASSERT if FileHandle is NULL
+ //
+ ASSERT (FileHandle != NULL);
+ //
+ // Perform the SetPosition based on EFI_FILE_PROTOCOL
+ //
+ return (FileHandle->SetPosition(FileHandle, Position));
+}
+
+/**
+ Gets a file's current position
+
+ This function retrieves the current file position for the file handle. For
+ directories, the current file position has no meaning outside of the file
+ system driver and as such the operation is not supported. An error is returned
+ if FileHandle is a directory.
+
+ @param FileHandle The open file handle on which to get the position.
+ @param Position Byte position from begining of file.
+
+ @retval EFI_SUCCESS the operation completed sucessfully.
+ @retval INVALID_PARAMETER One of the parameters has an invalid value.
+ @retval EFI_UNSUPPORTED the request is not valid on directories.
+**/
+EFI_STATUS
+EFIAPI
+FileHandleGetPosition (
+ IN EFI_FILE_HANDLE FileHandle,
+ OUT UINT64 *Position
+ )
+{
+ //
+ // ASSERT if FileHandle is NULL
+ //
+ ASSERT (FileHandle != NULL);
+ //
+ // Perform the GetPosition based on EFI_FILE_PROTOCOL
+ //
+ return (FileHandle->GetPosition(FileHandle, Position));
+}
+/**
+ Flushes data on a file
+
+ This function flushes all modified data associated with a file to a device.
+
+ @param FileHandle The file handle on which to flush data
+
+ @retval EFI_SUCCESS The data was flushed.
+ @retval EFI_NO_MEDIA The device has no media.
+ @retval EFI_DEVICE_ERROR The device reported an error.
+ @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
+ @retval EFI_WRITE_PROTECTED The file or medium is write protected.
+ @retval EFI_ACCESS_DENIED The file was opened for read only.
+**/
+EFI_STATUS
+EFIAPI
+FileHandleFlush (
+ IN EFI_FILE_HANDLE FileHandle
+ )
+{
+ //
+ // ASSERT if FileHandle is NULL
+ //
+ ASSERT (FileHandle != NULL);
+ //
+ // Perform the Flush based on EFI_FILE_PROTOCOL
+ //
+ return (FileHandle->Flush(FileHandle));
+}
+
+/**
+ function to determine if a given handle is a directory handle
+
+ if DirHandle is NULL then ASSERT()
+
+ open the file information on the DirHandle and verify that the Attribute
+ includes EFI_FILE_DIRECTORY bit set.
+
+ @param DirHandle Handle to open file
+
+ @retval EFI_SUCCESS DirHandle is a directory
+ @retval EFI_INVALID_PARAMETER DirHandle did not have EFI_FILE_INFO available
+ @retval EFI_NOT_FOUND DirHandle is not a directory
+**/
+EFI_STATUS
+EFIAPI
+FileHandleIsDirectory (
+ IN EFI_FILE_HANDLE DirHandle
+ )
+{
+ EFI_FILE_INFO *DirInfo;
+
+ //
+ // ASSERT if DirHandle is NULL
+ //
+ ASSERT(DirHandle != NULL);
+
+ //
+ // get the file information for DirHandle
+ //
+ DirInfo = FileHandleGetInfo (DirHandle);
+
+ //
+ // Parse DirInfo
+ //
+ if (DirInfo == NULL) {
+ //
+ // We got nothing...
+ //
+ return (EFI_INVALID_PARAMETER);
+ }
+ if ((DirInfo->Attribute & EFI_FILE_DIRECTORY) == 0) {
+ //
+ // Attributes say this is not a directory
+ //
+ FreePool (DirInfo);
+ return (EFI_NOT_FOUND);
+ }
+ //
+ // all good...
+ //
+ FreePool (DirInfo);
+ return (EFI_SUCCESS);
+}
+
+/**
+ Retrieves the first file from a directory
+
+ This function opens a directory and gets the first file’s info in the
+ directory. Caller can use FileHandleFindNextFile() to get other files. When
+ complete the caller is responsible for calling FreePool() on Buffer.
+
+ @param DirHandle The file handle of the directory to search
+ @param Buffer Pointer to buffer for file's information
+
+ @retval EFI_SUCCESS Found the first file.
+ @retval EFI_NOT_FOUND Cannot find the directory.
+ @retval EFI_NO_MEDIA The device has no media.
+ @retval EFI_DEVICE_ERROR The device reported an error.
+ @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
+ @return Others status of FileHandleGetInfo, FileHandleSetPosition,
+ or FileHandleRead
+**/
+EFI_STATUS
+EFIAPI
+FileHandleFindFirstFile (
+ IN EFI_FILE_HANDLE DirHandle,
+ OUT EFI_FILE_INFO **Buffer
+ )
+{
+ EFI_STATUS Status;
+ UINTN BufferSize;
+
+ //
+ // ASSERTs
+ //
+ ASSERT (DirHandle != NULL);
+ ASSERT (Buffer != NULL);
+
+ //
+ // verify that DirHandle is a directory
+ //
+ Status = FileHandleIsDirectory(DirHandle);
+ if (EFI_ERROR(Status)) {
+ return (Status);
+ }
+
+ //
+ // reset to the begining of the directory
+ //
+ Status = FileHandleSetPosition(DirHandle, 0);
+ if (EFI_ERROR(Status)) {
+ return (Status);
+ }
+
+ //
+ // Allocate a buffer sized to struct size + enough for the string at the end
+ //
+ BufferSize = FIND_XXXXX_FILE_BUFFER_SIZE;
+ *Buffer = AllocateZeroPool(BufferSize);
+ ASSERT (*Buffer != NULL);
+
+ //
+ // read in the info about the first file
+ //
+ Status = FileHandleRead (DirHandle, &BufferSize, *Buffer);
+ ASSERT(Status != EFI_BUFFER_TOO_SMALL);
+ if (EFI_ERROR(Status)) {
+ FreePool(*Buffer);
+ *Buffer = NULL;
+ return (Status);
+ }
+ return (EFI_SUCCESS);
+}
+/**
+ Retrieves the next file in a directory.
+
+ To use this function, caller must call the FileHandleFindFirstFile() to get the
+ first file, and then use this function get other files. This function can be
+ called for several times to get each file's information in the directory. If
+ the call of FileHandleFindNextFile() got the last file in the directory, the next
+ call of this function has no file to get. *NoFile will be set to TRUE and the
+ Buffer memory will be automatically freed.
+
+ @param DirHandle the file handle of the directory
+ @param Buffer pointer to buffer for file's information
+ @param NoFile pointer to boolean when last file is found
+
+ @retval EFI_SUCCESS Found the next file, or reached last file
+ @retval EFI_NO_MEDIA The device has no media.
+ @retval EFI_DEVICE_ERROR The device reported an error.
+ @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
+**/
+EFI_STATUS
+EFIAPI
+FileHandleFindNextFile(
+ IN EFI_FILE_HANDLE DirHandle,
+ OUT EFI_FILE_INFO *Buffer,
+ OUT BOOLEAN *NoFile
+ )
+{
+ EFI_STATUS Status;
+ UINTN BufferSize;
+
+ //
+ // ASSERTs for DirHandle or Buffer or NoFile poitners being NULL
+ //
+ ASSERT (DirHandle != NULL);
+ ASSERT (Buffer != NULL);
+ ASSERT (NoFile != NULL);
+
+ //
+ // verify that DirHandle is a directory
+ //
+ Status = FileHandleIsDirectory(DirHandle);
+ if (EFI_ERROR(Status)) {
+ return (Status);
+ }
+
+ //
+ // This BufferSize MUST stay equal to the originally allocated one in GetFirstFile
+ //
+ BufferSize = FIND_XXXXX_FILE_BUFFER_SIZE;
+
+ //
+ // read in the info about the next file
+ //
+ Status = FileHandleRead (DirHandle, &BufferSize, Buffer);
+ ASSERT(Status != EFI_BUFFER_TOO_SMALL);
+ if (EFI_ERROR(Status)) {
+ return (Status);
+ }
+
+ //
+ // If we read 0 bytes (but did not have erros) we already read in the last file.
+ //
+ if (BufferSize == 0) {
+ FreePool(Buffer);
+ *NoFile = TRUE;
+ }
+
+ return (EFI_SUCCESS);
+}
+/**
+ Retrieve the size of a file.
+
+ if FileHandle is NULL then ASSERT()
+ if Size is NULL then ASSERT()
+
+ This function extracts the file size info from the FileHandle’s EFI_FILE_INFO
+ data.
+
+ @param FileHandle file handle from which size is retrieved
+ @param Size pointer to size
+
+ @retval EFI_SUCCESS operation was completed sucessfully
+ @retval EFI_DEVICE_ERROR cannot access the file
+**/
+EFI_STATUS
+EFIAPI
+FileHandleGetSize (
+ IN EFI_FILE_HANDLE FileHandle,
+ OUT UINT64 *Size
+ )
+{
+ EFI_FILE_INFO *FileInfo;
+
+ //
+ // ASSERT for FileHandle or Size being NULL
+ //
+ ASSERT (FileHandle != NULL);
+ ASSERT (Size != NULL);
+
+ //
+ // get the FileInfo structure
+ //
+ FileInfo = FileHandleGetInfo(FileHandle);
+ if (FileInfo == NULL) {
+ return (EFI_DEVICE_ERROR);
+ }
+
+ //
+ // Assign the Size pointer to the correct value
+ //
+ *Size = FileInfo->FileSize;
+
+ //
+ // free the FileInfo memory
+ //
+ FreePool(FileInfo);
+
+ return (EFI_SUCCESS);
+} \ No newline at end of file
diff --git a/ShellPkg/Library/BaseFileHandleLib/BaseFileHandleLib.inf b/ShellPkg/Library/BaseFileHandleLib/BaseFileHandleLib.inf
new file mode 100644
index 0000000000..48489b405a
--- /dev/null
+++ b/ShellPkg/Library/BaseFileHandleLib/BaseFileHandleLib.inf
@@ -0,0 +1,49 @@
+#/** @file
+# Provides interface to shell functionality for shell commands and applications.
+#
+# Copyright (c) 2006 - 2009, Intel Corporation.
+#
+# 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010006
+ BASE_NAME = BaseFileHandleLib
+ FILE_GUID = 9495D344-9D8A-41f3-8D17-E2FD238C4E71
+ MODULE_TYPE = UEFI_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = FileHandleLib|UEFI_APPLICATION UEFI_DRIVER
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ BaseFileHandleLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ ShellPkg/ShellPkg.dec
+
+[LibraryClasses]
+ UefiBootServicesTableLib
+ MemoryAllocationLib
+ DevicePathLib
+ BaseLib
+ BaseMemoryLib
+ DebugLib
+
+[Protocols]
+
+[Guids]
+ gEfiFileInfoGuid # ALWAYS_CONSUMED
+
+[Pcd.common]
+
diff --git a/ShellPkg/Library/BaseShellLib/BaseShellLib.c b/ShellPkg/Library/BaseShellLib/BaseShellLib.c
index 205974d519..a0e2e492e1 100644
--- a/ShellPkg/Library/BaseShellLib/BaseShellLib.c
+++ b/ShellPkg/Library/BaseShellLib/BaseShellLib.c
@@ -20,21 +20,35 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/DevicePathLib.h>
+#include <Library/PcdLib.h>
+#include <Library/FileHandleLib.h>
#include <Protocol/EfiShellEnvironment2.h>
#include <Protocol/EfiShellInterface.h>
#include <Protocol/EfiShell.h>
#include <Protocol/EfiShellParameters.h>
#include <Protocol/SimpleFileSystem.h>
+#include "BaseShellLib.h"
+
#define MAX_FILE_NAME_LEN 522 // (20 * (6+5+2))+1) unicode characters from EFI FAT spec (doubled for bytes)
#define FIND_XXXXX_FILE_BUFFER_SIZE (SIZE_OF_EFI_FILE_INFO + MAX_FILE_NAME_LEN)
-EFI_SHELL_ENVIRONMENT2 *mEfiShellEnvironment2;
-EFI_SHELL_INTERFACE *mEfiShellInterface;
-EFI_SHELL_PROTOCOL *mEfiShellProtocol;
-EFI_SHELL_PARAMETERS_PROTOCOL *mEfiShellParametersProtocol;
-EFI_HANDLE mEfiShellEnvironment2Handle;
-EFI_LIST_ENTRY *mOldStyleFileList;
+//
+// This is not static since it's extern in the .h file
+//
+SHELL_PARAM_ITEM EmptyParamList[] = {
+ {NULL, TypeMax}
+ };
+
+//
+// Static file globals for the shell library
+//
+STATIC EFI_SHELL_ENVIRONMENT2 *mEfiShellEnvironment2;
+STATIC EFI_SHELL_INTERFACE *mEfiShellInterface;
+STATIC EFI_SHELL_PROTOCOL *mEfiShellProtocol;
+STATIC EFI_SHELL_PARAMETERS_PROTOCOL *mEfiShellParametersProtocol;
+STATIC EFI_HANDLE mEfiShellEnvironment2Handle;
+STATIC FILE_HANDLE_FUNCTION_MAP FileFunctionMap;
/**
helper function to find ShellEnvironment2 for constructor
@@ -112,36 +126,14 @@ ShellFindSE2 (
return (Status);
}
-/**
- Constructor for the Shell library.
-
- Initialize the library and determine if the underlying is a UEFI Shell 2.0 or an EFI shell.
-
- @param ImageHandle the image handle of the process
- @param SystemTable the EFI System Table pointer
-
- @retval EFI_SUCCESS the initialization was complete sucessfully
- @return others an error ocurred during initialization
-**/
EFI_STATUS
EFIAPI
-ShellLibConstructor (
+ShellLibConstructorWorker (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
- )
-{
+){
EFI_STATUS Status;
- ASSERT(SystemTable != NULL);
- ASSERT(gBS != NULL);
-
- mEfiShellEnvironment2 = NULL;
- mEfiShellProtocol = NULL;
- mEfiShellParametersProtocol = NULL;
- mEfiShellInterface = NULL;
- mEfiShellEnvironment2Handle = NULL;
- mOldStyleFileList = NULL;
-
//
// UEFI 2.0 shell interfaces (used preferentially)
//
@@ -192,10 +184,69 @@ ShellLibConstructor (
//
if ((mEfiShellEnvironment2 != NULL && mEfiShellInterface != NULL) ||
(mEfiShellProtocol != NULL && mEfiShellParametersProtocol != NULL) ) {
+ if (mEfiShellProtocol != NULL) {
+ FileFunctionMap.GetFileInfo = mEfiShellProtocol->GetFileInfo;
+ FileFunctionMap.SetFileInfo = mEfiShellProtocol->SetFileInfo;
+ FileFunctionMap.ReadFile = mEfiShellProtocol->ReadFile;
+ FileFunctionMap.WriteFile = mEfiShellProtocol->WriteFile;
+ FileFunctionMap.CloseFile = mEfiShellProtocol->CloseFile;
+ FileFunctionMap.DeleteFile = mEfiShellProtocol->DeleteFile;
+ FileFunctionMap.GetFilePosition = mEfiShellProtocol->GetFilePosition;
+ FileFunctionMap.SetFilePosition = mEfiShellProtocol->SetFilePosition;
+ FileFunctionMap.FlushFile = mEfiShellProtocol->FlushFile;
+ FileFunctionMap.GetFileSize = mEfiShellProtocol->GetFileSize;
+ } else {
+ FileFunctionMap.GetFileInfo = FileHandleGetInfo;
+ FileFunctionMap.SetFileInfo = FileHandleSetInfo;
+ FileFunctionMap.ReadFile = FileHandleRead;
+ FileFunctionMap.WriteFile = FileHandleWrite;
+ FileFunctionMap.CloseFile = FileHandleClose;
+ FileFunctionMap.DeleteFile = FileHandleDelete;
+ FileFunctionMap.GetFilePosition = FileHandleGetPosition;
+ FileFunctionMap.SetFilePosition = FileHandleSetPosition;
+ FileFunctionMap.FlushFile = FileHandleFlush;
+ FileFunctionMap.GetFileSize = FileHandleGetSize;
+ }
return (EFI_SUCCESS);
}
return (EFI_NOT_FOUND);
}
+/**
+ Constructor for the Shell library.
+
+ Initialize the library and determine if the underlying is a UEFI Shell 2.0 or an EFI shell.
+
+ @param ImageHandle the image handle of the process
+ @param SystemTable the EFI System Table pointer
+
+ @retval EFI_SUCCESS the initialization was complete sucessfully
+ @return others an error ocurred during initialization
+**/
+EFI_STATUS
+EFIAPI
+ShellLibConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+
+
+ mEfiShellEnvironment2 = NULL;
+ mEfiShellProtocol = NULL;
+ mEfiShellParametersProtocol = NULL;
+ mEfiShellInterface = NULL;
+ mEfiShellEnvironment2Handle = NULL;
+
+ ///@todo make a worker constructor so initialize function works
+ //
+ // verify that auto initialize is not set false
+ //
+ if (PcdGetBool(PcdShellLibAutoInitialize) == 0) {
+ return (EFI_SUCCESS);
+ }
+
+ return (ShellLibConstructorWorker(ImageHandle, SystemTable));
+}
/**
Destructory for the library. free any resources.
@@ -212,27 +263,68 @@ ShellLibDestructor (
&gEfiShellEnvironment2Guid,
ImageHandle,
NULL);
+ mEfiShellEnvironment2 = NULL;
}
if (mEfiShellInterface != NULL) {
gBS->CloseProtocol(ImageHandle,
&gEfiShellInterfaceGuid,
ImageHandle,
NULL);
+ mEfiShellInterface = NULL;
}
if (mEfiShellProtocol != NULL) {
gBS->CloseProtocol(ImageHandle,
&gEfiShellProtocolGuid,
ImageHandle,
- NULL);
+ NULL);
+ mEfiShellProtocol = NULL;
}
if (mEfiShellParametersProtocol != NULL) {
gBS->CloseProtocol(ImageHandle,
&gEfiShellParametersProtocolGuid,
ImageHandle,
NULL);
+ mEfiShellParametersProtocol = NULL;
}
+ mEfiShellEnvironment2Handle = NULL;
return (EFI_SUCCESS);
}
+
+/**
+ This function causes the shell library to initialize itself. If the shell library
+ is already initialized it will de-initialize all the current protocol poitners and
+ re-populate them again.
+
+ When the library is used with PcdShellLibAutoInitialize set to true this function
+ will return EFI_SUCCESS and perform no actions.
+
+ This function is intended for internal access for shell commands only.
+
+ @retval EFI_SUCCESS the initialization was complete sucessfully
+
+**/
+EFI_STATUS
+EFIAPI
+ShellInitialize (
+ ) {
+ //
+ // if auto initialize is not false then skip
+ //
+ if (PcdGetBool(PcdShellLibAutoInitialize) != 0) {
+ return (EFI_SUCCESS);
+ }
+
+ //
+ // deinit the current stuff
+ //
+ ASSERT_EFI_ERROR(ShellLibDestructor(gImageHandle, gST));
+
+ //
+ // init the new stuff
+ //
+ return (ShellLibConstructorWorker(gImageHandle, gST));
+}
+
/**
This function will retrieve the information about the file for the handle
specified and store it in allocated pool memory.
@@ -253,47 +345,7 @@ ShellGetFileInfo (
IN EFI_FILE_HANDLE FileHandle
)
{
- EFI_GUID FileInfoGuid;
- EFI_FILE_INFO *pFileInfo;
- UINTN FileInfoSize;
- EFI_STATUS Status;
-
- //
- // ASSERT if FileHandle is NULL
- //
- ASSERT (FileHandle != NULL);
-
- //
- // Get the required size to allocate
- //
- FileInfoGuid = gEfiFileInfoGuid;
- FileInfoSize = 0;
- pFileInfo = NULL;
- Status = FileHandle->GetInfo(FileHandle,
- &FileInfoGuid,
- &FileInfoSize,
- pFileInfo);
- //
- // error is expected. getting size to allocate
- //
- ASSERT (Status == EFI_BUFFER_TOO_SMALL);
- pFileInfo = AllocateZeroPool(FileInfoSize);
- ASSERT (pFileInfo != NULL);
- //
- // now get the information
- //
- Status = FileHandle->GetInfo(FileHandle,
- &FileInfoGuid,
- &FileInfoSize,
- pFileInfo);
- //
- // if we got an error free the memory and return NULL
- //
- if (EFI_ERROR(Status)) {
- FreePool(pFileInfo);
- return NULL;
- }
- return (pFileInfo);
+ return (FileFunctionMap.GetFileInfo(FileHandle));
}
/**
@@ -321,22 +373,7 @@ ShellSetFileInfo (
IN EFI_FILE_INFO *FileInfo
)
{
- EFI_GUID FileInfoGuid;
-
- //
- // ASSERT if the FileHandle or FileInfo is NULL
- //
- ASSERT (FileHandle != NULL);
- ASSERT (FileInfo != NULL);
-
- FileInfoGuid = gEfiFileInfoGuid;
- //
- // Set the info
- //
- return (FileHandle->SetInfo(FileHandle,
- &FileInfoGuid,
- (UINTN)FileInfo->Size,
- FileInfo));
+ return (FileFunctionMap.SetFileInfo(FileHandle, FileInfo));
}
/**
@@ -404,89 +441,90 @@ ShellOpenFileByDevicePath(
Status = ShellOpenFileByName(FileName, FileHandle, OpenMode, Attributes);
FreePool(FileName);
return (Status);
- } else {
+ }
+
+
+ //
+ // use old shell method.
+ //
+ Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid,
+ FilePath,
+ DeviceHandle);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ Status = gBS->OpenProtocol(*DeviceHandle,
+ &gEfiSimpleFileSystemProtocolGuid,
+ &EfiSimpleFileSystemProtocol,
+ gImageHandle,
+ NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ Status = EfiSimpleFileSystemProtocol->OpenVolume(EfiSimpleFileSystemProtocol, FileHandle);
+ if (EFI_ERROR (Status)) {
+ FileHandle = NULL;
+ return Status;
+ }
+
+ //
+ // go down directories one node at a time.
+ //
+ while (!IsDevicePathEnd (*FilePath)) {
//
- // use old shell method.
+ // For file system access each node should be a file path component
//
- Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid,
- FilePath,
- DeviceHandle);
- if (EFI_ERROR (Status)) {
- return Status;
- }
- Status = gBS->OpenProtocol(*DeviceHandle,
- &gEfiSimpleFileSystemProtocolGuid,
- &EfiSimpleFileSystemProtocol,
- gImageHandle,
- NULL,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL);
- if (EFI_ERROR (Status)) {
- return Status;
- }
- Status = EfiSimpleFileSystemProtocol->OpenVolume(EfiSimpleFileSystemProtocol, FileHandle);
- if (EFI_ERROR (Status)) {
+ if (DevicePathType (*FilePath) != MEDIA_DEVICE_PATH ||
+ DevicePathSubType (*FilePath) != MEDIA_FILEPATH_DP
+ ) {
FileHandle = NULL;
- return Status;
+ return (EFI_INVALID_PARAMETER);
}
+ //
+ // Open this file path node
+ //
+ LastHandle = *FileHandle;
+ *FileHandle = NULL;
//
- // go down directories one node at a time.
+ // Try to test opening an existing file
//
- while (!IsDevicePathEnd (*FilePath)) {
- //
- // For file system access each node should be a file path component
- //
- if (DevicePathType (*FilePath) != MEDIA_DEVICE_PATH ||
- DevicePathSubType (*FilePath) != MEDIA_FILEPATH_DP
- ) {
- FileHandle = NULL;
- return (EFI_INVALID_PARAMETER);
- }
- //
- // Open this file path node
- //
- LastHandle = *FileHandle;
- *FileHandle = NULL;
+ Status = LastHandle->Open (
+ LastHandle,
+ FileHandle,
+ ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName,
+ OpenMode &~EFI_FILE_MODE_CREATE,
+ 0
+ );
- //
- // Try to test opening an existing file
- //
+ //
+ // see if the error was that it needs to be created
+ //
+ if ((EFI_ERROR (Status)) && (OpenMode != (OpenMode &~EFI_FILE_MODE_CREATE))) {
Status = LastHandle->Open (
LastHandle,
FileHandle,
((FILEPATH_DEVICE_PATH*)*FilePath)->PathName,
- OpenMode &~EFI_FILE_MODE_CREATE,
- 0
+ OpenMode,
+ Attributes
);
+ }
+ //
+ // Close the last node
+ //
+ LastHandle->Close (LastHandle);
- //
- // see if the error was that it needs to be created
- //
- if ((EFI_ERROR (Status)) && (OpenMode != (OpenMode &~EFI_FILE_MODE_CREATE))) {
- Status = LastHandle->Open (
- LastHandle,
- FileHandle,
- ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName,
- OpenMode,
- Attributes
- );
- }
- //
- // Close the last node
- //
- LastHandle->Close (LastHandle);
-
- if (EFI_ERROR(Status)) {
- return (Status);
- }
-
- //
- // Get the next node
- //
- *FilePath = NextDevicePathNode (*FilePath);
+ if (EFI_ERROR(Status)) {
+ return (Status);
}
- return (EFI_SUCCESS);
+
+ //
+ // Get the next node
+ //
+ *FilePath = NextDevicePathNode (*FilePath);
}
+ return (EFI_SUCCESS);
}
/**
@@ -544,6 +582,8 @@ ShellOpenFileByName(
return (mEfiShellProtocol->OpenFileByName(FileName,
FileHandle,
OpenMode));
+
+ ///@todo add the attributes
}
//
// Using EFI Shell version
@@ -643,15 +683,7 @@ ShellReadFile(
OUT VOID *Buffer
)
{
- //
- // ASSERT if FileHandle is NULL
- //
- ASSERT (FileHandle != NULL);
-
- //
- // Perform the read based on EFI_FILE_PROTOCOL
- //
- return (FileHandle->Read(FileHandle, BufferSize, Buffer));
+ return (FileFunctionMap.ReadFile(FileHandle, BufferSize, Buffer));
}
@@ -687,14 +719,7 @@ ShellWriteFile(
IN VOID *Buffer
)
{
- //
- // ASSERT if FileHandle is NULL
- //
- ASSERT (FileHandle != NULL);
- //
- // Perform the write based on EFI_FILE_PROTOCOL
- //
- return (FileHandle->Write(FileHandle, BufferSize, Buffer));
+ return (FileFunctionMap.WriteFile(FileHandle, BufferSize, Buffer));
}
/**
@@ -714,18 +739,7 @@ ShellCloseFile (
IN EFI_FILE_HANDLE *FileHandle
)
{
- EFI_STATUS Status;
- //
- // ASSERT if FileHandle is NULL
- //
- ASSERT (FileHandle != NULL);
- ASSERT (*FileHandle != NULL);
- //
- // Perform the Close based on EFI_FILE_PROTOCOL
- //
- Status = (*FileHandle)->Close(*FileHandle);
- *FileHandle = NULL;
- return Status;
+ return (FileFunctionMap.CloseFile(*FileHandle));
}
/**
@@ -748,18 +762,7 @@ ShellDeleteFile (
IN EFI_FILE_HANDLE *FileHandle
)
{
- EFI_STATUS Status;
- //
- // ASSERT if FileHandle is NULL
- //
- ASSERT (FileHandle != NULL);
- ASSERT (*FileHandle != NULL);
- //
- // Perform the Delete based on EFI_FILE_PROTOCOL
- //
- Status = (*FileHandle)->Delete(*FileHandle);
- *FileHandle = NULL;
- return Status;
+ return (FileFunctionMap.DeleteFile(*FileHandle));
}
/**
@@ -788,14 +791,7 @@ ShellSetFilePosition (
IN UINT64 Position
)
{
- //
- // ASSERT if FileHandle is NULL
- //
- ASSERT (FileHandle != NULL);
- //
- // Perform the SetPosition based on EFI_FILE_PROTOCOL
- //
- return (FileHandle->SetPosition(FileHandle, Position));
+ return (FileFunctionMap.SetFilePosition(FileHandle, Position));
}
/**
@@ -820,14 +816,7 @@ ShellGetFilePosition (
OUT UINT64 *Position
)
{
- //
- // ASSERT if FileHandle is NULL
- //
- ASSERT (FileHandle != NULL);
- //
- // Perform the GetPosition based on EFI_FILE_PROTOCOL
- //
- return (FileHandle->GetPosition(FileHandle, Position));
+ return (FileFunctionMap.GetFilePosition(FileHandle, Position));
}
/**
Flushes data on a file
@@ -849,69 +838,7 @@ ShellFlushFile (
IN EFI_FILE_HANDLE FileHandle
)
{
- //
- // ASSERT if FileHandle is NULL
- //
- ASSERT (FileHandle != NULL);
- //
- // Perform the Flush based on EFI_FILE_PROTOCOL
- //
- return (FileHandle->Flush(FileHandle));
-}
-
-/**
- function to determine if a given handle is a directory handle
-
- if DirHandle is NULL then ASSERT()
-
- open the file information on the DirHandle and verify that the Attribute
- includes EFI_FILE_DIRECTORY bit set.
-
- @param DirHandle Handle to open file
-
- @retval EFI_SUCCESS DirHandle is a directory
- @retval EFI_INVALID_PARAMETER DirHandle did not have EFI_FILE_INFO available
- @retval EFI_NOT_FOUND DirHandle is not a directory
-**/
-EFI_STATUS
-EFIAPI
-InternalShellIsDirectory (
- IN EFI_FILE_HANDLE DirHandle
- )
-{
- EFI_FILE_INFO *DirInfo;
-
- //
- // ASSERT if DirHandle is NULL
- //
- ASSERT(DirHandle != NULL);
-
- //
- // get the file information for DirHandle
- //
- DirInfo = ShellGetFileInfo (DirHandle);
-
- //
- // Parse DirInfo
- //
- if (DirInfo == NULL) {
- //
- // We got nothing...
- //
- return (EFI_INVALID_PARAMETER);
- }
- if ((DirInfo->Attribute & EFI_FILE_DIRECTORY) == 0) {
- //
- // Attributes say this is not a directory
- //
- FreePool (DirInfo);
- return (EFI_NOT_FOUND);
- }
- //
- // all good...
- //
- FreePool (DirInfo);
- return (EFI_SUCCESS);
+ return (FileFunctionMap.FlushFile(FileHandle));
}
/**
@@ -936,49 +863,13 @@ EFI_STATUS
EFIAPI
ShellFindFirstFile (
IN EFI_FILE_HANDLE DirHandle,
- OUT EFI_FILE_INFO *Buffer
+ OUT EFI_FILE_INFO **Buffer
)
{
- EFI_STATUS Status;
- UINTN BufferSize;
-
- //
- // ASSERT if DirHandle is NULL
- //
- ASSERT (DirHandle != NULL);
-
- //
- // verify that DirHandle is a directory
- //
- Status = InternalShellIsDirectory(DirHandle);
- if (EFI_ERROR(Status)) {
- return (Status);
- }
-
- //
- // reset to the begining of the directory
- //
- Status = ShellSetFilePosition (DirHandle, 0);
- if (EFI_ERROR(Status)) {
- return (Status);
- }
-
//
- // Allocate a buffer sized to struct size + enough for the string at the end
+ // pass to file handle lib
//
- BufferSize = FIND_XXXXX_FILE_BUFFER_SIZE;
- Buffer = AllocateZeroPool(BufferSize);
- ASSERT (Buffer != NULL);
-
- //
- // read in the info about the first file
- //
- Status = ShellReadFile (DirHandle, &BufferSize, Buffer);
- ASSERT(Status != EFI_BUFFER_TOO_SMALL);
- if (EFI_ERROR(Status)) {
- return (Status);
- }
- return (EFI_SUCCESS);
+ return (FileHandleFindFirstFile(DirHandle, Buffer));
}
/**
Retrieves the next file in a directory.
@@ -1007,47 +898,10 @@ ShellFindNextFile(
OUT BOOLEAN *NoFile
)
{
- EFI_STATUS Status;
- UINTN BufferSize;
-
//
- // ASSERTs for DirHandle or Buffer or NoFile poitners being NULL
+ // pass to file handle lib
//
- ASSERT (DirHandle != NULL);
- ASSERT (Buffer != NULL);
- ASSERT (NoFile != NULL);
-
- //
- // verify that DirHandle is a directory
- //
- Status = InternalShellIsDirectory(DirHandle);
- if (EFI_ERROR(Status)) {
- return (Status);
- }
-
- //
- // This BufferSize MUST stay equal to the originally allocated one in GetFirstFile
- //
- BufferSize = FIND_XXXXX_FILE_BUFFER_SIZE;
-
- //
- // read in the info about the next file
- //
- Status = ShellReadFile (DirHandle, &BufferSize, Buffer);
- ASSERT(Status != EFI_BUFFER_TOO_SMALL);
- if (EFI_ERROR(Status)) {
- return (Status);
- }
-
- //
- // If we read 0 bytes (but did not have erros) we already read in the last file.
- //
- if (BufferSize == 0) {
- FreePool(Buffer);
- *NoFile = TRUE;
- }
-
- return (EFI_SUCCESS);
+ return (FileHandleFindNextFile(DirHandle, Buffer, NoFile));
}
/**
Retrieve the size of a file.
@@ -1071,33 +925,7 @@ ShellGetFileSize (
OUT UINT64 *Size
)
{
- EFI_FILE_INFO *FileInfo;
-
- //
- // ASSERT for FileHandle or Size being NULL
- //
- ASSERT (FileHandle != NULL);
- ASSERT (Size != NULL);
-
- //
- // get the FileInfo structure
- //
- FileInfo = ShellGetFileInfo(FileHandle);
- if (FileInfo == NULL) {
- return (EFI_DEVICE_ERROR);
- }
-
- //
- // Assign the Size pointer to the correct value
- //
- *Size = FileInfo->FileSize;
-
- //
- // free the FileInfo memory
- //
- FreePool(FileInfo);
-
- return (EFI_SUCCESS);
+ return (FileFunctionMap.GetFileSize(FileHandle, Size));
}
/**
Retrieves the status of the break execution flag
@@ -1366,7 +1194,7 @@ ShellSetPageBreakMode (
/// This allows for the struct to be populated.
///
typedef struct {
- EFI_LIST_ENTRY Link;
+ LIST_ENTRY Link;
EFI_STATUS Status;
CHAR16 *FullName;
CHAR16 *FileName;
@@ -1390,12 +1218,12 @@ typedef struct {
LIST_ENTRY*
EFIAPI
InternalShellConvertFileListType (
- EFI_LIST_ENTRY *FileList
+ LIST_ENTRY *FileList
)
{
LIST_ENTRY *ListHead;
SHELL_FILE_ARG *OldInfo;
- EFI_LIST_ENTRY *Link;
+ LIST_ENTRY *Link;
EFI_SHELL_FILE_INFO_NO_CONST *NewInfo;
//
@@ -1406,14 +1234,14 @@ InternalShellConvertFileListType (
//
// Allocate our list head and initialize the list
//
- ListHead = AllocateZeroPool(sizeof(EFI_LIST_ENTRY));
+ ListHead = AllocateZeroPool(sizeof(LIST_ENTRY));
ASSERT (ListHead != NULL);
ListHead = InitializeListHead (ListHead);
//
// enumerate through each member of the old list and copy
//
- for (Link = FileList->Flink; Link != FileList; Link = Link->Flink) {
+ for (Link = FileList->ForwardLink; Link != FileList; Link = Link->ForwardLink) {
OldInfo = CR (Link, SHELL_FILE_ARG, Link, SHELL_FILE_ARG_SIGNATURE);
//
@@ -1435,6 +1263,9 @@ InternalShellConvertFileListType (
NewInfo->Handle = OldInfo->Handle;
NewInfo->Status = OldInfo->Status;
+ // old shell checks for 0 not NULL
+ OldInfo->Handle = 0;
+
//
// allocate new space to copy strings and structure
//
@@ -1497,15 +1328,8 @@ ShellOpenFileMetaArg (
{
EFI_STATUS Status;
LIST_ENTRY *EmptyNode;
-
- //
- // make sure we have no outstanding list
- //
- if (mOldStyleFileList != NULL) {
- *ListHead = NULL;
- return (EFI_UNSUPPORTED);
- }
-
+ LIST_ENTRY *mOldStyleFileList;
+
//
// ASSERT that Arg and ListHead are not NULL
//
@@ -1529,7 +1353,7 @@ ShellOpenFileMetaArg (
//
// allocate memory for old list head
//
- mOldStyleFileList = (EFI_LIST_ENTRY*)AllocatePool(sizeof(EFI_LIST_ENTRY));
+ mOldStyleFileList = (LIST_ENTRY*)AllocatePool(sizeof(LIST_ENTRY));
ASSERT(mOldStyleFileList != NULL);
//
@@ -1552,6 +1376,13 @@ ShellOpenFileMetaArg (
EmptyNode = InternalShellConvertFileListType(mOldStyleFileList);
//
+ // Free the EFI Shell version that was converted.
+ //
+ ASSERT_EFI_ERROR(mEfiShellEnvironment2->FreeFileList(mOldStyleFileList));
+ FreePool(mOldStyleFileList);
+ mOldStyleFileList = NULL;
+
+ //
// remove the empty head of the list
//
*ListHead = (EFI_SHELL_FILE_INFO*)RemoveEntryList(EmptyNode);
@@ -1588,18 +1419,12 @@ ShellCloseFileMetaArg (
return (mEfiShellProtocol->FreeFileList(ListHead));
} else {
//
- // Free the EFI Shell version that was converted.
- //
- ASSERT_EFI_ERROR(mEfiShellEnvironment2->FreeFileList(mOldStyleFileList));
- FreePool(mOldStyleFileList);
- mOldStyleFileList = NULL;
-
- //
// Since this is EFI Shell version we need to free our internally made copy
// of the list
//
for (Node = GetFirstNode((LIST_ENTRY*)*ListHead) ; IsListEmpty((LIST_ENTRY*)*ListHead) == FALSE ; Node = GetFirstNode((LIST_ENTRY*)*ListHead)) {
RemoveEntryList(Node);
+ ((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->Handle->Close(((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->Handle);
FreePool(((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->FullName);
FreePool(((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->FileName);
FreePool(((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->Info);
@@ -1610,7 +1435,7 @@ ShellCloseFileMetaArg (
}
typedef struct {
- EFI_LIST_ENTRY List;
+ LIST_ENTRY List;
CHAR16 *Name;
ParamType Type;
CHAR16 *Value;
@@ -1634,7 +1459,7 @@ typedef struct {
**/
BOOLEAN
EFIAPI
-IsCheckList (
+InternalIsOnCheckList (
IN CONST CHAR16 *Name,
IN CONST SHELL_PARAM_ITEM *CheckList,
OUT ParamType *Type
@@ -1650,6 +1475,15 @@ IsCheckList (
ASSERT(Name != NULL);
//
+ // question mark and page break mode are always supported
+ //
+ if ((StrCmp(Name, L"-?") == 0) ||
+ (StrCmp(Name, L"-b") == 0)
+ ) {
+ return (TRUE);
+ }
+
+ //
// Enumerate through the list
//
for (TempListItem = (SHELL_PARAM_ITEM*)CheckList ; TempListItem->Name != NULL ; TempListItem++) {
@@ -1664,7 +1498,7 @@ IsCheckList (
return (FALSE);
}
/**
- Checks the string for indicators of "flag" status. this is a leading '/' or '-'
+ Checks the string for indicators of "flag" status. this is a leading '/', '-', or '+'
@param Name pointer to Name of parameter found
@@ -1673,7 +1507,7 @@ IsCheckList (
**/
BOOLEAN
EFIAPI
-IsFlag (
+InternalIsFlag (
IN CONST CHAR16 *Name
)
{
@@ -1685,7 +1519,10 @@ IsFlag (
//
// If the Name has a / or - as the first character return TRUE
//
- if ((Name[0] == L'/') || (Name[0] == L'-') ) {
+ if ((Name[0] == L'/') ||
+ (Name[0] == L'-') ||
+ (Name[0] == L'+')
+ ) {
return (TRUE);
}
return (FALSE);
@@ -1699,7 +1536,8 @@ IsFlag (
@param CheckList pointer to list of parameters to check
@param CheckPackage pointer to pointer to list checked values
@param ProblemParam optional pointer to pointer to unicode string for
- the paramater that caused failure.
+ the paramater that caused failure. If used then the
+ caller is responsible for freeing the memory.
@param AutoPageBreak will automatically set PageBreakEnabled for "b" parameter
@param Argc Count of parameters in Argv
@param Argv pointer to array of parameters
@@ -1774,7 +1612,7 @@ InternalCommandLineParse (
ASSERT(CurrentItemPackage->Value != NULL);
StrCpy(CurrentItemPackage->Value, Argv[LoopCounter]);
InsertTailList(*CheckPackage, (LIST_ENTRY*)CurrentItemPackage);
- } else if (IsFlag(Argv[LoopCounter]) == FALSE) {
+ } else if (InternalIsFlag(Argv[LoopCounter]) == FALSE) {
//
// add this one as a non-flag
//
@@ -1787,7 +1625,7 @@ InternalCommandLineParse (
StrCpy(CurrentItemPackage->Value, Argv[LoopCounter]);
CurrentItemPackage->OriginalPosition = Count++;
InsertTailList(*CheckPackage, (LIST_ENTRY*)CurrentItemPackage);
- } else if (IsCheckList(Argv[LoopCounter], CheckList, &CurrentItemType) == TRUE) {
+ } else if (InternalIsOnCheckList(Argv[LoopCounter], CheckList, &CurrentItemType) == TRUE) {
//
// this is a flag
//
@@ -1818,7 +1656,9 @@ InternalCommandLineParse (
//
// this was a non-recognised flag... error!
//
- *ProblemParam = (CHAR16*)Argv[LoopCounter];
+ *ProblemParam = AllocatePool(StrSize(Argv[LoopCounter]));
+ ASSERT(*ProblemParam != NULL);
+ StrCpy(*ProblemParam, Argv[LoopCounter]);
ShellCommandLineFreeVarList(*CheckPackage);
*CheckPackage = NULL;
return (EFI_VOLUME_CORRUPTED);
diff --git a/ShellPkg/Library/BaseShellLib/BaseShellLib.h b/ShellPkg/Library/BaseShellLib/BaseShellLib.h
new file mode 100644
index 0000000000..1620641648
--- /dev/null
+++ b/ShellPkg/Library/BaseShellLib/BaseShellLib.h
@@ -0,0 +1,26 @@
+/** @file
+ Provides interface to shell functionality for shell commands and applications.
+
+Copyright (c) 2006 - 2009, Intel Corporation
+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.
+
+**/
+
+typedef struct {
+ EFI_SHELL_GET_FILE_INFO GetFileInfo;
+ EFI_SHELL_SET_FILE_INFO SetFileInfo;
+ EFI_SHELL_READ_FILE ReadFile;
+ EFI_SHELL_WRITE_FILE WriteFile;
+ EFI_SHELL_CLOSE_FILE CloseFile;
+ EFI_SHELL_DELETE_FILE DeleteFile;
+ EFI_SHELL_GET_FILE_POSITION GetFilePosition;
+ EFI_SHELL_SET_FILE_POSITION SetFilePosition;
+ EFI_SHELL_FLUSH_FILE FlushFile;
+ EFI_SHELL_GET_FILE_SIZE GetFileSize;
+} FILE_HANDLE_FUNCTION_MAP;
diff --git a/ShellPkg/Library/BaseShellLib/BaseShellLib.inf b/ShellPkg/Library/BaseShellLib/BaseShellLib.inf
index 8a2c33b8a1..71c68cb280 100644
--- a/ShellPkg/Library/BaseShellLib/BaseShellLib.inf
+++ b/ShellPkg/Library/BaseShellLib/BaseShellLib.inf
@@ -29,6 +29,7 @@
[Sources.common]
BaseShellLib.c
+ BaseShellLib.h
[Packages]
MdePkg/MdePkg.dec
@@ -41,6 +42,7 @@
BaseLib
BaseMemoryLib
DebugLib
+ FileHandleLib
[Protocols]
gEfiSimpleFileSystemProtocolGuid # ALWAYS_CONSUMED
@@ -58,4 +60,4 @@
gEfiShellEnvironment2ExtGuid # ALWAYS_CONSUMED
[Pcd.common]
-
+ gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize # ALWAYS_CONSUMED