udk2010.up2.shell initial release.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10874 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
jcarsey 2010-09-14 05:18:09 +00:00
parent 52fb4d3d13
commit a405b86d27
102 changed files with 30419 additions and 1040 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,341 @@
/** @file
Provides interface to shell console logger.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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.
**/
#ifndef _CONSOLE_LOGGER_HEADER_
#define _CONSOLE_LOGGER_HEADER_
#include <Uefi.h>
#include <Protocol/SimpleTextOut.h>
#include <Protocol/EfiShell.h>
#include <Protocol/EfiShellParameters.h>
#include <Library/Debuglib.h>
#include <Library/Baselib.h>
#include <Library/BaseMemorylib.h>
#include <Library/MemoryAllocationlib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/HiiLib.h>
#include <Library/ShellLib.h>
#define CONSOLE_LOGGER_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('c', 'o', 'P', 'D')
typedef struct _CONSOLE_LOGGER_PRIVATE_DATA{
UINTN Signature;
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL OurConOut; ///< the protocol we installed onto the system table
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *OldConOut; ///< old protocol to reinstall upon exiting
EFI_HANDLE OldConHandle; ///< old protocol handle
UINTN ScreenCount; ///< How many screens worth of data to save
CHAR16 *Buffer; ///< Buffer to save data
UINTN BufferSize; ///< size of buffer in bytes
// start row is the top of the screen
UINTN OriginalStartRow; ///< What the originally visible start row was
UINTN CurrentStartRow; ///< what the currently visible start row is
UINTN RowsPerScreen; ///< how many rows the screen can display
UINTN ColsPerScreen; ///< how many columns the screen can display
INT32 *Attributes; ///< Buffer for Attribute to be saved for each character
UINTN AttribSize; ///< Size of Attributes in bytes
EFI_SIMPLE_TEXT_OUTPUT_MODE HistoryMode; ///< mode of the history log
BOOLEAN Enabled; ///< Set to FALSE when a break is requested.
UINTN RowCounter; ///< Initial row of each print job.
} CONSOLE_LOGGER_PRIVATE_DATA;
#define CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(a) CR (a, CONSOLE_LOGGER_PRIVATE_DATA, OurConOut, CONSOLE_LOGGER_PRIVATE_DATA_SIGNATURE)
/**
Install our intermediate ConOut into the system table to
keep a log of all the info that is displayed to the user.
@param[in] ScreensToSave Sets how many screen-worths of data to save.
@param[out] ConsoleInfo The object to pass into later functions.
@retval EFI_SUCCESS The operation was successful.
@return other The operation failed.
@sa ConsoleLoggerResetBuffers
@sa InstallProtocolInterface
**/
EFI_STATUS
EFIAPI
ConsoleLoggerInstall(
IN CONST UINTN ScreensToSave,
OUT CONSOLE_LOGGER_PRIVATE_DATA **ConsoleInfo
);
/**
Return the system to the state it was before InstallConsoleLogger
was installed.
@param[in,out] ConsoleInfo The object from the install function.
@retval EFI_SUCCESS The operation was successful
@return other The operation failed. This was from UninstallProtocolInterface.
**/
EFI_STATUS
EFIAPI
ConsoleLoggerUninstall(
IN OUT CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo
);
/**
Displays previously logged output back to the screen.
This will scroll the screen forwards and backwards through the log of previous
output. If Rows is 0 then the size of 1/2 the screen will be scrolled. If Rows
is (UINTN)(-1) then the size of the screen will be scrolled.
@param[in] Forward If TRUE then the log will be displayed forwards (scroll to newer).
If FALSE then the log will be displayed backwards (scroll to older).
@param[in] Rows Determines how many rows the log should scroll.
@param[in] ConsoleInfo The pointer to the instance of the console logger information.
**/
EFI_STATUS
EFIAPI
ConsoleLoggerDisplayHistory(
IN CONST BOOLEAN Forward,
IN CONST UINTN Rows,
IN CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo
);
/**
Function to return to normal output whent he scrolling is complete.
@param[in] ConsoleInfo The pointer to the instance of the console logger information.
@retval EFI_SUCCESS The operation was successful.
@return other The operation failed. See UpdateDisplayFromHistory.
@sa UpdateDisplayFromHistory
**/
EFI_STATUS
EFIAPI
ConsoleLoggerStopHistory(
IN CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo
);
/**
Updates the hidden ConOut to be displaying the correct stuff.
@param[in] ConsoleInfo The pointer to the instance of the console logger information.
@retval EFI_SUCCESS The operation was successful.
@return other The operation failed.
**/
EFI_STATUS
EFIAPI
UpdateDisplayFromHistory(
IN CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo
);
/**
Reset the text output device hardware and optionaly run diagnostics
@param This Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
@param ExtendedVerification Indicates that a more extensive test may be performed
@retval EFI_SUCCESS The text output device was reset.
@retval EFI_DEVICE_ERROR The text output device is not functioning correctly and
could not be reset.
**/
EFI_STATUS
EFIAPI
ConsoleLoggerReset (
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
);
/**
Write a Unicode string to the output device.
@param[in] This Protocol instance pointer.
@param[in] WString The NULL-terminated Unicode string to be displayed on the output
device(s). All output devices must also support the Unicode
drawing defined in this file.
@retval EFI_SUCCESS The string was output to the device.
@retval EFI_DEVICE_ERROR The device reported an error while attempting to output
the text.
@retval EFI_UNSUPPORTED The output device's mode is not currently in a
defined text mode.
@retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
characters in the Unicode string could not be
rendered and were skipped.
**/
EFI_STATUS
EFIAPI
ConsoleLoggerOutputString(
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
IN CHAR16 *WString
);
/**
Verifies that all characters in a Unicode string can be output to the
target device.
@param[in] This Protocol instance pointer.
@param[in] WString The NULL-terminated Unicode string to be examined for the output
device(s).
@retval EFI_SUCCESS The device(s) are capable of rendering the output string.
@retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be
rendered by one or more of the output devices mapped
by the EFI handle.
**/
EFI_STATUS
EFIAPI
ConsoleLoggerTestString (
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
IN CHAR16 *WString
);
/**
Returns information for an available text mode that the output device(s)
supports.
@param[in] This Protocol instance pointer.
@param[in] ModeNumber The mode number to return information on.
@param[out] Columns Upon return, the number of columns in the selected geometry
@param[out] Rows Upon return, the number of rows in the selected geometry
@retval EFI_SUCCESS The requested mode information was returned.
@retval EFI_DEVICE_ERROR The device had an error and could not
complete the request.
@retval EFI_UNSUPPORTED The mode number was not valid.
**/
EFI_STATUS
EFIAPI
ConsoleLoggerQueryMode (
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
IN UINTN ModeNumber,
OUT UINTN *Columns,
OUT UINTN *Rows
);
/**
Sets the output device(s) to a specified mode.
@param[in] This Protocol instance pointer.
@param[in] ModeNumber The mode number to set.
@retval EFI_SUCCESS The requested text mode was set.
@retval EFI_DEVICE_ERROR The device had an error and
could not complete the request.
@retval EFI_UNSUPPORTED The mode number was not valid.
**/
EFI_STATUS
EFIAPI
ConsoleLoggerSetMode (
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
IN UINTN ModeNumber
);
/**
Sets the background and foreground colors for the OutputString () and
ClearScreen () functions.
@param[in] This Protocol instance pointer.
@param[in] Attribute The attribute to set. Bits 0..3 are the foreground color, and
bits 4..6 are the background color. All other bits are undefined
and must be zero. The valid Attributes are defined in this file.
@retval EFI_SUCCESS The attribute was set.
@retval EFI_DEVICE_ERROR The device had an error and
could not complete the request.
@retval EFI_UNSUPPORTED The attribute requested is not defined.
**/
EFI_STATUS
EFIAPI
ConsoleLoggerSetAttribute (
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
IN UINTN Attribute
);
/**
Clears the output device(s) display to the currently selected background
color.
@param[in] This Protocol instance pointer.
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_DEVICE_ERROR The device had an error and
could not complete the request.
@retval EFI_UNSUPPORTED The output device is not in a valid text mode.
**/
EFI_STATUS
EFIAPI
ConsoleLoggerClearScreen (
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This
);
/**
Sets the current coordinates of the cursor position.
@param[in] This Protocol instance pointer.
@param[in] Column Column to put the cursor in. Must be between zero and Column returned from QueryMode
@param[in] Row Row to put the cursor in. Must be between zero and Row returned from QueryMode
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_DEVICE_ERROR The device had an error and
could not complete the request.
@retval EFI_UNSUPPORTED The output device is not in a valid text mode, or the
cursor position is invalid for the current mode.
**/
EFI_STATUS
EFIAPI
ConsoleLoggerSetCursorPosition (
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
IN UINTN Column,
IN UINTN Row
);
/**
Makes the cursor visible or invisible
@param[in] This Protocol instance pointer.
@param[in] Visible If TRUE, the cursor is set to be visible. If FALSE, the cursor is
set to be invisible.
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_DEVICE_ERROR The device had an error and could not complete the
request, or the device does not support changing
the cursor mode.
@retval EFI_UNSUPPORTED The output device is not in a valid text mode.
**/
EFI_STATUS
EFIAPI
ConsoleLoggerEnableCursor (
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
IN BOOLEAN Visible
);
/**
Function to update and verify that the current buffers are correct.
@param[in] ConsoleInfo The pointer to the instance of the console logger information.
This will be used when a mode has changed or a reset ocurred to verify all
history buffers.
**/
EFI_STATUS
EFIAPI
ConsoleLoggerResetBuffers(
IN CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo
);
#endif //_CONSOLE_LOGGER_HEADER_

View File

@ -0,0 +1,68 @@
/** @file
internal worker functions for FileHandleWrappers to use
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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.
**/
#ifndef _FILE_HANDLE_INTERNAL_HEADER_
#define _FILE_HANDLE_INTERNAL_HEADER_
/**
Move the cursor position one character backward.
@param[in] LineLength Length of a line. Get it by calling QueryMode
@param[in,out] Column Current column of the cursor position
@param[in,out] Row Current row of the cursor position
**/
VOID
EFIAPI
MoveCursorBackward (
IN UINTN LineLength,
IN OUT UINTN *Column,
IN OUT UINTN *Row
);
/**
Move the cursor position one character forward.
@param[in] LineLength Length of a line.
@param[in] TotalRow Total row of a screen
@param[in,out] Column Current column of the cursor position
@param[in,out] Row Current row of the cursor position
**/
VOID
EFIAPI
MoveCursorForward (
IN UINTN LineLength,
IN UINTN TotalRow,
IN OUT UINTN *Column,
IN OUT UINTN *Row
);
/**
Prints out each previously typed command in the command list history log.
When each screen is full it will pause for a key before continuing.
@param[in] TotalCols How many columns are on the screen
@param[in] TotalRows How many rows are on the screen
@param[in] StartColumn which column to start at
**/
VOID
EFIAPI
PrintCommandHistory (
IN CONST UINTN TotalCols,
IN CONST UINTN TotalRows,
IN CONST UINTN StartColumn
);
#endif //_FILE_HANDLE_INTERNAL_HEADER_

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,95 @@
/** @file
EFI_FILE_PROTOCOL wrappers for other items (Like Environment Variables, StdIn, StdOut, StdErr, etc...)
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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.
**/
#ifndef _SHELL_FILE_HANDLE_WRAPPERS_HEADER_
#define _SHELL_FILE_HANDLE_WRAPPERS_HEADER_
typedef struct {
LIST_ENTRY Link;
CHAR16* Buffer;
} SHELL_LINE_LIST;
typedef struct {
UINTN LogCount;
SHELL_LINE_LIST *Log;
} SHELL_LINE_LOG;
///
/// FILE sytle interfaces for StdIn.
///
extern EFI_FILE_PROTOCOL FileInterfaceStdIn;
///
/// FILE sytle interfaces for StdOut.
///
extern EFI_FILE_PROTOCOL FileInterfaceStdOut;
///
/// FILE sytle interfaces for StdErr.
///
extern EFI_FILE_PROTOCOL FileInterfaceStdErr;
///
/// FILE style interface for NUL file.
///
extern EFI_FILE_PROTOCOL FileInterfaceNulFile;
/**
Creates a EFI_FILE_PROTOCOL (almost) object for using to access
environment variables through file operations.
@param EnvName The name of the Environment Variable to be operated on.
@retval NULL Memory could not be allocated.
@return other a pointer to an EFI_FILE_PROTOCOL structure
**/
EFI_FILE_PROTOCOL*
EFIAPI
CreateFileInterfaceEnv(
CONST CHAR16 *EnvName
);
/**
Creates a EFI_FILE_PROTOCOL (almost) object for using to access
a file entirely in memory through file operations.
@param[in] Unicode TRUE if the data is UNICODE, FALSE otherwise.
@retval NULL Memory could not be allocated.
@return other a pointer to an EFI_FILE_PROTOCOL structure
**/
EFI_FILE_PROTOCOL*
EFIAPI
CreateFileInterfaceMem(
IN CONST BOOLEAN Unicode
);
/**
Creates a EFI_FILE_PROTOCOL (almost) object for using to access
a file entirely with unicode awareness through file operations.
@param[in] Template The pointer to the handle to start with.
@param[in] Unicode TRUE if the data is UNICODE, FALSE otherwise.
@retval NULL Memory could not be allocated.
@return other a pointer to an EFI_FILE_PROTOCOL structure
**/
EFI_FILE_PROTOCOL*
CreateFileInterfaceFile(
IN CONST EFI_FILE_PROTOCOL *Template,
IN CONST BOOLEAN Unicode
);
#endif //_SHELL_FILE_HANDLE_WRAPPERS_HEADER_

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,292 @@
/** @file
function definitions for internal to shell functions.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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.
**/
#ifndef _SHELL_INTERNAL_HEADER_
#define _SHELL_INTERNAL_HEADER_
#include <Uefi.h>
#include <ShellBase.h>
#include <Guid/ShellVariableGuid.h>
#include <Protocol/LoadedImage.h>
#include <Protocol/SimpleTextOut.h>
#include <Protocol/EfiShell.h>
#include <Protocol/EfiShellInterface.h>
#include <Protocol/EfiShellEnvironment2.h>
#include <Protocol/EfiShellParameters.h>
#include <Protocol/BlockIo.h>
#include <Library/BaseLib.h>
#include <Library/UefiApplicationEntryPoint.h>
#include <Library/UefiLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/ShellCommandLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DevicePathLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/PcdLib.h>
#include <Library/ShellLib.h>
#include <Library/SortLib.h>
#include <Library/HiiLib.h>
#include <Library/PrintLib.h>
#include <Library/HandleParsingLib.h>
#include "ShellParametersProtocol.h"
#include "ShellProtocol.h"
#include "ShellEnvVar.h"
#include "ConsoleLogger.h"
#include "ShellManParser.h"
typedef struct {
LIST_ENTRY Link; ///< Standard linked list handler.
SHELL_FILE_HANDLE *SplitStdOut; ///< ConsoleOut for use in the split.
SHELL_FILE_HANDLE *SplitStdIn; ///< ConsoleIn for use in the split.
} SPLIT_LIST;
typedef struct {
UINT32 Startup:1; ///< Was "-startup" found on command line.
UINT32 NoStartup:1; ///< Was "-nostartup" found on command line.
UINT32 NoConsoleOut:1; ///< Was "-noconsoleout" found on command line.
UINT32 NoConsoleIn:1; ///< Was "-noconsolein" found on command line.
UINT32 NoInterrupt:1; ///< Was "-nointerrupt" found on command line.
UINT32 NoMap:1; ///< Was "-nomap" found on command line.
UINT32 NoVersion:1; ///< Was "-noversion" found on command line.
UINT32 Delay:1; ///< Was "-delay[:n] found on command line
UINT32 Reserved:8; ///< Extra bits
} SHELL_BITS;
typedef union {
SHELL_BITS Bits;
UINT16 AllBits;
} SHELL_BIT_UNION;
typedef struct {
SHELL_BIT_UNION BitUnion;
UINTN Delay; ///< Seconds of delay default:5.
CHAR16 *FileName; ///< Filename to run upon successful initialization.
CHAR16 *FileOptions; ///< Options to pass to FileName.
} SHELL_INIT_SETTINGS;
typedef struct {
BUFFER_LIST CommandHistory;
UINTN VisibleRowNumber;
UINTN OriginalVisibleRowNumber;
BOOLEAN InsertMode; ///< Is the current typing mode insert (FALSE = overwrite).
} SHELL_VIEWING_SETTINGS;
typedef struct {
EFI_SHELL_PARAMETERS_PROTOCOL *NewShellParametersProtocol;
EFI_SHELL_PROTOCOL *NewEfiShellProtocol;
BOOLEAN PageBreakEnabled;
BOOLEAN RootShellInstance;
SHELL_INIT_SETTINGS ShellInitSettings;
BUFFER_LIST BufferToFreeList; ///< List of buffers that were returned to the user to free.
SHELL_VIEWING_SETTINGS ViewingSettings;
EFI_HII_HANDLE HiiHandle; ///< Handle from HiiLib.
UINTN LogScreenCount; ///< How many screens of log information to save.
EFI_EVENT UserBreakTimer; ///< Timer event for polling for CTRL-C.
EFI_DEVICE_PATH_PROTOCOL *ImageDevPath; ///< DevicePath for ourselves.
EFI_DEVICE_PATH_PROTOCOL *FileDevPath; ///< DevicePath for ourselves.
CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo; ///< Pointer for ConsoleInformation.
EFI_SHELL_PARAMETERS_PROTOCOL *OldShellParameters; ///< old shell parameters to reinstall upon exiting.
SHELL_PROTOCOL_HANDLE_LIST OldShellList; ///< List of other instances to reinstall when closing.
SPLIT_LIST SplitList; ///< List of Splits in FILO stack.
} SHELL_INFO;
extern SHELL_INFO ShellInfoObject;
/**
Sets all the alias' that were registered with the ShellCommandLib library.
@retval EFI_SUCCESS all init commands were run sucessfully.
**/
EFI_STATUS
EFIAPI
SetBuiltInAlias(
VOID
);
/**
This function will populate the 2 device path protocol parameters based on the
global gImageHandle. the DevPath will point to the device path for the handle that has
loaded image protocol installed on it. the FilePath will point to the device path
for the file that was loaded.
@param[in,out] DevPath on a sucessful return the device path to the loaded image
@param[in,out] FilePath on a sucessful return the device path to the file
@retval EFI_SUCCESS the 2 device paths were sucessfully returned.
@return other a error from gBS->HandleProtocol
@sa HandleProtocol
**/
EFI_STATUS
EFIAPI
GetDevicePathsForImageAndFile (
IN OUT EFI_DEVICE_PATH_PROTOCOL **DevPath,
IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath
);
/**
Process all Uefi Shell 2.0 command line options.
see Uefi Shell 2.0 section 3.2 for full details.
the command line should resemble the following:
shell.efi [ShellOpt-options] [options] [file-name [file-name-options]]
ShellOpt options Options which control the initialization behavior of the shell.
These options are read from the EFI global variable "ShellOpt"
and are processed before options or file-name.
options Options which control the initialization behavior of the shell.
file-name The name of a UEFI shell application or script to be executed
after initialization is complete. By default, if file-name is
specified, then -nostartup is implied. Scripts are not supported
by level 0.
file-nameoptions The command-line options that are passed to file-name when it
is invoked.
This will initialize the ShellInitSettings global variable.
@retval EFI_SUCCESS the variable is initialized.
**/
EFI_STATUS
EFIAPI
ProcessCommandLine(
VOID
);
/**
Handles all interaction with the default startup script.
this will check that the correct command line parameters were passed, handle the delay, and then start running the script.
@param[in] ImagePath The path to the image for shell. The first place to look for the startup script.
@param[in] FilePath The path to the file for shell. The second place to look for the startup script.
@retval EFI_SUCCESS The variable is initialized.
**/
EFI_STATUS
EFIAPI
DoStartupScript(
IN EFI_DEVICE_PATH_PROTOCOL *ImagePath,
IN EFI_DEVICE_PATH_PROTOCOL *FilePath
);
/**
Function to perform the shell prompt looping. It will do a single prompt,
dispatch the result, and then return. It is expected that the caller will
call this function in a loop many times.
@retval EFI_SUCCESS
@retval RETURN_ABORTED
**/
EFI_STATUS
EFIAPI
DoShellPrompt (
VOID
);
/**
Add a buffer to the Buffer To Free List for safely returning buffers to other
places without risking letting them modify internal shell information.
@param Buffer Something to pass to FreePool when the shell is exiting.
**/
VOID*
EFIAPI
AddBufferToFreeList(
VOID *Buffer
);
/**
Add a buffer to the Command History List.
@param Buffer[in] The line buffer to add.
**/
VOID
EFIAPI
AddLineToCommandHistory(
IN CONST CHAR16 *Buffer
);
/**
Function will process and run a command line.
This will determine if the command line represents an internal shell command or dispatch an external application.
@param[in] CmdLine the command line to parse
@retval EFI_SUCCESS the command was completed
@retval EFI_ABORTED the command's operation was aborted
**/
EFI_STATUS
EFIAPI
RunCommand(
IN CONST CHAR16 *CmdLine
);
/**
Function determins if the CommandName COULD be a valid command. It does not determine whether
this is a valid command. It only checks for invalid characters.
@param[in] CommandName The name to check
@retval TRUE CommandName could be a command name
@retval FALSE CommandName could not be a valid command name
**/
BOOLEAN
EFIAPI
IsValidCommandName(
IN CONST CHAR16 *CommandName
);
/**
Function to process a NSH script file via SHELL_FILE_HANDLE.
@param[in] Handle The handle to the already opened file.
@param[in] Name The name of the script file.
@retval EFI_SUCCESS the script completed sucessfully
**/
EFI_STATUS
EFIAPI
RunScriptFileHandle (
IN SHELL_FILE_HANDLE Handle,
IN CONST CHAR16 *Name
);
/**
Function to process a NSH script file.
@param[in] ScriptPath Pointer to the script file name (including file system path).
@retval EFI_SUCCESS the script completed sucessfully
**/
EFI_STATUS
EFIAPI
RunScriptFile (
IN CONST CHAR16 *ScriptPath
);
#endif //_SHELL_INTERNAL_HEADER_

View File

@ -0,0 +1,105 @@
## @file
# This is the shell application
#
# Copyright (c) 2009-2010, Intel Corporation. All rights reserved.<BR>
#
# 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 = Shell
FILE_GUID = 7C04A583-9E3E-4f1c-AD65-E05268D0B4D1
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0
ENTRY_POINT = UefiMain
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
Shell.c
Shell.h
ShellParametersProtocol.c
ShellParametersProtocol.h
ShellProtocol.c
ShellProtocol.h
FileHandleWrappers.c
FileHandleWrappers.h
FileHandleInternal.h
ShellEnvVar.c
ShellEnvVar.h
ShellManParser.c
ShellManParser.h
Shell.uni
ConsoleLogger.c
ConsoleLogger.h
[Packages]
MdePkg/MdePkg.dec
ShellPkg/ShellPkg.dec
MdeModulePkg/MdeModulePkg.dec
IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
[LibraryClasses]
BaseLib
UefiApplicationEntryPoint
UefiLib
DebugLib
MemoryAllocationLib
ShellCommandLib
UefiRuntimeServicesTableLib
UefiBootServicesTableLib
DevicePathLib
BaseMemoryLib
PcdLib
FileHandleLib
PrintLib
HiiLib
SortLib
HandleParsingLib
[Guids]
gShellVariableGuid # ALWAYS_CONSUMED
gShellMapGuid # ALWAYS_CONSUMED
gShellAliasGuid # ALWAYS_CONSUMED
[Protocols]
gEfiShellProtocolGuid # ALWAYS_PRODUCED
gEfiShellParametersProtocolGuid # ALWAYS_PRODUCED
gEfiShellEnvironment2Guid # SOMETIMES_PRODUCED
gEfiShellInterfaceGuid # SOMETIMES_PRODUCED
gEfiLoadedImageProtocolGuid # ALWAYS_CONSUMED
gEfiSimpleTextInputExProtocolGuid # ALWAYS_CONSUMED
gEfiSimpleTextOutProtocolGuid # ALWAYS_CONSUMED
gEfiSimpleFileSystemProtocolGuid # ALWAYS_CONSUMED
gEfiLoadedImageProtocolGuid # ALWAYS_CONSUMED
gEfiComponentName2ProtocolGuid # ALWAYS_CONSUMED
gEfiUnicodeCollation2ProtocolGuid # ALWAYS_CONSUMED
gEfiDevicePathProtocolGuid # ALWAYS_CONSUMED
gEfiDevicePathToTextProtocolGuid # ALWAYS_CONSUMED
[Pcd]
gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel # ALWAYS_CONSUMED
gEfiShellPkgTokenSpaceGuid.PcdShellSupportOldProtocols # ALWAYS_CONSUMED
gEfiShellPkgTokenSpaceGuid.PcdShellRequireHiiPlatform # ALWAYS_CONSUMED
gEfiShellPkgTokenSpaceGuid.PcdShellSupportFrameworkHii # ALWAYS_CONSUMED
gEfiShellPkgTokenSpaceGuid.PcdShellPageBreakDefault # ALWAYS_CONSUMED
gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize # ALWAYS_CONSUMED
gEfiShellPkgTokenSpaceGuid.PcdShellInsertModeDefault # ALWAYS_CONSUMED
gEfiShellPkgTokenSpaceGuid.PcdShellScreenLogCount # ALWAYS_CONSUMED
gEfiShellPkgTokenSpaceGuid.PcdShellMapNameLength # ALWAYS_CONSUMED
gEfiShellPkgTokenSpaceGuid.PcdShellPrintBufferSize # ALWAYS_CONSUMED
gEfiShellPkgTokenSpaceGuid.PcdShellForceConsole # ALWAYS_CONSUMED

Binary file not shown.

View File

@ -0,0 +1,326 @@
/** @file
function declarations for shell environment functions.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 <Guid/ShellVariableGuid.h>
#include <Library/BaseLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include "ShellEnvVar.h"
/**
Reports whether an environment variable is Volatile or Non-Volatile.
@param EnvVarName The name of the environment variable in question
@retval TRUE This environment variable is Volatile
@retval FALSE This environment variable is NON-Volatile
**/
BOOLEAN
EFIAPI
IsVolatileEnv (
IN CONST CHAR16 *EnvVarName
)
{
EFI_STATUS Status;
UINTN Size;
VOID *Buffer;
UINT32 Attribs;
Size = 0;
Buffer = NULL;
//
// get the variable
//
Status = gRT->GetVariable((CHAR16*)EnvVarName,
&gShellVariableGuid,
&Attribs,
&Size,
Buffer);
if (Status == EFI_BUFFER_TOO_SMALL) {
Buffer = AllocatePool(Size);
ASSERT(Buffer != NULL);
Status = gRT->GetVariable((CHAR16*)EnvVarName,
&gShellVariableGuid,
&Attribs,
&Size,
Buffer);
FreePool(Buffer);
}
//
// not found means volatile
//
if (Status == EFI_NOT_FOUND) {
return (TRUE);
}
ASSERT_EFI_ERROR(Status);
//
// check for the Non Volatile bit
//
if ((Attribs & EFI_VARIABLE_NON_VOLATILE) == EFI_VARIABLE_NON_VOLATILE) {
return (FALSE);
}
//
// everything else is volatile
//
return (TRUE);
}
/**
free function for ENV_VAR_LIST objects.
@param[in] List The pointer to pointer to list.
**/
VOID
EFIAPI
FreeEnvironmentVariableList(
IN LIST_ENTRY *List
)
{
ENV_VAR_LIST *Node;
ASSERT (List != NULL);
if (List == NULL) {
return;
}
for ( Node = (ENV_VAR_LIST*)GetFirstNode(List)
; IsListEmpty(List)
; Node = (ENV_VAR_LIST*)GetFirstNode(List)
){
ASSERT(Node != NULL);
RemoveEntryList(&Node->Link);
if (Node->Key != NULL) {
FreePool(Node->Key);
}
if (Node->Val != NULL) {
FreePool(Node->Val);
}
FreePool(Node);
}
}
/**
Creates a list of all Shell-Guid-based environment variables.
@param[in,out] ListHead The pointer to pointer to LIST ENTRY object for
storing this list.
@retval EFI_SUCCESS the list was created sucessfully.
**/
EFI_STATUS
EFIAPI
GetEnvironmentVariableList(
IN OUT LIST_ENTRY *ListHead
)
{
CHAR16 *VariableName;
UINTN NameSize;
UINT64 MaxStorSize;
UINT64 RemStorSize;
UINT64 MaxVarSize;
EFI_STATUS Status;
EFI_GUID Guid;
UINTN ValSize;
ENV_VAR_LIST *VarList;
ASSERT(ListHead != NULL);
Status = gRT->QueryVariableInfo(EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS, &MaxStorSize, &RemStorSize, &MaxVarSize);
ASSERT_EFI_ERROR(Status);
NameSize = (UINTN)MaxVarSize;
VariableName = AllocatePool(NameSize);
StrCpy(VariableName, L"");
while (TRUE) {
NameSize = (UINTN)MaxVarSize;
Status = gRT->GetNextVariableName(&NameSize, VariableName, &Guid);
if (Status == EFI_NOT_FOUND){
Status = EFI_SUCCESS;
break;
}
ASSERT_EFI_ERROR(Status);
if (EFI_ERROR(Status)) {
break;
}
if (CompareGuid(&Guid, &gShellVariableGuid)){
VarList = AllocateZeroPool(sizeof(ENV_VAR_LIST));
ValSize = 0;
Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(VariableName, &VarList->Atts, &ValSize, VarList->Val);
if (Status == EFI_BUFFER_TOO_SMALL){
VarList->Val = AllocatePool(ValSize);
ASSERT(VarList->Val != NULL);
Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(VariableName, &VarList->Atts, &ValSize, VarList->Val);
}
ASSERT_EFI_ERROR(Status);
VarList->Key = AllocatePool(StrSize(VariableName));
ASSERT(VarList->Key != NULL);
StrCpy(VarList->Key, VariableName);
InsertTailList(ListHead, &VarList->Link);
} // compare guid
} // while
FreePool(VariableName);
if (EFI_ERROR(Status)) {
FreeEnvironmentVariableList(ListHead);
}
return (Status);
}
/**
Sets a list of all Shell-Guid-based environment variables. this will
also eliminate all existing shell environment variables (even if they
are not on the list).
This function will also deallocate the memory from List.
@param[in] ListHead The pointer to LIST_ENTRY from
GetShellEnvVarList().
@retval EFI_SUCCESS the list was Set sucessfully.
**/
EFI_STATUS
EFIAPI
SetEnvironmentVariableList(
IN LIST_ENTRY *ListHead
)
{
ENV_VAR_LIST VarList;
ENV_VAR_LIST *Node;
EFI_STATUS Status;
UINTN Size;
InitializeListHead(&VarList.Link);
//
// Delete all the current environment variables
//
Status = GetEnvironmentVariableList(&VarList.Link);
ASSERT_EFI_ERROR(Status);
for ( Node = (ENV_VAR_LIST*)GetFirstNode(&VarList.Link)
; !IsNull(&VarList.Link, &Node->Link)
; Node = (ENV_VAR_LIST*)GetNextNode(&VarList.Link, &Node->Link)
){
if (Node->Key != NULL) {
Status = SHELL_DELETE_ENVIRONMENT_VARIABLE(Node->Key);
}
ASSERT_EFI_ERROR(Status);
}
FreeEnvironmentVariableList(&VarList.Link);
//
// set all the variables fron the list
//
for ( Node = (ENV_VAR_LIST*)GetFirstNode(ListHead)
; !IsNull(ListHead, &Node->Link)
; Node = (ENV_VAR_LIST*)GetNextNode(ListHead, &Node->Link)
){
Size = StrSize(Node->Val);
if (Node->Atts & EFI_VARIABLE_NON_VOLATILE) {
Status = SHELL_SET_ENVIRONMENT_VARIABLE_NV(Node->Key, Size, Node->Val);
} else {
Status = SHELL_SET_ENVIRONMENT_VARIABLE_V (Node->Key, Size, Node->Val);
}
ASSERT_EFI_ERROR(Status);
}
FreeEnvironmentVariableList(ListHead);
return (Status);
}
/**
sets a list of all Shell-Guid-based environment variables.
@param Environment Points to a NULL-terminated array of environment
variables with the format 'x=y', where x is the
environment variable name and y is the value.
@retval EFI_SUCCESS The command executed successfully.
@retval EFI_INVALID_PARAMETER The parameter is invalid.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@sa SetEnvironmentVariableList
**/
EFI_STATUS
EFIAPI
SetEnvironmentVariables(
IN CONST CHAR16 **Environment
)
{
CONST CHAR16 *CurrentString;
UINTN CurrentCount;
ENV_VAR_LIST *VarList;
ENV_VAR_LIST *Node;
UINTN NewSize;
VarList = NULL;
if (Environment == NULL) {
return (EFI_INVALID_PARAMETER);
}
//
// Build a list identical to the ones used for get/set list functions above
//
for ( CurrentCount = 0
;
; CurrentCount++
){
CurrentString = Environment[CurrentCount];
if (CurrentString == NULL) {
break;
}
ASSERT(StrStr(CurrentString, L"=") != NULL);
Node = AllocatePool(sizeof(ENV_VAR_LIST));
ASSERT(Node != NULL);
Node->Key = AllocateZeroPool((StrStr(CurrentString, L"=") - CurrentString + 1) * sizeof(CHAR16));
ASSERT(Node->Key != NULL);
StrnCpy(Node->Key, CurrentString, StrStr(CurrentString, L"=") - CurrentString);
NewSize = StrSize(CurrentString);
NewSize -= StrLen(Node->Key) - 1;
Node->Val = AllocateZeroPool(NewSize);
ASSERT(Node->Val != NULL);
StrCpy(Node->Val, CurrentString + StrLen(Node->Key) + 1);
Node->Atts = EFI_VARIABLE_BOOTSERVICE_ACCESS;
if (VarList == NULL) {
VarList = AllocateZeroPool(sizeof(ENV_VAR_LIST));
ASSERT(VarList != NULL);
InitializeListHead(&VarList->Link);
}
InsertTailList(&VarList->Link, &Node->Link);
} // for loop
//
// set this new list as the set of all environment variables.
// this function also frees the memory and deletes all pre-existing
// shell-guid based environment variables.
//
return (SetEnvironmentVariableList(&VarList->Link));
}

View File

@ -0,0 +1,210 @@
/** @file
function definitions for shell environment functions.
the following includes are required:
//#include <Guid/ShellVariableGuid.h>
//#include <Library/UefiRuntimeServicesTableLib.h>
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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.
**/
#ifndef _SHELL_ENVIRONMENT_VARIABLE_HEADER_
#define _SHELL_ENVIRONMENT_VARIABLE_HEADER_
typedef struct {
LIST_ENTRY Link;
CHAR16 *Key;
CHAR16 *Val;
UINT32 Atts;
} ENV_VAR_LIST;
/**
Reports whether an environment variable is Volatile or Non-Volatile
This will use the Runtime Services call GetVariable to to search for the variable.
@param EnvVarName The name of the environment variable in question
@retval TRUE This environment variable is Volatile
@retval FALSE This environment variable is NON-Volatile
**/
BOOLEAN
EFIAPI
IsVolatileEnv (
IN CONST CHAR16 *EnvVarName
);
/**
Delete a Non-Violatile environment variable.
This will use the Runtime Services call SetVariable to remove a non-violatile variable.
@param EnvVarName The name of the environment variable in question
@retval EFI_SUCCESS The variable was deleted sucessfully
@retval other An error ocurred
@sa SetVariable
**/
#define SHELL_DELETE_ENVIRONMENT_VARIABLE(EnvVarName) \
(gRT->SetVariable((CHAR16*)EnvVarName, \
&gShellVariableGuid, \
0, \
0, \
NULL))
/**
Set a Non-Violatile environment variable.
This will use the Runtime Services call SetVariable to set a non-violatile variable.
@param EnvVarName The name of the environment variable in question
@param BufferSize UINTN size of Buffer
@param Buffer Pointer to value to set variable to
@retval EFI_SUCCESS The variable was changed sucessfully
@retval other An error ocurred
@sa SetVariable
**/
#define SHELL_SET_ENVIRONMENT_VARIABLE_NV(EnvVarName,BufferSize,Buffer) \
(gRT->SetVariable((CHAR16*)EnvVarName, \
&gShellVariableGuid, \
EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS, \
BufferSize, \
(VOID*)Buffer))
/**
Get an environment variable.
This will use the Runtime Services call GetVariable to get a variable.
@param EnvVarName The name of the environment variable in question
@param BufferSize Pointer to the UINTN size of Buffer
@param Buffer Pointer buffer to get variable value into
@retval EFI_SUCCESS The variable's value was retrieved sucessfully
@retval other An error ocurred
@sa SetVariable
**/
#define SHELL_GET_ENVIRONMENT_VARIABLE(EnvVarName,BufferSize,Buffer) \
(gRT->GetVariable((CHAR16*)EnvVarName, \
&gShellVariableGuid, \
0, \
BufferSize, \
Buffer))
/**
Get an environment variable.
This will use the Runtime Services call GetVariable to get a variable.
@param EnvVarName The name of the environment variable in question
@param Atts Pointer to the UINT32 for attributes (or NULL)
@param BufferSize Pointer to the UINTN size of Buffer
@param Buffer Pointer buffer to get variable value into
@retval EFI_SUCCESS The variable's value was retrieved sucessfully
@retval other An error ocurred
@sa SetVariable
**/
#define SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(EnvVarName,Atts,BufferSize,Buffer) \
(gRT->GetVariable((CHAR16*)EnvVarName, \
&gShellVariableGuid, \
Atts, \
BufferSize, \
Buffer))
/**
Set a Violatile environment variable.
This will use the Runtime Services call SetVariable to set a violatile variable.
@param EnvVarName The name of the environment variable in question
@param BufferSize UINTN size of Buffer
@param Buffer Pointer to value to set variable to
@retval EFI_SUCCESS The variable was changed sucessfully
@retval other An error ocurred
@sa SetVariable
**/
#define SHELL_SET_ENVIRONMENT_VARIABLE_V(EnvVarName,BufferSize,Buffer) \
(gRT->SetVariable((CHAR16*)EnvVarName, \
&gShellVariableGuid, \
EFI_VARIABLE_BOOTSERVICE_ACCESS, \
BufferSize, \
(VOID*)Buffer))
/**
Creates a list of all Shell-Guid-based environment variables.
@param[in,out] List The pointer to pointer to LIST_ENTRY object for
storing this list.
@retval EFI_SUCCESS the list was created sucessfully.
**/
EFI_STATUS
EFIAPI
GetEnvironmentVariableList(
IN OUT LIST_ENTRY *List
);
/**
Sets a list of all Shell-Guid-based environment variables. this will
also eliminate all pre-existing shell environment variables (even if they
are not on the list).
This function will also deallocate the memory from List.
@param[in] List The pointer to LIST_ENTRY from
GetShellEnvVarList().
@retval EFI_SUCCESS The list was Set sucessfully.
**/
EFI_STATUS
EFIAPI
SetEnvironmentVariableList(
IN LIST_ENTRY *List
);
/**
sets all Shell-Guid-based environment variables. this will
also eliminate all pre-existing shell environment variables (even if they
are not on the list).
@param[in] Environment Points to a NULL-terminated array of environment
variables with the format 'x=y', where x is the
environment variable name and y is the value.
@retval EFI_SUCCESS The command executed successfully.
@retval EFI_INVALID_PARAMETER The parameter is invalid.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@sa SetEnvironmentVariableList
**/
EFI_STATUS
EFIAPI
SetEnvironmentVariables(
IN CONST CHAR16 **Environment
);
/**
free function for ENV_VAR_LIST objects.
@param[in] List The pointer to pointer to list.
**/
VOID
EFIAPI
FreeEnvironmentVariableList(
IN LIST_ENTRY *List
);
#endif //_SHELL_ENVIRONMENT_VARIABLE_HEADER_

View File

@ -0,0 +1,615 @@
/** @file
Provides interface to shell MAN file parser.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 "Shell.h"
/**
Verifies that the filename has .MAN on the end.
allocates a new buffer and copies the name (appending .MAN if necessary)
ASSERT if ManFileName is NULL
@param[in] ManFileName original filename
@return the new filename with .man as the extension.
**/
CHAR16 *
EFIAPI
GetManFileName(
IN CONST CHAR16 *ManFileName
)
{
CHAR16 *Buffer;
ASSERT(ManFileName != NULL);
//
// Fix the file name
//
if (StrnCmp(ManFileName+StrLen(ManFileName)-4, L".man", 4)==0) {
Buffer = AllocateZeroPool(StrSize(ManFileName));
StrCpy(Buffer, ManFileName);
} else {
Buffer = AllocateZeroPool(StrSize(ManFileName) + 4*sizeof(CHAR16));
StrCpy(Buffer, ManFileName);
StrCat(Buffer, L".man");
}
return (Buffer);
}
/**
Search the path environment variable for possible locations and test for
which one contains a man file with the name specified. If a valid file is found
stop searching and return the (opened) SHELL_FILE_HANDLE for that file.
@param[in] FileName Name of the file to find and open.
@param[out] Handle Pointer to the handle of the found file. The
value of this is undefined for return values
except EFI_SUCCESS.
@retval EFI_SUCCESS The file was found. Handle is a valid SHELL_FILE_HANDLE
@retval EFI_INVALID_PARAMETER A parameter had an invalid value.
@retval EFI_NOT_FOUND The file was not found.
**/
EFI_STATUS
EFIAPI
SearchPathForFile(
IN CONST CHAR16 *FileName,
OUT SHELL_FILE_HANDLE *Handle
)
{
CHAR16 *FullFileName;
EFI_STATUS Status;
if ( FileName == NULL
|| Handle == NULL
|| StrLen(FileName) == 0
){
return (EFI_INVALID_PARAMETER);
}
FullFileName = ShellFindFilePath(FileName);
if (FullFileName == NULL) {
return (EFI_NOT_FOUND);
}
//
// now open that file
//
Status = EfiShellOpenFileByName(FullFileName, Handle, EFI_FILE_MODE_READ);
FreePool(FullFileName);
return (Status);
}
/**
parses through Buffer (which is MAN file formatted) and returns the
detailed help for any sub section specified in the comma seperated list of
sections provided. If the end of the file or a .TH section is found then
return.
Upon a sucessful return the caller is responsible to free the memory in *HelpText
@param[in] Buffer Buffer to read from
@param[in] Sections name of command's sub sections to find
@param[in] HelpText pointer to pointer to string where text goes.
@param[in] HelpSize pointer to size of allocated HelpText (may be updated)
@retval EFI_OUT_OF_RESOURCES a memory allocation failed.
@retval EFI_SUCCESS the section was found and its description sotred in
an alloceted buffer.
**/
EFI_STATUS
EFIAPI
ManBufferFindSections(
IN CONST CHAR16 *Buffer,
IN CONST CHAR16 *Sections,
IN CHAR16 **HelpText,
IN UINTN *HelpSize
)
{
EFI_STATUS Status;
CONST CHAR16 *CurrentLocation;
BOOLEAN CurrentlyReading;
CHAR16 *SectionName;
UINTN SectionLen;
BOOLEAN Found;
CHAR16 *TempString;
CHAR16 *TempString2;
if ( Buffer == NULL
|| HelpText == NULL
|| HelpSize == NULL
){
return (EFI_INVALID_PARAMETER);
}
Status = EFI_SUCCESS;
CurrentlyReading = FALSE;
Found = FALSE;
for (CurrentLocation = Buffer,TempString = NULL
; CurrentLocation != NULL && *CurrentLocation != CHAR_NULL
; CurrentLocation=StrStr(CurrentLocation, L"\r\n"),TempString = NULL
){
while(CurrentLocation[0] == L'\r' || CurrentLocation[0] == L'\n') {
CurrentLocation++;
}
if (CurrentLocation[0] == L'#') {
//
// Skip comment lines
//
continue;
}
if (StrnCmp(CurrentLocation, L".TH", 3) == 0) {
//
// we hit the end of this commands section so stop.
//
break;
}
if (StrnCmp(CurrentLocation, L".SH ", 4) == 0) {
if (Sections == NULL) {
CurrentlyReading = TRUE;
continue;
} else if (CurrentlyReading) {
CurrentlyReading = FALSE;
}
CurrentLocation += 4;
//
// is this a section we want to read in?
//
if (StrLen(CurrentLocation)!=0) {
TempString2 = StrStr(CurrentLocation, L" ");
TempString2 = MIN(TempString2, StrStr(CurrentLocation, L"\r"));
TempString2 = MIN(TempString2, StrStr(CurrentLocation, L"\n"));
ASSERT(TempString == NULL);
TempString = StrnCatGrow(&TempString, NULL, CurrentLocation, TempString2==NULL?0:TempString2 - CurrentLocation);
SectionName = TempString;
SectionLen = StrLen(SectionName);
SectionName = StrStr(Sections, SectionName);
if (SectionName == NULL) {
continue;
}
if (*(SectionName + SectionLen) == CHAR_NULL || *(SectionName + SectionLen) == L',') {
CurrentlyReading = TRUE;
}
}
} else if (CurrentlyReading) {
Found = TRUE;
if (StrLen(CurrentLocation)!=0) {
TempString2 = StrStr(CurrentLocation, L"\r");
TempString2 = MIN(TempString2, StrStr(CurrentLocation, L"\n"));
ASSERT(TempString == NULL);
TempString = StrnCatGrow(&TempString, NULL, CurrentLocation, TempString2==NULL?0:TempString2 - CurrentLocation);
//
// copy and save the current line.
//
ASSERT((*HelpText == NULL && *HelpSize == 0) || (*HelpText != NULL));
StrnCatGrow (HelpText, HelpSize, TempString, 0);
StrnCatGrow (HelpText, HelpSize, L"\r\n", 0);
}
}
SHELL_FREE_NON_NULL(TempString);
}
if (!Found && !EFI_ERROR(Status)) {
return (EFI_NOT_FOUND);
}
return (Status);
}
/**
parses through the MAN file specified by SHELL_FILE_HANDLE and returns the
detailed help for any sub section specified in the comma seperated list of
sections provided. If the end of the file or a .TH section is found then
return.
Upon a sucessful return the caller is responsible to free the memory in *HelpText
@param[in] Handle FileHandle to read from
@param[in] Sections name of command's sub sections to find
@param[out] HelpText pointer to pointer to string where text goes.
@param[out] HelpSize pointer to size of allocated HelpText (may be updated)
@param[in] Ascii TRUE if the file is ASCII, FALSE otherwise.
@retval EFI_OUT_OF_RESOURCES a memory allocation failed.
@retval EFI_SUCCESS the section was found and its description sotred in
an alloceted buffer.
**/
EFI_STATUS
EFIAPI
ManFileFindSections(
IN SHELL_FILE_HANDLE Handle,
IN CONST CHAR16 *Sections,
OUT CHAR16 **HelpText,
OUT UINTN *HelpSize,
IN BOOLEAN Ascii
)
{
EFI_STATUS Status;
CHAR16 *ReadLine;
UINTN Size;
BOOLEAN CurrentlyReading;
CHAR16 *SectionName;
UINTN SectionLen;
BOOLEAN Found;
if ( Handle == NULL
|| HelpText == NULL
|| HelpSize == NULL
){
return (EFI_INVALID_PARAMETER);
}
Status = EFI_SUCCESS;
CurrentlyReading = FALSE;
Size = 1024;
Found = FALSE;
ReadLine = AllocateZeroPool(Size);
if (ReadLine == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
for (;!ShellFileHandleEof(Handle);Size = 1024) {
Status = ShellFileHandleReadLine(Handle, ReadLine, &Size, TRUE, &Ascii);
if (ReadLine[0] == L'#') {
//
// Skip comment lines
//
continue;
}
//
// ignore too small of buffer...
//
if (Status == EFI_BUFFER_TOO_SMALL) {
Status = EFI_SUCCESS;
}
if (EFI_ERROR(Status)) {
break;
} else if (StrnCmp(ReadLine, L".TH", 3) == 0) {
//
// we hit the end of this commands section so stop.
//
break;
} else if (StrnCmp(ReadLine, L".SH", 3) == 0) {
if (Sections == NULL) {
CurrentlyReading = TRUE;
continue;
}
//
// we found a section
//
if (CurrentlyReading) {
CurrentlyReading = FALSE;
}
//
// is this a section we want to read in?
//
for ( SectionName = ReadLine + 3
; *SectionName == L' '
; SectionName++);
SectionLen = StrLen(SectionName);
SectionName = StrStr(Sections, SectionName);
if (SectionName == NULL) {
continue;
}
if (*(SectionName + SectionLen) == CHAR_NULL || *(SectionName + SectionLen) == L',') {
CurrentlyReading = TRUE;
}
} else if (CurrentlyReading) {
Found = TRUE;
//
// copy and save the current line.
//
ASSERT((*HelpText == NULL && *HelpSize == 0) || (*HelpText != NULL));
StrnCatGrow (HelpText, HelpSize, ReadLine, 0);
StrnCatGrow (HelpText, HelpSize, L"\r\n", 0);
}
}
FreePool(ReadLine);
if (!Found && !EFI_ERROR(Status)) {
return (EFI_NOT_FOUND);
}
return (Status);
}
/**
parses through the MAN file formatted Buffer and returns the
"Brief Description" for the .TH section as specified by Command. If the
command section is not found return EFI_NOT_FOUND.
Upon a sucessful return the caller is responsible to free the memory in *BriefDesc
@param[in] Handle Buffer to read from
@param[in] Command name of command's section to find
@param[in] BriefDesc pointer to pointer to string where description goes.
@param[in] BriefSize pointer to size of allocated BriefDesc
@retval EFI_OUT_OF_RESOURCES a memory allocation failed.
@retval EFI_SUCCESS the section was found and its description sotred in
an alloceted buffer.
**/
EFI_STATUS
EFIAPI
ManBufferFindTitleSection(
IN CHAR16 **Buffer,
IN CONST CHAR16 *Command,
IN CHAR16 **BriefDesc,
IN UINTN *BriefSize
)
{
EFI_STATUS Status;
CHAR16 *TitleString;
CHAR16 *TitleEnd;
CHAR16 *CurrentLocation;
if ( Buffer == NULL
|| Command == NULL
|| (BriefDesc != NULL && BriefSize == NULL)
){
return (EFI_INVALID_PARAMETER);
}
Status = EFI_SUCCESS;
TitleString = AllocatePool((7*sizeof(CHAR16)) + StrSize(Command));
if (TitleString == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
StrCpy(TitleString, L".TH ");
StrCat(TitleString, Command);
StrCat(TitleString, L" 0 ");
CurrentLocation = StrStr(*Buffer, TitleString);
if (CurrentLocation == NULL){
Status = EFI_NOT_FOUND;
} else {
//
// we found it so copy out the rest of the line into BriefDesc
// After skipping any spaces or zeroes
//
for (CurrentLocation += StrLen(TitleString)
; *CurrentLocation == L' ' || *CurrentLocation == L'0' || *CurrentLocation == L'1' || *CurrentLocation == L'\"'
; CurrentLocation++);
TitleEnd = StrStr(CurrentLocation, L"\"");
ASSERT(TitleEnd != NULL);
if (BriefDesc != NULL) {
*BriefSize = StrSize(TitleEnd);
*BriefDesc = AllocateZeroPool(*BriefSize);
if (*BriefDesc == NULL) {
Status = EFI_OUT_OF_RESOURCES;
} else {
StrnCpy(*BriefDesc, CurrentLocation, TitleEnd-CurrentLocation);
}
}
for (CurrentLocation = TitleEnd
; *CurrentLocation != L'\n'
; CurrentLocation++);
for (
; *CurrentLocation == L' ' || *CurrentLocation == L'\n' || *CurrentLocation == L'\r'
; CurrentLocation++);
*Buffer = CurrentLocation;
}
FreePool(TitleString);
return (Status);
}
/**
parses through the MAN file specified by SHELL_FILE_HANDLE and returns the
"Brief Description" for the .TH section as specified by Command. if the
command section is not found return EFI_NOT_FOUND.
Upon a sucessful return the caller is responsible to free the memory in *BriefDesc
@param[in] Handle FileHandle to read from
@param[in] Command name of command's section to find
@param[out] BriefDesc pointer to pointer to string where description goes.
@param[out] BriefSize pointer to size of allocated BriefDesc
@param[in,out] Ascii TRUE if the file is ASCII, FALSE otherwise, will be
set if the file handle is at the 0 position.
@retval EFI_OUT_OF_RESOURCES a memory allocation failed.
@retval EFI_SUCCESS the section was found and its description sotred in
an alloceted buffer.
**/
EFI_STATUS
EFIAPI
ManFileFindTitleSection(
IN SHELL_FILE_HANDLE Handle,
IN CONST CHAR16 *Command,
OUT CHAR16 **BriefDesc OPTIONAL,
OUT UINTN *BriefSize OPTIONAL,
IN OUT BOOLEAN *Ascii
)
{
EFI_STATUS Status;
CHAR16 *TitleString;
CHAR16 *ReadLine;
UINTN Size;
CHAR16 *TitleEnd;
UINTN TitleLen;
BOOLEAN Found;
if ( Handle == NULL
|| Command == NULL
|| (BriefDesc != NULL && BriefSize == NULL)
){
return (EFI_INVALID_PARAMETER);
}
Status = EFI_SUCCESS;
Size = 1024;
Found = FALSE;
ReadLine = AllocateZeroPool(Size);
if (ReadLine == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
TitleString = AllocatePool((4*sizeof(CHAR16)) + StrSize(Command));
if (TitleString == NULL) {
FreePool(ReadLine);
return (EFI_OUT_OF_RESOURCES);
}
StrCpy(TitleString, L".TH ");
StrCat(TitleString, Command);
TitleLen = StrLen(TitleString);
for (;!ShellFileHandleEof(Handle);Size = 1024) {
Status = ShellFileHandleReadLine(Handle, ReadLine, &Size, TRUE, Ascii);
if (ReadLine[0] == L'#') {
//
// Skip comment lines
//
continue;
}
//
// ignore too small of buffer...
//
if (Status == EFI_BUFFER_TOO_SMALL) {
Status = EFI_SUCCESS;
}
if (EFI_ERROR(Status)) {
break;
}
if (StrnCmp(ReadLine, TitleString, TitleLen) == 0) {
Found = TRUE;
//
// we found it so copy out the rest of the line into BriefDesc
// After skipping any spaces or zeroes
//
for ( TitleEnd = ReadLine+TitleLen
; *TitleEnd == L' ' || *TitleEnd == L'0' || *TitleEnd == L'1'
; TitleEnd++);
if (BriefDesc != NULL) {
*BriefSize = StrSize(TitleEnd);
*BriefDesc = AllocateZeroPool(*BriefSize);
if (*BriefDesc == NULL) {
Status = EFI_OUT_OF_RESOURCES;
break;
}
StrCpy(*BriefDesc, TitleEnd);
}
break;
}
}
FreePool(ReadLine);
FreePool(TitleString);
if (!Found && !EFI_ERROR(Status)) {
return (EFI_NOT_FOUND);
}
return (Status);
}
/**
This function returns the help information for the specified command. The help text
will be parsed from a UEFI Shell manual page. (see UEFI Shell 2.0 Appendix B)
If Sections is specified, then each section name listed will be compared in a casesensitive
manner, to the section names described in Appendix B. If the section exists,
it will be appended to the returned help text. If the section does not exist, no
information will be returned. If Sections is NULL, then all help text information
available will be returned.
if BriefDesc is NULL, then the breif description will not be savedd seperatly,
but placed first in the main HelpText.
@param[in] ManFileName Points to the NULL-terminated UEFI Shell MAN file name.
@param[in] Command Points to the NULL-terminated UEFI Shell command name.
@param[in] Sections Points to the NULL-terminated comma-delimited
section names to return. If NULL, then all
sections will be returned.
@param[out] BriefDesc On return, points to a callee-allocated buffer
containing brief description text.
@param[out] HelpText On return, points to a callee-allocated buffer
containing all specified help text.
@retval EFI_SUCCESS The help text was returned.
@retval EFI_OUT_OF_RESOURCES The necessary buffer could not be allocated to hold the
returned help text.
@retval EFI_INVALID_PARAMETER HelpText is NULL
@retval EFI_NOT_FOUND There is no help text available for Command.
**/
EFI_STATUS
EFIAPI
ProcessManFile(
IN CONST CHAR16 *ManFileName,
IN CONST CHAR16 *Command,
IN CONST CHAR16 *Sections OPTIONAL,
OUT CHAR16 **BriefDesc OPTIONAL,
OUT CHAR16 **HelpText
)
{
CHAR16 *TempString;
SHELL_FILE_HANDLE FileHandle;
EFI_STATUS Status;
UINTN HelpSize;
UINTN BriefSize;
BOOLEAN Ascii;
CHAR16 *TempString2;
EFI_DEVICE_PATH_PROTOCOL *FileDevPath;
EFI_DEVICE_PATH_PROTOCOL *DevPath;
if ( ManFileName == NULL
|| Command == NULL
|| HelpText == NULL
){
return (EFI_INVALID_PARAMETER);
}
HelpSize = 0;
BriefSize = 0;
TempString = NULL;
//
// See if it's in HII first
//
TempString = ShellCommandGetCommandHelp(Command);
if (TempString != NULL) {
TempString2 = TempString;
Status = ManBufferFindTitleSection(&TempString2, Command, BriefDesc, &BriefSize);
if (!EFI_ERROR(Status) && HelpText != NULL){
Status = ManBufferFindSections(TempString2, Sections, HelpText, &HelpSize);
}
} else {
FileHandle = NULL;
TempString = GetManFileName(ManFileName);
Status = SearchPathForFile(TempString, &FileHandle);
if (EFI_ERROR(Status)) {
FileDevPath = FileDevicePath(NULL, TempString);
DevPath = AppendDevicePath (ShellInfoObject.ImageDevPath, FileDevPath);
Status = InternalOpenFileDevicePath(DevPath, &FileHandle, EFI_FILE_MODE_READ, 0);
FreePool(FileDevPath);
FreePool(DevPath);
}
if (!EFI_ERROR(Status)) {
HelpSize = 0;
BriefSize = 0;
Status = ManFileFindTitleSection(FileHandle, Command, BriefDesc, &BriefSize, &Ascii);
if (!EFI_ERROR(Status) && HelpText != NULL){
Status = ManFileFindSections(FileHandle, Sections, HelpText, &HelpSize, Ascii);
}
ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle);
} else {
*HelpText = NULL;
}
}
if (TempString != NULL) {
FreePool(TempString);
}
return (Status);
}

View File

@ -0,0 +1,86 @@
/** @file
Provides interface to shell MAN file parser.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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.
**/
#ifndef _SHELL_MAN_FILE_PARSER_HEADER_
#define _SHELL_MAN_FILE_PARSER_HEADER_
/**
This function returns the help information for the specified command. The help text
will be parsed from a UEFI Shell manual page. (see UEFI Shell 2.0 Appendix B)
If Sections is specified, then each section name listed will be compared in a casesensitive
manner, to the section names described in Appendix B. If the section exists,
it will be appended to the returned help text. If the section does not exist, no
information will be returned. If Sections is NULL, then all help text information
available will be returned.
if BriefDesc is NULL, then the breif description will not be savedd seperatly,
but placed first in the main HelpText.
@param[in] ManFileName Points to the NULL-terminated UEFI Shell MAN file name.
@param[in] Command Points to the NULL-terminated UEFI Shell command name.
@param[in] Sections Points to the NULL-terminated comma-delimited
section names to return. If NULL, then all
sections will be returned.
@param[out] BriefDesc On return, points to a callee-allocated buffer
containing brief description text.
@param[out] HelpText On return, points to a callee-allocated buffer
containing all specified help text.
@retval EFI_SUCCESS The help text was returned.
@retval EFI_OUT_OF_RESOURCES The necessary buffer could not be allocated to hold the
returned help text.
@retval EFI_INVALID_PARAMETER HelpText is NULL
@retval EFI_NOT_FOUND There is no help text available for Command.
**/
EFI_STATUS
EFIAPI
ProcessManFile(
IN CONST CHAR16 *ManFileName,
IN CONST CHAR16 *Command,
IN CONST CHAR16 *Sections OPTIONAL,
OUT CHAR16 **BriefDesc,
OUT CHAR16 **HelpText
);
/**
parses through the MAN file specified by SHELL_FILE_HANDLE and returns the
detailed help for any sub section specified in the comma seperated list of
sections provided. If the end of the file or a .TH section is found then
return.
Upon a sucessful return the caller is responsible to free the memory in *HelpText
@param[in] Handle FileHandle to read from
@param[in] Sections name of command's sub sections to find
@param[out] HelpText pointer to pointer to string where text goes.
@param[out] HelpSize pointer to size of allocated HelpText (may be updated)
@param[in] Ascii TRUE if the file is ASCII, FALSE otherwise.
@retval EFI_OUT_OF_RESOURCES a memory allocation failed.
@retval EFI_SUCCESS the section was found and its description sotred in
an alloceted buffer.
**/
EFI_STATUS
EFIAPI
ManFileFindSections(
IN SHELL_FILE_HANDLE Handle,
IN CONST CHAR16 *Sections,
OUT CHAR16 **HelpText,
OUT UINTN *HelpSize,
IN BOOLEAN Ascii
);
#endif //_SHELL_MAN_FILE_PARSER_HEADER_

View File

@ -0,0 +1,949 @@
/** @file
Member functions of EFI_SHELL_PARAMETERS_PROTOCOL and functions for creation,
manipulation, and initialization of EFI_SHELL_PARAMETERS_PROTOCOL.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 "ShellParametersProtocol.h"
/**
return the next parameter from a command line string;
This function moves the next parameter from Walker into TempParameter and moves
Walker up past that parameter for recursive calling. When the final parameter
is moved *Walker will be set to NULL;
Temp Parameter must be large enough to hold the parameter before calling this
function.
@param[in,out] Walker pointer to string of command line. Adjusted to
reminaing command line on return
@param[in,out] TempParameter pointer to string of command line item extracted.
**/
VOID
EFIAPI
GetNextParameter(
CHAR16 **Walker,
CHAR16 **TempParameter
)
{
CHAR16 *NextDelim;
CHAR16 *TempLoc;
ASSERT(Walker != NULL);
ASSERT(*Walker != NULL);
ASSERT(TempParameter != NULL);
ASSERT(*TempParameter != NULL);
//
// make sure we dont have any leading spaces
//
while ((*Walker)[0] == L' ') {
(*Walker)++;
}
//
// make sure we still have some params now...
//
if (StrLen(*Walker) == 0) {
ASSERT((*Walker)[0] == CHAR_NULL);
*Walker = NULL;
return;
}
//
// we have a quoted parameter
// could be the last parameter, but SHOULD have a trailing quote
//
if ((*Walker)[0] == L'\"') {
NextDelim = NULL;
for (TempLoc = *Walker + 1 ; TempLoc != NULL && *TempLoc != CHAR_NULL ; TempLoc++) {
if (*TempLoc == L'^' && *(TempLoc+1) == L'^') {
TempLoc++;
} else if (*TempLoc == L'^' && *(TempLoc+1) == L'\"') {
TempLoc++;
} else if (*TempLoc == L'^' && *(TempLoc+1) == L'|') {
TempLoc++;
} else if (*TempLoc == L'^') {
*TempLoc = L' ';
} else if (*TempLoc == L'\"') {
NextDelim = TempLoc;
break;
}
}
if (NextDelim - ((*Walker)+1) == 0) {
//
// found ""
//
StrCpy(*TempParameter, L"");
*Walker = NextDelim + 1;
} else if (NextDelim != NULL) {
StrnCpy(*TempParameter, (*Walker)+1, NextDelim - ((*Walker)+1));
*Walker = NextDelim + 1;
} else {
//
// last one... someone forgot the training quote!
//
StrCpy(*TempParameter, *Walker);
*Walker = NULL;
}
for (TempLoc = *TempParameter ; TempLoc != NULL && *TempLoc != CHAR_NULL ; TempLoc++) {
if ((*TempLoc == L'^' && *(TempLoc+1) == L'^')
|| (*TempLoc == L'^' && *(TempLoc+1) == L'|')
|| (*TempLoc == L'^' && *(TempLoc+1) == L'\"')
){
CopyMem(TempLoc, TempLoc+1, StrSize(TempLoc) - sizeof(TempLoc[0]));
}
}
} else {
//
// we have a regular parameter (no quote) OR
// we have the final parameter (no trailing space)
//
NextDelim = StrStr((*Walker), L" ");
if (NextDelim != NULL) {
StrnCpy(*TempParameter, *Walker, NextDelim - (*Walker));
(*TempParameter)[NextDelim - (*Walker)] = CHAR_NULL;
*Walker = NextDelim+1;
} else {
//
// last one.
//
StrCpy(*TempParameter, *Walker);
*Walker = NULL;
}
for (NextDelim = *TempParameter ; NextDelim != NULL && *NextDelim != CHAR_NULL ; NextDelim++) {
if (*NextDelim == L'^' && *(NextDelim+1) == L'^') {
CopyMem(NextDelim, NextDelim+1, StrSize(NextDelim) - sizeof(NextDelim[0]));
} else if (*NextDelim == L'^') {
*NextDelim = L' ';
}
}
while ((*TempParameter)[StrLen(*TempParameter)-1] == L' ') {
(*TempParameter)[StrLen(*TempParameter)-1] = CHAR_NULL;
}
while ((*TempParameter)[0] == L' ') {
CopyMem(*TempParameter, (*TempParameter)+1, StrSize(*TempParameter) - sizeof((*TempParameter)[0]));
}
}
return;
}
/**
function to populate Argc and Argv.
This function parses the CommandLine and divides it into standard C style Argc/Argv
parameters for inclusion in EFI_SHELL_PARAMETERS_PROTOCOL. this supports space
delimited and quote surrounded parameter definition.
@param[in] CommandLine String of command line to parse
@param[in,out] Argv pointer to array of strings; one for each parameter
@param[in,out] Argc pointer to number of strings in Argv array
@return EFI_SUCCESS the operation was sucessful
@return EFI_OUT_OF_RESOURCES a memory allocation failed.
**/
EFI_STATUS
EFIAPI
ParseCommandLineToArgs(
IN CONST CHAR16 *CommandLine,
IN OUT CHAR16 ***Argv,
IN OUT UINTN *Argc
)
{
UINTN Count;
CHAR16 *TempParameter;
CHAR16 *Walker;
CHAR16 *NewParam;
UINTN Size;
ASSERT(Argc != NULL);
ASSERT(Argv != NULL);
if (CommandLine == NULL || StrLen(CommandLine)==0) {
(*Argc) = 0;
(*Argv) = NULL;
return (EFI_SUCCESS);
}
Size = StrSize(CommandLine);
TempParameter = AllocateZeroPool(Size);
if (TempParameter == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
for ( Count = 0
, Walker = (CHAR16*)CommandLine
; Walker != NULL && *Walker != CHAR_NULL
; GetNextParameter(&Walker, &TempParameter)
, Count++
);
/* Count = 0;
Walker = (CHAR16*)CommandLine;
while(Walker != NULL) {
GetNextParameter(&Walker, &TempParameter);
Count++;
}
*/
//
// lets allocate the pointer array
//
(*Argv) = AllocateZeroPool((Count)*sizeof(CHAR16*));
if (*Argv == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
*Argc = 0;
Walker = (CHAR16*)CommandLine;
while(Walker != NULL && *Walker != CHAR_NULL) {
SetMem16(TempParameter, Size, CHAR_NULL);
GetNextParameter(&Walker, &TempParameter);
NewParam = AllocateZeroPool(StrSize(TempParameter));
ASSERT(NewParam != NULL);
StrCpy(NewParam, TempParameter);
((CHAR16**)(*Argv))[(*Argc)] = NewParam;
(*Argc)++;
}
ASSERT(Count >= (*Argc));
return (EFI_SUCCESS);
}
/**
creates a new EFI_SHELL_PARAMETERS_PROTOCOL instance and populates it and then
installs it on our handle and if there is an existing version of the protocol
that one is cached for removal later.
@param[in,out] NewShellParameters on a successful return, a pointer to pointer
to the newly installed interface.
@param[in,out] RootShellInstance on a successful return, pointer to boolean.
TRUE if this is the root shell instance.
@retval EFI_SUCCESS the operation completed successfully.
@return other the operation failed.
@sa ReinstallProtocolInterface
@sa InstallProtocolInterface
@sa ParseCommandLineToArgs
**/
EFI_STATUS
EFIAPI
CreatePopulateInstallShellParametersProtocol (
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL **NewShellParameters,
IN OUT BOOLEAN *RootShellInstance
)
{
EFI_STATUS Status;
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
CHAR16 *FullCommandLine;
UINTN Size;
Size = 0;
FullCommandLine = NULL;
LoadedImage = NULL;
//
// Assert for valid parameters
//
ASSERT(NewShellParameters != NULL);
ASSERT(RootShellInstance != NULL);
//
// See if we have a shell parameters placed on us
//
Status = gBS->OpenProtocol (
gImageHandle,
&gEfiShellParametersProtocolGuid,
(VOID **) &ShellInfoObject.OldShellParameters,
gImageHandle,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
//
// if we don't then we must be the root shell (error is expected)
//
if (EFI_ERROR (Status)) {
*RootShellInstance = TRUE;
}
//
// Allocate the new structure
//
*NewShellParameters = AllocateZeroPool(sizeof(EFI_SHELL_PARAMETERS_PROTOCOL));
ASSERT(NewShellParameters != NULL);
//
// get loaded image protocol
//
Status = gBS->OpenProtocol (
gImageHandle,
&gEfiLoadedImageProtocolGuid,
(VOID **) &LoadedImage,
gImageHandle,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
ASSERT_EFI_ERROR(Status);
//
// Build the full command line
//
Status = SHELL_GET_ENVIRONMENT_VARIABLE(L"ShellOpt", &Size, &FullCommandLine);
if (Status == EFI_BUFFER_TOO_SMALL) {
FullCommandLine = AllocateZeroPool(Size + LoadedImage->LoadOptionsSize);
Status = SHELL_GET_ENVIRONMENT_VARIABLE(L"ShellOpt", &Size, &FullCommandLine);
}
if (Status == EFI_NOT_FOUND) {
//
// no parameters via environment... ok
//
} else {
ASSERT_EFI_ERROR(Status);
}
if (Size == 0 && LoadedImage->LoadOptionsSize != 0) {
//
// Now we need to include a NULL terminator in the size.
//
Size = LoadedImage->LoadOptionsSize + sizeof(FullCommandLine[0]);
FullCommandLine = AllocateZeroPool(Size);
}
if (LoadedImage->LoadOptionsSize != 0){
StrCpy(FullCommandLine, LoadedImage->LoadOptions);
}
if (FullCommandLine != NULL) {
//
// Populate Argc and Argv
//
Status = ParseCommandLineToArgs(FullCommandLine,
&(*NewShellParameters)->Argv,
&(*NewShellParameters)->Argc);
FreePool(FullCommandLine);
ASSERT_EFI_ERROR(Status);
} else {
(*NewShellParameters)->Argv = NULL;
(*NewShellParameters)->Argc = 0;
}
//
// Populate the 3 faked file systems...
//
if (*RootShellInstance) {
(*NewShellParameters)->StdIn = &FileInterfaceStdIn;
(*NewShellParameters)->StdOut = &FileInterfaceStdOut;
(*NewShellParameters)->StdErr = &FileInterfaceStdErr;
Status = gBS->InstallProtocolInterface(&gImageHandle,
&gEfiShellParametersProtocolGuid,
EFI_NATIVE_INTERFACE,
(VOID*)(*NewShellParameters));
} else {
//
// copy from the existing ones
//
(*NewShellParameters)->StdIn = ShellInfoObject.OldShellParameters->StdIn;
(*NewShellParameters)->StdOut = ShellInfoObject.OldShellParameters->StdOut;
(*NewShellParameters)->StdErr = ShellInfoObject.OldShellParameters->StdErr;
Status = gBS->ReinstallProtocolInterface(gImageHandle,
&gEfiShellParametersProtocolGuid,
(VOID*)ShellInfoObject.OldShellParameters,
(VOID*)(*NewShellParameters));
}
return (Status);
}
/**
frees all memory used by createion and installation of shell parameters protocol
and if there was an old version installed it will restore that one.
@param NewShellParameters the interface of EFI_SHELL_PARAMETERS_PROTOCOL that is
being cleaned up.
@retval EFI_SUCCESS the cleanup was successful
@return other the cleanup failed
@sa ReinstallProtocolInterface
@sa UninstallProtocolInterface
**/
EFI_STATUS
EFIAPI
CleanUpShellParametersProtocol (
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *NewShellParameters
)
{
EFI_STATUS Status;
UINTN LoopCounter;
//
// If the old exists we need to restore it
//
if (ShellInfoObject.OldShellParameters != NULL) {
Status = gBS->ReinstallProtocolInterface(gImageHandle,
&gEfiShellParametersProtocolGuid,
(VOID*)NewShellParameters,
(VOID*)ShellInfoObject.OldShellParameters);
DEBUG_CODE(ShellInfoObject.OldShellParameters = NULL;);
} else {
//
// No old one, just uninstall us...
//
Status = gBS->UninstallProtocolInterface(gImageHandle,
&gEfiShellParametersProtocolGuid,
(VOID*)NewShellParameters);
}
if (NewShellParameters->Argv != NULL) {
for ( LoopCounter = 0
; LoopCounter < NewShellParameters->Argc
; LoopCounter++
){
FreePool(NewShellParameters->Argv[LoopCounter]);
}
FreePool(NewShellParameters->Argv);
}
FreePool(NewShellParameters);
return (Status);
}
/**
Funcion will replace the current StdIn and StdOut in the ShellParameters protocol
structure by parsing NewCommandLine. The current values are returned to the
user.
If OldStdIn or OldStdOut is NULL then that value is not returned.
@param[in,out] ShellParameters Pointer to parameter structure to modify.
@param[in] NewCommandLine The new command line to parse and use.
@param[out] OldStdIn Pointer to old StdIn.
@param[out] OldStdOut Pointer to old StdOut.
@param[out] OldStdErr Pointer to old StdErr.
@retval EFI_SUCCESS Operation was sucessful, Argv and Argc are valid.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
**/
EFI_STATUS
EFIAPI
UpdateStdInStdOutStdErr(
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
IN CONST CHAR16 *NewCommandLine,
OUT SHELL_FILE_HANDLE *OldStdIn,
OUT SHELL_FILE_HANDLE *OldStdOut,
OUT SHELL_FILE_HANDLE *OldStdErr
)
{
CHAR16 *CommandLineCopy;
CHAR16 *CommandLineWalker;
CHAR16 *StdErrFileName;
CHAR16 *StdOutFileName;
CHAR16 *StdInFileName;
CHAR16 *StdInVarName;
CHAR16 *StdOutVarName;
CHAR16 *StdErrVarName;
EFI_STATUS Status;
SHELL_FILE_HANDLE TempHandle;
UINT64 FileSize;
BOOLEAN OutUnicode;
BOOLEAN InUnicode;
BOOLEAN ErrUnicode;
BOOLEAN OutAppend;
BOOLEAN ErrAppend;
UINTN Size;
CHAR16 TagBuffer[2];
SPLIT_LIST *Split;
ASSERT(ShellParameters != NULL);
OutUnicode = TRUE;
InUnicode = TRUE;
ErrUnicode = TRUE;
StdInVarName = NULL;
StdOutVarName = NULL;
StdErrVarName = NULL;
StdErrFileName = NULL;
StdInFileName = NULL;
StdOutFileName = NULL;
ErrAppend = FALSE;
OutAppend = FALSE;
CommandLineCopy = NULL;
if (OldStdIn != NULL) {
*OldStdIn = ShellParameters->StdIn;
}
if (OldStdOut != NULL) {
*OldStdOut = ShellParameters->StdOut;
}
if (OldStdErr != NULL) {
*OldStdErr = ShellParameters->StdErr;
}
if (NewCommandLine == NULL) {
return (EFI_SUCCESS);
}
CommandLineCopy = StrnCatGrow(&CommandLineCopy, NULL, NewCommandLine, 0);
Status = EFI_SUCCESS;
Split = NULL;
if (!IsListEmpty(&ShellInfoObject.SplitList.Link)) {
Split = (SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link);
if (Split != NULL && Split->SplitStdIn != NULL) {
ShellParameters->StdIn = Split->SplitStdIn;
}
if (Split != NULL && Split->SplitStdOut != NULL) {
ShellParameters->StdOut = Split->SplitStdOut;
}
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>>v ")) != NULL) {
StdErrVarName = CommandLineWalker += 6;
ErrAppend = TRUE;
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>>v ")) != NULL) {
StdOutVarName = CommandLineWalker += 6;
OutAppend = TRUE;
} else if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >>v ")) != NULL) {
StdOutVarName = CommandLineWalker += 5;
OutAppend = TRUE;
} else if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >v ")) != NULL) {
StdOutVarName = CommandLineWalker += 4;
OutAppend = FALSE;
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>>a ")) != NULL) {
StdOutFileName = CommandLineWalker += 6;
OutAppend = TRUE;
OutUnicode = FALSE;
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>> ")) != NULL) {
if (StdOutFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdOutFileName = CommandLineWalker += 5;
OutAppend = TRUE;
}
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >> ")) != NULL) {
if (StdOutFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdOutFileName = CommandLineWalker += 4;
OutAppend = TRUE;
}
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >>a ")) != NULL) {
if (StdOutFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdOutFileName = CommandLineWalker += 5;
OutAppend = TRUE;
OutUnicode = FALSE;
}
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>a ")) != NULL) {
if (StdOutFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdOutFileName = CommandLineWalker += 5;
OutAppend = FALSE;
OutUnicode = FALSE;
}
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >a ")) != NULL) {
if (StdOutFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdOutFileName = CommandLineWalker += 4;
OutAppend = FALSE;
OutUnicode = FALSE;
}
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>> ")) != NULL) {
if (StdErrFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdErrFileName = CommandLineWalker += 5;
ErrAppend = TRUE;
}
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>v ")) != NULL) {
if (StdErrVarName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdErrVarName = CommandLineWalker += 5;
ErrAppend = FALSE;
}
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>v ")) != NULL) {
if (StdOutVarName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdOutVarName = CommandLineWalker += 5;
OutAppend = FALSE;
}
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>a ")) != NULL) {
if (StdErrFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdErrFileName = CommandLineWalker += 5;
ErrAppend = FALSE;
ErrUnicode = FALSE;
}
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2> ")) != NULL) {
if (StdErrFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdErrFileName = CommandLineWalker += 4;
ErrAppend = FALSE;
}
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1> ")) != NULL) {
if (StdOutFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdOutFileName = CommandLineWalker += 4;
OutAppend = FALSE;
}
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" > ")) != NULL) {
if (StdOutFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdOutFileName = CommandLineWalker += 3;
OutAppend = FALSE;
}
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" < ")) != NULL) {
if (StdInFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdInFileName = CommandLineWalker += 3;
OutAppend = FALSE;
}
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" <a ")) != NULL) {
if (StdInFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdInFileName = CommandLineWalker += 4;
OutAppend = FALSE;
}
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" <v ")) != NULL) {
if (StdInVarName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdInVarName = CommandLineWalker += 4;
OutAppend = FALSE;
}
}
if (!EFI_ERROR(Status)) {
if (StdErrFileName != NULL && (CommandLineWalker = StrStr(StdErrFileName, L" ")) != NULL) {
CommandLineWalker[0] = CHAR_NULL;
}
if (StdOutFileName != NULL && (CommandLineWalker = StrStr(StdOutFileName, L" ")) != NULL) {
CommandLineWalker[0] = CHAR_NULL;
}
if (StdInFileName != NULL && (CommandLineWalker = StrStr(StdInFileName , L" ")) != NULL) {
CommandLineWalker[0] = CHAR_NULL;
}
if (StdErrVarName != NULL && (CommandLineWalker = StrStr(StdErrVarName , L" ")) != NULL) {
CommandLineWalker[0] = CHAR_NULL;
}
if (StdOutVarName != NULL && (CommandLineWalker = StrStr(StdOutVarName , L" ")) != NULL) {
CommandLineWalker[0] = CHAR_NULL;
}
if (StdInVarName != NULL && (CommandLineWalker = StrStr(StdInVarName , L" ")) != NULL) {
CommandLineWalker[0] = CHAR_NULL;
}
//
// Verify not the same and not duplicating something from a split
//
if ((StdErrFileName != NULL && StdOutFileName!= NULL && StringNoCaseCompare(&StdErrFileName, &StdOutFileName) == 0)
||(StdErrFileName != NULL && StdInFileName != NULL && StringNoCaseCompare(&StdErrFileName, &StdInFileName ) == 0)
||(StdOutFileName != NULL && StdInFileName != NULL && StringNoCaseCompare(&StdOutFileName, &StdInFileName ) == 0)
||(StdErrVarName != NULL && StdInVarName != NULL && StringNoCaseCompare(&StdErrVarName , &StdInVarName ) == 0)
||(StdOutVarName != NULL && StdInVarName != NULL && StringNoCaseCompare(&StdOutVarName , &StdInVarName ) == 0)
||(StdErrVarName != NULL && StdOutVarName != NULL && StringNoCaseCompare(&StdErrVarName , &StdOutVarName ) == 0)
||(Split != NULL && Split->SplitStdIn != NULL && (StdInVarName != NULL || StdInFileName != NULL))
||(Split != NULL && Split->SplitStdOut != NULL && (StdOutVarName != NULL || StdOutFileName != NULL))
||(StdErrFileName != NULL && StdErrVarName != NULL)
||(StdOutFileName != NULL && StdOutVarName != NULL)
||(StdInFileName != NULL && StdInVarName != NULL)
||(StdErrVarName != NULL && !IsVolatileEnv(StdErrVarName))
||(StdOutVarName != NULL && !IsVolatileEnv(StdOutVarName))
){
Status = EFI_INVALID_PARAMETER;
} else {
//
// Open the Std<Whatever> and we should not have conflicts here...
//
//
// StdErr to a file
//
if (StdErrFileName != NULL) {
if (!ErrAppend) {
//
// delete existing file.
//
ShellInfoObject.NewEfiShellProtocol->DeleteFileByName(StdErrFileName);
}
Status = ShellOpenFileByName(StdErrFileName, &TempHandle, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE,0);
ASSERT(TempHandle != NULL);
if (!ErrAppend && ErrUnicode && !EFI_ERROR(Status)) {
//
// Write out the UnicodeFileTag
//
Size = sizeof(CHAR16);
TagBuffer[0] = UnicodeFileTag;
TagBuffer[1] = CHAR_NULL;
ShellInfoObject.NewEfiShellProtocol->WriteFile(TempHandle, &Size, TagBuffer);
}
if (!ErrUnicode && !EFI_ERROR(Status)) {
TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
ASSERT(TempHandle != NULL);
}
if (!EFI_ERROR(Status)) {
ShellParameters->StdErr = TempHandle;
}
}
//
// StdOut to a file
//
if (!EFI_ERROR(Status) && StdOutFileName != NULL) {
if (!OutAppend) {
//
// delete existing file.
//
ShellInfoObject.NewEfiShellProtocol->DeleteFileByName(StdOutFileName);
}
Status = ShellOpenFileByName(StdOutFileName, &TempHandle, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE,0);
ASSERT(TempHandle != NULL);
if (!OutAppend && OutUnicode && !EFI_ERROR(Status)) {
//
// Write out the UnicodeFileTag
//
Size = sizeof(CHAR16);
TagBuffer[0] = UnicodeFileTag;
TagBuffer[1] = CHAR_NULL;
ShellInfoObject.NewEfiShellProtocol->WriteFile(TempHandle, &Size, TagBuffer);
} else if (OutAppend) {
//
// Move to end of file
//
Status = ShellInfoObject.NewEfiShellProtocol->GetFileSize(TempHandle, &FileSize);
if (!EFI_ERROR(Status)) {
Status = ShellInfoObject.NewEfiShellProtocol->SetFilePosition(TempHandle, FileSize);
}
}
if (!OutUnicode && !EFI_ERROR(Status)) {
TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
ASSERT(TempHandle != NULL);
}
if (!EFI_ERROR(Status)) {
ShellParameters->StdOut = TempHandle;
}
}
//
// StdOut to a var
//
if (!EFI_ERROR(Status) && StdOutVarName != NULL) {
if (!OutAppend) {
//
// delete existing variable.
//
SHELL_SET_ENVIRONMENT_VARIABLE_V(StdOutVarName, 0, L"");
}
TempHandle = CreateFileInterfaceEnv(StdOutVarName);
ASSERT(TempHandle != NULL);
if (!OutUnicode) {
TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
ASSERT(TempHandle != NULL);
}
ShellParameters->StdOut = TempHandle;
}
//
// StdErr to a var
//
if (!EFI_ERROR(Status) && StdErrVarName != NULL) {
if (!ErrAppend) {
//
// delete existing variable.
//
SHELL_SET_ENVIRONMENT_VARIABLE_V(StdErrVarName, 0, L"");
}
TempHandle = CreateFileInterfaceEnv(StdErrVarName);
ASSERT(TempHandle != NULL);
if (!ErrUnicode) {
TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
ASSERT(TempHandle != NULL);
}
ShellParameters->StdErr = TempHandle;
}
//
// StdIn from a var
//
if (!EFI_ERROR(Status) && StdInVarName != NULL) {
TempHandle = CreateFileInterfaceEnv(StdInVarName);
if (!InUnicode) {
TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
}
Size = 0;
ASSERT(TempHandle != NULL);
if (((EFI_FILE_PROTOCOL*)TempHandle)->Read(TempHandle, &Size, NULL) != EFI_BUFFER_TOO_SMALL) {
Status = EFI_INVALID_PARAMETER;
} else {
ShellParameters->StdIn = TempHandle;
}
}
//
// StdIn from a file
//
if (!EFI_ERROR(Status) && StdInFileName != NULL) {
Status = ShellOpenFileByName(
StdInFileName,
&TempHandle,
EFI_FILE_MODE_READ,
0);
if (!InUnicode && !EFI_ERROR(Status)) {
TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
}
if (!EFI_ERROR(Status)) {
ShellParameters->StdIn = TempHandle;
}
}
}
}
FreePool(CommandLineCopy);
return (Status);
}
/**
Funcion will replace the current StdIn and StdOut in the ShellParameters protocol
structure with StdIn and StdOut. The current values are de-allocated.
@param[in,out] ShellParameters pointer to parameter structure to modify
@param[out] OldStdIn Pointer to old StdIn.
@param[out] OldStdOut Pointer to old StdOut.
@param[out] OldStdErr Pointer to old StdErr.
**/
EFI_STATUS
EFIAPI
RestoreStdInStdOutStdErr (
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
OUT SHELL_FILE_HANDLE *OldStdIn OPTIONAL,
OUT SHELL_FILE_HANDLE *OldStdOut OPTIONAL,
OUT SHELL_FILE_HANDLE *OldStdErr OPTIONAL
)
{
SPLIT_LIST *Split;
if (!IsListEmpty(&ShellInfoObject.SplitList.Link)) {
Split = (SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link);
} else {
Split = NULL;
}
if (OldStdIn != NULL && ShellParameters->StdIn != *OldStdIn) {
if ((Split != NULL && Split->SplitStdIn != ShellParameters->StdIn) || Split == NULL) {
gEfiShellProtocol->CloseFile(ShellParameters->StdIn);
}
ShellParameters->StdIn = OldStdIn==NULL?NULL:*OldStdIn;
}
if (OldStdOut != NULL && ShellParameters->StdOut != *OldStdOut) {
if ((Split != NULL && Split->SplitStdOut != ShellParameters->StdOut) || Split == NULL) {
gEfiShellProtocol->CloseFile(ShellParameters->StdOut);
}
ShellParameters->StdOut = OldStdOut==NULL?NULL:*OldStdOut;
}
return (EFI_SUCCESS);
}
/**
Funcion will replace the current Argc and Argv in the ShellParameters protocol
structure by parsing NewCommandLine. The current values are returned to the
user.
If OldArgv or OldArgc is NULL then that value is not returned.
@param[in,out] ShellParameters Pointer to parameter structure to modify.
@param[in] NewCommandLine The new command line to parse and use.
@param[out] OldArgv Pointer to old list of parameters.
@param[out] OldArgc Pointer to old number of items in Argv list.
@retval EFI_SUCCESS Operation was sucessful, Argv and Argc are valid.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
**/
EFI_STATUS
EFIAPI
UpdateArgcArgv(
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
IN CONST CHAR16 *NewCommandLine,
OUT CHAR16 ***OldArgv OPTIONAL,
OUT UINTN *OldArgc OPTIONAL
)
{
ASSERT(ShellParameters != NULL);
if (OldArgc != NULL) {
*OldArgc = ShellParameters->Argc;
}
if (OldArgc != NULL) {
*OldArgv = ShellParameters->Argv;
}
return (ParseCommandLineToArgs(NewCommandLine, &(ShellParameters->Argv), &(ShellParameters->Argc)));
}
/**
Funcion will replace the current Argc and Argv in the ShellParameters protocol
structure with Argv and Argc. The current values are de-allocated and the
OldArgv must not be deallocated by the caller.
@param[in,out] ShellParameters pointer to parameter structure to modify
@param[in] OldArgv pointer to old list of parameters
@param[in] OldArgc pointer to old number of items in Argv list
**/
VOID
EFIAPI
RestoreArgcArgv(
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
IN CHAR16 ***OldArgv,
IN UINTN *OldArgc
)
{
UINTN LoopCounter;
ASSERT(ShellParameters != NULL);
ASSERT(OldArgv != NULL);
ASSERT(OldArgc != NULL);
if (ShellParameters->Argv != NULL) {
for ( LoopCounter = 0
; LoopCounter < ShellParameters->Argc
; LoopCounter++
){
FreePool(ShellParameters->Argv[LoopCounter]);
}
FreePool(ShellParameters->Argv);
}
ShellParameters->Argv = *OldArgv;
*OldArgv = NULL;
ShellParameters->Argc = *OldArgc;
*OldArgc = 0;
}

View File

@ -0,0 +1,208 @@
/** @file
Member functions of EFI_SHELL_PARAMETERS_PROTOCOL and functions for creation,
manipulation, and initialization of EFI_SHELL_PARAMETERS_PROTOCOL.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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.
**/
#ifndef _SHELL_PARAMETERS_PROTOCOL_PROVIDER_HEADER_
#define _SHELL_PARAMETERS_PROTOCOL_PROVIDER_HEADER_
#include <Uefi.h>
#include <Protocol/SimpleFileSystem.h>
#include <Protocol/EfiShellParameters.h>
#include <Protocol/LoadedImage.h>
#include <Guid/ShellVariableGuid.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiLib.h>
#include <Library/DebugLib.h>
#include <Library/ShellLib.h>
#include <Library/FileHandleLib.h>
#include "ShellEnvVar.h"
#include "FileHandleWrappers.h"
#include "Shell.h"
/**
creates a new EFI_SHELL_PARAMETERS_PROTOCOL instance and populates it and then
installs it on our handle and if there is an existing version of the protocol
that one is cached for removal later.
@param[in,out] NewShellParameters on a successful return, a pointer to pointer
to the newly installed interface.
@param[in,out] RootShellInstance on a successful return, pointer to boolean.
TRUE if this is the root shell instance.
@retval EFI_SUCCESS the operation completed successfully.
@return other the operation failed.
@sa ReinstallProtocolInterface
@sa InstallProtocolInterface
@sa ParseCommandLineToArgs
**/
EFI_STATUS
EFIAPI
CreatePopulateInstallShellParametersProtocol (
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL **NewShellParameters,
IN OUT BOOLEAN *RootShellInstance
);
/**
frees all memory used by createion and installation of shell parameters protocol
and if there was an old version installed it will restore that one.
@param NewShellParameters the interface of EFI_SHELL_PARAMETERS_PROTOCOL that is
being cleaned up.
@retval EFI_SUCCESS the cleanup was successful
@return other the cleanup failed
@sa ReinstallProtocolInterface
@sa UninstallProtocolInterface
**/
EFI_STATUS
EFIAPI
CleanUpShellParametersProtocol (
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *NewShellParameters
);
/**
Funcion will replace the current Argc and Argv in the ShellParameters protocol
structure by parsing NewCommandLine. The current values are returned to the
user.
@param[in,out] ShellParameters pointer to parameter structure to modify
@param[in] NewCommandLine the new command line to parse and use
@param[out] OldArgv pointer to old list of parameters
@param[out] OldArgc pointer to old number of items in Argv list
@retval EFI_SUCCESS operation was sucessful, Argv and Argc are valid
@retval EFI_OUT_OF_RESOURCES a memory allocation failed.
**/
EFI_STATUS
EFIAPI
UpdateArgcArgv(
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
IN CONST CHAR16 *NewCommandLine,
OUT CHAR16 ***OldArgv,
OUT UINTN *OldArgc
);
/**
Funcion will replace the current Argc and Argv in the ShellParameters protocol
structure with Argv and Argc. The current values are de-allocated and the
OldArgv must not be deallocated by the caller.
@param[in,out] ShellParameters pointer to parameter structure to modify
@param[in] OldArgv pointer to old list of parameters
@param[in] OldArgc pointer to old number of items in Argv list
**/
VOID
EFIAPI
RestoreArgcArgv(
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
IN CHAR16 ***OldArgv,
IN UINTN *OldArgc
);
/**
Funcion will replace the current StdIn and StdOut in the ShellParameters protocol
structure by parsing NewCommandLine. The current values are returned to the
user.
If OldStdIn or OldStdOut is NULL then that value is not returned.
@param[in,out] ShellParameters Pointer to parameter structure to modify.
@param[in] NewCommandLine The new command line to parse and use.
@param[out] OldStdIn Pointer to old StdIn.
@param[out] OldStdOut Pointer to old StdOut.
@param[out] OldStdErr Pointer to old StdErr.
@retval EFI_SUCCESS Operation was sucessful, Argv and Argc are valid.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
**/
EFI_STATUS
EFIAPI
UpdateStdInStdOutStdErr(
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
IN CONST CHAR16 *NewCommandLine,
OUT SHELL_FILE_HANDLE *OldStdIn OPTIONAL,
OUT SHELL_FILE_HANDLE *OldStdOut OPTIONAL,
OUT SHELL_FILE_HANDLE *OldStdErr OPTIONAL
);
/**
Funcion will replace the current StdIn and StdOut in the ShellParameters protocol
structure with StdIn and StdOut. The current values are de-allocated.
@param[in,out] ShellParameters pointer to parameter structure to modify
@param[out] OldStdIn Pointer to old StdIn.
@param[out] OldStdOut Pointer to old StdOut.
@param[out] OldStdErr Pointer to old StdErr.
**/
EFI_STATUS
EFIAPI
RestoreStdInStdOutStdErr (
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
OUT SHELL_FILE_HANDLE *OldStdIn OPTIONAL,
OUT SHELL_FILE_HANDLE *OldStdOut OPTIONAL,
OUT SHELL_FILE_HANDLE *OldStdErr OPTIONAL
);
/**
function to populate Argc and Argv.
This function parses the CommandLine and divides it into standard C style Argc/Argv
parameters for inclusion in EFI_SHELL_PARAMETERS_PROTOCOL. this supports space
delimited and quote surrounded parameter definition.
@param[in] CommandLine String of command line to parse
@param[in,out] Argv pointer to array of strings; one for each parameter
@param[in,out] Argc pointer to number of strings in Argv array
@return EFI_SUCCESS the operation was sucessful
@return EFI_OUT_OF_RESOURCES a memory allocation failed.
**/
EFI_STATUS
EFIAPI
ParseCommandLineToArgs(
IN CONST CHAR16 *CommandLine,
IN OUT CHAR16 ***Argv,
IN OUT UINTN *Argc
);
/**
return the next parameter from a command line string;
This function moves the next parameter from Walker into TempParameter and moves
Walker up past that parameter for recursive calling. When the final parameter
is moved *Walker will be set to NULL;
Temp Parameter must be large enough to hold the parameter before calling this
function.
@param[in,out] Walker pointer to string of command line. Adjusted to
reminaing command line on return
@param[in,out] TempParameter pointer to string of command line item extracted.
**/
VOID
EFIAPI
GetNextParameter(
CHAR16 **Walker,
CHAR16 **TempParameter
);
#endif //_SHELL_PARAMETERS_PROTOCOL_PROVIDER_HEADER_

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,950 @@
/** @file
Member functions of EFI_SHELL_PROTOCOL and functions for creation,
manipulation, and initialization of EFI_SHELL_PROTOCOL.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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.
**/
#ifndef _SHELL_PROTOCOL_HEADER_
#define _SHELL_PROTOCOL_HEADER_
#include <Uefi.h>
#include <ShellBase.h>
#include <Guid/ShellVariableGuid.h>
#include <Guid/ShellMapGuid.h>
#include <Guid/ShellAliasGuid.h>
#include <Protocol/EfiShell.h>
#include <Protocol/EfiShellParameters.h>
#include <Protocol/SimpleFileSystem.h>
#include <Protocol/DevicePathToText.h>
#include <Protocol/ComponentName2.h>
#include <Protocol/LoadedImage.h>
#include <Protocol/UnicodeCollation.h>
#include <Protocol/DevicePath.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/BaseLib.h>
#include <Library/ShellCommandLib.h>
#include <Library/PrintLib.h>
#include <Library/DevicePathLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/UefiLib.h>
#include <Library/SortLib.h>
#include <Library/PcdLib.h>
#include <Library/ShellLib.h>
#include "FileHandleWrappers.h"
#include "ShellEnvVar.h"
#include "ShellManParser.h"
typedef struct {
LIST_ENTRY Link;
EFI_SHELL_PROTOCOL *Interface;
EFI_HANDLE Handle;
} SHELL_PROTOCOL_HANDLE_LIST;
// flags values...
#define SHELL_MAP_FLAGS_CONSIST BIT1
/**
Function to create and install on the current handle.
Will overwrite any existing ShellProtocols in the system to be sure that
the current shell is in control.
This must be removed via calling CleanUpShellProtocol().
@param[in,out] NewShell The pointer to the pointer to the structure
to install.
@retval EFI_SUCCESS The operation was successful.
@return An error from LocateHandle, CreateEvent, or other core function.
**/
EFI_STATUS
EFIAPI
CreatePopulateInstallShellProtocol (
IN OUT EFI_SHELL_PROTOCOL **NewShell
);
/**
Opposite of CreatePopulateInstallShellProtocol.
Free all memory and restore the system to the state it was in before calling
CreatePopulateInstallShellProtocol.
@param[in,out] NewShell The pointer to the new shell protocol structure.
@retval EFI_SUCCESS The operation was successful.
**/
EFI_STATUS
EFIAPI
CleanUpShellProtocol (
IN OUT EFI_SHELL_PROTOCOL *NewShell
);
/**
This function creates a mapping for a device path.
@param DevicePath Points to the device path. If this is NULL and Mapping points to a valid mapping,
then the mapping will be deleted.
@param Mapping Points to the NULL-terminated mapping for the device path. Must end with a ':'
@retval EFI_SUCCESS Mapping created or deleted successfully.
@retval EFI_NO_MAPPING There is no handle that corresponds exactly to DevicePath. See the
boot service function LocateDevicePath().
@retval EFI_ACCESS_DENIED The mapping is a built-in alias.
@retval EFI_INVALID_PARAMETER Mapping was NULL
@retval EFI_INVALID_PARAMETER Mapping did not end with a ':'
@retval EFI_INVALID_PARAMETER DevicePath was not pointing at a device that had a SIMPLE_FILE_SYSTEM_PROTOCOL installed.
@retval EFI_NOT_FOUND There was no mapping found to delete
@retval EFI_OUT_OF_RESOURCES Memory allocation failed
**/
EFI_STATUS
EFIAPI
EfiShellSetMap(
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,
IN CONST CHAR16 *Mapping
);
/**
Gets the device path from the mapping.
This function gets the device path associated with a mapping.
@param Mapping A pointer to the mapping
@retval !=NULL Pointer to the device path that corresponds to the
device mapping. The returned pointer does not need
to be freed.
@retval NULL There is no device path associated with the
specified mapping.
**/
CONST EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
EfiShellGetDevicePathFromMap(
IN CONST CHAR16 *Mapping
);
/**
Gets the mapping that most closely matches the device path.
This function gets the mapping which corresponds to the device path *DevicePath. If
there is no exact match, then the mapping which most closely matches *DevicePath
is returned, and *DevicePath is updated to point to the remaining portion of the
device path. If there is an exact match, the mapping is returned and *DevicePath
points to the end-of-device-path node.
@param DevicePath On entry, points to a device path pointer. On
exit, updates the pointer to point to the
portion of the device path after the mapping.
@retval NULL No mapping was found.
@return !=NULL Pointer to NULL-terminated mapping. The buffer
is callee allocated and should be freed by the caller.
**/
CONST CHAR16 *
EFIAPI
EfiShellGetMapFromDevicePath(
IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
);
/**
Converts a device path to a file system-style path.
This function converts a device path to a file system path by replacing part, or all, of
the device path with the file-system mapping. If there are more than one application
file system mappings, the one that most closely matches Path will be used.
@param Path The pointer to the device path
@retval NULL the device path could not be found.
@return all The pointer of the NULL-terminated file path. The path
is callee-allocated and should be freed by the caller.
**/
CHAR16 *
EFIAPI
EfiShellGetFilePathFromDevicePath(
IN CONST EFI_DEVICE_PATH_PROTOCOL *Path
);
/**
Converts a file system style name to a device path.
This function converts a file system style name to a device path, by replacing any
mapping references to the associated device path.
@param Path the pointer to the path
@return all The pointer of the file path. The file path is callee
allocated and should be freed by the caller.
**/
EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
EfiShellGetDevicePathFromFilePath(
IN CONST CHAR16 *Path
);
/**
Gets the name of the device specified by the device handle.
This function gets the user-readable name of the device specified by the device
handle. If no user-readable name could be generated, then *BestDeviceName will be
NULL and EFI_NOT_FOUND will be returned.
If EFI_DEVICE_NAME_USE_COMPONENT_NAME is set, then the function will return the
device's name using the EFI_COMPONENT_NAME2_PROTOCOL, if present on
DeviceHandle.
If EFI_DEVICE_NAME_USE_DEVICE_PATH is set, then the function will return the
device's name using the EFI_DEVICE_PATH_PROTOCOL, if present on DeviceHandle.
If both EFI_DEVICE_NAME_USE_COMPONENT_NAME and
EFI_DEVICE_NAME_USE_DEVICE_PATH are set, then
EFI_DEVICE_NAME_USE_COMPONENT_NAME will have higher priority.
@param DeviceHandle The handle of the device.
@param Flags Determines the possible sources of component names.
Valid bits are:
EFI_DEVICE_NAME_USE_COMPONENT_NAME
EFI_DEVICE_NAME_USE_DEVICE_PATH
@param Language A pointer to the language specified for the device
name, in the same format as described in the UEFI
specification, Appendix M
@param BestDeviceName On return, points to the callee-allocated NULL-
terminated name of the device. If no device name
could be found, points to NULL. The name must be
freed by the caller...
@retval EFI_SUCCESS Get the name successfully.
@retval EFI_NOT_FOUND Fail to get the device name.
@retval EFI_INVALID_PARAMETER Flags did not have a valid bit set.
@retval EFI_INVALID_PARAMETER BestDeviceName was NULL
@retval EFI_INVALID_PARAMETER DeviceHandle was NULL
**/
EFI_STATUS
EFIAPI
EfiShellGetDeviceName(
IN EFI_HANDLE DeviceHandle,
IN EFI_SHELL_DEVICE_NAME_FLAGS Flags,
IN CHAR8 *Language,
OUT CHAR16 **BestDeviceName
);
/**
Opens the root directory of a device on a handle
This function opens the root directory of a device and returns a file handle to it.
@param DeviceHandle The handle of the device that contains the volume.
@param FileHandle On exit, points to the file handle corresponding to the root directory on the
device.
@retval EFI_SUCCESS Root opened successfully.
@retval EFI_NOT_FOUND EFI_SIMPLE_FILE_SYSTEM could not be found or the root directory
could not be opened.
@retval EFI_VOLUME_CORRUPTED The data structures in the volume were corrupted.
@retval EFI_DEVICE_ERROR The device had an error
**/
EFI_STATUS
EFIAPI
EfiShellOpenRootByHandle(
IN EFI_HANDLE DeviceHandle,
OUT SHELL_FILE_HANDLE *FileHandle
);
/**
Opens the root directory of a device.
This function opens the root directory of a device and returns a file handle to it.
@param DevicePath Points to the device path corresponding to the device where the
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL is installed.
@param FileHandle On exit, points to the file handle corresponding to the root directory on the
device.
@retval EFI_SUCCESS Root opened successfully.
@retval EFI_NOT_FOUND EFI_SIMPLE_FILE_SYSTEM could not be found or the root directory
could not be opened.
@retval EFI_VOLUME_CORRUPTED The data structures in the volume were corrupted.
@retval EFI_DEVICE_ERROR The device had an error
**/
EFI_STATUS
EFIAPI
EfiShellOpenRoot(
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
OUT SHELL_FILE_HANDLE *FileHandle
);
/**
Returns whether any script files are currently being processed.
@retval TRUE There is at least one script file active.
@retval FALSE No script files are active now.
**/
BOOLEAN
EFIAPI
EfiShellBatchIsActive (
VOID
);
/**
Worker function to open a file based on a device path. this will open the root
of the volume and then traverse down to the file itself.
@param DevicePath2 Device Path of the file
@param FileHandle Pointer to the file upon a successful return
@param OpenMode mode to open file in.
@param Attributes the File Attributes to use when creating a new file
@retval EFI_SUCCESS the file is open and FileHandle is valid
@retval EFI_UNSUPPORTED the device path cotained non-path elements
@retval other an error ocurred.
**/
EFI_STATUS
EFIAPI
InternalOpenFileDevicePath(
IN OUT EFI_DEVICE_PATH_PROTOCOL *DevicePath2,
OUT SHELL_FILE_HANDLE *FileHandle,
IN UINT64 OpenMode,
IN UINT64 Attributes OPTIONAL
);
/**
Creates a file or directory by name.
This function creates an empty new file or directory with the specified attributes and
returns the new file's handle. If the file already exists and is read-only, then
EFI_INVALID_PARAMETER will be returned.
If the file already existed, it is truncated and its attributes updated. If the file is
created successfully, the FileHandle is the file's handle, else, the FileHandle is NULL.
If the file name begins with >v, then the file handle which is returned refers to the
shell environment variable with the specified name. If the shell environment variable
already exists and is non-volatile then EFI_INVALID_PARAMETER is returned.
@param FileName Pointer to NULL-terminated file path
@param FileAttribs The new file's attrbiutes. the different attributes are
described in EFI_FILE_PROTOCOL.Open().
@param FileHandle On return, points to the created file handle or directory's handle
@retval EFI_SUCCESS The file was opened. FileHandle points to the new file's handle.
@retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
@retval EFI_UNSUPPORTED could not open the file path
@retval EFI_NOT_FOUND the specified file could not be found on the devide, or could not
file the file system on the device.
@retval EFI_NO_MEDIA the device has no medium.
@retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no
longer supported.
@retval EFI_DEVICE_ERROR The device reported an error or can't get the file path according
the DirName.
@retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
@retval EFI_WRITE_PROTECTED An attempt was made to create a file, or open a file for write
when the media is write-protected.
@retval EFI_ACCESS_DENIED The service denied access to the file.
@retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file.
@retval EFI_VOLUME_FULL The volume is full.
**/
EFI_STATUS
EFIAPI
EfiShellCreateFile(
IN CONST CHAR16 *FileName,
IN UINT64 FileAttribs,
OUT SHELL_FILE_HANDLE *FileHandle
);
/**
Opens a file or a directory by file name.
This function opens the specified file in the specified OpenMode and returns a file
handle.
If the file name begins with >v, then the file handle which is returned refers to the
shell environment variable with the specified name. If the shell environment variable
exists, is non-volatile and the OpenMode indicates EFI_FILE_MODE_WRITE, then
EFI_INVALID_PARAMETER is returned.
If the file name is >i, then the file handle which is returned refers to the standard
input. If the OpenMode indicates EFI_FILE_MODE_WRITE, then EFI_INVALID_PARAMETER
is returned.
If the file name is >o, then the file handle which is returned refers to the standard
output. If the OpenMode indicates EFI_FILE_MODE_READ, then EFI_INVALID_PARAMETER
is returned.
If the file name is >e, then the file handle which is returned refers to the standard
error. If the OpenMode indicates EFI_FILE_MODE_READ, then EFI_INVALID_PARAMETER
is returned.
If the file name is NUL, then the file handle that is returned refers to the standard NUL
file. If the OpenMode indicates EFI_FILE_MODE_READ, then EFI_INVALID_PARAMETER is
returned.
If return EFI_SUCCESS, the FileHandle is the opened file's handle, else, the
FileHandle is NULL.
@param FileName Points to the NULL-terminated UCS-2 encoded file name.
@param FileHandle On return, points to the file handle.
@param OpenMode File open mode. Either EFI_FILE_MODE_READ or
EFI_FILE_MODE_WRITE from section 12.4 of the UEFI
Specification.
@retval EFI_SUCCESS The file was opened. FileHandle has the opened file's handle.
@retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. FileHandle is NULL.
@retval EFI_UNSUPPORTED Could not open the file path. FileHandle is NULL.
@retval EFI_NOT_FOUND The specified file could not be found on the device or the file
system could not be found on the device. FileHandle is NULL.
@retval EFI_NO_MEDIA The device has no medium. FileHandle is NULL.
@retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no
longer supported. FileHandle is NULL.
@retval EFI_DEVICE_ERROR The device reported an error or can't get the file path according
the FileName. FileHandle is NULL.
@retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. FileHandle is NULL.
@retval EFI_WRITE_PROTECTED An attempt was made to create a file, or open a file for write
when the media is write-protected. FileHandle is NULL.
@retval EFI_ACCESS_DENIED The service denied access to the file. FileHandle is NULL.
@retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file. FileHandle
is NULL.
@retval EFI_VOLUME_FULL The volume is full. FileHandle is NULL.
**/
EFI_STATUS
EFIAPI
EfiShellOpenFileByName(
IN CONST CHAR16 *FileName,
OUT SHELL_FILE_HANDLE *FileHandle,
IN UINT64 OpenMode
);
/**
Deletes the file specified by the file name.
This function deletes a file.
@param FileName Points to the NULL-terminated file name.
@retval EFI_SUCCESS The file was closed and deleted, and the handle was closed.
@retval EFI_WARN_DELETE_FAILURE The handle was closed but the file was not deleted.
@sa EfiShellCreateFile
@sa FileHandleDelete
**/
EFI_STATUS
EFIAPI
EfiShellDeleteFileByName(
IN CONST CHAR16 *FileName
);
/**
Disables the page break output mode.
**/
VOID
EFIAPI
EfiShellDisablePageBreak (
VOID
);
/**
Enables the page break output mode.
**/
VOID
EFIAPI
EfiShellEnablePageBreak (
VOID
);
/**
internal worker function to run a command via Device Path
@param ParentImageHandle A handle of the image that is executing the specified
command line.
@param DevicePath device path of the file to execute
@param CommandLine Points to the NULL-terminated UCS-2 encoded string
containing the command line. If NULL then the command-
line will be empty.
@param Environment Points to a NULL-terminated array of environment
variables with the format 'x=y', where x is the
environment variable name and y is the value. If this
is NULL, then the current shell environment is used.
@param StatusCode Points to the status code returned by the command.
@retval EFI_SUCCESS The command executed successfully. The status code
returned by the command is pointed to by StatusCode.
@retval EFI_INVALID_PARAMETER The parameters are invalid.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_UNSUPPORTED Nested shell invocations are not allowed.
**/
EFI_STATUS
EFIAPI
InternalShellExecuteDevicePath(
IN CONST EFI_HANDLE *ParentImageHandle,
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN CONST CHAR16 *CommandLine OPTIONAL,
IN CONST CHAR16 **Environment OPTIONAL,
OUT EFI_STATUS *StatusCode OPTIONAL
);
/**
Execute the command line.
This function creates a nested instance of the shell and executes the specified
command (CommandLine) with the specified environment (Environment). Upon return,
the status code returned by the specified command is placed in StatusCode.
If Environment is NULL, then the current environment is used and all changes made
by the commands executed will be reflected in the current environment. If the
Environment is non-NULL, then the changes made will be discarded.
The CommandLine is executed from the current working directory on the current
device.
@param ParentImageHandle A handle of the image that is executing the specified
command line.
@param CommandLine Points to the NULL-terminated UCS-2 encoded string
containing the command line. If NULL then the command-
line will be empty.
@param Environment Points to a NULL-terminated array of environment
variables with the format 'x=y', where x is the
environment variable name and y is the value. If this
is NULL, then the current shell environment is used.
@param StatusCode Points to the status code returned by the command.
@retval EFI_SUCCESS The command executed successfully. The status code
returned by the command is pointed to by StatusCode.
@retval EFI_INVALID_PARAMETER The parameters are invalid.
@retval EFI_OUT_OF_RESOURCES Out of resources.
@retval EFI_UNSUPPORTED Nested shell invocations are not allowed.
**/
EFI_STATUS
EFIAPI
EfiShellExecute(
IN EFI_HANDLE *ParentImageHandle,
IN CHAR16 *CommandLine OPTIONAL,
IN CHAR16 **Environment OPTIONAL,
OUT EFI_STATUS *StatusCode OPTIONAL
);
/**
Utility cleanup function for EFI_SHELL_FILE_INFO objects.
1) frees all pointers (non-NULL)
2) Closes the SHELL_FILE_HANDLE
@param FileListNode pointer to the list node to free
**/
VOID
EFIAPI
FreeShellFileInfoNode(
IN EFI_SHELL_FILE_INFO *FileListNode
);
/**
Frees the file list.
This function cleans up the file list and any related data structures. It has no
impact on the files themselves.
@param FileList The file list to free. Type EFI_SHELL_FILE_INFO is
defined in OpenFileList()
@retval EFI_SUCCESS Free the file list successfully.
@retval EFI_INVALID_PARAMETER FileList was NULL or *FileList was NULL;
**/
EFI_STATUS
EFIAPI
EfiShellFreeFileList(
IN EFI_SHELL_FILE_INFO **FileList
);
/**
Deletes the duplicate file names files in the given file list.
This function deletes the reduplicate files in the given file list.
@param FileList A pointer to the first entry in the file list.
@retval EFI_SUCCESS Always success.
@retval EFI_INVALID_PARAMETER FileList was NULL or *FileList was NULL;
**/
EFI_STATUS
EFIAPI
EfiShellRemoveDupInFileList(
IN EFI_SHELL_FILE_INFO **FileList
);
/**
Allocates and populates a EFI_SHELL_FILE_INFO structure. if any memory operation
failed it will return NULL.
@param[in] BasePath the Path to prepend onto filename for FullPath
@param[in] Status Status member initial value.
@param[in] FullName FullName member initial value.
@param[in] FileName FileName member initial value.
@param[in] Handle Handle member initial value.
@param[in] Info Info struct to copy.
**/
EFI_SHELL_FILE_INFO *
EFIAPI
CreateAndPopulateShellFileInfo(
IN CONST CHAR16 *BasePath,
IN CONST EFI_STATUS Status,
IN CONST CHAR16 *FullName,
IN CONST CHAR16 *FileName,
IN CONST SHELL_FILE_HANDLE Handle,
IN CONST EFI_FILE_INFO *Info
);
/**
Find all files in a specified directory.
@param FileDirHandle Handle of the directory to search.
@param FileList On return, points to the list of files in the directory
or NULL if there are no files in the directory.
@retval EFI_SUCCESS File information was returned successfully.
@retval EFI_VOLUME_CORRUPTED The file system structures have been corrupted.
@retval EFI_DEVICE_ERROR The device reported an error.
@retval EFI_NO_MEDIA The device media is not present.
@retval EFI_INVALID_PARAMETER The FileDirHandle was not a directory.
**/
EFI_STATUS
EFIAPI
EfiShellFindFilesInDir(
IN SHELL_FILE_HANDLE FileDirHandle,
OUT EFI_SHELL_FILE_INFO **FileList
);
/**
Find files that match a specified pattern.
This function searches for all files and directories that match the specified
FilePattern. The FilePattern can contain wild-card characters. The resulting file
information is placed in the file list FileList.
Wildcards are processed
according to the rules specified in UEFI Shell 2.0 spec section 3.7.1.
The files in the file list are not opened. The OpenMode field is set to 0 and the FileInfo
field is set to NULL.
if *FileList is not NULL then it must be a pre-existing and properly initialized list.
@param FilePattern Points to a NULL-terminated shell file path, including wildcards.
@param FileList On return, points to the start of a file list containing the names
of all matching files or else points to NULL if no matching files
were found. only on a EFI_SUCCESS return will; this be non-NULL.
@retval EFI_SUCCESS Files found. FileList is a valid list.
@retval EFI_NOT_FOUND No files found.
@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
EfiShellFindFiles(
IN CONST CHAR16 *FilePattern,
OUT EFI_SHELL_FILE_INFO **FileList
);
/**
Opens the files that match the path specified.
This function opens all of the files specified by Path. Wildcards are processed
according to the rules specified in UEFI Shell 2.0 spec section 3.7.1. Each
matching file has an EFI_SHELL_FILE_INFO structure created in a linked list.
@param Path A pointer to the path string.
@param OpenMode Specifies the mode used to open each file, EFI_FILE_MODE_READ or
EFI_FILE_MODE_WRITE.
@param FileList Points to the start of a list of files opened.
@retval EFI_SUCCESS Create the file list successfully.
@return Others Can't create the file list.
**/
EFI_STATUS
EFIAPI
EfiShellOpenFileList(
IN CHAR16 *Path,
IN UINT64 OpenMode,
IN OUT EFI_SHELL_FILE_INFO **FileList
);
/**
Gets the environment variable.
This function returns the current value of the specified environment variable.
@param Name A pointer to the environment variable name
@return !=NULL The environment variable's value. The returned
pointer does not need to be freed by the caller.
@retval NULL The environment variable doesn't exist.
**/
CONST CHAR16 *
EFIAPI
EfiShellGetEnv(
IN CONST CHAR16 *Name
);
/**
Sets the environment variable.
This function changes the current value of the specified environment variable. If the
environment variable exists and the Value is an empty string, then the environment
variable is deleted. If the environment variable exists and the Value is not an empty
string, then the value of the environment variable is changed. If the environment
variable does not exist and the Value is an empty string, there is no action. If the
environment variable does not exist and the Value is a non-empty string, then the
environment variable is created and assigned the specified value.
For a description of volatile and non-volatile environment variables, see UEFI Shell
2.0 specification section 3.6.1.
@param Name Points to the NULL-terminated environment variable name.
@param Value Points to the NULL-terminated environment variable value. If the value is an
empty string then the environment variable is deleted.
@param Volatile Indicates whether the variable is non-volatile (FALSE) or volatile (TRUE).
@retval EFI_SUCCESS The environment variable was successfully updated.
**/
EFI_STATUS
EFIAPI
EfiShellSetEnv(
IN CONST CHAR16 *Name,
IN CONST CHAR16 *Value,
IN BOOLEAN Volatile
);
/**
Returns the current directory on the specified device.
If FileSystemMapping is NULL, it returns the current working directory. If the
FileSystemMapping is not NULL, it returns the current directory associated with the
FileSystemMapping. In both cases, the returned name includes the file system
mapping (i.e. fs0:\current-dir).
@param FileSystemMapping A pointer to the file system mapping. If NULL,
then the current working directory is returned.
@retval !=NULL The current directory.
@retval NULL Current directory does not exist.
**/
CONST CHAR16 *
EFIAPI
EfiShellGetCurDir(
IN CONST CHAR16 *FileSystemMapping OPTIONAL
);
/**
Changes the current directory on the specified device.
If the FileSystem is NULL, and the directory Dir does not contain a file system's
mapped name, this function changes the current working directory. If FileSystem is
NULL and the directory Dir contains a mapped name, then the current file system and
the current directory on that file system are changed.
If FileSystem is not NULL, and Dir is NULL, then this changes the current working file
system.
If FileSystem is not NULL and Dir is not NULL, then this function changes the current
directory on the specified file system.
If the current working directory or the current working file system is changed then the
%cwd% environment variable will be updated
@param FileSystem A pointer to the file system's mapped name. If NULL, then the current working
directory is changed.
@param Dir Points to the NULL-terminated directory on the device specified by FileSystem.
@retval EFI_SUCCESS The operation was sucessful
**/
EFI_STATUS
EFIAPI
EfiShellSetCurDir(
IN CONST CHAR16 *FileSystem OPTIONAL,
IN CONST CHAR16 *Dir
);
/**
Return help information about a specific command.
This function returns the help information for the specified command. The help text
can be internal to the shell or can be from a UEFI Shell manual page.
If Sections is specified, then each section name listed will be compared in a casesensitive
manner, to the section names described in Appendix B. If the section exists,
it will be appended to the returned help text. If the section does not exist, no
information will be returned. If Sections is NULL, then all help text information
available will be returned.
@param Command Points to the NULL-terminated UEFI Shell command name.
@param Sections Points to the NULL-terminated comma-delimited
section names to return. If NULL, then all
sections will be returned.
@param HelpText On return, points to a callee-allocated buffer
containing all specified help text.
@retval EFI_SUCCESS The help text was returned.
@retval EFI_OUT_OF_RESOURCES The necessary buffer could not be allocated to hold the
returned help text.
@retval EFI_INVALID_PARAMETER HelpText is NULL
@retval EFI_NOT_FOUND There is no help text available for Command.
**/
EFI_STATUS
EFIAPI
EfiShellGetHelpText(
IN CONST CHAR16 *Command,
IN CONST CHAR16 *Sections OPTIONAL,
OUT CHAR16 **HelpText
);
/**
Gets the enable status of the page break output mode.
User can use this function to determine current page break mode.
@retval TRUE The page break output mode is enabled
@retval FALSE The page break output mode is disabled
**/
BOOLEAN
EFIAPI
EfiShellGetPageBreak(
VOID
);
/**
Judges whether the active shell is the root shell.
This function makes the user to know that whether the active Shell is the root shell.
@retval TRUE The active Shell is the root Shell.
@retval FALSE The active Shell is NOT the root Shell.
**/
BOOLEAN
EFIAPI
EfiShellIsRootShell(
VOID
);
/**
This function returns the command associated with a alias or a list of all
alias'.
@param[in] Command Points to the NULL-terminated shell alias.
If this parameter is NULL, then all
aliases will be returned in ReturnedData.
@param[out] Volatile upon return of a single command if TRUE indicates
this is stored in a volatile fashion. FALSE otherwise.
@return If Alias is not NULL, it will return a pointer to
the NULL-terminated command for that alias.
If Alias is NULL, ReturnedData points to a ';'
delimited list of alias (e.g.
ReturnedData = "dir;del;copy;mfp") that is NULL-terminated.
@retval NULL an error ocurred
@retval NULL Alias was not a valid Alias
**/
CONST CHAR16 *
EFIAPI
EfiShellGetAlias(
IN CONST CHAR16 *Command,
OUT BOOLEAN *Volatile OPTIONAL
);
/**
Changes a shell command alias.
This function creates an alias for a shell command or if Alias is NULL it will delete an existing alias.
this function does not check for built in alias'.
@param[in] Command Points to the NULL-terminated shell command or existing alias.
@param[in] Alias Points to the NULL-terminated alias for the shell command. If this is NULL, and
Command refers to an alias, that alias will be deleted.
@param[in] Volatile if TRUE the Alias being set will be stored in a volatile fashion. if FALSE the
Alias being set will be stored in a non-volatile fashion.
@retval EFI_SUCCESS Alias created or deleted successfully.
@retval EFI_NOT_FOUND the Alias intended to be deleted was not found
**/
EFI_STATUS
EFIAPI
InternalSetAlias(
IN CONST CHAR16 *Command,
IN CONST CHAR16 *Alias OPTIONAL,
IN BOOLEAN Volatile
);
/**
Changes a shell command alias.
This function creates an alias for a shell command or if Alias is NULL it will delete an existing alias.
@param[in] Command Points to the NULL-terminated shell command or existing alias.
@param[in] Alias Points to the NULL-terminated alias for the shell command. If this is NULL, and
Command refers to an alias, that alias will be deleted.
@param[in] Replace If TRUE and the alias already exists, then the existing alias will be replaced. If
FALSE and the alias already exists, then the existing alias is unchanged and
EFI_ACCESS_DENIED is returned.
@param[in] Volatile if TRUE the Alias being set will be stored in a volatile fashion. if FALSE the
Alias being set will be stored in a non-volatile fashion.
@retval EFI_SUCCESS Alias created or deleted successfully.
@retval EFI_NOT_FOUND the Alias intended to be deleted was not found
@retval EFI_ACCESS_DENIED The alias is a built-in alias or already existed and Replace was set to
FALSE.
**/
EFI_STATUS
EFIAPI
EfiShellSetAlias(
IN CONST CHAR16 *Command,
IN CONST CHAR16 *Alias OPTIONAL,
IN BOOLEAN Replace,
IN BOOLEAN Volatile
);
/**
Utility cleanup function for EFI_SHELL_FILE_INFO objects.
1) frees all pointers (non-NULL)
2) Closes the SHELL_FILE_HANDLE
@param FileListNode pointer to the list node to free
**/
VOID
EFIAPI
InternalFreeShellFileInfoNode(
IN EFI_SHELL_FILE_INFO *FileListNode
);
/**
Internal variable setting function. Allows for setting of the read only variables.
@param Name Points to the NULL-terminated environment variable name.
@param Value Points to the NULL-terminated environment variable value. If the value is an
empty string then the environment variable is deleted.
@param Volatile Indicates whether the variable is non-volatile (FALSE) or volatile (TRUE).
@retval EFI_SUCCESS The environment variable was successfully updated.
**/
EFI_STATUS
EFIAPI
InternalEfiShellSetEnv(
IN CONST CHAR16 *Name,
IN CONST CHAR16 *Value,
IN BOOLEAN Volatile
);
#endif //_SHELL_PROTOCOL_HEADER_

View File

@ -52,7 +52,7 @@ UefiMain (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_FILE_HANDLE FileHandle;
SHELL_FILE_HANDLE FileHandle;
EFI_STATUS Status;
CHAR16 FileName[100];
UINTN BufferSize;

View File

@ -0,0 +1,25 @@
/** @file
GUID for Shell Variable for Get/Set via runtime services.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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.
**/
#ifndef _SHELL_ALIAS_VARIABLE_GUID_H_
#define _SHELL_ALIAS_VARIABLE_GUID_H_
#define SHELL_ALIAS_VARIABLE_GUID \
{ \
0x0053d9d6, 0x2659, 0x4599, { 0xa2, 0x6b, 0xef, 0x45, 0x36, 0xe6, 0x31, 0xa9 } \
}
extern EFI_GUID gShellAliasGuid;
#endif

View File

@ -1,5 +1,5 @@
/** @file
GUID for EFI shell Environment2 Extension
GUID for EFI shell Environment2 Extension.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
@ -12,8 +12,8 @@
**/
#ifndef _SHELLPKG_SHELL_ENV2_EXT_GUID_H
#define _SHELLPKG_SHELL_ENV2_EXT_GUID_H
#ifndef _SHELLPKG_SHELL_ENV2_EXT_GUID_H_
#define _SHELLPKG_SHELL_ENV2_EXT_GUID_H_
#define SHELLPKG_SHELL_ENV2_EXT_GUID \
{ \

View File

@ -0,0 +1,25 @@
/** @file
GUID for Shell Map for Get/Set via runtime services.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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.
**/
#ifndef _SHELL_MAP_GUID_H_
#define _SHELL_MAP_GUID_H_
#define SHELL_MAP_GUID \
{ \
0x51271e13, 0x7de3, 0x43af, { 0x8b, 0xc2, 0x71, 0xad, 0x3b, 0x82, 0x43, 0x25 } \
}
extern EFI_GUID gShellMapGuid;
#endif

View File

@ -0,0 +1,25 @@
/** @file
GUID for Shell Variable for Get/Set via runtime services.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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.
**/
#ifndef _SHELL_VARIABLE_GUID_H_
#define _SHELL_VARIABLE_GUID_H_
#define SHELL_VARIABLE_GUID \
{ \
0x158def5a, 0xf656, 0x419c, { 0xb0, 0x27, 0x7a, 0x31, 0x92, 0xc0, 0x79, 0xd2 } \
}
extern EFI_GUID gShellVariableGuid;
#endif

View File

@ -12,28 +12,29 @@
**/
#if !defined (_FILE_HANDLE_LIBRARY_HEADER_)
#ifndef _FILE_HANDLE_LIBRARY_HEADER_
#define _FILE_HANDLE_LIBRARY_HEADER_
/// Tag for use in identifying UNICODE files.
/// If the file is UNICODE the first 16 bits of the file will equal this value.
#include <Protocol/SimpleFileSystem.h>
/// The tag for use in identifying UNICODE files.
/// If the file is UNICODE, the first 16 bits of the file will equal this value.
enum {
UnicodeFileTag = 0xFEFF
};
/**
This function will retrieve the information about the file for the handle
specified and store it in allocated pool memory.
This function retrieves information about the file for the handle
specified and stores it in the 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.
@param[in] FileHandle The file handle of the file for which information is
being requested.
@retval NULL information could not be retrieved.
@retval !NULL the information about the file
@retval NULL Information could not be retrieved.
@retval !NULL The information about the file.
**/
EFI_FILE_INFO*
EFIAPI
@ -42,23 +43,23 @@ FileHandleGetInfo (
);
/**
This function will set the information about the file for the opened handle
This function sets the information about the file for the opened handle
specified.
@param FileHandle The file handle of the file for which information
@param[in] FileHandle The file handle of the file for which information
is being set.
@param FileInfo The information to set.
@param[in] FileInfo The information to set.
@retval EFI_SUCCESS The information was set.
@retval EFI_INVALID_PARAMETER A Parameter was out of range or invalid.
@retval EFI_INVALID_PARAMETER A parameter was out of range or invalid.
@retval EFI_UNSUPPORTED The FileHandle does not support FileInfo.
@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.
@retval EFI_ACCESS_DENIED The file was opened read only.
@retval EFI_VOLUME_FULL The volume is full.
**/
EFI_STATUS
EFIAPI
@ -83,16 +84,16 @@ FileHandleSetInfo (
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
@param[in] FileHandle The opened file handle.
@param[in,out] 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.
@param[out] Buffer The buffer to put read data into.
@retval EFI_SUCCESS Data was read.
@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_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
@retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required
size.
**/
@ -114,19 +115,19 @@ FileHandleRead(
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
@param[in] FileHandle The opened file for writing.
@param[in,out] 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.
@param[in] 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_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_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.
@retval EFI_WRITE_PROTECTED The device is write-protected.
@retval EFI_ACCESS_DENIED The file was opened for read only.
@retval EFI_VOLUME_FULL The volume is full.
**/
EFI_STATUS
EFIAPI
@ -143,9 +144,9 @@ FileHandleWrite(
flushed to the device, and the file is closed. In all cases the handle is
closed.
@param FileHandle The file handle to close.
@param[in] FileHandle The file handle to close.
@retval EFI_SUCCESS The file handle was closed sucessfully.
@retval EFI_SUCCESS The file handle was closed successfully.
**/
EFI_STATUS
EFIAPI
@ -160,11 +161,11 @@ FileHandleClose (
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.
@param[in] 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 EFI_SUCCESS The file was closed successfully.
@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
@ -177,18 +178,18 @@ FileHandleDelete (
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
supplied. With the exception of moving to position 0xFFFFFFFFFFFFFFFF, only
absolute positioning is supported, and moving past the end of the file is
allowed (a subsequent write would grow the file). Moving 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.
has the effect of starting the read process of the directory entries over again.
@param FileHandle The file handle on which the position is being set
@param Position Byte position from begining of file
@param[in] FileHandle The file handle on which the position is being set.
@param[in] Position The byte position from the begining of the file.
@retval EFI_SUCCESS Operation completed sucessfully.
@retval EFI_UNSUPPORTED the seek request for non-zero is not valid on
@retval EFI_SUCCESS The operation completed sucessfully.
@retval EFI_UNSUPPORTED The request for non-zero is not valid on
directories.
@retval INVALID_PARAMETER One of the parameters has an invalid value.
**/
@ -204,15 +205,15 @@ FileHandleSetPosition (
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
system driver. 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.
@param[in] FileHandle The open file handle on which to get the position.
@param[out] Position The byte position from begining of file.
@retval EFI_SUCCESS the operation completed sucessfully.
@retval EFI_SUCCESS The operation completed successfully.
@retval INVALID_PARAMETER One of the parameters has an invalid value.
@retval EFI_UNSUPPORTED the request is not valid on directories.
@retval EFI_UNSUPPORTED The request is not valid on directories.
**/
EFI_STATUS
EFIAPI
@ -225,7 +226,7 @@ FileHandleGetPosition (
This function flushes all modified data associated with a file to a device.
@param FileHandle The file handle on which to flush data.
@param[in] 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.
@ -243,16 +244,16 @@ FileHandleFlush (
/**
Function to determine if a given handle is a directory handle.
If DirHandle is NULL then ASSERT().
If DirHandle is NULL, then ASSERT().
Open the file information on the DirHandle and verify that the Attribute
Open the file information on the DirHandle, and verify that the Attribute
includes EFI_FILE_DIRECTORY bit set.
@param DirHandle Handle to open file.
@param[in] DirHandle The handle to open the 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
@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
@ -263,20 +264,20 @@ FileHandleIsDirectory (
/**
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.
This function opens a directory and gets the first file's information in the
directory. The caller the uses 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 pointer to buffer for file's information
@param[in] DirHandle The file handle of the directory to search.
@param[out] Buffer The pointer to 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
@return Others The status of FileHandleGetInfo, FileHandleSetPosition,
or FileHandleRead.
**/
EFI_STATUS
EFIAPI
@ -294,11 +295,11 @@ FileHandleFindFirstFile (
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
@param[in] DirHandle The file handle of the directory.
@param[out] Buffer The pointer to buffer for file's information.
@param[out] NoFile The pointer to boolean when last file is found.
@retval EFI_SUCCESS Found the next file, or reached last file
@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.
@ -314,17 +315,17 @@ FileHandleFindNextFile(
/**
Retrieve the size of a file.
If FileHandle is NULL then ASSERT()
If Size is NULL then ASSERT()
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 The file handle from which size is retrieved.
@param Size pointer to size.
@param[in] FileHandle The file handle from which size is retrieved.
@param[out] Size The pointer to size.
@retval EFI_SUCCESS operation was completed sucessfully
@retval EFI_DEVICE_ERROR cannot access the file
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_DEVICE_ERROR Cannot access the file.
**/
EFI_STATUS
EFIAPI
@ -333,6 +334,27 @@ FileHandleGetSize (
OUT UINT64 *Size
);
/**
Set the size of a file.
If FileHandle is NULL then ASSERT().
This function changes the file size info from the FileHandle's EFI_FILE_INFO
data.
@param[in] FileHandle The file handle whose size is to be changed.
@param[in] Size The new size.
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_DEVICE_ERROR Cannot access the file.
**/
EFI_STATUS
EFIAPI
FileHandleSetSize (
IN EFI_FILE_HANDLE FileHandle,
IN UINT64 Size
);
/**
Function to get a full filename given a EFI_FILE_HANDLE somewhere lower on the
directory 'stack'.
@ -341,10 +363,10 @@ FileHandleGetSize (
@param[out] FullFileName Pointer to pointer to generated full file name. It
is the responsibility of the caller to free this memory
with a call to FreePool().
@retval EFI_SUCCESS the operation was sucessful and the FullFileName is valid.
@retval EFI_SUCCESS The operation was successful and FullFileName is valid.
@retval EFI_INVALID_PARAMETER Handle was NULL.
@retval EFI_INVALID_PARAMETER FullFileName was NULL.
@retval EFI_OUT_OF_MEMORY a memory allocation failed.
@retval EFI_OUT_OF_MEMORY A memory allocation failed.
**/
EFI_STATUS
EFIAPI
@ -359,21 +381,24 @@ FileHandleGetFileName (
If the position upon start is 0, then the Ascii Boolean will be set. This should be
maintained and not changed for all operations with the same file.
@param[in] Handle FileHandle to read from
@param[in,out] Buffer pointer to buffer to read into
@param[in,out] Size pointer to number of bytes in buffer
@param[in] Truncate if TRUE then allows for truncation of the line to fit.
if FALSE will reset the position to the begining of the
line if the buffer is not large enough.
@param[in,out] Ascii Boolean value for indicating whether the file is
Ascii (TRUE) or UCS2 (FALSE);
@param[in] Handle FileHandle to read from.
@param[in,out] Buffer The pointer to buffer to read into.
@param[in,out] Size The pointer to number of bytes in Buffer.
@param[in] Truncate If the buffer is large enough, this has no effect.
If the buffer is is too small and Truncate is TRUE,
the line will be truncated.
If the buffer is is too small and Truncate is FALSE,
then no read will occur.
@retval EFI_SUCCESS the operation was sucessful. the line is stored in
@param[in,out] Ascii Boolean value for indicating whether the file is
Ascii (TRUE) or UCS2 (FALSE).
@retval EFI_SUCCESS The operation was successful. The line is stored in
Buffer.
@retval EFI_INVALID_PARAMETER Handle was NULL.
@retval EFI_INVALID_PARAMETER Size was NULL.
@retval EFI_BUFFER_TOO_SMALL Size was not enough space to store the line.
Size was updated to minimum space required.
@retval EFI_BUFFER_TOO_SMALL Size was not large enough to store the line.
Size was updated to the minimum space required.
@sa FileHandleRead
**/
EFI_STATUS
@ -394,7 +419,8 @@ FileHandleReadLine(
maintained and not changed for all operations with the same file.
@param[in] Handle FileHandle to read from.
@param[in,out] Ascii Boolean value for indicating whether the file is Ascii (TRUE) or UCS2 (FALSE);
@param[in,out] Ascii Boolean value for indicating whether the file is
Ascii (TRUE) or UCS2 (FALSE).
@return The line of text from the file.
@ -412,12 +438,12 @@ FileHandleReturnLine(
If Handle is NULL, ASSERT.
@param[in] Handle FileHandle to write to
@param[in] Handle FileHandle to write to.
@param[in] Buffer Buffer to write, if NULL the function will
take no action and return EFI_SUCCESS.
@retval EFI_SUCCESS the data was written.
@retval other failure.
@retval EFI_SUCCESS The data was written.
@retval other Failure.
@sa FileHandleWrite
**/
@ -429,14 +455,14 @@ FileHandleWriteLine(
);
/**
function to take a formatted argument and print it to a file.
Function to take a formatted argument and print it to a file.
@param[in] Handle the file handle for the file to write to
@param[in] Format the format argument (see printlib for format specifier)
@param[in] ... the variable arguments for the format
@param[in] Handle The file handle for the file to write to.
@param[in] Format The format argument (see printlib for the format specifier).
@param[in] ... The variable arguments for the format.
@retval EFI_SUCCESS the operation was sucessful
@return other a return value from FileHandleWriteLine
@retval EFI_SUCCESS The operation was successful.
@retval other A return value from FileHandleWriteLine.
@sa FileHandleWriteLine
**/
@ -453,12 +479,12 @@ FileHandlePrintLine(
This will NOT work on directories.
If Handle is NULL, then ASSERT.
If Handle is NULL, then ASSERT().
@param[in] Handle the file handle
@param[in] Handle The file handle.
@retval TRUE the position is at the end of the file
@retval FALSE the position is not at the end of the file
@retval TRUE The position is at the end of the file.
@retval FALSE The position is not at the end of the file.
**/
BOOLEAN
EFIAPI

View File

@ -0,0 +1,342 @@
/** @file
Provides interface to advanced shell functionality for parsing both handle and protocol database.
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
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.
**/
#ifndef __HANDLE_PARSING_LIB__
#define __HANDLE_PARSING_LIB__
#include <Uefi.h>
/**
Function to get the name of a protocol or struct from it's GUID.
If Guid is NULL, then ASSERT.
@param[in] Guid The GUID to look for the name of.
@param[in] Lang The language to use.
@return The pointer to a string of the name. The caller
is responsible to free this memory.
**/
CHAR16*
EFIAPI
GetStringNameFromGuid(
IN CONST EFI_GUID *Guid,
IN CONST CHAR8 *Lang OPTIONAL
);
/**
Function to get the Guid for a protocol or struct based on it's string name.
@param[in] Name The pointer to the string name.
@param[in] Lang The pointer to the language code (string).
@param[in] Guid The pointer to the pointer to the Guid.
@retval EFI_SUCCESS The operation was successful.
**/
EFI_STATUS
EFIAPI
GetGuidFromStringName(
IN CONST CHAR16 *Name,
IN CONST CHAR8 *Lang OPTIONAL,
IN EFI_GUID **Guid
);
/**
Function to dump protocol information from a handle.
This function will return a allocated string buffer containing the
information. The caller is responsible for freeing the memory.
If Guid is NULL, ASSERT().
If TheHandle is NULL, ASSERT().
@param[in] TheHandle The handle to dump information from.
@param[in] Guid The GUID of the protocol to dump.
@param[in] Verbose TRUE for extra info. FALSE otherwise.
@return The pointer to string.
@retval NULL An error was encountered.
**/
CHAR16*
EFIAPI
GetProtocolInformationDump(
IN CONST EFI_HANDLE TheHandle,
IN CONST EFI_GUID *Guid,
IN CONST BOOLEAN Verbose
);
/**
Function to retrieve the driver name (if possible) from the ComponentName or
ComponentName2 protocol.
The string returned must be callee freed.
@param[in] TheHandle The driver handle to get the name of.
@param[in] Language The language to use.
@retval NULL The name could not be found.
@return A pointer to the string name. Do not de-allocate the memory.
**/
CONST CHAR16*
EFIAPI
GetStringNameFromHandle(
IN CONST EFI_HANDLE TheHandle,
IN CONST CHAR8 *Language
);
#define HR_UNKNOWN 0
#define HR_IMAGE_HANDLE BIT1
#define HR_DRIVER_BINDING_HANDLE BIT2 // has driver binding
#define HR_DEVICE_DRIVER BIT3 // device driver (hybrid?)
#define HR_BUS_DRIVER BIT4 // a bus driver (hybrid?)
#define HR_DRIVER_CONFIGURATION_HANDLE BIT5
#define HR_DRIVER_DIAGNOSTICS_HANDLE BIT6
#define HR_COMPONENT_NAME_HANDLE BIT7
#define HR_DEVICE_HANDLE BIT8
#define HR_PARENT_HANDLE BIT9
#define HR_CONTROLLER_HANDLE BIT10
#define HR_CHILD_HANDLE BIT11
#define HR_VALID_MASK (BIT1|BIT2|BIT3|BIT4|BIT5|BIT6|BIT7|BIT8|BIT9|BIT10|BIT11)
/**
Gets all the related EFI_HANDLEs based on the mask supplied.
This function will scan all EFI_HANDLES in the UEFI environment's handle database
and return all the ones with the specified relationship (Mask) to the specified
controller handle.
If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
If MatchingHandleCount is NULL, then ASSERT.
If MatchingHandleBuffer is not NULL upon a successful return, the memory must be
caller freed.
@param[in] DriverBindingHandle The handle with Driver Binding protocol on it.
@param[in] ControllerHandle The handle with Device Path protocol on it.
@param[in] Mask The mask of what relationship(s) is desired.
@param[in] MatchingHandleCount The pointer to UINTN specifying number of HANDLES in
MatchingHandleBuffer.
@param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount
EFI_HANDLEs with a terminating NULL EFI_HANDLE.
@retval EFI_SUCCESS The operation was successful, and any related handles
are in MatchingHandleBuffer.
@retval EFI_NOT_FOUND No matching handles were found.
@retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
@sa ParseHandleDatabaseByRelationshipWithType
**/
EFI_STATUS
EFIAPI
ParseHandleDatabaseByRelationship (
IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL,
IN CONST EFI_HANDLE ControllerHandle OPTIONAL,
IN CONST UINTN Mask,
IN UINTN *MatchingHandleCount,
OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL
);
/**
Gets all the related EFI_HANDLEs based on the mask supplied.
This function scans all EFI_HANDLES in the UEFI environment's handle database
and returns the ones with the specified relationship (Mask) to the specified
controller handle.
If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
If MatchingHandleCount is NULL, then ASSERT.
If MatchingHandleBuffer is not NULL upon a successful return the memory must be
caller freed.
@param[in] DriverBindingHandle The handle with Driver Binding protocol on it.
@param[in] ControllerHandle The handle with Device Path protocol on it.
@param[in] MatchingHandleCount The pointer to UINTN that specifies the number of HANDLES in
MatchingHandleBuffer.
@param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount
EFI_HANDLEs with a terminating NULL EFI_HANDLE.
@param[out] HandleType An array of type information.
@retval EFI_SUCCESS The operation was successful, and any related handles
are in MatchingHandleBuffer.
@retval EFI_NOT_FOUND No matching handles were found.
@retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
**/
EFI_STATUS
EFIAPI
ParseHandleDatabaseByRelationshipWithType (
IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL,
IN CONST EFI_HANDLE ControllerHandle OPTIONAL,
IN UINTN *HandleCount,
OUT EFI_HANDLE **HandleBuffer,
OUT UINTN **HandleType
);
/**
Gets handles for any parents of the passed in controller.
@param[in] ControllerHandle The handle of the controller.
@param[in] Count The pointer to the number of handles in
MatchingHandleBuffer on return.
@param[out] Buffer The buffer containing handles on a successful
return.
@retval EFI_SUCCESS The operation was successful.
@sa ParseHandleDatabaseByRelationship
**/
#define PARSE_HANDLE_DATABASE_PARENTS(ControllerHandle, Count, Buffer) \
ParseHandleDatabaseByRelationship(NULL, ControllerHandle, HR_PARENT_HANDLE, Count, Buffer)
/**
Gets handles for any UEFI drivers of the passed in controller.
@param[in] ControllerHandle The handle of the controller.
@param[in] Count The pointer to the number of handles in
MatchingHandleBuffer on return.
@param[out] Buffer The buffer containing handles on a successful
return.
@retval EFI_SUCCESS The operation was successful.
@sa ParseHandleDatabaseByRelationship
**/
#define PARSE_HANDLE_DATABASE_UEFI_DRIVERS(ControllerHandle, Count, Buffer) \
ParseHandleDatabaseByRelationship(NULL, ControllerHandle, HR_DRIVER_BINDING_HANDLE|HR_DEVICE_DRIVER, Count, Buffer)
/**
Gets handles for any children of the passed in controller by the passed in driver handle.
@param[in] DriverHandle The handle of the driver.
@param[in] ControllerHandle The handle of the controller.
@param[in] Count The pointer to the number of handles in
MatchingHandleBuffer on return.
@param[out] Buffer The buffer containing handles on a successful
return.
@retval EFI_SUCCESS The operation was successful.
@sa ParseHandleDatabaseByRelationship
**/
#define PARSE_HANDLE_DATABASE_MANAGED_CHILDREN(DriverHandle, ControllerHandle, Count, Buffer) \
ParseHandleDatabaseByRelationship(DriverHandle, ControllerHandle, HR_CHILD_HANDLE|HR_DEVICE_HANDLE, Count, Buffer)
/**
Gets handles for any devices managed by the passed in driver.
@param[in] DriverHandle The handle of the driver.
@param[in] Count The pointer to the number of handles in
MatchingHandleBuffer on return.
@param[out] Buffer The buffer containing handles on a successful
return.
@retval EFI_SUCCESS The operation was successful.
@sa ParseHandleDatabaseByRelationship
**/
#define PARSE_HANDLE_DATABASE_DEVICES(DriverHandle, Count, Buffer) \
ParseHandleDatabaseByRelationship(DriverHandle, NULL, HR_CONTROLLER_HANDLE|HR_DEVICE_HANDLE, Count, Buffer)
/**
Gets handles for any child devices produced by the passed in driver.
@param[in] DriverHandle The handle of the driver.
@param[in] MatchingHandleCount The pointer to the number of handles in
MatchingHandleBuffer on return.
@param[out] MatchingHandleBuffer The buffer containing handles on a successful
return.
@retval EFI_SUCCESS The operation was successful.
@sa ParseHandleDatabaseByRelationship
**/
EFI_STATUS
EFIAPI
ParseHandleDatabaseForChildDevices(
IN CONST EFI_HANDLE DriverHandle,
IN UINTN *MatchingHandleCount,
OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL
);
/**
Gets handles for any child controllers of the passed in controller.
@param[in] ControllerHandle The handle of the "parent controller".
@param[in] MatchingHandleCount The pointer to the number of handles in
MatchingHandleBuffer on return.
@param[out] MatchingHandleBuffer The buffer containing handles on a successful
return.
@retval EFI_SUCCESS The operation was successful.
@sa ParseHandleDatabaseByRelationship
**/
EFI_STATUS
EFIAPI
ParseHandleDatabaseForChildControllers(
IN CONST EFI_HANDLE ControllerHandle,
IN UINTN *MatchingHandleCount,
OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL
);
/**
Function to retrieve the human-friendly index of a given handle. If the handle
does not have a index one will be automatically assigned. The index value is valid
until the termination of the shell application.
@param[in] TheHandle The handle to retrieve an index for.
@retval 0 A memory allocation failed.
@return The index of the handle.
**/
UINTN
EFIAPI
ConvertHandleToHandleIndex(
IN CONST EFI_HANDLE TheHandle
);
/**
Function to retrieve the EFI_HANDLE from the human-friendly index.
@param[in] TheIndex The index to retrieve the EFI_HANDLE for.
@retval NULL The index was invalid.
@return The EFI_HANDLE that index represents.
**/
EFI_HANDLE
EFIAPI
ConvertHandleIndexToHandle(
IN CONST UINTN TheIndex
);
/**
Function to get all handles that support a given protocol or all handles.
@param[in] ProtocolGuid The guid of the protocol to get handles for. If NULL
then the function will return all handles.
@retval NULL A memory allocation failed.
@return A NULL terminated list of handles.
**/
EFI_HANDLE*
EFIAPI
GetHandleListByPotocol (
IN CONST EFI_GUID *ProtocolGuid OPTIONAL
);
/**
Function to get all handles that support some protocols.
@param[in] ProtocolGuids A NULL terminated list of protocol GUIDs.
@retval NULL A memory allocation failed.
@return A NULL terminated list of handles.
**/
EFI_HANDLE*
EFIAPI
GetHandleListByPotocolList (
IN CONST EFI_GUID **ProtocolGuids
);
#endif // __HANDLE_PARSING_LIB__

View File

@ -1,5 +1,5 @@
/** @file
Provides application point extension for "C" style main funciton
Provides application point extension for "C" style main funciton.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
@ -19,8 +19,8 @@
The ShellCEntryLib library instance wrappers the actual UEFI application
entry point and calls this ShellAppMain function.
@param ImageHandle The image handle of the UEFI Application.
@param SystemTable A pointer to the EFI System Table.
@param[in] Argc The number of parameters.
@param[in] Argv The array of pointers to parameters.
@retval 0 The application exited normally.
@retval Other An error occurred.

View File

@ -0,0 +1,757 @@
/** @file
Provides interface to shell internal functions for shell commands.
This library is for use ONLY by shell commands linked into the shell application.
This library will not funciton if it is used for UEFI Shell 2.0 Applications.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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.
**/
#ifndef _SHELL_COMMAND_LIB_
#define _SHELL_COMMAND_LIB_
#include <Uefi.h>
#include <ShellBase.h>
#include <Protocol/EfiShell.h>
#include <Protocol/EfiShellParameters.h>
#include <Protocol/UnicodeCollation.h>
#include <Protocol/DevicePathToText.h>
#include <Protocol/SimpleFileSystem.h>
#include <Library/UefiBootServicesTableLib.h>
//
// The extern global protocol poionters.
//
extern EFI_SHELL_PROTOCOL *gEfiShellProtocol;
extern EFI_SHELL_PARAMETERS_PROTOCOL *gEfiShellParametersProtocol;
extern EFI_UNICODE_COLLATION_PROTOCOL *gUnicodeCollation;
extern EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *gDevPathToText;
extern CONST CHAR16* SupportLevel[];
//
// The map list objects.
//
typedef struct {
LIST_ENTRY Link;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
CHAR16 *MapName;
CHAR16 *CurrentDirectoryPath;
UINT64 Flags;
} SHELL_MAP_LIST;
/// List of Mappings - DeviceName and Drive Letter(ism).
extern SHELL_MAP_LIST gShellMapList;
/// Pointer to node of current directory in the mMapList.
extern SHELL_MAP_LIST *gShellCurDir;
/**
Returns the help MAN fileName for a given shell command.
@retval !NULL The unicode string of the MAN filename.
@retval NULL An error ocurred.
**/
typedef
CONST CHAR16 *
(EFIAPI *SHELL_GET_MAN_FILENAME)(
VOID
);
/**
Runs a shell command on a given command line.
The specific operation of a given shell command is specified in the UEFI Shell
Specification 2.0, or in the source of the given command.
Upon completion of the command run the shell protocol and environment variables
may have been updated due to the operation.
@param[in] ImageHandle The ImageHandle to the app, or NULL if
the command built into shell.
@param[in] SystemTable The pointer to the system table.
@retval RETURN_SUCCESS The shell command was sucessful.
@retval RETURN_UNSUPPORTED The command is not supported.
**/
typedef
SHELL_STATUS
(EFIAPI *SHELL_RUN_COMMAND)(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Registers the handlers of type SHELL_RUN_COMMAND and
SHELL_GET_MAN_FILENAME for each shell command.
If the ShellSupportLevel is greater than the value of
PcdShellSupportLevel, then return RETURN_UNSUPPORTED.
Registers the the handlers specified by GetHelpInfoHandler and CommandHandler
with the command specified by CommandString. If the command named by
CommandString has already been registered, then return
RETURN_ALREADY_STARTED.
If there are not enough resources available to register the handlers, then
RETURN_OUT_OF_RESOURCES is returned.
If CommandString is NULL, then ASSERT().
If GetHelpInfoHandler is NULL, then ASSERT().
If CommandHandler is NULL, then ASSERT().
If ProfileName is NULL, then ASSERT().
@param[in] CommandString The pointer to the command name. This is the
name to look for on the command line in
the shell.
@param[in] CommandHandler The pointer to a function that runs the
specified command.
@param[in] GetManFileName The pointer to a function that provides man
filename.
@param[in] ShellMinSupportLevel The minimum Shell Support Level which has this
function.
@param[in] ProfileName The profile name to require for support of this
function.
@param[in] CanAffectLE Indicates whether this command's return value
can change the LASTERROR environment variable.
@param[in] HiiHandle The handle of this command's HII entry.
@param[in] ManFormatHelp The HII locator for the help text.
@retval RETURN_SUCCESS The handlers were registered.
@retval RETURN_OUT_OF_RESOURCES There are not enough resources available to
register the shell command.
@retval RETURN_UNSUPPORTED The ShellMinSupportLevel was higher than the
currently allowed support level.
@retval RETURN_ALREADY_STARTED The CommandString represents a command that
is already registered. Only one handler set for
a given command is allowed.
@sa SHELL_GET_MAN_FILENAME
@sa SHELL_RUN_COMMAND
**/
RETURN_STATUS
EFIAPI
ShellCommandRegisterCommandName (
IN CONST CHAR16 *CommandString,
IN SHELL_RUN_COMMAND CommandHandler,
IN SHELL_GET_MAN_FILENAME GetManFileName,
IN UINT32 ShellMinSupportLevel,
IN CONST CHAR16 *ProfileName,
IN CONST BOOLEAN CanAffectLE,
IN CONST EFI_HANDLE HiiHandle,
IN CONST EFI_STRING_ID ManFormatHelp
);
/**
Checks if a command string has been registered for CommandString, and if so, it runs
the previously registered handler for that command with the command line.
If CommandString is NULL, then ASSERT().
If Sections is specified, then each section name listed will be compared in a case sensitive
manner to the section names described in Appendix B UEFI Shell 2.0 Specification. If the section exists,
it is appended to the returned help text. If the section does not exist, no
information is returned. If Sections is NULL, then all help text information
available is returned.
@param[in] CommandString The pointer to the command name. This is the name
found on the command line in the shell.
@param[in,out] RetVal The pointer to the return value from the command handler.
@param[in,out] CanAffectLE Indicates whether this command's return value
needs to be placed into LASTERROR environment variable.
@retval RETURN_SUCCESS The handler was run.
@retval RETURN_NOT_FOUND The CommandString did not match a registered
command name.
@sa SHELL_RUN_COMMAND
**/
RETURN_STATUS
EFIAPI
ShellCommandRunCommandHandler (
IN CONST CHAR16 *CommandString,
IN OUT SHELL_STATUS *RetVal,
IN OUT BOOLEAN *CanAffectLE OPTIONAL
);
/**
Checks if a command string has been registered for CommandString, and if so, it
returns the MAN filename specified for that command.
If CommandString is NULL, then ASSERT().
@param[in] CommandString The pointer to the command name. This is the name
found on the command line in the shell.
@retval NULL The CommandString was not a registered command.
@retval other The name of the MAN file.
@sa SHELL_GET_MAN_FILENAME
**/
CONST CHAR16*
EFIAPI
ShellCommandGetManFileNameHandler (
IN CONST CHAR16 *CommandString
);
typedef struct {
LIST_ENTRY Link;
CHAR16 *CommandString;
} COMMAND_LIST;
/**
Get the list of all available shell internal commands. This is a linked list,
via the LIST_ENTRY structure. Enumerate through it using the BaseLib linked
list functions. Do not modify the values.
@return A linked list of all available shell commands.
**/
CONST COMMAND_LIST*
EFIAPI
ShellCommandGetCommandList (
VOID
);
typedef struct {
LIST_ENTRY Link;
CHAR16 *CommandString;
CHAR16 *Alias;
} ALIAS_LIST;
/**
Registers aliases to be set as part of the initialization of the shell application.
If Command is NULL, then ASSERT().
If Alias is NULL, then ASSERT().
@param[in] Command The pointer to the Command.
@param[in] Alias The pointer to Alias.
@retval RETURN_SUCCESS The handlers were registered.
@retval RETURN_OUT_OF_RESOURCES There are not enough resources available to
register the shell command.
**/
RETURN_STATUS
EFIAPI
ShellCommandRegisterAlias (
IN CONST CHAR16 *Command,
IN CONST CHAR16 *Alias
);
/**
Get the list of all shell alias commands. This is a linked list,
via LIST_ENTRY structure. Enumerate through it using the BaseLib linked
list functions. Do not modify the values.
@return A linked list of all requested shell aliases.
**/
CONST ALIAS_LIST*
EFIAPI
ShellCommandGetInitAliasList (
VOID
);
/**
Determine if a given alias is on the list of built in aliases.
@param[in] Alias The alias to test for.
@retval TRUE The alias is a built in alias.
@retval FALSE The alias is not a built in alias.
**/
BOOLEAN
EFIAPI
ShellCommandIsOnAliasList (
IN CONST CHAR16 *Alias
);
/**
Checks if a command is already on the list.
@param[in] CommandString The command string to check for on the list.
@retval TRUE CommandString represents a registered command.
@retval FALSE CommandString does not represent a registered command.
**/
BOOLEAN
EFIAPI
ShellCommandIsCommandOnList (
IN CONST CHAR16 *CommandString
);
/**
Get the help text for a command.
@param[in] CommandString The command name.
@retval NULL No help text was found.
@return The string of the help text. The caller required to free.
**/
CHAR16*
EFIAPI
ShellCommandGetCommandHelp (
IN CONST CHAR16 *CommandString
);
/**
Function to make sure that the above pointers are valid.
**/
EFI_STATUS
EFIAPI
CommandInit (
VOID
);
/**
Function to determine current state of ECHO. Echo determines if lines from scripts
and ECHO commands are enabled.
@retval TRUE Echo is currently enabled.
@retval FALSE Echo is currently disabled.
**/
BOOLEAN
EFIAPI
ShellCommandGetEchoState (
VOID
);
/**
Function to set current state of ECHO. Echo determines if lines from scripts
and ECHO commands are enabled.
@param[in] State TRUE to enable Echo, FALSE otherwise.
**/
VOID
EFIAPI
ShellCommandSetEchoState (
IN BOOLEAN State
);
/**
Indicate that the current shell or script should exit.
@param[in] ScriptOnly TRUE if exiting a script; FALSE otherwise.
**/
VOID
EFIAPI
ShellCommandRegisterExit (
IN BOOLEAN ScriptOnly
);
/**
Retrieve the Exit indicator.
@retval TRUE Exit was indicated.
@retval FALSE Exit was not indicated.
**/
BOOLEAN
EFIAPI
ShellCommandGetExit (
VOID
);
/**
Retrieve the Exit script indicator.
If ShellCommandGetExit returns FALSE, then the return from this is undefined.
@retval TRUE ScriptOnly was indicated.
@retval FALSE ScriptOnly was not indicated.
**/
BOOLEAN
EFIAPI
ShellCommandGetScriptExit (
VOID
);
typedef struct {
LIST_ENTRY Link; ///< List enumerator items.
UINTN Line; ///< What line of the script file this was on.
CHAR16 *Cl; ///< The original command line.
VOID *Data; ///< The data structure format dependant upon Command. (not always used)
BOOLEAN Reset; ///< Reset the command (it must be treated like a initial run (but it may have data already))
} SCRIPT_COMMAND_LIST;
typedef struct {
CHAR16 *ScriptName; ///< The filename of this script.
CHAR16 **Argv; ///< The parmameters to the script file.
UINTN Argc; ///< The count of parameters.
LIST_ENTRY CommandList; ///< The script converted to a list of commands (SCRIPT_COMMAND_LIST objects).
SCRIPT_COMMAND_LIST *CurrentCommand; ///< The command currently being operated. If !=NULL must be a member of CommandList.
LIST_ENTRY SubstList; ///< A list of current script loop alias' (ALIAS_LIST objects) (Used for the for %-based replacement).
} SCRIPT_FILE;
/**
Function to return a pointer to the currently running script file object.
@retval NULL A script file is not currently running.
@return A pointer to the current script file object.
**/
SCRIPT_FILE*
EFIAPI
ShellCommandGetCurrentScriptFile (
VOID
);
/**
Function to set a new script as the currently running one.
This function will correctly stack and unstack nested scripts.
@param[in] Script The pointer to new script information structure. If NULL,
it removes and de-allocates the topmost Script structure.
@return A pointer to the current running script file after this
change. It is NULL if removing the final script.
**/
SCRIPT_FILE*
EFIAPI
ShellCommandSetNewScript (
IN SCRIPT_FILE *Script OPTIONAL
);
/**
Function to get the current Profile string.
This is used to retrieve what profiles were installed.
@retval NULL There are no installed profiles.
@return A semicolon-delimited list of profiles.
**/
CONST CHAR16 *
EFIAPI
ShellCommandGetProfileList (
VOID
);
typedef enum {
MappingTypeFileSystem,
MappingTypeBlockIo,
MappingTypeMax
} SHELL_MAPPING_TYPE;
/**
Function to generate the next default mapping name.
If the return value is not NULL then it must be callee freed.
@param Type What kind of mapping name to make.
@retval NULL a memory allocation failed.
@return a new map name string
**/
CHAR16*
EFIAPI
ShellCommandCreateNewMappingName(
IN CONST SHELL_MAPPING_TYPE Type
);
/**
Function to initialize the table for creating consistent map names.
@param[out] Table The pointer to pointer to pointer to DevicePathProtocol object.
@retval EFI_SUCCESS The table was created successfully.
**/
EFI_STATUS
EFIAPI
ShellCommandConsistMappingInitialize (
EFI_DEVICE_PATH_PROTOCOL ***Table
);
/**
Function to uninitialize the table for creating consistent map names.
The parameter must have been received from ShellCommandConsistMappingInitialize.
@param[out] Table The pointer to pointer to DevicePathProtocol object.
@retval EFI_SUCCESS The table was deleted successfully.
**/
EFI_STATUS
EFIAPI
ShellCommandConsistMappingUnInitialize (
EFI_DEVICE_PATH_PROTOCOL **Table
);
/**
Create a consistent mapped name for the device specified by DevicePath
based on the Table.
This must be called after ShellCommandConsistMappingInitialize() and
before ShellCommandConsistMappingUnInitialize() is called.
@param[in] DeviecPath The pointer to the dev path for the device.
@param[in] Table The Table of mapping information.
@retval NULL A consistent mapped name could not be created.
@return A pointer to a string allocated from pool with the device name.
**/
CHAR16*
EFIAPI
ShellCommandConsistMappingGenMappingName (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN EFI_DEVICE_PATH_PROTOCOL **Table
);
/**
Function to search the list of mappings for the first matching node on the
list based on the MapKey.
@param[in] MapKey The pointer to the string key to search for in the map.
@return the node on the list.
**/
SHELL_MAP_LIST*
EFIAPI
ShellCommandFindMapItem (
IN CONST CHAR16 *MapKey
);
/**
Function to add a map node to the list of map items and update the "path" environment variable (optionally).
If Path is TRUE (during initialization only), the path environment variable will also be updated to include
default paths on the new map name...
Path should be FALSE when this function is called from the protocol SetMap function.
@param[in] Name The human readable mapped name.
@param[in] DevicePath The Device Path for this map.
@param[in] Flags The Flags attribute for this map item.
@param[in] Path TRUE to update path, FALSE to skip this step (should only be TRUE during initialization).
@retval EFI_SUCCESS The addition was sucessful.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
@retval EFI_INVALID_PARAMETER A parameter was invalid.
**/
EFI_STATUS
EFIAPI
ShellCommandAddMapItemAndUpdatePath(
IN CONST CHAR16 *Name,
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN CONST UINT64 Flags,
IN CONST BOOLEAN Path
);
/**
Creates the default map names for each device path in the system with
a protocol depending on the Type.
Also sets up the default path environment variable if Type is FileSystem.
@retval EFI_SUCCESS All map names were created sucessfully.
@retval EFI_NOT_FOUND No protocols were found in the system.
@return Error returned from gBS->LocateHandle().
@sa LocateHandle
**/
EFI_STATUS
EFIAPI
ShellCommandCreateInitialMappingsAndPaths(
VOID
);
/**
Function to standardize the directory indicators to \ characters.
@param[in,out] Path The pointer to the path string to fix.
@retval NULL The operation failed.
@return The Path pointer.
**/
CHAR16*
EFIAPI
ShellCommandCleanPath (
IN OUT CHAR16 *Path
);
/**
Converts a SHELL_FILE_HANDLE to an EFI_FILE_PROTOCOL*.
@param[in] Handle The SHELL_FILE_HANDLE to convert.
@return a EFI_FILE_PROTOCOL* representing the same file.
**/
EFI_FILE_PROTOCOL*
EFIAPI
ConvertShellHandleToEfiFileProtocol(
IN CONST SHELL_FILE_HANDLE Handle
);
/**
Remove a SHELL_FILE_HANDLE frmo the list of SHELL_FILE_HANDLES.
@param[in] Handle The SHELL_FILE_HANDLE to remove.
@retval TRUE The item was removed.
@retval FALSE The item was not found.
**/
BOOLEAN
EFIAPI
ShellFileHandleRemove(
IN CONST SHELL_FILE_HANDLE Handle
);
/**
Converts a EFI_FILE_PROTOCOL* to an SHELL_FILE_HANDLE.
@param[in] Handle The pointer to EFI_FILE_PROTOCOL to convert.
@param[in] Path The path to the file for verification.
@return a SHELL_FILE_HANDLE representing the same file.
**/
SHELL_FILE_HANDLE
EFIAPI
ConvertEfiFileProtocolToShellHandle(
IN CONST EFI_FILE_PROTOCOL *Handle,
IN CONST CHAR16 *Path
);
/**
Find the path that was logged with the specified SHELL_FILE_HANDLE.
@param[in] Handle The SHELL_FILE_HANDLE to query on.
@return A pointer to the path for the file.
**/
CONST CHAR16*
EFIAPI
ShellFileHandleGetPath(
IN CONST SHELL_FILE_HANDLE Handle
);
/**
Function to determine if a SHELL_FILE_HANDLE is at the end of the file.
This will NOT work on directories.
If Handle is NULL, then ASSERT.
@param[in] Handle the file handle
@retval TRUE the position is at the end of the file
@retval FALSE the position is not at the end of the file
**/
BOOLEAN
EFIAPI
ShellFileHandleEof(
IN SHELL_FILE_HANDLE Handle
);
/**
Function to read a single line from a SHELL_FILE_HANDLE. The \n is not included in the returned
buffer. The returned buffer must be callee freed.
If the position upon start is 0, then the Ascii Boolean will be set. This should be
maintained and not changed for all operations with the same file.
@param[in] Handle SHELL_FILE_HANDLE to read from.
@param[in,out] Ascii Boolean value for indicating whether the file is
Ascii (TRUE) or UCS2 (FALSE).
@return The line of text from the file.
@sa ShellFileHandleReadLine
**/
CHAR16*
EFIAPI
ShellFileHandleReturnLine(
IN SHELL_FILE_HANDLE Handle,
IN OUT BOOLEAN *Ascii
);
/**
Function to read a single line (up to but not including the \n) from a SHELL_FILE_HANDLE.
If the position upon start is 0, then the Ascii Boolean will be set. This should be
maintained and not changed for all operations with the same file.
@param[in] Handle SHELL_FILE_HANDLE to read from.
@param[in,out] Buffer The pointer to buffer to read into.
@param[in,out] Size The pointer to number of bytes in Buffer.
@param[in] Truncate If the buffer is large enough, this has no effect.
If the buffer is is too small and Truncate is TRUE,
the line will be truncated.
If the buffer is is too small and Truncate is FALSE,
then no read will occur.
@param[in,out] Ascii Boolean value for indicating whether the file is
Ascii (TRUE) or UCS2 (FALSE).
@retval EFI_SUCCESS The operation was successful. The line is stored in
Buffer.
@retval EFI_INVALID_PARAMETER Handle was NULL.
@retval EFI_INVALID_PARAMETER Size was NULL.
@retval EFI_BUFFER_TOO_SMALL Size was not large enough to store the line.
Size was updated to the minimum space required.
@sa ShellFileHandleRead
**/
EFI_STATUS
EFIAPI
ShellFileHandleReadLine(
IN SHELL_FILE_HANDLE Handle,
IN OUT CHAR16 *Buffer,
IN OUT UINTN *Size,
IN BOOLEAN Truncate,
IN OUT BOOLEAN *Ascii
);
typedef struct {
LIST_ENTRY Link;
void *Buffer;
} BUFFER_LIST;
/**
Frees any BUFFER_LIST defined type.
@param[in] List The pointer to the list head.
**/
VOID
EFIAPI
FreeBufferList (
IN BUFFER_LIST *List
);
/**
Chops off last directory or file entry in a path by changing the last '\' to a CHAR_NULL
@param[in,out] PathToReturn The pointer to the path to modify.
@retval FALSE No directory was found to chop off.
@retval TRUE A directory was chopped off.
**/
BOOLEAN
EFIAPI
ChopLastSlash(
IN OUT CHAR16 *PathToReturn
);
/**
Function to clean up paths. Removes the following items:
single periods in the path (no need for the current directory tag)
double periods in the path and removes a single parent directory.
This will be done inline and the resultant string may be be 'too big'.
@param[in] PathToReturn The pointer to the string containing the path.
@return PathToReturn is always returned.
**/
CHAR16*
EFIAPI
CleanPath(
IN CHAR16 *PathToReturn
);
#endif //_SHELL_COMMAND_LIB_

View File

@ -12,7 +12,7 @@
**/
#if !defined(__SHELL_LIB__)
#ifndef __SHELL_LIB__
#define __SHELL_LIB__
#include <Uefi.h>
@ -24,6 +24,12 @@
#include <Protocol/EfiShell.h>
#include <Protocol/EfiShellParameters.h>
// (20 * (6+5+2))+1) unicode characters from EFI FAT spec (doubled for bytes)
#define MAX_FILE_NAME_LEN 512
extern EFI_SHELL_PARAMETERS_PROTOCOL *mEfiShellParametersProtocol;
extern EFI_SHELL_PROTOCOL *mEfiShellProtocol;
/**
This function will retrieve the information about the file for the handle
specified and store it in allocated pool memory.
@ -41,31 +47,32 @@
EFI_FILE_INFO*
EFIAPI
ShellGetFileInfo (
IN EFI_FILE_HANDLE FileHandle
IN SHELL_FILE_HANDLE FileHandle
);
/**
This function will set the information about the file for the opened handle
This function sets the information about the file for the opened handle
specified.
@param[in] FileHandle The file handle of the file for which information
is being set.
@param[in] FileInfo The infotmation to set.
@param[in] FileInfo The information to set.
@retval EFI_SUCCESS The information was set.
@retval EFI_UNSUPPORTED The InformationType is not known.
@retval EFI_SUCCESS The information was set.
@retval EFI_INVALID_PARAMETER A parameter was out of range or invalid.
@retval EFI_UNSUPPORTED The FileHandle does not support FileInfo.
@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.
@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
ShellSetFileInfo (
IN EFI_FILE_HANDLE FileHandle,
IN SHELL_FILE_HANDLE FileHandle,
IN EFI_FILE_INFO *FileInfo
);
@ -75,36 +82,36 @@ ShellSetFileInfo (
This function opens a file with the open mode according to the file path. The
Attributes is valid only for EFI_FILE_MODE_CREATE.
@param[in] FilePath On input the device path to the file. On output
@param[in,out] FilePath On input, the device path to the file. On output,
the remaining device path.
@param[out] DeviceHandle Pointer to the system device handle.
@param[out] FileHandle Pointer to the file handle.
@param[in] OpenMode The mode to open the file with.
@param[in] Attributes The file's file attributes.
@param[out] DeviceHandle Pointer to the system device handle.
@param[out] FileHandle Pointer to the file handle.
@param[in] OpenMode The mode to open the file with.
@param[in] Attributes The file's file attributes.
@retval EFI_SUCCESS The information was set.
@retval EFI_SUCCESS The information was set.
@retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
@retval EFI_UNSUPPORTED Could not open the file path.
@retval EFI_UNSUPPORTED Could not open the file path.
@retval EFI_NOT_FOUND The specified file could not be found on the
device or the file system could not be found on
the device.
@retval EFI_NO_MEDIA The device has no medium.
@retval EFI_MEDIA_CHANGED The device has a different medium in it or the
@retval EFI_NO_MEDIA The device has no medium.
@retval EFI_MEDIA_CHANGED The device has a different medium in it or the
medium is no longer supported.
@retval EFI_DEVICE_ERROR The device reported an error.
@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_WRITE_PROTECTED The file or medium is write protected.
@retval EFI_ACCESS_DENIED The file was opened read only.
@retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the
file.
@retval EFI_VOLUME_FULL The volume is full.
@retval EFI_VOLUME_FULL The volume is full.
**/
EFI_STATUS
EFIAPI
ShellOpenFileByDevicePath(
IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,
OUT EFI_HANDLE *DeviceHandle,
OUT EFI_FILE_HANDLE *FileHandle,
OUT SHELL_FILE_HANDLE *FileHandle,
IN UINT64 OpenMode,
IN UINT64 Attributes
);
@ -113,36 +120,36 @@ ShellOpenFileByDevicePath(
This function will open a file or directory referenced by filename.
If return is EFI_SUCCESS, the Filehandle is the opened file's handle;
otherwise, the Filehandle is NULL. The Attributes is valid only for
otherwise, the Filehandle is NULL. Attributes is valid only for
EFI_FILE_MODE_CREATE.
@param[in] FileName Pointer to file name.
@param[out] FileHandle Pointer to the file handle.
@param[in] OpenMode The mode to open the file with.
@param[in] Attributes The file's file attributes.
@param[in] FilePath The pointer to file name.
@param[out] FileHandle The pointer to the file handle.
@param[in] OpenMode The mode to open the file with.
@param[in] Attributes The file's file attributes.
@retval EFI_SUCCESS The information was set.
@retval EFI_SUCCESS The information was set.
@retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
@retval EFI_UNSUPPORTED Could not open the file path.
@retval EFI_UNSUPPORTED Could not open the file path.
@retval EFI_NOT_FOUND The specified file could not be found on the
device or the file system could not be found
on the device.
@retval EFI_NO_MEDIA The device has no medium.
@retval EFI_MEDIA_CHANGED The device has a different medium in it or the
@retval EFI_NO_MEDIA The device has no medium.
@retval EFI_MEDIA_CHANGED The device has a different medium in it or the
medium is no longer supported.
@retval EFI_DEVICE_ERROR The device reported an error.
@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_WRITE_PROTECTED The file or medium is write protected.
@retval EFI_ACCESS_DENIED The file was opened read only.
@retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the
file.
@retval EFI_VOLUME_FULL The volume is full.
@retval EFI_VOLUME_FULL The volume is full.
**/
EFI_STATUS
EFIAPI
ShellOpenFileByName(
IN CONST CHAR16 *FilePath,
OUT EFI_FILE_HANDLE *FileHandle,
OUT SHELL_FILE_HANDLE *FileHandle,
IN UINT64 OpenMode,
IN UINT64 Attributes
);
@ -154,31 +161,31 @@ ShellOpenFileByName(
otherwise, the Filehandle is NULL. If the directory already existed, this
function opens the existing directory.
@param[in] DirectoryName Pointer to Directory name.
@param[out] FileHandle Pointer to the file handle.
@param[in] DirectoryName The pointer to Directory name.
@param[out] FileHandle The pointer to the file handle.
@retval EFI_SUCCESS The information was set.
@retval EFI_SUCCESS The information was set.
@retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
@retval EFI_UNSUPPORTED Could not open the file path.
@retval EFI_UNSUPPORTED Could not open the file path.
@retval EFI_NOT_FOUND The specified file could not be found on the
device or the file system could not be found
device, or the file system could not be found
on the device.
@retval EFI_NO_MEDIA The device has no medium.
@retval EFI_MEDIA_CHANGED The device has a different medium in it or the
@retval EFI_NO_MEDIA The device has no medium.
@retval EFI_MEDIA_CHANGED The device has a different medium in it or the
medium is no longer supported.
@retval EFI_DEVICE_ERROR The device reported an error.
@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_WRITE_PROTECTED The file or medium is write protected.
@retval EFI_ACCESS_DENIED The file was opened read only.
@retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the
file.
@retval EFI_VOLUME_FULL The volume is full.
@retval EFI_VOLUME_FULL The volume is full.
**/
EFI_STATUS
EFIAPI
ShellCreateDirectory(
IN CONST CHAR16 *DirectoryName,
OUT EFI_FILE_HANDLE *FileHandle
OUT SHELL_FILE_HANDLE *FileHandle
);
/**
@ -198,22 +205,22 @@ ShellCreateDirectory(
EFI_FILE_INFO is the structure returned as the directory entry.
@param[in] FileHandle The opened file handle.
@param[in] ReadSize On input the size of buffer in bytes. On return
@param[in,out] ReadSize On input the size of buffer in bytes. On return
the number of bytes written.
@param[out] Buffer The buffer to put read data into.
@retval EFI_SUCCESS Data was read.
@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_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
@retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required
size.
**/
EFI_STATUS
EFIAPI
ShellReadFile(
IN EFI_FILE_HANDLE FileHandle,
IN SHELL_FILE_HANDLE FileHandle,
IN OUT UINTN *ReadSize,
OUT VOID *Buffer
);
@ -230,24 +237,24 @@ ShellReadFile(
@param[in] FileHandle The opened file for writing.
@param[in] BufferSize On input the number of bytes in Buffer. On output
@param[in,out] BufferSize On input the number of bytes in Buffer. On output
the number of bytes written.
@param[in] 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_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.
@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
ShellWriteFile(
IN EFI_FILE_HANDLE FileHandle,
IN SHELL_FILE_HANDLE FileHandle,
IN OUT UINTN *BufferSize,
IN VOID *Buffer
);
@ -262,12 +269,12 @@ ShellWriteFile(
@param[in] FileHandle The file handle to close.
@retval EFI_SUCCESS The file handle was closed sucessfully.
@retval INVALID_PARAMETER One of the parameters has an invalid value.
@retval INVALID_PARAMETER One of the parameters has an invalid value.
**/
EFI_STATUS
EFIAPI
ShellCloseFile (
IN EFI_FILE_HANDLE *FileHandle
IN SHELL_FILE_HANDLE *FileHandle
);
/**
@ -287,7 +294,7 @@ ShellCloseFile (
EFI_STATUS
EFIAPI
ShellDeleteFile (
IN EFI_FILE_HANDLE *FileHandle
IN SHELL_FILE_HANDLE *FileHandle
);
/**
@ -295,15 +302,15 @@ ShellDeleteFile (
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
absolute positioning is supported, and moving past the end of the file is
allowed (a subsequent write would grow the file). Moving 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[in] FileHandle The file handle on which the position is being set.
@param[in] Position Byte position from begining of file.
@param[in] Position The byte position from the begining of the file.
@retval EFI_SUCCESS Operation completed sucessfully.
@retval EFI_UNSUPPORTED The seek request for non-zero is not valid on
@ -313,7 +320,7 @@ ShellDeleteFile (
EFI_STATUS
EFIAPI
ShellSetFilePosition (
IN EFI_FILE_HANDLE FileHandle,
IN SHELL_FILE_HANDLE FileHandle,
IN UINT64 Position
);
@ -326,7 +333,7 @@ ShellSetFilePosition (
if FileHandle is a directory.
@param[in] FileHandle The open file handle on which to get the position.
@param[out] Position Byte position from begining of file.
@param[out] Position The byte position from the begining of the file.
@retval EFI_SUCCESS The operation completed sucessfully.
@retval INVALID_PARAMETER One of the parameters has an invalid value.
@ -335,7 +342,7 @@ ShellSetFilePosition (
EFI_STATUS
EFIAPI
ShellGetFilePosition (
IN EFI_FILE_HANDLE FileHandle,
IN SHELL_FILE_HANDLE FileHandle,
OUT UINT64 *Position
);
@ -356,7 +363,7 @@ ShellGetFilePosition (
EFI_STATUS
EFIAPI
ShellFlushFile (
IN EFI_FILE_HANDLE FileHandle
IN SHELL_FILE_HANDLE FileHandle
);
/**
@ -368,20 +375,20 @@ ShellFlushFile (
Caller must use FreePool on *Buffer opon completion of all file searching.
@param[in] DirHandle The file handle of the directory to search
@param[out] Buffer Pointer to pointer to buffer for file's information
@param[in] DirHandle The file handle of the directory to search.
@param[out] Buffer The pointer to the buffer for the 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 ShellReadFile
@sa ShellReadFile
**/
EFI_STATUS
EFIAPI
ShellFindFirstFile (
IN EFI_FILE_HANDLE DirHandle,
IN SHELL_FILE_HANDLE DirHandle,
OUT EFI_FILE_INFO **Buffer
);
@ -392,24 +399,25 @@ ShellFindFirstFile (
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 ShellFindNextFile() 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
call of this function has no file to get. *NoFile will be set to TRUE, and the
data in Buffer is meaningless.
@param[in] DirHandle The file handle of the directory.
@param[out] Buffer Pointer to buffer for file's information.
@param[out] NoFile Pointer to boolean when last file is found.
@param[in,out] Buffer The pointer to buffer for file's information.
@param[in,out] NoFile The pointer to boolean when last file is found.
@retval EFI_SUCCESS Found the next 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.
@sa ShellReadFile
**/
EFI_STATUS
EFIAPI
ShellFindNextFile(
IN EFI_FILE_HANDLE DirHandle,
OUT EFI_FILE_INFO *Buffer,
OUT BOOLEAN *NoFile
IN SHELL_FILE_HANDLE DirHandle,
IN OUT EFI_FILE_INFO *Buffer,
IN OUT BOOLEAN *NoFile
);
/**
@ -419,7 +427,7 @@ ShellFindNextFile(
data.
@param[in] FileHandle The file handle from which size is retrieved.
@param[out] Size Pointer to size.
@param[out] Size The pointer to size.
@retval EFI_SUCCESS The operation was completed sucessfully.
@retval EFI_DEVICE_ERROR Cannot access the file.
@ -427,7 +435,7 @@ ShellFindNextFile(
EFI_STATUS
EFIAPI
ShellGetFileSize (
IN EFI_FILE_HANDLE FileHandle,
IN SHELL_FILE_HANDLE FileHandle,
OUT UINT64 *Size
);
@ -436,8 +444,8 @@ ShellGetFileSize (
This function is useful to check whether the application is being asked to halt by the shell.
@retval TRUE the execution break is enabled
@retval FALSE the execution break is not enabled
@retval TRUE The execution break is enabled.
@retval FALSE The execution break is not enabled.
**/
BOOLEAN
EFIAPI
@ -454,7 +462,7 @@ ShellGetExecutionBreakFlag(
@param[in] EnvKey The key name of the environment variable.
@retval NULL The named environment variable does not exist.
@return != NULL pointer to the value of the environment variable.
@return != NULL The pointer to the value of the environment variable.
**/
CONST CHAR16*
EFIAPI
@ -479,8 +487,8 @@ ShellGetEnvironmentVariable (
@param[in] EnvVal The Value of the environment variable
@param[in] Volatile Indicates whether the variable is non-volatile (FALSE) or volatile (TRUE).
@retval EFI_SUCCESS the operation was completed sucessfully
@retval EFI_UNSUPPORTED This operation is not allowed in pre UEFI 2.0 Shell environments
@retval EFI_SUCCESS The operation completed sucessfully
@retval EFI_UNSUPPORTED This operation is not allowed in pre-UEFI 2.0 Shell environments.
**/
EFI_STATUS
EFIAPI
@ -507,11 +515,11 @@ ShellSetEnvironmentVariable (
ShellExecute() function. The Output parameter has no effect in a
UEFI Shell 2.0 environment.
@param[in] ImageHandle Parent image that is starting the operation.
@param[in] CommandLine Pointer to NULL terminated command line.
@param[in] ParentHandle The parent image starting the operation.
@param[in] CommandLine The pointer to a NULL terminated command line.
@param[in] Output True to display debug output. False to hide it.
@param[in] EnvironmentVariables Optional pointer to array of environment variables
in the form "x=y". If NULL current set is used.
in the form "x=y". If NULL, the current set is used.
@param[out] Status The status of the run command line.
@retval EFI_SUCCESS The operation completed sucessfully. Status
@ -545,7 +553,7 @@ ShellExecute (
CONST CHAR16*
EFIAPI
ShellGetCurrentDir (
IN CHAR16 *DeviceName OPTIONAL
IN CHAR16 * CONST DeviceName OPTIONAL
);
/**
@ -575,9 +583,9 @@ ShellSetPageBreakMode (
If you are NOT appending to an existing list *ListHead must be NULL. If
*ListHead is NULL then it must be callee freed.
@param[in] Arg Pointer to path string.
@param[in] Arg The pointer to path string.
@param[in] OpenMode Mode to open files with.
@param[in] ListHead Head of linked list of results.
@param[in,out] ListHead Head of linked list of results.
@retval EFI_SUCCESS The operation was sucessful and the list head
contains the list of opened files.
@ -596,7 +604,7 @@ ShellOpenFileMetaArg (
/**
Free the linked list returned from ShellOpenFileMetaArg.
@param[in] ListHead The pointer to free.
@param[in,out] ListHead The pointer to free.
@retval EFI_SUCCESS The operation was sucessful.
@retval EFI_INVALID_PARAMETER A parameter was invalid.
@ -631,12 +639,12 @@ ShellFindFilePath (
in the order provided and return the first one that is successful.
If FileName is NULL, then ASSERT.
If FileExtension is NULL, then behavior is identical to ShellFindFilePath.
If FileExtension is NULL, then the behavior is identical to ShellFindFilePath.
If the return value is not NULL then the memory must be caller freed.
@param[in] FileName Filename string.
@param[in] FileExtension Semi-colon delimeted list of possible extensions.
@param[in] FileName The filename string.
@param[in] FileExtension Semicolon delimited list of possible extensions.
@retval NULL The file was not found.
@retval !NULL The path to the file.
@ -656,25 +664,28 @@ typedef enum {
TypeDoubleValue, ///< A flag that has 2 space seperated value data following it (IE "-a 1 2").
TypeMaxValue, ///< A flag followed by all the command line data before the next flag.
TypeMax,
} ParamType;
} SHELL_PARAM_TYPE;
typedef struct {
CHAR16 *Name;
ParamType Type;
CHAR16 *Name;
SHELL_PARAM_TYPE Type;
} SHELL_PARAM_ITEM;
/// Helper structure for no parameters (besides -? and -b)
extern SHELL_PARAM_ITEM EmptyParamList[];
/// Helper structure for -sfo only (besides -? and -b)
extern SHELL_PARAM_ITEM SfoParamList[];
/**
Checks the command line arguments passed against the list of valid ones.
Optionally removes NULL values first.
If no initialization is required, then return RETURN_SUCCESS.
@param[in] CheckList Pointer to list of parameters to check.
@param[out] CheckPackage Package of checked values.
@param[in] CheckList The pointer to list of parameters to check.
@param[out] CheckPackage The package of checked values.
@param[out] ProblemParam Optional pointer to pointer to unicode string for
the paramater that caused failure.
@param[in] AutoPageBreak Will automatically set PageBreakEnabled.
@ -683,9 +694,7 @@ extern SHELL_PARAM_ITEM EmptyParamList[];
@retval EFI_SUCCESS The operation completed sucessfully.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
@retval EFI_INVALID_PARAMETER A parameter was invalid.
@retval EFI_VOLUME_CORRUPTED The command line was corrupt. An argument was
duplicated. The duplicated command line argument
was returned in ProblemParam if provided.
@retval EFI_VOLUME_CORRUPTED The command line was corrupt.
@retval EFI_DEVICE_ERROR The commands contained 2 opposing arguments. One
of the command line arguments was returned in
ProblemParam if provided.
@ -735,12 +744,12 @@ ShellCommandLineFreeVarList (
@retval TRUE The flag is on the command line.
@retval FALSE The flag is not on the command line.
**/
**/
BOOLEAN
EFIAPI
ShellCommandLineGetFlag (
IN CONST LIST_ENTRY *CheckPackage,
IN CHAR16 *KeyString
IN CONST LIST_ENTRY * CONST CheckPackage,
IN CONST CHAR16 * CONST KeyString
);
/**
@ -754,8 +763,8 @@ ShellCommandLineGetFlag (
@param[in] KeyString The Key of the command line argument to check for.
@retval NULL The flag is not on the command line.
@retval !=NULL Pointer to unicode string of the value.
**/
@retval !=NULL The pointer to unicode string of the value.
**/
CONST CHAR16*
EFIAPI
ShellCommandLineGetValue (
@ -774,13 +783,13 @@ ShellCommandLineGetValue (
@param[in] Position The position of the value.
@retval NULL The flag is not on the command line.
@retval !=NULL Pointer to unicode string of the value.
**/
@retval !=NULL The pointer to unicode string of the value.
**/
CONST CHAR16*
EFIAPI
ShellCommandLineGetRawValue (
IN CONST LIST_ENTRY *CheckPackage,
IN UINT32 Position
IN CONST LIST_ENTRY * CONST CheckPackage,
IN UINTN Position
);
/**
@ -788,20 +797,22 @@ ShellCommandLineGetRawValue (
This will not include flags.
@retval (UINTN)-1 No parsing has ocurred.
@return The number of value parameters found.
@param[in] CheckPackage The package of parsed command line arguments.
@retval (UINTN)-1 No parsing has occurred.
@retval other The number of value parameters found.
**/
UINTN
EFIAPI
ShellCommandLineGetCount(
VOID
IN CONST LIST_ENTRY *CheckPackage
);
/**
Determins if a parameter is duplicated.
Determines if a parameter is duplicated.
If Param is not NULL then it will point to a callee allocated string buffer
with the parameter value if a duplicate is found.
If Param is not NULL, then it will point to a callee-allocated string buffer
with the parameter value, if a duplicate is found.
If CheckPackage is NULL, then ASSERT.
@ -820,7 +831,7 @@ ShellCommandLineCheckDuplicate (
/**
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
is already initialized it will de-initialize all the current protocol pointers and
re-populate them again.
When the library is used with PcdShellLibAutoInitialize set to true this function
@ -828,7 +839,7 @@ ShellCommandLineCheckDuplicate (
This function is intended for internal access for shell commands only.
@retval EFI_SUCCESS the initialization was complete sucessfully
@retval EFI_SUCCESS The initialization was complete sucessfully.
**/
EFI_STATUS
@ -858,14 +869,15 @@ ShellInitialize (
Note: The background color is controlled by the shell command cls.
@param[in] Row The row to print at.
@param[in] Col The column to print at.
@param[in] Row The row to print at.
@param[in] Format The format string.
@param[in] ... The variable argument list.
@return The number of characters printed to the screen.
@return EFI_SUCCESS The printing was successful.
@return EFI_DEVICE_ERROR The console device reported an error.
**/
UINTN
EFI_STATUS
EFIAPI
ShellPrintEx(
IN INT32 Col OPTIONAL,
@ -895,16 +907,18 @@ ShellPrintEx(
Note: The background color is controlled by the shell command cls.
@param[in] Row The row to print at.
@param[in] Col The column to print at.
@param[in] Row The row to print at.
@param[in] Language The language of the string to retrieve. If this parameter
is NULL, then the current platform language is used.
@param[in] HiiFormatStringId The format string Id for getting from Hii.
@param[in] HiiFormatHandle The format string Handle for getting from Hii.
@param[in] ... The variable argument list.
@return the number of characters printed to the screen.
@return EFI_SUCCESS The printing was successful.
@return EFI_DEVICE_ERROR The console device reported an error.
**/
UINTN
EFI_STATUS
EFIAPI
ShellPrintHiiEx(
IN INT32 Col OPTIONAL,
@ -999,7 +1013,7 @@ ShellStrToUintn(
given in CurrentSize the string will be grown such that the copy can be performed
and CurrentSize will be updated to the new size.
If Source is NULL, there is nothing to append, just return the current buffer in
If Source is NULL, there is nothing to append, so return the current buffer in
Destination.
If Destination is NULL, then ASSERT().
@ -1007,14 +1021,14 @@ ShellStrToUintn(
CurrentSize, then ASSERT().
@param[in,out] Destination The String to append onto.
@param[in,out] CurrentSize On call the number of bytes in Destination. On
return possibly the new size (still in bytes). If NULL
@param[in,out] CurrentSize On call, the number of bytes in Destination. On
return, possibly the new size (still in bytes). If NULL,
then allocate whatever is needed.
@param[in] Source The String to append from.
@param[in] Count Maximum number of characters to append. If 0 then
@param[in] Count The maximum number of characters to append. If 0, then
all are appended.
@return The Destination after apending the Source.
@return The Destination after appending the Source.
**/
CHAR16*
EFIAPI
@ -1033,13 +1047,14 @@ StrnCatGrow (
If the string would grow bigger than NewSize it will halt and return error.
@param[in] SourceString String with source buffer.
@param[in,out] NewString String with resultant buffer.
@param[in] NewSize Size in bytes of NewString.
@param[in] FindTarget String to look for.
@param[in] ReplaceWith String to replace FindTarget with.
@param[in] SourceString The string with source buffer.
@param[in,out] NewString The string with resultant buffer.
@param[in] NewSize The size in bytes of NewString.
@param[in] FindTarget The string to look for.
@param[in] ReplaceWith The string to replace FindTarget with.
@param[in] SkipPreCarrot If TRUE will skip a FindTarget that has a '^'
immediately before it.
@param[in] ParameterReplacing If TRUE will add "" around items with spaces.
@retval EFI_INVALID_PARAMETER SourceString was NULL.
@retval EFI_INVALID_PARAMETER NewString was NULL.
@ -1049,36 +1064,32 @@ StrnCatGrow (
@retval EFI_INVALID_PARAMETER SourceString had length < 1.
@retval EFI_BUFFER_TOO_SMALL NewSize was less than the minimum size to hold
the new string (truncation occurred).
@retval EFI_SUCCESS The string was sucessfully copied with replacement.
@retval EFI_SUCCESS The string was successfully copied with replacement.
**/
EFI_STATUS
EFIAPI
ShellCopySearchAndReplace2(
ShellCopySearchAndReplace(
IN CHAR16 CONST *SourceString,
IN CHAR16 *NewString,
IN OUT CHAR16 *NewString,
IN UINTN NewSize,
IN CONST CHAR16 *FindTarget,
IN CONST CHAR16 *ReplaceWith,
IN CONST BOOLEAN SkipPreCarrot
IN CONST BOOLEAN SkipPreCarrot,
IN CONST BOOLEAN ParameterReplacing
);
///
/// make upgrades easier from old version
///
#define ShellLibCopySearchAndReplace(a,b,c,d,e) ShellCopySearchAndReplace2(a,b,c,d,e,FALSE)
/**
Check if a Unicode character is a hexadecimal character.
This internal function checks if a Unicode character is a
decimal character. The valid hexadecimal character is
numeric character. The valid hexadecimal characters are
L'0' to L'9', L'a' to L'f', or L'A' to L'F'.
@param[in] Char The character to check.
@retval TRUE The Char is a hexadecmial character.
@retval FALSE The Char is not a hexadecmial character.
@param Char The character to check against.
@retval TRUE The Char is a hexadecmial character.
@retval FALSE The Char is not a hexadecmial character.
**/
BOOLEAN
@ -1087,31 +1098,51 @@ ShellIsHexaDecimalDigitCharacter (
IN CHAR16 Char
);
/**
Check if a Unicode character is a decimal character.
This internal function checks if a Unicode character is a
decimal character. The valid characters are
L'0' to L'9'.
@param Char The character to check against.
@retval TRUE The Char is a hexadecmial character.
@retval FALSE The Char is not a hexadecmial character.
**/
BOOLEAN
EFIAPI
ShellIsDecimalDigitCharacter (
IN CHAR16 Char
);
///
/// What type of answer is requested
/// What type of answer is requested.
///
typedef enum {
SHELL_PROMPT_REQUEST_TYPE_YES_NO,
SHELL_PROMPT_REQUEST_TYPE_YES_NO_CANCEL,
SHELL_PROMPT_REQUEST_TYPE_FREEFORM,
SHELL_PROMPT_REQUEST_TYPE_QUIT_CONTINUE,
SHELL_PROMPT_REQUEST_TYPE_YES_NO_ALL_CANCEL,
SHELL_PROMPT_REQUEST_TYPE_ENTER_TO_COMTINUE,
SHELL_PROMPT_REQUEST_TYPE_ANYKEY_TO_COMTINUE,
SHELL_PROMPT_REQUEST_TYPE_MAX
ShellPromptResponseTypeYesNo,
ShellPromptResponseTypeYesNoCancel,
ShellPromptResponseTypeFreeform,
ShellPromptResponseTypeQuitContinue,
ShellPromptResponseTypeYesNoAllCancel,
ShellPromptResponseTypeEnterContinue,
ShellPromptResponseTypeAnyKeyContinue,
ShellPromptResponseTypeMax
} SHELL_PROMPT_REQUEST_TYPE;
///
/// what answer was given
/// What answer was given.
///
typedef enum {
SHELL_PROMPT_RESPONSE_YES,
SHELL_PROMPT_RESPONSE_NO,
SHELL_PROMPT_RESPONSE_CANCEL,
SHELL_PROMPT_RESPONSE_QUIT,
SHELL_PROMPT_RESPONSE_CONTINUE,
SHELL_PROMPT_RESPONSE_ALL,
SHELL_PROMPT_RESPONSE_MAX
ShellPromptResponseYes,
ShellPromptResponseNo,
ShellPromptResponseCancel,
ShellPromptResponseQuit,
ShellPromptResponseContinue,
ShellPromptResponseAll,
ShellPromptResponseMax
} SHELL_PROMPT_RESPONSE;
/**
@ -1120,23 +1151,22 @@ typedef enum {
This function will display the requested question on the shell prompt and then
wait for an apropriate answer to be input from the console.
if the SHELL_PROMPT_REQUEST_TYPE is SHELL_PROMPT_REQUEST_TYPE_YESNO, SHELL_PROMPT_REQUEST_TYPE_QUIT_CONTINUE
If the SHELL_PROMPT_REQUEST_TYPE is SHELL_PROMPT_REQUEST_TYPE_YESNO, ShellPromptResponseTypeQuitContinue
or SHELL_PROMPT_REQUEST_TYPE_YESNOCANCEL then *Response is of type SHELL_PROMPT_RESPONSE.
if the SHELL_PROMPT_REQUEST_TYPE is SHELL_PROMPT_REQUEST_TYPE_FREEFORM then *Response is of type
If the SHELL_PROMPT_REQUEST_TYPE is ShellPromptResponseTypeFreeform then *Response is of type
CHAR16*.
In either case *Response must be callee freed if Response was not NULL;
@param Type What type of question is asked. This is used to filter the input
to prevent invalid answers to question.
@param Prompt Pointer to string prompt to use to request input.
@param Response Pointer to Response which will be populated upon return.
@param Prompt The pointer to a string prompt used to request input.
@param Response The pointer to Response, which will be populated upon return.
@retval EFI_SUCCESS The operation was sucessful.
@retval EFI_SUCCESS The operation was successful.
@retval EFI_UNSUPPORTED The operation is not supported as requested.
@retval EFI_INVALID_PARAMETER A parameter was invalid.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
@return other The operation failed.
**/
EFI_STATUS
@ -1155,11 +1185,12 @@ ShellPromptForResponse (
@param Type What type of question is asked. This is used to filter the input
to prevent invalid answers to question.
@param Prompt Pointer to string prompt to use to request input.
@param Response Pointer to Response which will be populated upon return.
@param[in] HiiFormatStringId The format string Id for getting from Hii.
@param[in] HiiFormatHandle The format string Handle for getting from Hii.
@param Response The pointer to Response, which will be populated upon return.
@retval EFI_SUCCESS the operation was sucessful.
@return other the operation failed.
@retval EFI_SUCCESS The operation was sucessful.
@return other The operation failed.
@sa ShellPromptForResponse
**/
@ -1172,5 +1203,39 @@ ShellPromptForResponseHii (
IN OUT VOID **Response
);
/**
Function to determin if an entire string is a valid number.
If Hex it must be preceeded with a 0x or has ForceHex, set TRUE.
@param[in] String The string to evaluate.
@param[in] ForceHex TRUE - always assume hex.
@param[in] StopAtSpace TRUE to halt upon finding a space, FALSE to keep going.
@retval TRUE It is all numeric (dec/hex) characters.
@retval FALSE There is a non-numeric character.
**/
BOOLEAN
EFIAPI
ShellIsHexOrDecimalNumber (
IN CONST CHAR16 *String,
IN CONST BOOLEAN ForceHex,
IN CONST BOOLEAN StopAtSpace
);
/**
Function to determine if a given filename exists.
@param[in] Name Path to test.
@retval EFI_SUCCESS The Path represents a file.
@retval EFI_NOT_FOUND The Path does not represent a file.
@retval other The path failed to open.
**/
EFI_STATUS
EFIAPI
ShellFileExists(
IN CONST CHAR16 *Name
);
#endif // __SHELL_LIB__

View File

@ -1,7 +1,7 @@
/** @file
Library used for sorting and comparison routines.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2009 - 2010, Intel Corporation.All rights reserved. <BR>
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
@ -12,18 +12,18 @@
**/
#if !defined(__SORT_LIB_H__)
#ifndef __SORT_LIB_H__
#define __SORT_LIB_H__
/**
Prototype for comparison function for any 2 element types.
Prototype for comparison function for any two element types.
@param[in] Buffer1 Pointer to first buffer.
@param[in] Buffer2 Pointer to second buffer.
@param[in] Buffer1 The pointer to first buffer.
@param[in] Buffer2 The pointer to second buffer.
@retval 0 Buffer1 equal to Buffer2.
@return < 0 Buffer1 is less than Buffer2.
@return > 0 Buffer1 is greater than Buffer2.
@return <0 Buffer1 is less than Buffer2.
@return >0 Buffer1 is greater than Buffer2.
**/
typedef
INTN
@ -40,15 +40,15 @@ INTN
If BufferToSort is NULL, then ASSERT.
If CompareFunction is NULL, then ASSERT.
If Count is < 2 then perform no action.
If Size is < 1 then perform no action.
If Count is < 2 , then perform no action.
If Size is < 1 , then perform no action.
@param[in,out] BufferToSort On call a Buffer of (possibly sorted) elements
on return a buffer of sorted elements.
@param[in] Count The number of elements in the buffer to sort
@param[in] ElementSize Size of an element in bytes.
@param[in,out] BufferToSort On call, a Buffer of (possibly sorted) elements;
on return, a buffer of sorted elements.
@param[in] Count The number of elements in the buffer to sort.
@param[in] ElementSize The size of an element in bytes.
@param[in] CompareFunction The function to call to perform the comparison
of any 2 elements.
of any two elements.
**/
VOID
EFIAPI
@ -63,8 +63,8 @@ PerformQuickSort (
/**
Function to compare 2 device paths for use as CompareFunction.
@param[in] Buffer1 Pointer to Device Path to compare.
@param[in] Buffer2 Pointer to second DevicePath to compare.
@param[in] Buffer1 The pointer to Device Path to compare.
@param[in] Buffer2 The pointer to second DevicePath to compare.
@retval 0 Buffer1 equal to Buffer2.
@return < 0 Buffer1 is less than Buffer2.
@ -80,8 +80,8 @@ DevicePathCompare (
/**
Function to compare 2 strings without regard to case of the characters.
@param[in] Buffer1 Pointer to String to compare (CHAR16**).
@param[in] Buffer2 Pointer to second String to compare (CHAR16**).
@param[in] Buffer1 The pointer to String to compare (CHAR16**).
@param[in] Buffer2 The pointer to second String to compare (CHAR16**).
@retval 0 Buffer1 equal to Buffer2.
@return < 0 Buffer1 is less than Buffer2.
@ -94,4 +94,21 @@ StringNoCaseCompare (
IN CONST VOID *Buffer2
);
/**
Function to compare 2 strings.
@param[in] Buffer1 The pointer to String to compare (CHAR16**).
@param[in] Buffer2 The pointer to second String to compare (CHAR16**).
@retval 0 Buffer1 equal to Buffer2.
@return < 0 Buffer1 is less than Buffer2.
@return > 0 Buffer1 is greater than Buffer2.
**/
INTN
EFIAPI
StringCompare (
IN CONST VOID *Buffer1,
IN CONST VOID *Buffer2
);
#endif //__SORT_LIB_H__

View File

@ -1,7 +1,7 @@
/** @file
EFI Shell protocol as defined in the UEFI Shell 2.0 specification including errata.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
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
@ -15,7 +15,7 @@
#ifndef __EFI_SHELL_PROTOCOL__
#define __EFI_SHELL_PROTOCOL__
#include <Protocol/SimpleFileSystem.h>
#include <ShellBase.h>
#include <Guid/FileInfo.h>
#define EFI_SHELL_PROTOCOL_GUID \
@ -26,12 +26,12 @@
// replaced EFI_LIST_ENTRY with LIST_ENTRY for simplicity.
// they are identical outside of the name.
typedef struct {
LIST_ENTRY Link; ///< Linked list members.
EFI_STATUS Status; ///< Status of opening the file. Valid only if Handle != NULL.
CONST CHAR16 *FullName; ///< Fully qualified filename.
CONST CHAR16 *FileName; ///< name of this file.
EFI_FILE_HANDLE Handle; ///< Handle for interacting with the opened file or NULL if closed.
EFI_FILE_INFO *Info; ///< Pointer to the FileInfo struct for this file or NULL.
LIST_ENTRY Link; ///< Linked list members.
EFI_STATUS Status; ///< Status of opening the file. Valid only if Handle != NULL.
CONST CHAR16 *FullName; ///< Fully qualified filename.
CONST CHAR16 *FileName; ///< name of this file.
SHELL_FILE_HANDLE Handle; ///< Handle for interacting with the opened file or NULL if closed.
EFI_FILE_INFO *Info; ///< Pointer to the FileInfo struct for this file or NULL.
} EFI_SHELL_FILE_INFO;
/**
@ -61,7 +61,7 @@ BOOLEAN
typedef
EFI_STATUS
(EFIAPI *EFI_SHELL_CLOSE_FILE)(
IN EFI_FILE_HANDLE FileHandle
IN SHELL_FILE_HANDLE FileHandle
);
/**
@ -79,9 +79,9 @@ EFI_STATUS
already exists and is non-volatile then EFI_INVALID_PARAMETER is returned.
@param[in] FileName Pointer to NULL-terminated file path.
@param[in] FileAttribs The new file's attrbiutes. the different attributes are
@param[in] FileAttribs The new file's attrbiutes. The different attributes are
described in EFI_FILE_PROTOCOL.Open().
@param[out] FileHandle On return, points to the created file handle or directory's handle
@param[out] FileHandle On return, points to the created file handle or directory's handle.
@retval EFI_SUCCESS The file was opened. FileHandle points to the new file's handle.
@retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
@ -103,9 +103,9 @@ EFI_STATUS
typedef
EFI_STATUS
(EFIAPI *EFI_SHELL_CREATE_FILE)(
IN CONST CHAR16 *FileName,
IN UINT64 FileAttribs,
OUT EFI_FILE_HANDLE *FileHandle
IN CONST CHAR16 *FileName,
IN UINT64 FileAttribs,
OUT SHELL_FILE_HANDLE *FileHandle
);
/**
@ -123,7 +123,7 @@ EFI_STATUS
typedef
EFI_STATUS
(EFIAPI *EFI_SHELL_DELETE_FILE)(
IN EFI_FILE_HANDLE FileHandle
IN SHELL_FILE_HANDLE FileHandle
);
/**
@ -194,10 +194,10 @@ VOID
typedef
EFI_STATUS
(EFIAPI *EFI_SHELL_EXECUTE) (
IN EFI_HANDLE *ParentImageHandle,
IN CHAR16 *CommandLine OPTIONAL,
IN CHAR16 **Environment OPTIONAL,
OUT EFI_STATUS *StatusCode OPTIONAL
IN EFI_HANDLE *ParentImageHandle,
IN CHAR16 *CommandLine OPTIONAL,
IN CHAR16 **Environment OPTIONAL,
OUT EFI_STATUS *StatusCode OPTIONAL
);
/**
@ -224,8 +224,8 @@ EFI_STATUS
typedef
EFI_STATUS
(EFIAPI *EFI_SHELL_FIND_FILES)(
IN CONST CHAR16 *FilePattern,
OUT EFI_SHELL_FILE_INFO **FileList
IN CONST CHAR16 *FilePattern,
OUT EFI_SHELL_FILE_INFO **FileList
);
/**
@ -243,8 +243,8 @@ EFI_STATUS
typedef
EFI_STATUS
(EFIAPI *EFI_SHELL_FIND_FILES_IN_DIR)(
IN EFI_FILE_HANDLE FileDirHandle,
OUT EFI_SHELL_FILE_INFO **FileList
IN SHELL_FILE_HANDLE FileDirHandle,
OUT EFI_SHELL_FILE_INFO **FileList
);
/**
@ -265,7 +265,7 @@ OUT EFI_SHELL_FILE_INFO **FileList
typedef
EFI_STATUS
(EFIAPI *EFI_SHELL_FLUSH_FILE)(
IN EFI_FILE_HANDLE FileHandle
IN SHELL_FILE_HANDLE FileHandle
);
/**
@ -342,10 +342,10 @@ typedef UINT32 EFI_SHELL_DEVICE_NAME_FLAGS;
typedef
EFI_STATUS
(*EFI_SHELL_GET_DEVICE_NAME) (
IN EFI_HANDLE DeviceHandle,
IN EFI_SHELL_DEVICE_NAME_FLAGS Flags,
IN CHAR8 *Language,
OUT CHAR16 **BestDeviceName
IN EFI_HANDLE DeviceHandle,
IN EFI_SHELL_DEVICE_NAME_FLAGS Flags,
IN CHAR8 *Language,
OUT CHAR16 **BestDeviceName
);
/**
@ -427,7 +427,7 @@ CONST CHAR16 *
typedef
EFI_FILE_INFO *
(EFIAPI *EFI_SHELL_GET_FILE_INFO)(
IN EFI_FILE_HANDLE FileHandle
IN SHELL_FILE_HANDLE FileHandle
);
/**
@ -464,7 +464,7 @@ CHAR16 *
typedef
EFI_STATUS
(EFIAPI *EFI_SHELL_GET_FILE_POSITION)(
IN EFI_FILE_HANDLE FileHandle,
IN SHELL_FILE_HANDLE FileHandle,
OUT UINT64 *Position
);
@ -482,7 +482,7 @@ EFI_STATUS
typedef
EFI_STATUS
(EFIAPI *EFI_SHELL_GET_FILE_SIZE)(
IN EFI_FILE_HANDLE FileHandle,
IN SHELL_FILE_HANDLE FileHandle,
OUT UINT64 *Size
);
@ -629,7 +629,7 @@ typedef
EFI_STATUS
(EFIAPI *EFI_SHELL_OPEN_FILE_BY_NAME) (
IN CONST CHAR16 *FileName,
OUT EFI_FILE_HANDLE *FileHandle,
OUT SHELL_FILE_HANDLE *FileHandle,
IN UINT64 OpenMode
);
@ -676,7 +676,7 @@ typedef
EFI_STATUS
(EFIAPI *EFI_SHELL_OPEN_ROOT)(
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
OUT EFI_FILE_HANDLE *FileHandle
OUT SHELL_FILE_HANDLE *FileHandle
);
/**
@ -698,7 +698,7 @@ typedef
EFI_STATUS
(EFIAPI *EFI_SHELL_OPEN_ROOT_BY_HANDLE)(
IN EFI_HANDLE DeviceHandle,
OUT EFI_FILE_HANDLE *FileHandle
OUT SHELL_FILE_HANDLE *FileHandle
);
/**
@ -723,7 +723,7 @@ EFI_STATUS
typedef
EFI_STATUS
(EFIAPI *EFI_SHELL_READ_FILE) (
IN EFI_FILE_HANDLE FileHandle,
IN SHELL_FILE_HANDLE FileHandle,
IN OUT UINTN *ReadSize,
IN OUT VOID *Buffer
);
@ -873,7 +873,7 @@ EFI_STATUS
typedef
EFI_STATUS
(EFIAPI *EFI_SHELL_SET_FILE_INFO)(
IN EFI_FILE_HANDLE FileHandle,
IN SHELL_FILE_HANDLE FileHandle,
IN CONST EFI_FILE_INFO *FileInfo
);
@ -895,7 +895,7 @@ EFI_STATUS
typedef
EFI_STATUS
(EFIAPI *EFI_SHELL_SET_FILE_POSITION)(
IN EFI_FILE_HANDLE FileHandle,
IN SHELL_FILE_HANDLE FileHandle,
IN UINT64 Position
);
@ -945,7 +945,7 @@ EFI_STATUS
typedef
EFI_STATUS
(EFIAPI *EFI_SHELL_WRITE_FILE)(
IN EFI_FILE_HANDLE FileHandle,
IN SHELL_FILE_HANDLE FileHandle,
IN OUT UINTN *BufferSize,
IN VOID *Buffer
);

View File

@ -13,7 +13,7 @@
**/
#if !defined (_SHELL_ENVIRONMENT_2_PROTOCOL_H_)
#ifndef _SHELL_ENVIRONMENT_2_PROTOCOL_H_
#define _SHELL_ENVIRONMENT_2_PROTOCOL_H_
#define DEFAULT_INIT_ROW 1
@ -24,8 +24,8 @@
to a given location. The location is dependant on the implementation. This is
used when programatically adding shell commands.
@param Handle The handle the protocol is on.
@param Interface The interface to the protocol.
@param[in] Handle The handle the protocol is on.
@param[in] Interface The interface to the protocol.
**/
typedef
@ -40,11 +40,11 @@ VOID
implementation. The specific command depends on the implementation. This is
used when programatically adding shell commands.
@param ImageHandle The handle to the binary shell.
@param SystemTable Pointer to the system table.
@param[in] ImageHandle The handle to the binary shell.
@param[in] SystemTable The pointer to the system table.
@retval EFI_SUCCESS The command ran to completion
@retval other An error ocurred. Any error is possible
@retval EFI_SUCCESS The command completed.
@retval other An error occurred. Any error is possible
depending on the implementation of the shell
command.
@ -61,7 +61,7 @@ EFI_STATUS
This is used when programatically adding shell commands. Upon successful return
the memory allocated is up to the caller to free.
@param Str Pointer to pointer to string to display for help.
@param[in,out] Str Pointer to pointer to string to display for help.
@retval EFI_SUCCESS The help string is in the parameter Str.
@ -111,8 +111,8 @@ GUID for the shell environment2 extension (main GUID above).
0xd2c18636, 0x40e5, 0x4eb5, {0xa3, 0x1b, 0x36, 0x69, 0x5f, 0xd4, 0x2c, 0x87} \
}
#define EFI_SHELL_MAJOR_VER 0x00000001 ///< Major version of the EFI_SHELL_ENVIRONMENT2
#define EFI_SHELL_MINOR_VER 0x00000000 ///< Minor version of the EFI_SHELL_ENVIRONMENT2
#define EFI_SHELL_MAJOR_VER 0x00000001 ///< Major version of the EFI_SHELL_ENVIRONMENT2.
#define EFI_SHELL_MINOR_VER 0x00000000 ///< Minor version of the EFI_SHELL_ENVIRONMENT2.
/**
Execute a command line.
@ -121,13 +121,13 @@ GUID for the shell environment2 extension (main GUID above).
parsing any requires scripts, and if DebugOutput is TRUE printing errors
encountered directly to the screen.
@param ParentImageHandle Handle of image executing this operation.
@param CommandLine The string command line to execute.
@param DebugOutput TRUE indicates that errors should be printed directly.
@param[in] ParentImageHandle Handle of the image executing this operation.
@param[in] CommandLine The string command line to execute.
@param[in] DebugOutput TRUE indicates that errors should be printed directly.
FALSE supresses error messages.
@retval EFI_SUCCESS The command line executed and completed.
@retval EFI_ABORTED The operation did not complete due to abort.
@retval EFI_ABORTED The operation aborted.
@retval EFI_INVALID_PARAMETER A parameter did not have a valid value.
@retval EFI_OUT_OF_RESOURCES A required memory allocation failed.
@ -144,7 +144,7 @@ EFI_STATUS
/**
This function returns a shell environment variable value.
@param Name Pointer to the string with the shell environment
@param[in] Name The pointer to the string with the shell environment
variable name.
@retval NULL The shell environment variable's value could not be found.
@ -160,7 +160,7 @@ CHAR16 *
/**
This function returns a shell environment map value.
@param Name Pointer to the string with the shell environment
@param[in] Name The pointer to the string with the shell environment
map name.
@retval NULL The shell environment map's value could not be found.
@ -179,9 +179,9 @@ CHAR16 *
This will allocate all required memory, put the new command on the command
list in the correct location.
@param Handler The handler function to call when the command gets called.
@param Cmd The command name.
@param GetLineHelp Function to call of get help for this command.
@param[in] Handler The handler function to call when the command gets called.
@param[in] Cmd The command name.
@param[in] GetLineHelp The function to call of type "get help" for this command.
@retval EFI_SUCCESS The command is now part of the command list.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
@ -203,12 +203,12 @@ EFI_STATUS
This will get the current protocol info and add the new info or update existing info
and then resave the info.
@param Protocol Pointer to the protocol's GUID.
@param DumpToken The function pointer to dump token function or
@param[in] Protocol The pointer to the protocol's GUID.
@param[in] DumpToken The function pointer to dump token function or
NULL.
@param DumpInfo The function pointer to dump infomation function
@param[in] DumpInfo The function pointer to dump infomation function
or NULL.
@param IdString The english name of the protocol.
@param[in] IdString The English name of the protocol.
**/
typedef
VOID
@ -226,11 +226,11 @@ VOID
found it will return the name of that protocol. If no name is found and
GenId is TRUE it will generate ths string.
@param Protocol The GUID of the protocol to look for.
@param GenId Whether to generate a name string if its not found.
@param[in] Protocol The GUID of the protocol to look for.
@param[in] GenId Whether to generate a name string if it is not found.
@return !NULL The Name of the protocol.
@retval NULL The Name was not found and GenId was not TRUE.
@return !NULL The Name of the protocol.
@retval NULL The Name was not found, and GenId was not TRUE.
**/
typedef
CHAR16*
@ -246,10 +246,10 @@ CHAR16*
If DeviceName is specified, then return the current shell directory on that
device. If DeviceName is NULL, then return the current directory on the
current device. The caller us responsible to free the returned string when
no londer required.
no longer required.
@param DeviceName The name of the device to get the current
directory on or NULL for current device.
@param[in] DeviceName The name of the device to get the current
directory on, or NULL for current device.
@return String array with the current directory on the current or specified device.
@ -270,11 +270,11 @@ CHAR16*
The memory allocated by the callee for this list is freed by making a call to
SHELLENV_FREE_FILE_LIST.
@param Arg Pointer Path to files to open.
@param ListHead Pointer to allocated and initialized list head
upon which to append all the opened file structures.
@param[in] Arg The pointer Path to files to open.
@param[in,out] ListHead The pointer to the allocated and initialized list head
upon which to append all opened file structures.
@retval EFI_SUCCESS 1 or more files was opened and a struct of each file's
@retval EFI_SUCCESS One or more files was opened and a struct of each file's
information was appended to ListHead.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
@retval EFI_NOT_FOUND No matching files could be found.
@ -289,9 +289,9 @@ EFI_STATUS
/**
This frees all of the nodes under the ListHead, but not ListHead itself.
@param ListHead Pointer to list to free all nodes of.
@param[in,out] ListHead Pointer to list to free all nodes of.
@retval EFI_SUCCESS Always returned.
@retval EFI_SUCCESS This function always returns EFI_SUCCESS.
**/
typedef
EFI_STATUS
@ -307,10 +307,10 @@ EFI_STATUS
EFI_SHELL_INTERFACE protocol. It is the caller's responsibility to free the
memory.
@param ImageHandle The handle which will use the new ShellInterface
@param[in] ImageHandle The handle which will use the new ShellInterface
protocol.
@return the newly allocated shell interface protocol.
@return The newly allocated shell interface protocol.
**/
typedef
@ -332,12 +332,12 @@ EFI_SHELL_INTERFACE*
typedef
BOOLEAN
(EFIAPI *SHELLENV_BATCH_IS_ACTIVE) (
IN VOID
VOID
);
/**
This is an internal shell function to free any and all allocated resources.
This should be called just closing the shell.
This should be called immediately prior to closing the shell.
**/
typedef
VOID
@ -349,12 +349,12 @@ VOID
This function enables the page break mode.
This mode causes the output to pause after each complete screen to enable a
user to more easily read it. If AutoWrap is TRUE then rows with too many
characters will be chopped and divided into 2 rows. If FALSE then rows with
user to more easily read it. If AutoWrap is TRUE, then rows with too many
characters will be chopped and divided into 2 rows. If FALSE, then rows with
too many characters may not be fully visible to the user on the screen.
@param StartRow The row number to start this on.
@param AutoWrap Whether to auto wrap rows that are too long.
@param[in] StartRow The row number to start this on.
@param[in] AutoWrap Whether to auto wrap rows that are too long.
**/
typedef
VOID
@ -366,13 +366,13 @@ VOID
/**
This function disables the page break mode.
Tisabling this causes the output to print out exactly as coded with no breaks
Disabling this causes the output to print out exactly as coded, with no breaks
for readability.
**/
typedef
VOID
(EFIAPI *SHELLENV_DISABLE_PAGE_BREAK) (
IN VOID
VOID
);
/**
@ -384,7 +384,7 @@ VOID
typedef
BOOLEAN
(EFIAPI *SHELLENV_GET_PAGE_BREAK) (
IN VOID
VOID
);
/**
@ -395,7 +395,7 @@ BOOLEAN
#define EFI_OUTPUT_PAUSE 0x00000002
#define EFI_EXECUTION_BREAK 0x00000004
@param KeyFilter The new key filter to use.
@param[in] KeyFilter The new key filter to use.
**/
typedef
VOID
@ -411,12 +411,12 @@ VOID
#define EFI_OUTPUT_PAUSE 0x00000002
#define EFI_EXECUTION_BREAK 0x00000004
@retval the current filter mask.
@retval The current filter mask.
**/
typedef
UINT32
(EFIAPI *SHELLENV_GET_KEY_FILTER) (
IN VOID
VOID
);
/**
@ -425,33 +425,33 @@ UINT32
This is used to inform a shell application that a break condition has been
initiated. Long loops should check this to prevent delays to the break.
@retval TRUE A break has been signaled. the application
@retval TRUE A break has been signaled. The application
should exit with EFI_ABORTED as soon as possible.
@retval FALSE Continue as normal.
**/
typedef
BOOLEAN
(EFIAPI *SHELLENV_GET_EXECUTION_BREAK) (
IN VOID
VOID
);
/**
This is an internal-shell function used to increment the shell nesting level.
This is an internal shell function used to increment the shell nesting level.
**/
typedef
VOID
(EFIAPI *SHELLENV_INCREMENT_SHELL_NESTING_LEVEL) (
IN VOID
VOID
);
/**
This is an internal-shell function used to decrement the shell nesting level.
This is an internal shell function used to decrement the shell nesting level.
**/
typedef
VOID
(EFIAPI *SHELLENV_DECREMENT_SHELL_NESTING_LEVEL) (
IN VOID
VOID
);
/**
@ -464,7 +464,7 @@ VOID
typedef
BOOLEAN
(EFIAPI *SHELLENV_IS_ROOT_SHELL) (
IN VOID
VOID
);
/**
@ -473,11 +473,11 @@ BOOLEAN
This is an internal shell function to handle shell cascading. It restores the
original set of console protocols.
@param ConInHandle The handle of ConIn.
@param ConIn Pointer to the location to return the pointer to
@param[in] ConInHandle The handle of ConIn.
@param[in,out] ConIn The pointer to the location to return the pointer to
the original console input.
@param ConOutHandle The handle of ConOut
@param ConOut Pointer to the location to return the pointer to
@param[in] ConOutHandle The handle of ConOut
@param[in,out] ConOut The pointer to the location to return the pointer to
the original console output.
**/
typedef
@ -507,12 +507,12 @@ VOID
This is an internal shell function to enumerate the handle database.
This function gets the next handle in the handle database. If no handles are
found EFI_NOT_FOUND is returned. If the previous Handle was the last handle
found, EFI_NOT_FOUND is returned. If the previous Handle was the last handle,
it is set to NULL before returning.
This must be called after INIT_HANDLE_ENUMERATOR and before CLOSE_HANDLE_ENUMERATOR.
@param Handle Pointer to pointer to Handle. Will be set
@param[in,out] Handle The pointer to pointer to Handle. It is set
on a sucessful return.
@retval EFI_SUCCESS The next handle in the handle database is *Handle.
@ -533,10 +533,10 @@ EFI_STATUS
This must be called after INIT_HANDLE_ENUMERATOR and before CLOSE_HANDLE_ENUMERATOR.
@param SkipNum how many handles to skip
@param[in] SkipNum How many handles to skip
@retval EFI_SUCCESS the next handle in the handle database is *Handle
@retval EFI_ACCESS_DENIED there are not SkipNum handles left in the database
@retval EFI_SUCCESS The next handle in the handle database is *Handle
@retval EFI_ACCESS_DENIED There are not SkipNum handles left in the database
**/
typedef
EFI_STATUS
@ -552,9 +552,9 @@ EFI_STATUS
This must be called after INIT_HANDLE_ENUMERATOR and before CLOSE_HANDLE_ENUMERATOR.
@param EnumIndex Where to start.
@param[in] EnumIndex Where to start.
@return the number of handles either read out or skipped before this reset.
@return The number of handles either read out or skipped before this reset.
**/
typedef
UINTN
@ -568,7 +568,7 @@ UINTN
This must be called after INIT_HANDLE_ENUMERATOR.
This function releases all memory and resources associated with the handle database.
Tfter this no other handle enumerator functions except INIT_HANDLE_ENUMERATOR will
After this no other handle enumerator functions except INIT_HANDLE_ENUMERATOR will
function properly.
**/
typedef
@ -584,7 +584,7 @@ VOID
This must be called after INIT_HANDLE_ENUMERATOR and before CLOSE_HANDLE_ENUMERATOR.
@return the number of handles in the handle database.
@return The number of handles in the handle database.
**/
typedef
UINTN
@ -596,12 +596,12 @@ UINTN
Handle Enumerator structure.
**/
typedef struct {
INIT_HANDLE_ENUMERATOR Init; ///< Pointer to INIT_HANDLE_ENUMERATOR function.
NEXT_HANDLE Next; ///< Pointer to NEXT_HANDLE function.
SKIP_HANDLE Skip; ///< Pointer to SKIP_HANDLE function.
RESET_HANDLE_ENUMERATOR Reset; ///< Pointer to RESET_HANDLE_ENUMERATOR function.
CLOSE_HANDLE_ENUMERATOR Close; ///< Pointer to CLOSE_HANDLE_ENUMERATOR function.
GET_NUM GetNum; ///< Pointer to GET_NUM function.
INIT_HANDLE_ENUMERATOR Init; ///< The pointer to INIT_HANDLE_ENUMERATOR function.
NEXT_HANDLE Next; ///< The pointer to NEXT_HANDLE function.
SKIP_HANDLE Skip; ///< The pointer to SKIP_HANDLE function.
RESET_HANDLE_ENUMERATOR Reset; ///< The pointer to RESET_HANDLE_ENUMERATOR function.
CLOSE_HANDLE_ENUMERATOR Close; ///< The pointer to CLOSE_HANDLE_ENUMERATOR function.
GET_NUM GetNum; ///< The pointer to GET_NUM function.
} HANDLE_ENUMERATOR;
/**
@ -614,18 +614,18 @@ typedef struct {
**/
typedef struct {
UINTN Signature; ///< PROTOCOL_INFO_SIGNATURE.
LIST_ENTRY Link; ///< Standard lined list helper member.
LIST_ENTRY Link; ///< Standard linked list helper member.
//
// The parsing info for the protocol.
//
EFI_GUID ProtocolId; ///< GUID for the protocol.
CHAR16 *IdString; ///< Name of the protocol.
SHELLENV_DUMP_PROTOCOL_INFO DumpToken; ///< Pointer to DumpToken function for the protocol.
SHELLENV_DUMP_PROTOCOL_INFO DumpInfo; ///< Pointer to DumpInfo function for the protocol.
EFI_GUID ProtocolId; ///< The GUID for the protocol.
CHAR16 *IdString; ///< The name of the protocol.
SHELLENV_DUMP_PROTOCOL_INFO DumpToken; ///< The pointer to DumpToken function for the protocol.
SHELLENV_DUMP_PROTOCOL_INFO DumpInfo; ///< The pointer to DumpInfo function for the protocol.
//
// Patabase info on which handles are supporting this protocol.
//
UINTN NoHandles; ///< How many handles produce this protocol.
UINTN NoHandles; ///< The number of handles producing this protocol.
EFI_HANDLE *Handles; ///< The array of handles.
} PROTOCOL_INFO;
@ -649,14 +649,14 @@ VOID
/**
This function is an internal shell function for enumeration of protocols.
This functiol will return the next protocol in the list. If this is called
immediately after initialization it will return the first. If this is called
immediately after reset it will return the protocol first again.
This function returns the next protocol on the list. If this is called
immediately after initialization, it will return the first protocol on the list.
If this is called immediately after reset, it will return the first protocol again.
This cannot be called after CLOSE_PROTOCOL_INFO_ENUMERATOR, but it must be
called after INIT_PROTOCOL_INFO_ENUMERATOR.
@param ProtocolInfo Pointer to pointer to protocol information structure.
@param[in,out] ProtocolInfo The pointer to pointer to protocol information structure.
@retval EFI_SUCCESS The next protocol's information was sucessfully returned.
@retval NULL There are no more protocols.
@ -675,7 +675,7 @@ EFI_STATUS
This function does nothing and always returns EFI_SUCCESS.
@retval EFI_SUCCESS always returned (see above).
@retval EFI_SUCCESS Always returned (see above).
**/
typedef
EFI_STATUS
@ -718,11 +718,11 @@ VOID
Protocol enumerator structure of function pointers.
**/
typedef struct {
INIT_PROTOCOL_INFO_ENUMERATOR Init; ///< Pointer to INIT_PROTOCOL_INFO_ENUMERATOR function.
NEXT_PROTOCOL_INFO Next; ///< Pointer to NEXT_PROTOCOL_INFO function.
SKIP_PROTOCOL_INFO Skip; ///< Pointer to SKIP_PROTOCOL_INFO function.
RESET_PROTOCOL_INFO_ENUMERATOR Reset; ///< Pointer to RESET_PROTOCOL_INFO_ENUMERATOR function.
CLOSE_PROTOCOL_INFO_ENUMERATOR Close; ///< Pointer to CLOSE_PROTOCOL_INFO_ENUMERATOR function.
INIT_PROTOCOL_INFO_ENUMERATOR Init; ///< The pointer to INIT_PROTOCOL_INFO_ENUMERATOR function.
NEXT_PROTOCOL_INFO Next; ///< The pointer to NEXT_PROTOCOL_INFO function.
SKIP_PROTOCOL_INFO Skip; ///< The pointer to SKIP_PROTOCOL_INFO function.
RESET_PROTOCOL_INFO_ENUMERATOR Reset; ///< The pointer to RESET_PROTOCOL_INFO_ENUMERATOR function.
CLOSE_PROTOCOL_INFO_ENUMERATOR Close; ///< The pointer to CLOSE_PROTOCOL_INFO_ENUMERATOR function.
} PROTOCOL_INFO_ENUMERATOR;
/**
@ -742,42 +742,42 @@ typedef struct {
whether the handle in question produced either EFI_DRIVER_DIAGNOSTICS_PROTOCOL or
EFI_DRIVER_DIAGNOSTICS2_PROTOCOL.
Upon sucessful return the memory for *BestDeviceName is up to the caller to free.
Upon successful return, the memory for *BestDeviceName is up to the caller to free.
@param DeviceHandle The device handle whose name is desired.
@param UseComponentName Whether to use the ComponentName protocol at all.
@param UseDevicePath Whether to use the DevicePath protocol at all.
@param Language Pointer to language string to use.
@param BestDeviceName Pointer to pointer to string allocated with the name.
@param ConfigurationStatus Pointer to status for opening a Configuration protocol.
@param DiagnosticsStatus Pointer to status for opening a Diagnostics protocol.
@param Display Whether to Print this out to default Print location.
@param Indent How many characters to indent the printing.
@param[in] DeviceHandle The device handle whose name is desired.
@param[in] UseComponentName Whether to use the ComponentName protocol at all.
@param[in] UseDevicePath Whether to use the DevicePath protocol at all.
@param[in] Language The pointer to the language string to use.
@param[in,out] BestDeviceName The pointer to pointer to string allocated with the name.
@param[out] ConfigurationStatus The pointer to status for opening a Configuration protocol.
@param[out] DiagnosticsStatus The pointer to status for opening a Diagnostics protocol.
@param[in] Display Whether to Print this out to default Print location.
@param[in] Indent How many characters to indent the printing.
@retval EFI_SUCCESS This function always returns EFI_SUCCESS.
**/
typedef
EFI_STATUS
(EFIAPI *GET_DEVICE_NAME) (
EFI_HANDLE DeviceHandle,
BOOLEAN UseComponentName,
BOOLEAN UseDevicePath,
CHAR8 *Language,
CHAR16 **BestDeviceName,
EFI_STATUS *ConfigurationStatus,
EFI_STATUS *DiagnosticsStatus,
BOOLEAN Display,
UINTN Indent
IN EFI_HANDLE DeviceHandle,
IN BOOLEAN UseComponentName,
IN BOOLEAN UseDevicePath,
IN CHAR8 *Language,
IN OUT CHAR16 **BestDeviceName,
OUT EFI_STATUS *ConfigurationStatus,
OUT EFI_STATUS *DiagnosticsStatus,
IN BOOLEAN Display,
IN UINTN Indent
);
#define EFI_SHELL_COMPATIBLE_MODE_VER L"1.1.1" ///< string for lowest version this shell supports
#define EFI_SHELL_ENHANCED_MODE_VER L"1.1.2" ///< string for highest version this shell supports
#define EFI_SHELL_COMPATIBLE_MODE_VER L"1.1.1" ///< The string for lowest version this shell supports.
#define EFI_SHELL_ENHANCED_MODE_VER L"1.1.2" ///< The string for highest version this shell supports.
/**
This function gets the shell mode as stored in the shell environment
"efishellmode". It will not fail.
@param Mode Returns a string representing one of the
@param[out] Mode Returns a string representing one of the
2 supported modes of the shell.
@retval EFI_SUCCESS This function always returns success.
@ -798,6 +798,8 @@ EFI_STATUS
If anything prevents the complete conversion free any allocated memory and
return NULL.
@param[in] Path The path to convert.
@retval !NULL A pointer to the callee allocated Device Path.
@retval NULL The operation could not be completed.
**/
@ -820,9 +822,9 @@ EFI_DEVICE_PATH_PROTOCOL*
This function will use the internal lock to prevent changes to the map during
the lookup operation.
@param DevPath The device path to search for a name for.
@param ConsistMapping What state to verify map flag VAR_ID_CONSIST.
@param Name On sucessful return the name of that device path.
@param[in] DevPath The device path to search for a name for.
@param[in] ConsistMapping What state to verify map flag VAR_ID_CONSIST.
@param[out] Name On sucessful return the name of that device path.
@retval EFI_SUCCESS The DevPath was found and the name returned
in Name.
@ -847,11 +849,11 @@ EFI_STATUS
The memory allocated by the callee for this list is freed by making a call to
SHELLENV_FREE_FILE_LIST.
@param Arg Pointer Path to files to open.
@param ListHead Pointer to allocated and initialized list head
@param[in] Arg The pointer to the path of the files to be opened.
@param[in,out] ListHead The pointer to allocated and initialized list head
upon which to append all the opened file structures.
@retval EFI_SUCCESS 1 or more files was opened and a struct of each file's
@retval EFI_SUCCESS One or more files was opened and a struct of each file's
information was appended to ListHead.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
@retval EFI_NOT_FOUND No matching files could be found.
@ -872,7 +874,7 @@ EFI_STATUS
files in the list of returned files. Any file listed twice will have one of its
instances removed.
@param ListHead Pointer to linked list head that was returned from
@param[in] ListHead The pointer to linked list head that was returned from
SHELLENV_FILE_META_ARG_NO_WILDCARD or
SHELLENV_FILE_META_ARG.
@ -888,22 +890,22 @@ EFI_STATUS
/**
Converts a File System map name to a device path.
if DevPath is NULL, then ASSERT().
If DevPath is NULL, then ASSERT().
This function looks through the shell environment map for a map whose Name
matches the Name parameter. If one is found the device path pointer is
matches the Name parameter. If one is found, the device path pointer is
updated to point to that file systems device path. The caller should not
free the memory from that device path.
This function will use the internal lock to prevent changes to the map during
the lookup operation.
@param Name Pointer to NULL terminated UNICODE string of the
@param[in] Name The pointer to the NULL terminated UNICODE string of the
file system name.
@param DevPath Pointer to pointer to DevicePath. only valid on
OUT if sucessful.
@param[out] DevPath The pointer to pointer to DevicePath. Only valid on
successful return.
@retval EFI_SUCCESS The conversion was successful and the device
@retval EFI_SUCCESS The conversion was successful, and the device
path was returned.
@retval EFI_NOT_FOUND The file system could not be found in the map.
**/

View File

@ -4,9 +4,7 @@
Shell Interface - additional information (over image_info) provided
to an application started by the shell.
ConIo - provides a file style interface to the console. Note that the
ConOut & ConIn interfaces in the system table will work as well, and both
all will be redirected to a file if needed on a command line
ConIo provides a file-style interface to the console.
The shell interface's and data (including ConIo) are only valid during
the applications Entry Point. Once the application returns from it's
@ -23,16 +21,18 @@
**/
#if !defined(_SHELLINTERFACE_H_)
#ifndef _SHELLINTERFACE_H_
#define _SHELLINTERFACE_H_
#include <Protocol/SimpleFileSystem.h>
#define SHELL_INTERFACE_PROTOCOL_GUID \
{ \
0x47c7b223, 0xc42a, 0x11d2, {0x8e, 0x57, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b} \
}
///
/// bit definitions for EFI_SHELL_ARG_INFO
/// Bit definitions for EFI_SHELL_ARG_INFO
///
typedef enum {
ARG_NO_ATTRIB = 0x0,
@ -43,48 +43,48 @@ typedef enum {
} EFI_SHELL_ARG_INFO_TYPES;
///
/// attributes for an argument.
/// Attributes for an argument.
///
typedef struct _EFI_SHELL_ARG_INFO {
UINT32 Attributes;
} EFI_SHELL_ARG_INFO;
///
/// This protocol provides access to additional information about a shell app.
/// This protocol provides access to additional information about a shell application.
///
typedef struct {
///
/// Handle back to original image handle & image info
/// Handle back to original image handle & image information.
///
EFI_HANDLE ImageHandle;
EFI_LOADED_IMAGE_PROTOCOL *Info;
///
/// Parsed arg list converted more C like format
/// Parsed arg list converted more C-like format.
///
CHAR16 **Argv;
UINTN Argc;
///
/// Storage for file redirection args after parsing
/// Storage for file redirection args after parsing.
///
CHAR16 **RedirArgv;
UINTN RedirArgc;
///
/// A file style handle for console io
/// A file style handle for console io.
///
EFI_FILE_HANDLE StdIn;
EFI_FILE_HANDLE StdOut;
EFI_FILE_HANDLE StdErr;
EFI_FILE_PROTOCOL *StdIn;
EFI_FILE_PROTOCOL *StdOut;
EFI_FILE_PROTOCOL *StdErr;
///
/// list of attributes for each argument
/// List of attributes for each argument.
///
EFI_SHELL_ARG_INFO *ArgInfo;
///
/// whether we are echoing
/// Whether we are echoing.
///
BOOLEAN EchoOn;
} EFI_SHELL_INTERFACE;

View File

@ -12,6 +12,8 @@
**/
#include <ShellBase.h>
#ifndef __EFI_SHELL_PARAMETERS_PROTOCOL__
#define __EFI_SHELL_PARAMETERS_PROTOCOL__
@ -36,21 +38,21 @@ typedef struct _EFI_SHELL_PARAMETERS_PROTOCOL {
///
/// The file handle for the standard input for this executable. This may be different
/// from the ConInHandle in the EFI_SYSTEM_TABLE.
/// from the ConInHandle in EFI_SYSTEM_TABLE.
///
EFI_FILE_HANDLE StdIn;
SHELL_FILE_HANDLE StdIn;
///
/// The file handle for the standard output for this executable. This may be different
/// from the ConOutHandle in the EFI_SYSTEM_TABLE.
/// from the ConOutHandle in EFI_SYSTEM_TABLE.
///
EFI_FILE_HANDLE StdOut;
SHELL_FILE_HANDLE StdOut;
///
/// The file handle for the standard error output for this executable. This may be
/// different from the StdErrHandle in the EFI_SYSTEM_TABLE.
/// different from the StdErrHandle in EFI_SYSTEM_TABLE.
///
EFI_FILE_HANDLE StdErr;
SHELL_FILE_HANDLE StdErr;
} EFI_SHELL_PARAMETERS_PROTOCOL;
extern EFI_GUID gEfiShellParametersProtocolGuid;

View File

@ -1,7 +1,7 @@
/** @file
Root include file for Shell Package modules that utilize the SHELL_RETURN type
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2009 - 2010, Intel Corporation.All rights reserved.<BR>
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
@ -12,9 +12,20 @@
**/
#if !defined(__SHELL_BASE__)
#ifndef __SHELL_BASE__
#define __SHELL_BASE__
typedef VOID *SHELL_FILE_HANDLE;
#ifndef SHELL_FREE_NON_NULL
#define SHELL_FREE_NON_NULL(Pointer) \
do { \
if (Pointer != NULL) { \
FreePool(Pointer); \
} \
} while(FALSE)
#endif //SHELL_FREE_NON_NULL
typedef enum {
///
/// The operation completed successfully.
@ -60,7 +71,7 @@ SHELL_NOT_READY = 6,
SHELL_DEVICE_ERROR = 7,
///
/// The device can not be written to.
/// The device cannot be written to.
///
SHELL_WRITE_PROTECTED = 8,

View File

@ -1,7 +1,7 @@
/** @file
Provides interface to EFI_FILE_HANDLE functionality.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved. <BR>
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
@ -30,13 +30,13 @@
#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
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
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
@param FileHandle The file handle of the file for which information is
being requested.
@retval NULL information could not be retrieved.
@ -49,7 +49,7 @@ FileHandleGetInfo (
IN EFI_FILE_HANDLE FileHandle
)
{
EFI_FILE_INFO *pFileInfo;
EFI_FILE_INFO *FileInfo;
UINTN FileInfoSize;
EFI_STATUS Status;
@ -62,51 +62,52 @@ FileHandleGetInfo (
// Get the required size to allocate
//
FileInfoSize = 0;
pFileInfo = NULL;
Status = FileHandle->GetInfo(FileHandle,
&gEfiFileInfoGuid,
&FileInfoSize,
pFileInfo);
FileInfo = NULL;
Status = FileHandle->GetInfo(FileHandle,
&gEfiFileInfoGuid,
&FileInfoSize,
FileInfo);
//
// error is expected. getting size to allocate
//
ASSERT (Status == EFI_BUFFER_TOO_SMALL);
pFileInfo = AllocateZeroPool(FileInfoSize);
ASSERT (pFileInfo != NULL);
FileInfo = AllocateZeroPool(FileInfoSize);
ASSERT (FileInfo != NULL);
//
// now get the information
//
Status = FileHandle->GetInfo(FileHandle,
&gEfiFileInfoGuid,
&FileInfoSize,
pFileInfo);
Status = FileHandle->GetInfo(FileHandle,
&gEfiFileInfoGuid,
&FileInfoSize,
FileInfo);
//
// if we got an error free the memory and return NULL
//
if (EFI_ERROR(Status)) {
FreePool(pFileInfo);
FreePool(FileInfo);
return NULL;
}
return (pFileInfo);
return (FileInfo);
}
/**
This function will set the information about the file for the opened handle
This function sets 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[in] FileHandle The file handle of the file for which information
is being set.
@param FileInfo The infotmation to set.
@param[in] FileInfo The information 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_SUCCESS The information was set.
@retval EFI_INVALID_PARAMETER A parameter was out of range or invalid.
@retval EFI_UNSUPPORTED The FileHandle does not support FileInfo.
@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.
@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
@ -115,7 +116,7 @@ FileHandleSetInfo (
IN CONST EFI_FILE_INFO *FileInfo
)
{
//
// ASSERT if the FileHandle or FileInfo is NULL
//
@ -125,38 +126,38 @@ FileHandleSetInfo (
//
// Set the info
//
return (FileHandle->SetInfo(FileHandle,
return (FileHandle->SetInfo(FileHandle,
&gEfiFileInfoGuid,
(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 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.
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
@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
@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.
**/
@ -183,11 +184,11 @@ FileHandleRead(
/**
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
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
@ -222,11 +223,11 @@ FileHandleWrite(
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
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.
@ -255,13 +256,13 @@ FileHandleClose (
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
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
@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.
**/
@ -286,19 +287,19 @@ FileHandleDelete (
/**
Set the current position in a file.
This function sets the current file position for the handle to the position
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
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
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
@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.
**/
@ -319,11 +320,11 @@ FileHandleSetPosition (
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
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.
@ -341,6 +342,9 @@ FileHandleGetPosition (
OUT UINT64 *Position
)
{
if (Position == NULL) {
return (EFI_INVALID_PARAMETER);
}
//
// ASSERT if FileHandle is NULL
//
@ -352,7 +356,7 @@ FileHandleGetPosition (
}
/**
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
@ -406,12 +410,12 @@ FileHandleIsDirectory (
// ASSERT if DirHandle is NULL
//
ASSERT(DirHandle != NULL);
//
// get the file information for DirHandle
//
DirInfo = FileHandleGetInfo (DirHandle);
//
// Parse DirInfo
//
@ -420,7 +424,7 @@ FileHandleIsDirectory (
// We got nothing...
//
return (EFI_INVALID_PARAMETER);
}
}
if ((DirInfo->Attribute & EFI_FILE_DIRECTORY) == 0) {
//
// Attributes say this is not a directory
@ -438,8 +442,8 @@ FileHandleIsDirectory (
/**
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
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
@ -475,15 +479,15 @@ FileHandleFindFirstFile (
Status = FileHandleIsDirectory(DirHandle);
if (EFI_ERROR(Status)) {
return (Status);
}
}
//
// reset to the begining of the directory
// 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
@ -507,12 +511,12 @@ FileHandleFindFirstFile (
/**
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.
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
@ -565,13 +569,14 @@ FileHandleFindNextFile(
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
This function extracts the file size info from the FileHandle's EFI_FILE_INFO
data.
@param FileHandle file handle from which size is retrieved
@ -594,7 +599,7 @@ FileHandleGetSize (
//
ASSERT (FileHandle != NULL);
ASSERT (Size != NULL);
//
// get the FileInfo structure
//
@ -607,7 +612,7 @@ FileHandleGetSize (
// Assign the Size pointer to the correct value
//
*Size = FileInfo->FileSize;
//
// free the FileInfo memory
//
@ -616,47 +621,98 @@ FileHandleGetSize (
return (EFI_SUCCESS);
}
/**
Set the size of a file.
If FileHandle is NULL then ASSERT().
This function changes the file size info from the FileHandle's EFI_FILE_INFO
data.
@param FileHandle File handle whose size is to be changed.
@param Size New size.
@retval EFI_SUCCESS operation was completed sucessfully.
@retval EFI_DEVICE_ERROR cannot access the file.
**/
EFI_STATUS
EFIAPI
FileHandleSetSize (
IN EFI_FILE_HANDLE FileHandle,
IN UINT64 Size
)
{
EFI_FILE_INFO *FileInfo;
EFI_STATUS Status;
//
// ASSERT for FileHandle or Size being NULL
//
ASSERT (FileHandle != NULL);
//
// get the FileInfo structure
//
FileInfo = FileHandleGetInfo(FileHandle);
if (FileInfo == NULL) {
return (EFI_DEVICE_ERROR);
}
//
// Assign the FileSize pointer to the new value
//
FileInfo->FileSize = Size;
Status = FileHandleSetInfo(FileHandle, FileInfo);
//
// free the FileInfo memory
//
FreePool(FileInfo);
return (Status);
}
/**
Safely append (on the left) with automatic string resizing given length of Destination and
Safely append (on the left) with automatic string resizing given length of Destination and
desired length of copy from Source.
append the first D characters of Source to the end of Destination, where D is
the lesser of Count and the StrLen() of Source. If appending those D characters
will fit within Destination (whose Size is given as CurrentSize) and
still leave room for a NULL terminator, then those characters are appended,
starting at the original terminating NULL of Destination, and a new terminating
append the first D characters of Source to the end of Destination, where D is
the lesser of Count and the StrLen() of Source. If appending those D characters
will fit within Destination (whose Size is given as CurrentSize) and
still leave room for a NULL terminator, then those characters are appended,
starting at the original terminating NULL of Destination, and a new terminating
NULL is appended.
If appending D characters onto Destination will result in a overflow of the size
given in CurrentSize the string will be grown such that the copy can be performed
and CurrentSize will be updated to the new size.
If Source is NULL, there is nothing to append, just return the current buffer in
If Source is NULL, there is nothing to append, just return the current buffer in
Destination.
if Destination is NULL, then ASSERT()
if Destination's current length (including NULL terminator) is already more then
if Destination's current length (including NULL terminator) is already more then
CurrentSize, then ASSERT()
@param[in,out] Destination The String to append onto
@param[in,out] CurrentSize on call the number of bytes in Destination. On
@param[in,out] CurrentSize on call the number of bytes in Destination. On
return possibly the new size (still in bytes). if NULL
then allocate whatever is needed.
@param[in] Source The String to append from
@param[in] Count Maximum number of characters to append. if 0 then
@param[in] Count Maximum number of characters to append. if 0 then
all are appended.
@return Destination return the resultant string.
**/
CHAR16*
CHAR16*
EFIAPI
StrnCatGrowLeft (
IN OUT CHAR16 **Destination,
IN OUT UINTN *CurrentSize,
IN CONST CHAR16 *Source,
IN UINTN Count
){
)
{
UINTN DestinationStartSize;
UINTN NewSize;
UINTN CopySize;
@ -713,13 +769,13 @@ StrnCatGrowLeft (
}
/**
Function to get a full filename given a EFI_FILE_HANDLE somewhere lower on the
Function to get a full filename given a EFI_FILE_HANDLE somewhere lower on the
directory 'stack'.
if Handle is NULL, return EFI_INVALID_PARAMETER
@param[in] Handle Handle to the Directory or File to create path to.
@param[out] FullFileName pointer to pointer to generated full file name. It
@param[out] FullFileName pointer to pointer to generated full file name. It
is the responsibility of the caller to free this memory
with a call to FreePool().
@retval EFI_SUCCESS the operation was sucessful and the FullFileName is valid.
@ -732,7 +788,8 @@ EFIAPI
FileHandleGetFileName (
IN CONST EFI_FILE_HANDLE Handle,
OUT CHAR16 **FullFileName
){
)
{
EFI_STATUS Status;
UINTN Size;
EFI_FILE_HANDLE CurrentHandle;
@ -749,6 +806,7 @@ FileHandleGetFileName (
}
*FullFileName = NULL;
CurrentHandle = NULL;
Status = Handle->Open(Handle, &CurrentHandle, L".", EFI_FILE_MODE_READ, 0);
if (!EFI_ERROR(Status)) {
@ -766,14 +824,17 @@ FileHandleGetFileName (
//
if (StrLen (FileInfo->FileName) == 0) {
if (*FullFileName == NULL) {
ASSERT((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));
*FullFileName = StrnCatGrowLeft(FullFileName, &Size, L"\\", 0);
}
FreePool(FileInfo);
break;
} else {
if (*FullFileName == NULL) {
ASSERT((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));
*FullFileName = StrnCatGrowLeft(FullFileName, &Size, L"\\", 0);
}
ASSERT((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));
*FullFileName = StrnCatGrowLeft(FullFileName, &Size, FileInfo->FileName, 0);
*FullFileName = StrnCatGrowLeft(FullFileName, &Size, L"\\", 0);
FreePool(FileInfo);
@ -790,6 +851,10 @@ FileHandleGetFileName (
FileHandleClose(CurrentHandle);
CurrentHandle = NextHigherHandle;
}
} else if (Status == EFI_NOT_FOUND) {
Status = EFI_SUCCESS;
ASSERT((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));
*FullFileName = StrnCatGrowLeft(FullFileName, &Size, L"\\", 0);
}
if (CurrentHandle != NULL) {
@ -804,10 +869,10 @@ FileHandleGetFileName (
}
/**
Function to read a single line from a file. The \n is not included in the returned
Function to read a single line from a file. The \n is not included in the returned
buffer. The returned buffer must be callee freed.
If the position upon start is 0, then the Ascii Boolean will be set. This should be
If the position upon start is 0, then the Ascii Boolean will be set. This should be
maintained and not changed for all operations with the same file.
@param[in] Handle FileHandle to read from.
@ -845,24 +910,24 @@ FileHandleReturnLine(
}
/**
Function to read a single line (up to but not including the \n) from a file.
Function to read a single line (up to but not including the \n) from a EFI_FILE_HANDLE.
If the position upon start is 0, then the Ascii Boolean will be set. This should be
If the position upon start is 0, then the Ascii Boolean will be set. This should be
maintained and not changed for all operations with the same file.
@param[in] Handle FileHandle to read from
@param[in,out] Buffer pointer to buffer to read into
@param[in,out] Size pointer to number of bytes in buffer
@param[in] Truncate if TRUE then allows for truncation of the line to fit.
if FALSE will reset the position to the begining of the
if FALSE will reset the position to the begining of the
line if the buffer is not large enough.
@param[in,out] Ascii Boolean value for indicating whether the file is Ascii (TRUE) or UCS2 (FALSE);
@retval EFI_SUCCESS the operation was sucessful. the line is stored in
@retval EFI_SUCCESS the operation was sucessful. the line is stored in
Buffer.
@retval EFI_INVALID_PARAMETER Handle was NULL.
@retval EFI_INVALID_PARAMETER Size was NULL.
@retval EFI_BUFFER_TOO_SMALL Size was not enough space to store the line.
@retval EFI_BUFFER_TOO_SMALL Size was not enough space to store the line.
Size was updated to minimum space required.
@sa FileHandleRead
**/
@ -874,7 +939,8 @@ FileHandleReadLine(
IN OUT UINTN *Size,
IN BOOLEAN Truncate,
IN OUT BOOLEAN *Ascii
){
)
{
EFI_STATUS Status;
CHAR16 CharBuffer;
UINTN CharSize;
@ -884,8 +950,13 @@ FileHandleReadLine(
if (Handle == NULL
||Size == NULL
){
return (EFI_INVALID_PARAMETER);
){
return (EFI_INVALID_PARAMETER);
}
if (Buffer == NULL) {
ASSERT(*Size == 0);
} else {
*Buffer = CHAR_NULL;
}
FileHandleGetPosition(Handle, &OriginalFilePosition);
if (OriginalFilePosition == 0) {
@ -908,17 +979,11 @@ FileHandleReadLine(
CharSize = sizeof(CHAR16);
}
Status = FileHandleRead(Handle, &CharSize, &CharBuffer);
if (OriginalFilePosition == 0 && *Ascii == FALSE && CountSoFar == 0) {
//
// we need to skip the unicode tag
//
continue;
}
if ( EFI_ERROR(Status)
|| CharSize == 0
|| (CharBuffer == L'\n' && *Ascii == FALSE)
|| (CharBuffer == '\n' && *Ascii != FALSE )
){
if ( EFI_ERROR(Status)
|| CharSize == 0
|| (CharBuffer == L'\n' && !(*Ascii))
|| (CharBuffer == '\n' && *Ascii)
){
break;
}
//
@ -936,7 +1001,7 @@ FileHandleReadLine(
//
if ((CountSoFar+1)*sizeof(CHAR16) > *Size){
*Size = (CountSoFar+1)*sizeof(CHAR16);
if (Truncate == FALSE) {
if (!Truncate) {
FileHandleSetPosition(Handle, OriginalFilePosition);
} else {
DEBUG((DEBUG_WARN, "The line was truncated in FileHandleReadLine"));
@ -969,7 +1034,8 @@ EFIAPI
FileHandleWriteLine(
IN EFI_FILE_HANDLE Handle,
IN CHAR16 *Buffer
){
)
{
EFI_STATUS Status;
UINTN Size;
@ -1031,7 +1097,7 @@ FileHandlePrintLine(
Status = FileHandleWriteLine(Handle, Buffer);
//
// Cleanup and return
// Cleanup and return
//
FreePool(Buffer);
return (Status);
@ -1063,15 +1129,15 @@ FileHandleEof(
// ASSERT if Handle is NULL
//
ASSERT(Handle != NULL);
FileHandleGetPosition(Handle, &Pos);
Info = FileHandleGetInfo (Handle);
ASSERT(Info != NULL);
FileHandleSetPosition(Handle, Pos);
if (Info == NULL) {
return (FALSE);
}
}
if (Pos == Info->FileSize) {
RetVal = TRUE;

View File

@ -1,7 +1,7 @@
## @file
## @file
# Provides interface to shell functionality for shell commands and applications.
#
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2006 - 2010, Intel Corporation.All rights reserved. <BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@ -25,7 +25,7 @@
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
[Sources.common]
BaseFileHandleLib.c
[Packages]
@ -46,5 +46,5 @@
[Guids]
gEfiFileInfoGuid # ALWAYS_CONSUMED
[Pcd]
[Pcd.common]
gEfiShellPkgTokenSpaceGuid.PcdShellPrintBufferSize # ALWAYS_CONSUMED

View File

@ -1,7 +1,7 @@
/** @file
Library used for sorting routines.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
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
@ -62,7 +62,7 @@ QuickSortWorker (
if ( Count < 2
|| ElementSize < 1
){
){
return;
}
@ -80,7 +80,7 @@ QuickSortWorker (
for ( LoopCount = 0
; LoopCount < Count -1
; LoopCount++
){
){
//
// if the element is less than the pivot
//
@ -174,6 +174,9 @@ PerformQuickSort (
/**
Not supported in Base version.
@param[in] Buffer1 Ignored.
@param[in] Buffer2 Ignored.
ASSERT and return 0.
**/
INTN
@ -209,3 +212,25 @@ StringNoCaseCompare (
}
/**
Function to compare 2 strings.
@param[in] Buffer1 Pointer to String to compare (CHAR16**).
@param[in] Buffer2 Pointer to second String to compare (CHAR16**).
@retval 0 Buffer1 equal to Buffer2.
@return < 0 Buffer1 is less than Buffer2.
@return > 0 Buffer1 is greater than Buffer2.
**/
INTN
EFIAPI
StringCompare (
IN CONST VOID *Buffer1,
IN CONST VOID *Buffer2
)
{
ASSERT(FALSE);
return 0;
}

View File

@ -1,7 +1,7 @@
## @file
## @file
# Library used for sorting routines.
#
# Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2009-2010, Intel Corporation.All rights reserved. <BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@ -19,13 +19,13 @@
FILE_GUID = 03F3331B-F12D-494f-BF37-E55A657F2497
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = SORTLib|UEFI_APPLICATION UEFI_DRIVER
LIBRARY_CLASS = SortLib|UEFI_APPLICATION UEFI_DRIVER
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
[Sources.common]
BaseSortLib.c
[Packages]
@ -42,4 +42,4 @@
[Guids]
[Pcd]
[Pcd.common]

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,142 @@
/** @file
Provides interface to advanced shell functionality for parsing both handle and protocol database.
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
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 <Guid/FileInfo.h>
#include <Guid/ConsoleInDevice.h>
#include <Guid/ConsoleOutDevice.h>
#include <Guid/StandardErrorDevice.h>
#include <Guid/GlobalVariable.h>
#include <Guid/Gpt.h>
#include <Guid/FileSystemInfo.h>
#include <Protocol/SimpleFileSystem.h>
#include <Protocol/LoadedImage.h>
#include <Protocol/EfiShellInterface.h>
#include <Protocol/EfiShellEnvironment2.h>
#include <Protocol/EfiShell.h>
#include <Protocol/EfiShellParameters.h>
#include <Protocol/DevicePathToText.h>
#include <Protocol/DriverBinding.h>
#include <Protocol/DriverConfiguration2.h>
#include <Protocol/DriverConfiguration.h>
#include <Protocol/DriverDiagnostics2.h>
#include <Protocol/DriverDiagnostics.h>
#include <Protocol/ComponentName2.h>
#include <Protocol/ComponentName.h>
#include <Protocol/PlatformDriverOverride.h>
#include <Protocol/DevicePathUtilities.h>
#include <Protocol/DevicePathFromText.h>
#include <Protocol/BusSpecificDriverOverride.h>
#include <Protocol/PlatformToDriverConfiguration.h>
#include <Protocol/DriverSupportedEfiVersion.h>
#include <Protocol/SimpleTextInEx.h>
#include <Protocol/SimplePointer.h>
#include <Protocol/SerialIo.h>
#include <Protocol/AbsolutePointer.h>
#include <Protocol/GraphicsOutput.h>
#include <Protocol/EdidDiscovered.h>
#include <Protocol/EdidActive.h>
#include <Protocol/EdidOverride.h>
#include <Protocol/LoadFile.h>
#include <Protocol/LoadFile2.h>
#include <Protocol/SimpleFilesystem.h>
#include <Protocol/TapeIo.h>
#include <Protocol/DiskIo.h>
#include <Protocol/BlockIo.h>
#include <Protocol/UnicodeCollation.h>
#include <Protocol/PciRootBridgeIo.h>
#include <Protocol/PciIo.h>
#include <Protocol/ScsiPassThru.h>
#include <Protocol/ScsiPassThruExt.h>
#include <Protocol/ScsiIo.h>
#include <Protocol/IScsiInitiatorName.h>
#include <Protocol/UsbIo.h>
#include <Protocol/UsbHostController.h>
#include <Protocol/Usb2HostController.h>
#include <Protocol/DebugSupport.h>
#include <Protocol/DebugPort.h>
#include <Protocol/Decompress.h>
#include <Protocol/AcpiTable.h>
#include <Protocol/Ebc.h>
#include <Protocol/SimpleNetwork.h>
#include <Protocol/NetworkInterfaceIdentifier.h>
#include <Protocol/PxeBaseCode.h>
#include <Protocol/PxeBaseCodeCallBack.h>
#include <Protocol/Bis.h>
#include <Protocol/ManagedNetwork.h>
#include <Protocol/Arp.h>
#include <Protocol/Dhcp4.h>
#include <Protocol/Tcp4.h>
#include <Protocol/Ip4.h>
#include <Protocol/Ip4Config.h>
#include <Protocol/Udp4.h>
#include <Protocol/Mtftp4.h>
#include <Protocol/AuthenticationInfo.h>
#include <Protocol/Hash.h>
#include <Protocol/HiiFont.h>
#include <Protocol/HiiString.h>
#include <Protocol/HiiImage.h>
#include <Protocol/HiiDatabase.h>
#include <Protocol/HiiConfigRouting.h>
#include <Protocol/HiiConfigAccess.h>
#include <Protocol/FormBrowser2.h>
#include <Protocol/DeviceIo.h>
#include <Protocol/UgaDraw.h>
#include <Protocol/UgaIo.h>
#include <Protocol/DriverConfiguration.h>
#include <Protocol/DriverConfiguration2.h>
#include <Protocol/DevicePathUtilities.h>
//#include <Protocol/FirmwareVolume.h>
//#include <Protocol/FirmwareVolume2.h>
#include <Library/HandleParsingLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/DevicePathLib.h>
#include <Library/PcdLib.h>
#include <Library/PrintLib.h>
#include <Library/UefiLib.h>
#include <Library/HiiLib.h>
#include <Library/ShellLib.h>
typedef struct {
LIST_ENTRY Link;
EFI_HANDLE TheHandle;
UINTN TheIndex;
}HANDLE_LIST;
typedef struct {
HANDLE_LIST List;
UINTN NextIndex;
} HANDLE_INDEX_LIST;
typedef
CHAR16 *
(EFIAPI *DUMP_PROTOCOL_INFO)(
IN CONST EFI_HANDLE TheHandle,
IN CONST BOOLEAN Verbose
);
typedef struct {
EFI_STRING_ID StringId;
EFI_GUID *GuidId;
DUMP_PROTOCOL_INFO DumpInfo;
} PROTOCOL_INFO_BLOCK;

View File

@ -0,0 +1,158 @@
## @file
# Provides interface to advanced shell functionality for parsing both handle and protocol database.
# Copyright (c) 2010, Intel Corporation. All rights reserved. <BR>
#
# 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 = UefiHandleParsingLib
FILE_GUID = 3CDC7177-CC2A-4678-BA8F-1A936A093FA4
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = HandleParsingLib|UEFI_APPLICATION UEFI_DRIVER
CONSTRUCTOR = HandleParsingLibConstructor
DESTRUCTOR = HandleParsingLibDestructor
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources.common]
UefiHandleParsingLib.c
UefiHandleParsingLib.h
UefiHandleParsingLib.uni
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
ShellPkg/ShellPkg.dec
IntelFrameworkPkg/IntelFrameworkPkg.dec
[LibraryClasses]
UefiBootServicesTableLib
MemoryAllocationLib
DevicePathLib
BaseLib
BaseMemoryLib
DebugLib
FileHandleLib
PrintLib
UefiLib
HiiLib
[Protocols]
gEfiSimpleFileSystemProtocolGuid # ALWAYS_CONSUMED
# shell 2.0
gEfiShellProtocolGuid # SOMETIMES_CONSUMED
gEfiShellParametersProtocolGuid # SOMETIMES_CONSUMED
# 'old' shell
gEfiShellEnvironment2Guid # SOMETIMES_CONSUMED
gEfiShellInterfaceGuid # SOMETIMES_CONSUMED
gEfiUnicodeCollation2ProtocolGuid # ALWAYS_CONSUMED
gEfiDevicePathToTextProtocolGuid # ALWAYS_CONSUMED
gEfiBusSpecificDriverOverrideProtocolGuid # ALWAYS_CONSUMED
gEfiDevicePathUtilitiesProtocolGuid # ALWAYS_CONSUMED
gEfiDevicePathFromTextProtocolGuid # ALWAYS_CONSUMED
gEfiPlatformDriverOverrideProtocolGuid # ALWAYS_CONSUMED
gEfiSimpleTextInProtocolGuid # ALWAYS_CONSUMED
gEfiPlatformToDriverConfigurationProtocolGuid # ALWAYS_CONSUMED
gEfiDriverSupportedEfiVersionProtocolGuid # ALWAYS_CONSUMED
gEfiLoadedImageProtocolGuid # ALWAYS_CONSUMED
gEfiDevicePathProtocolGuid # ALWAYS_CONSUMED
gEfiLoadedImageDevicePathProtocolGuid # ALWAYS_CONSUMED
gEfiSimpleTextOutProtocolGuid
gEfiSimplePointerProtocolGuid
gEfiAbsolutePointerProtocolGuid
gEfiSerialIoProtocolGuid
gEfiEdidDiscoveredProtocolGuid
gEfiEdidActiveProtocolGuid
gEfiEdidOverrideProtocolGuid
gEfiLoadFileProtocolGuid
gEfiLoadFile2ProtocolGuid
gEfiTapeIoProtocolGuid
gEfiDiskIoProtocolGuid
gEfiBlockIoProtocolGuid
gEfiUnicodeCollationProtocolGuid
gEfiUnicodeCollation2ProtocolGuid
gEfiPciRootBridgeIoProtocolGuid
gEfiPciIoProtocolGuid
gEfiScsiPassThruProtocolGuid
gEfiScsiIoProtocolGuid
gEfiExtScsiPassThruProtocolGuid
gEfiIScsiInitiatorNameProtocolGuid
gEfiUsbIoProtocolGuid
gEfiUsbHcProtocolGuid
gEfiUsb2HcProtocolGuid
gEfiDebugSupportProtocolGuid
gEfiDebugPortProtocolGuid
gEfiDecompressProtocolGuid
gEfiAcpiTableProtocolGuid
gEfiEbcProtocolGuid
gEfiSimpleNetworkProtocolGuid
gEfiNetworkInterfaceIdentifierProtocolGuid
gEfiNetworkInterfaceIdentifierProtocolGuid_31
gEfiPxeBaseCodeProtocolGuid
gEfiPxeBaseCodeCallbackProtocolGuid
gEfiBisProtocolGuid
gEfiManagedNetworkServiceBindingProtocolGuid
gEfiManagedNetworkProtocolGuid
gEfiArpServiceBindingProtocolGuid
gEfiArpProtocolGuid
gEfiDhcp4ServiceBindingProtocolGuid
gEfiDhcp4ProtocolGuid
gEfiTcp4ServiceBindingProtocolGuid
gEfiTcp4ProtocolGuid
gEfiIp4ServiceBindingProtocolGuid
gEfiIp4ProtocolGuid
gEfiIp4ConfigProtocolGuid
gEfiUdp4ServiceBindingProtocolGuid
gEfiUdp4ProtocolGuid
gEfiMtftp4ServiceBindingProtocolGuid
gEfiMtftp4ProtocolGuid
gEfiAuthenticationInfoProtocolGuid
gEfiHashServiceBindingProtocolGuid
gEfiHashProtocolGuid
gEfiHiiFontProtocolGuid
gEfiHiiStringProtocolGuid
gEfiHiiImageProtocolGuid
gEfiHiiConfigRoutingProtocolGuid
gEfiHiiConfigAccessProtocolGuid
gEfiFormBrowser2ProtocolGuid
gEfiDeviceIoProtocolGuid
gEfiUgaDrawProtocolGuid
gEfiUgaIoProtocolGuid
gEfiDriverConfigurationProtocolGuid
gEfiDriverConfiguration2ProtocolGuid
gEfiSimpleTextInputExProtocolGuid
[Guids]
gEfiFileInfoGuid # ALWAYS_CONSUMED
gEfiShellEnvironment2ExtGuid # ALWAYS_CONSUMED
gEfiPcAnsiGuid
gEfiVT100Guid
gEfiVT100PlusGuid
gEfiVTUTF8Guid
gEfiStandardErrorDeviceGuid
gEfiConsoleInDeviceGuid
gEfiConsoleOutDeviceGuid
gEfiFileSystemInfoGuid
gEfiGlobalVariableGuid
gEfiPartTypeSystemPartGuid
gEfiPartTypeLegacyMbrGuid
[Pcd.common]
gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize # ALWAYS_CONSUMED
gEfiShellPkgTokenSpaceGuid.PcdShellPrintBufferSize # ALWAYS_CONSUMED
gEfiShellPkgTokenSpaceGuid.PcdShellIncludeNtGuids # ALWAYS_CONSUMED

View File

@ -59,7 +59,7 @@ ShellCEntryLib (
ImageHandle,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
);
if (!EFI_ERROR(Status)) {
//
// use shell 2.0 interface
@ -67,7 +67,7 @@ ShellCEntryLib (
ReturnFromMain = ShellAppMain (
EfiShellParametersProtocol->Argc,
EfiShellParametersProtocol->Argv
);
);
} else {
//
// try to get shell 1.0 interface instead.
@ -78,7 +78,7 @@ ShellCEntryLib (
ImageHandle,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
);
if (!EFI_ERROR(Status)) {
//
// use shell 1.0 interface
@ -86,7 +86,7 @@ ShellCEntryLib (
ReturnFromMain = ShellAppMain (
EfiShellInterface->Argc,
EfiShellInterface->Argv
);
);
} else {
ASSERT(FALSE);
}

View File

@ -1,7 +1,7 @@
## @file
## @file
# Provides interface to shell functionality for shell commands and applications.
#
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2006 - 2010, Intel Corporation.All rights reserved. <BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@ -19,13 +19,13 @@
FILE_GUID = 0e205c8a-8586-4dec-9f5c-4f9e394aefe8
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = ShellCEntryLib|UEFI_APPLICATION
LIBRARY_CLASS = ShellCEntryLib|UEFI_APPLICATION UEFI_DRIVER
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
[Sources.common]
UefiShellCEntryLib.c
[Packages]
@ -43,5 +43,5 @@
[Guids]
[Pcd]
[Pcd.common]

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,79 @@
/** @file
Provides interface to shell internal functions for shell commands.
Copyright (c) 2006 - 2010, Intel Corporation.All rights reserved. <BR>
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.
**/
#ifndef _UEFI_COMMAND_LIB_INTERNAL_HEADER_
#define _UEFI_COMMAND_LIB_INTERNAL_HEADER_
#include <Uefi.h>
#include <ShellBase.h>
#include <Guid/FileInfo.h>
#include <Protocol/SimpleFileSystem.h>
#include <Protocol/LoadedImage.h>
#include <Protocol/EfiShellInterface.h>
#include <Protocol/EfiShellEnvironment2.h>
#include <Protocol/EfiShell.h>
#include <Protocol/EfiShellParameters.h>
#include <Protocol/UnicodeCollation.h>
#include <Protocol/BlockIo.h>
#include <Library/DevicePathLib.h>
#include <Library/SortLib.h>
#include <Library/HandleParsingLib.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
#include <library/ShellCommandLib.h>
#include <Library/PrintLib.h>
#include <Library/ShellLib.h>
#include <Library/HiiLib.h>
#include <Library/UefiBootServicesTableLib.h>
typedef struct{
LIST_ENTRY Link;
CHAR16 *CommandString;
SHELL_GET_MAN_FILENAME GetManFileName;
SHELL_RUN_COMMAND CommandHandler;
BOOLEAN LastError;
EFI_HANDLE HiiHandle;
EFI_STRING_ID ManFormatHelp;
} SHELL_COMMAND_INTERNAL_LIST_ENTRY;
typedef struct {
LIST_ENTRY Link;
SCRIPT_FILE *Data;
} SCRIPT_FILE_LIST;
/**
Function to cleanup all memory from a SCRIPT_FILE structure.
@param[in] Script The pointer to the structure to cleanup.
**/
VOID
EFIAPI
DeleteScriptFileStruct (
IN SCRIPT_FILE *Script
);
typedef struct {
EFI_FILE_PROTOCOL *FileHandle;
CHAR16 *Path;
} SHELL_COMMAND_FILE_HANDLE;
#endif //_UEFI_COMMAND_LIB_INTERNAL_HEADER_

View File

@ -0,0 +1,61 @@
## @file
# Provides interface to shell internal functions for shell commands.
#
# Copyright (c) 2006 - 2010, Intel Corporation.All rights reserved. <BR>
#
# 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 = UefiShellCommandLib
FILE_GUID = 5C12F31F-EBAC-466e-A400-FCA8C9EA3A05
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = ShellCommandLib|UEFI_APPLICATION UEFI_DRIVER
CONSTRUCTOR = ShellCommandLibConstructor
DESTRUCTOR = ShellCommandLibDestructor
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources.common]
UefiShellCommandLib.c
UefiShellCommandLib.h
ConsistMapping.c
[Packages]
MdePkg/MdePkg.dec
ShellPkg/ShellPkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
MemoryAllocationLib
BaseLib
BaseMemoryLib
DebugLib
PrintLib
UefiBootServicesTableLib
ShellLib
HiiLib
[Protocols]
gEfiUnicodeCollation2ProtocolGuid # ALWAYS_CONSUMED
gEfiShellProtocolGuid # ALWAYS_CONSUMED
gEfiShellParametersProtocolGuid # ALWAYS_CONSUMED
gEfiDevicePathToTextProtocolGuid # ALWAYS_CONSUMED
[Guids]
[Pcd.common]
gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel ## ALWAYS_CONSUMED
gEfiShellPkgTokenSpaceGuid.PcdShellMapNameLength ## ALWAYS_CONSUMED

View File

@ -0,0 +1,273 @@
/** @file
Main file for connect shell Driver1 function.
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellDriver1CommandsLib.h"
#include <Guid/GlobalVariable.h>
#include <Guid/ConsoleInDevice.h>
#include <Guid/ConsoleOutDevice.h>
EFI_STATUS
EFIAPI
ConnectControllers (
IN CONST EFI_HANDLE ControllerHandle,
IN CONST EFI_HANDLE DriverHandle,
IN CONST BOOLEAN Recursive,
IN CONST BOOLEAN Output
){
EFI_STATUS Status;
EFI_HANDLE *ControllerHandleList;
EFI_HANDLE *DriverHandleList;
EFI_HANDLE *HandleWalker;
ControllerHandleList = NULL;
Status = EFI_NOT_FOUND;
//
// If we have a single handle to connect make that a 'list'
//
if (DriverHandle == NULL) {
DriverHandleList = NULL;
} else {
DriverHandleList = AllocatePool(2*sizeof(EFI_HANDLE));
DriverHandleList[0] = DriverHandle;
DriverHandleList[1] = NULL;
}
//
// do we connect all controllers (with a loop) or a single one...
// This is where we call the gBS->ConnectController function.
//
if (ControllerHandle == NULL) {
ControllerHandleList = GetHandleListByPotocol(&gEfiDevicePathProtocolGuid);
for (HandleWalker = ControllerHandleList
; HandleWalker != NULL && *HandleWalker != NULL
; HandleWalker++
){
Status = gBS->ConnectController(*HandleWalker, DriverHandleList, NULL, Recursive);
if (Output) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_CON_RESULT), gShellDriver1HiiHandle, *HandleWalker, Status);
}
}
} else {
Status = gBS->ConnectController(ControllerHandle, DriverHandleList, NULL, Recursive);
ASSERT(Output == FALSE);
}
//
// Free any memory we allocated.
//
if (ControllerHandleList != NULL) {
FreePool(ControllerHandleList);
}
if (DriverHandleList != NULL) {
FreePool(DriverHandleList);
}
return (Status);
}
EFI_STATUS
EFIAPI
ConnectFromDevPaths (
IN CONST CHAR16 *Key
){
EFI_DEVICE_PATH_PROTOCOL *DevPath;
EFI_DEVICE_PATH_PROTOCOL *DevPathWalker;
UINTN Length;
EFI_HANDLE Handle;
EFI_STATUS Status;
DevPath = NULL;
Length = 0;
//
// Get the DevicePath buffer from the variable...
//
Status = gRT->GetVariable((CHAR16*)Key, (EFI_GUID*)&gEfiGlobalVariableGuid, NULL, &Length, DevPath);
if (Status == EFI_BUFFER_TOO_SMALL) {
DevPath = AllocatePool(Length);
Status = gRT->GetVariable((CHAR16*)Key, (EFI_GUID*)&gEfiGlobalVariableGuid, NULL, &Length, DevPath);
}
//
// walk the list of devices and connect them
//
for (DevPathWalker = DevPath
; DevPathWalker < (DevPath + Length) && !EFI_ERROR(Status) && DevPath != NULL
; DevPathWalker += GetDevicePathSize(DevPathWalker)
){
//
// get the correct handle from a given device path
//
if (StrCmp(Key, L"ConInDev") == 0) {
Status = gBS->LocateDevicePath((EFI_GUID*)&gEfiConsoleInDeviceGuid, &DevPathWalker, &Handle);
} else if (StrCmp(Key, L"ConOutDev") == 0) {
Status = gBS->LocateDevicePath((EFI_GUID*)&gEfiConsoleOutDeviceGuid, &DevPathWalker, &Handle);
} else {
Handle = NULL;
Status = EFI_INVALID_PARAMETER;
ASSERT(FALSE);
}
if (!EFI_ERROR(Status)) {
Status = ConnectControllers(Handle, NULL, FALSE, FALSE);
}
}
if (DevPath != NULL) {
FreePool(DevPath);
}
return (Status);
}
EFI_STATUS
EFIAPI
ConvertAndConnectControllers (
IN CONST CHAR16 *StringHandle1,
IN CONST CHAR16 *StringHandle2 OPTIONAL,
IN CONST BOOLEAN Recursive,
IN CONST BOOLEAN Output
){
EFI_HANDLE Handle1;
EFI_HANDLE Handle2;
//
// Convert the command line parameters to HANDLES. They must be in HEX according to spec.
//
if (StringHandle1 != NULL) {
Handle1 = (EFI_HANDLE)StrHexToUintn(StringHandle1);
} else {
Handle1 = NULL;
}
if (StringHandle2 != NULL) {
Handle2 = (EFI_HANDLE)StrHexToUintn(StringHandle2);
} else {
Handle2 = NULL;
}
//
// if only one is NULL verify it's the proper one...
//
if ( (Handle1 == NULL && Handle2 != NULL)
|| (Handle1 != NULL && Handle2 == NULL)
){
//
// Figure out which one should be NULL and move the handle to the right place.
// If Handle1 is NULL then test Handle2 and vise versa.
// The one that DOES has driver binding must be Handle2
//
if (Handle1 == NULL) {
if (EFI_ERROR(gBS->OpenProtocol(Handle2, &gEfiDriverBindingProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
// swap
Handle1 = Handle2;
Handle2 = NULL;
} else {
// We're all good...
}
} else {
if (EFI_ERROR(gBS->OpenProtocol(Handle1, &gEfiDriverBindingProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
// We're all good...
} else {
// swap
Handle2 = Handle1;
Handle1 = NULL;
}
}
}
return (ConnectControllers(Handle1, Handle2, Recursive, Output));
}
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{L"-c", TypeFlag},
{L"-r", TypeFlag},
{NULL, TypeMax}
};
SHELL_STATUS
EFIAPI
ShellCommandRunConnect (
VOID *RESERVED
) {
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
ShellStatus = SHELL_SUCCESS;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
if EFI_ERROR(Status) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
//
// if more than 2 'value' parameters (plus the name one) or either -r or -c with any value parameters we have too many parameters
//
if ((ShellCommandLineGetCount() > 3)
||((ShellCommandLineGetFlag(Package, L"-r") != FALSE || ShellCommandLineGetFlag(Package, L"-c") != FALSE) && ShellCommandLineGetCount()!=0)
){
//
// error for too many parameters
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else if (ShellCommandLineGetFlag(Package, L"-c") != FALSE) {
//
// do the conin and conout from EFI variables
// if the first fails dont 'loose' the error
//
Status = ConnectFromDevPaths(L"ConInDev");
if (EFI_ERROR(Status)) {
ConnectFromDevPaths(L"ConOutDev");
} else {
Status = ConnectFromDevPaths(L"ConOutDev");
}
ShellStatus = Status & (~MAX_BIT);
} else {
//
// 0, 1, or 2 specific handles and possibly recursive
//
if (ShellCommandLineGetRawValue(Package, 1) != NULL && CommandLibGetHandleValue(StrHexToUintn(ShellCommandLineGetRawValue(Package, 1))) == NULL){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, ShellCommandLineGetRawValue(Package, 1));
ShellStatus = SHELL_INVALID_PARAMETER;
} else if (ShellCommandLineGetRawValue(Package, 2) != NULL && CommandLibGetHandleValue(StrHexToUintn(ShellCommandLineGetRawValue(Package, 2))) == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, ShellCommandLineGetRawValue(Package, 2));
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
Status = ConvertAndConnectControllers(ShellCommandLineGetRawValue(Package, 1), ShellCommandLineGetRawValue(Package, 2), ShellCommandLineGetFlag(Package, L"-r"), (BOOLEAN)(ShellCommandLineGetCount()!=0));
ShellStatus = Status & (~MAX_BIT);
}
}
ShellCommandLineFreeVarList (Package);
}
return (ShellStatus);
}

View File

@ -0,0 +1,164 @@
/** @file
Main file for devices shell Driver1 function.
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellDriver1CommandsLib.h"
EFI_STATUS
EFIAPI
GetDeviceHandleInfo (
IN EFI_HANDLE TheHandle,
IN CHAR16 *Type,
IN BOOLEAN *Cfg,
IN BOOLEAN *Diag,
IN UINT8 *Parents,
IN UINT8 *Devices,
IN UINT8 *Children,
OUT CHAR16 **Name,
IN CONST CHAR8 *Language
){
*Name = NULL;
gEfiShellProtocol->GetDeviceName(TheHandle, EFI_DEVICE_NAME_USE_COMPONENT_NAME|EFI_DEVICE_NAME_USE_DEVICE_PATH, (CHAR8*)Language, Name);
return (EFI_SUCCESS);
}
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{L"-l", TypeValue},
{NULL, TypeMax}
};
SHELL_STATUS
EFIAPI
ShellCommandRunDevices (
VOID *RESERVED
) {
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
CHAR8 *Language;
EFI_HANDLE *HandleList;
EFI_HANDLE *HandleListWalker;
CHAR16 Type;
BOOLEAN Cfg;
BOOLEAN Diag;
UINT8 Parents;
UINT8 Devices;
UINT8 Children;
CHAR16 *Name;
ShellStatus = SHELL_SUCCESS;
Language = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
if EFI_ERROR(Status) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
//
// if more than 0 'value' parameters we have too many parameters
//
if (ShellCommandLineGetRawValue(Package, 1) != NULL){
//
// error for too many parameters
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// get the language if necessary
//
if (ShellCommandLineGetFlag(Package, L"-l") != FALSE) {
Language = AllocateZeroPool(StrSize(ShellCommandLineGetValue(Package, L"-l")));
AsciiSPrint(Language, StrSize(ShellCommandLineGetValue(Package, L"-l")), "%S", ShellCommandLineGetValue(Package, L"-l"));
}
//
// Print Header
//
ShellPrintHiiEx(-1, -1, Language, STRING_TOKEN (STR_DEVICES_HEADER_LINES), gShellDriver1HiiHandle);
//
// loop through each handle
//
HandleList = GetHandleListByPotocol(NULL);
ASSERT(HandleList != NULL);
for (HandleListWalker = HandleList
; HandleListWalker != NULL && *HandleListWalker != NULL && !EFI_ERROR(Status)
; HandleListWalker++
){
//
// get all the info on each handle
//
Status = GetDeviceHandleInfo(*HandleListWalker, &Type, &Cfg, &Diag, &Parents, &Devices, &Children, &Name, Language);
if (Parents != 0 || Devices != 0 || Children != 0) {
ShellPrintHiiEx(
-1,
-1,
Language,
STRING_TOKEN (STR_DEVICES_ITEM_LINE),
gShellDriver1HiiHandle,
*HandleListWalker,
Type,
Cfg!=FALSE?L'X':L'-',
Diag!=FALSE?L'X':L'-',
Parents,
Devices,
Children,
Name);
}
if (Name != NULL) {
FreePool(Name);
}
}
if (HandleList != NULL) {
FreePool(HandleList);
}
}
ShellCommandLineFreeVarList (Package);
}
return (ShellStatus);
}

View File

@ -0,0 +1,243 @@
/** @file
Main file for OpenInfo shell Driver1 function.
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellDriver1CommandsLib.h"
EFI_STATUS
EFIAPI
TraverseHandleDatabase (
IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL,
IN CONST EFI_HANDLE ControllerHandle OPTIONAL,
IN UINTN *HandleCount,
OUT EFI_HANDLE **HandleBuffer,
OUT UINTN **HandleType
){
EFI_STATUS Status;
UINTN HandleIndex;
EFI_GUID **ProtocolGuidArray;
UINTN ArrayCount;
UINTN ProtocolIndex;
EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;
UINTN OpenInfoCount;
UINTN OpenInfoIndex;
UINTN ChildIndex;
ASSERT(HandleCount != NULL);
ASSERT(HandleBuffer != NULL);
ASSERT(HandleType != NULL);
ASSERT(DriverBindingHandle != NULL || ControllerHandle != NULL);
*HandleCount = 0;
*HandleBuffer = NULL;
*HandleType = NULL;
//
// Retrieve the list of all handles from the handle database
//
Status = gBS->LocateHandleBuffer (
AllHandles,
NULL,
NULL,
HandleCount,
HandleBuffer
);
if (EFI_ERROR (Status)) {
return (Status);
}
*HandleType = AllocateZeroPool (*HandleCount * sizeof (UINTN));
ASSERT(*HandleType != NULL);
for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) {
//
// Retrieve the list of all the protocols on each handle
//
Status = gBS->ProtocolsPerHandle (
(*HandleBuffer)[HandleIndex],
&ProtocolGuidArray,
&ArrayCount
);
if (!EFI_ERROR (Status)) {
for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {
//
// Set the bit describing what this handle has
//
if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiLoadedImageProtocolGuid) != FALSE) {
(*HandleType)[HandleIndex] |= HANDLE_RELATIONSHIP_IMAGE_HANDLE;
} else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverBindingProtocolGuid) != FALSE) {
(*HandleType)[HandleIndex] |= HANDLE_RELATIONSHIP_DRIVER_BINDING_HANDLE;
} else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfiguration2ProtocolGuid) != FALSE) {
(*HandleType)[HandleIndex] |= HANDLE_RELATIONSHIP_DRIVER_CONFIGURATION_HANDLE;
} else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfigurationProtocolGuid) != FALSE) {
(*HandleType)[HandleIndex] |= HANDLE_RELATIONSHIP_DRIVER_CONFIGURATION_HANDLE;
} else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnostics2ProtocolGuid) != FALSE) {
(*HandleType)[HandleIndex] |= HANDLE_RELATIONSHIP_DRIVER_DIAGNOSTICS_HANDLE;
} else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnosticsProtocolGuid) != FALSE) {
(*HandleType)[HandleIndex] |= HANDLE_RELATIONSHIP_DRIVER_DIAGNOSTICS_HANDLE;
} else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentName2ProtocolGuid) != FALSE) {
(*HandleType)[HandleIndex] |= HANDLE_RELATIONSHIP_COMPONENT_NAME_HANDLE;
} else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentNameProtocolGuid) != FALSE) {
(*HandleType)[HandleIndex] |= HANDLE_RELATIONSHIP_COMPONENT_NAME_HANDLE;
} else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDevicePathProtocolGuid) != FALSE) {
(*HandleType)[HandleIndex] |= HANDLE_RELATIONSHIP_DEVICE_HANDLE;
} else {
DEBUG_CODE_BEGIN();
ASSERT((*HandleType)[HandleIndex] == (*HandleType)[HandleIndex]);
DEBUG_CODE_END();
}
//
// Retrieve the list of agents that have opened each protocol
//
Status = gBS->OpenProtocolInformation (
(*HandleBuffer)[HandleIndex],
ProtocolGuidArray[ProtocolIndex],
&OpenInfo,
&OpenInfoCount
);
if (!EFI_ERROR (Status)) {
for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
if (DriverBindingHandle != NULL && OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle) {
if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) == EFI_OPEN_PROTOCOL_BY_DRIVER) {
//
// Mark the device handle as being managed by the driver specified by DriverBindingHandle
//
(*HandleType)[HandleIndex] |= (HANDLE_RELATIONSHIP_DEVICE_HANDLE | HANDLE_RELATIONSHIP_CONTROLLER_HANDLE);
}
if (ControllerHandle != NULL && (*HandleBuffer)[HandleIndex] == ControllerHandle) {
if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) == EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) {
for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
if ((*HandleBuffer)[ChildIndex] == OpenInfo[OpenInfoIndex].ControllerHandle) {
(*HandleType)[ChildIndex] |= (HANDLE_RELATIONSHIP_DEVICE_HANDLE | HANDLE_RELATIONSHIP_CHILD_HANDLE);
}
}
}
}
} else if (DriverBindingHandle == NULL && OpenInfo[OpenInfoIndex].ControllerHandle == ControllerHandle) {
if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) == EFI_OPEN_PROTOCOL_BY_DRIVER) {
for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
if ((*HandleBuffer)[ChildIndex] == OpenInfo[OpenInfoIndex].AgentHandle) {
//
// mark the handle who opened this as a device driver
//
(*HandleType)[ChildIndex] |= HANDLE_RELATIONSHIP_DEVICE_DRIVER;
}
}
}
if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) == EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) {
//
// this handle has people opening by child so it must be a parent
//
(*HandleType)[HandleIndex] |= HANDLE_RELATIONSHIP_PARENT_HANDLE;
for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
if ((*HandleBuffer)[ChildIndex] == OpenInfo[OpenInfoIndex].AgentHandle) {
(*HandleType)[ChildIndex] |= HANDLE_RELATIONSHIP_BUS_DRIVER;
}
}
}
}
}
FreePool (OpenInfo);
}
}
FreePool (ProtocolGuidArray);
}
}
if (EFI_ERROR(Status)) {
if (*HandleType != NULL) {
FreePool (*HandleType);
}
if (*HandleBuffer != NULL) {
FreePool (*HandleBuffer);
}
*HandleCount = 0;
*HandleBuffer = NULL;
*HandleType = NULL;
}
return Status;
}
SHELL_STATUS
EFIAPI
ShellCommandRunOpenInfo (
VOID *RESERVED
) {
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
EFI_HANDLE theHandle;
EFI_HANDLE *HandleList;
UINTN Count;
UINTN *Type;
ShellStatus = SHELL_SUCCESS;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
if EFI_ERROR(Status) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
if (ShellCommandLineGetCount() > 2){
//
// error for too many parameters
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else if (ShellCommandLineGetCount() == 0) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
if (ShellCommandLineGetRawValue(Package, 1) != NULL && CommandLibGetHandleValue(StrHexToUintn(ShellCommandLineGetRawValue(Package, 1))) == NULL){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, ShellCommandLineGetRawValue(Package, 1));
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
theHandle = CommandLibGetHandleValue(StrHexToUintn(ShellCommandLineGetRawValue(Package, 1)));
ASSERT(theHandle != NULL);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_OPENINFO_HEADER_LINE), gShellDriver1HiiHandle, StrHexToUintn(ShellCommandLineGetRawValue(Package, 1)), theHandle);
Status = TraverseHandleDatabase (NULL, theHandle, &Count, &HandleList, &Type);
if (EFI_ERROR(Status) == FALSE && Count > 0) {
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, ShellCommandLineGetRawValue(Package, 1));
ShellStatus = SHELL_NOT_FOUND;
}
}
}
}
return (ShellStatus);
}

View File

@ -0,0 +1,137 @@
/** @file
Main file for NULL named library for level 1 shell command functions.
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellDriver1CommandsLib.h"
STATIC CONST CHAR16 mFileName[] = L"Driver1Commands";
EFI_HANDLE gShellDriver1HiiHandle = NULL;
CONST EFI_GUID gShellDriver1HiiGuid = \
{ \
0xaf0b742, 0x63ec, 0x45bd, {0x8d, 0xb6, 0x71, 0xad, 0x7f, 0x2f, 0xe8, 0xe8} \
};
CONST CHAR16*
EFIAPI
ShellCommandGetManFileNameDriver1 (
VOID
){
return (mFileName);
}
/**
Constructor for the Shell Driver1 Commands library.
@param ImageHandle the image handle of the process
@param SystemTable the EFI System Table pointer
@retval EFI_SUCCESS the shell command handlers were installed sucessfully
@retval EFI_UNSUPPORTED the shell level required was not found.
**/
EFI_STATUS
EFIAPI
UefiShellDriver1CommandsLibConstructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
) {
//
// check or bit of the profiles mask
//
if (PcdGet8(PcdShellProfileMask) && BIT0 == 0) {
return (EFI_UNSUPPORTED);
}
//
// install our shell command handlers that are always installed
//
ShellCommandRegisterCommandName(L"connect", ShellCommandRunConnect , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE);
ShellCommandRegisterCommandName(L"devices", ShellCommandRunDevices , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE);
ShellCommandRegisterCommandName(L"openinfo", ShellCommandRunOpenInfo , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE);
/*
ShellCommandRegisterCommandName(L"devtree", ShellCommandRunDevTree , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE);
ShellCommandRegisterCommandName(L"dh", ShellCommandRunDH , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE);
ShellCommandRegisterCommandName(L"disconnect", ShellCommandRunDisconnect , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE);
ShellCommandRegisterCommandName(L"drivers", ShellCommandRunDrivers , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE);
ShellCommandRegisterCommandName(L"drvcfg", ShellCommandRunDrvCfg , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE);
ShellCommandRegisterCommandName(L"drvdiag", ShellCommandRunDrvDiag , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE);
ShellCommandRegisterCommandName(L"reconnect", ShellCommandRunReconnect , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE);
ShellCommandRegisterCommandName(L"unload", ShellCommandRunUnload , ShellCommandGetManFileNameDriver1, 0, L"Driver1", TRUE);
*/
//
// install the HII stuff.
//
gShellDriver1HiiHandle = HiiAddPackages (&gShellDriver1HiiGuid, gImageHandle, UefiShellDriver1CommandsLibStrings, NULL);
if (gShellDriver1HiiHandle == NULL) {
return (EFI_DEVICE_ERROR);
}
return (EFI_SUCCESS);
}
/**
Destructory for the library. free any resources.
**/
EFI_STATUS
EFIAPI
UefiShellDriver1CommandsLibDestructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
if (gShellDriver1HiiHandle != NULL) {
HiiRemovePackages(gShellDriver1HiiHandle);
}
return (EFI_SUCCESS);
}
EFI_HANDLE*
EFIAPI
GetHandleListByPotocol (
IN CONST EFI_GUID *ProtocolGuid
){
EFI_HANDLE *HandleList;
UINTN Size;
EFI_STATUS Status;
Size = 0;
HandleList = NULL;
//
// We cannot use LocateHandleBuffer since we need that NULL item on the ends of the list!
//
if (ProtocolGuid == NULL) {
Status = gBS->LocateHandle(AllHandles, NULL, NULL, &Size, HandleList);
if (Status == EFI_BUFFER_TOO_SMALL) {
HandleList = AllocatePool(Size + sizeof(EFI_HANDLE));
Status = gBS->LocateHandle(AllHandles, NULL, NULL, &Size, HandleList);
HandleList[Size/sizeof(EFI_HANDLE)] = NULL;
}
} else {
Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)ProtocolGuid, NULL, &Size, HandleList);
if (Status == EFI_BUFFER_TOO_SMALL) {
HandleList = AllocatePool(Size + sizeof(EFI_HANDLE));
Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)ProtocolGuid, NULL, &Size, HandleList);
HandleList[Size/sizeof(EFI_HANDLE)] = NULL;
}
}
if (EFI_ERROR(Status)) {
if (HandleList != NULL) {
FreePool(HandleList);
}
return (NULL);
}
return (HandleList);
}

View File

@ -0,0 +1,71 @@
/** @file
Main file for NULL named library for Profile1 shell command functions.
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
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 <ShellBase.h>
#include <Protocol/EfiShell.h>
#include <Protocol/EfiShellParameters.h>
#include <Protocol/DevicePath.h>
#include <Protocol/LoadedImage.h>
#include <Protocol/UnicodeCollation.h>
#include <Protocol/DevicePathToText.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
#include <Library/ShellCommandLib.h>
#include <Library/ShellLib.h>
#include <Library/SortLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/HiiLib.h>
#include <Library/FileHandleLib.h>
#include <Library/DevicePathLib.h>
#include <Library/PrintLib.h>
extern EFI_HANDLE gShellDriver1HiiHandle;
extern CONST EFI_GUID gShellDriver1HiiGuid;
EFI_HANDLE*
EFIAPI
GetHandleListByPotocol (
IN CONST EFI_GUID *ProtocolGuid
);
SHELL_STATUS
EFIAPI
ShellCommandRunConnect (
VOID *RESERVED
);
SHELL_STATUS
EFIAPI
ShellCommandRunDevices (
VOID *RESERVED
);
SHELL_STATUS
EFIAPI
ShellCommandRunOpenInfo (
VOID *RESERVED
);

View File

@ -0,0 +1,57 @@
#/** @file
# Provides shell driver1 profile functions
#
# Copyright (c) 2010, Intel Corporation.All rights reserved. <BR>
#
# 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 = UefiShellDriver1CommandsLib
FILE_GUID = 313D3674-3ED4-48fd-BF97-7DB35D4190D1
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = NULL|UEFI_APPLICATION UEFI_DRIVER
CONSTRUCTOR = UefiShellDriver1CommandsLibConstructor
DESTRUCTOR = UefiShellDriver1CommandsLibDestructor
[Sources]
Connect.c
Devices.c
OpenInfo.c
UefiShellDriver1CommandsLib.c
UefiShellDriver1CommandsLib.h
UefiShellDriver1CommandsLib.uni
[Packages]
MdePkg/MdePkg.dec
ShellPkg/ShellPkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
MemoryAllocationLib
BaseLib
BaseMemoryLib
DebugLib
ShellCommandLib
ShellLib
UefiLib
UefiRuntimeServicesTableLib
UefiBootServicesTableLib
SortLib
PrintLib
[Pcd]
gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask # ALWAYS_CONSUMED
[Guids]
gEfiGlobalVariableGuid
gEfiConsoleInDeviceGuid
gEfiConsoleOutDeviceGuid

View File

@ -0,0 +1,81 @@
/** @file
Main file for exit shell level 1 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellLevel1CommandsLib.h"
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{L"/b", TypeFlag},
{NULL, TypeMax}
};
/**
Function for 'exit' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunExit (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
ShellStatus = SHELL_SUCCESS;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel1HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
//
// If we are in a batch file and /b then pass TRUE otherwise false...
//
ShellCommandRegisterExit((BOOLEAN)(gEfiShellProtocol->BatchIsActive() && ShellCommandLineGetFlag(Package, L"/b")));
//
// return the specified error code
//
if (ShellCommandLineGetRawValue(Package, 1) != NULL) {
ShellStatus = (SHELL_STATUS)(ShellStrToUintn(ShellCommandLineGetRawValue(Package, 1)));
}
ShellCommandLineFreeVarList (Package);
}
return (ShellStatus);
}

View File

@ -0,0 +1,581 @@
/** @file
Main file for endfor and for shell level 1 functions.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellLevel1CommandsLib.h"
#include <Library/PrintLib.h>
BOOLEAN
EFIAPI
ShellIsValidForNumber (
IN CONST CHAR16 *Number
)
{
if (Number == NULL || *Number == CHAR_NULL) {
return (FALSE);
}
if (*Number == L'-') {
Number++;
}
if (StrLen(Number) == 0) {
return (FALSE);
}
if (StrLen(Number) >= 7) {
if (StrStr(Number, L" ") != NULL && (StrStr(Number, L" ") - Number) >= 7) {
return (FALSE);
}
}
if (!ShellIsDecimalDigitCharacter(*Number)) {
return (FALSE);
}
return (TRUE);
}
/**
Function for 'endfor' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunEndFor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
BOOLEAN Found;
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
if (!gEfiShellProtocol->BatchIsActive()) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"EndFor");
return (SHELL_UNSUPPORTED);
}
if (gEfiShellParametersProtocol->Argc > 1) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle);
return (SHELL_INVALID_PARAMETER);
}
Found = MoveToTag(GetPreviousNode, L"for", L"endfor", NULL, ShellCommandGetCurrentScriptFile(), FALSE, FALSE, FALSE);
if (!Found) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"For", L"EndFor", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
return (SHELL_NOT_FOUND);
}
return (SHELL_SUCCESS);
}
typedef struct {
UINT32 Signature;
INTN Current;
INTN End;
INTN Step;
CHAR16 *ReplacementName;
CHAR16 *CurrentValue;
BOOLEAN RemoveSubstAlias;
CHAR16 Set[1];
} SHELL_FOR_INFO;
#define SIZE_OF_SHELL_FOR_INFO OFFSET_OF (SHELL_FOR_INFO, Set)
#define SHELL_FOR_INFO_SIGNATURE SIGNATURE_32 ('S', 'F', 'I', 's')
/**
Update the value of a given alias on the list. If the alias is not there then add it.
@param[in] Alias The alias to test for.
@param[in] CommandString The updated command string.
@param[in,out] List The list to search.
**/
VOID
EFIAPI
InternalUpdateAliasOnList(
IN CONST CHAR16 *Alias,
IN CONST CHAR16 *CommandString,
IN OUT LIST_ENTRY *List
)
{
ALIAS_LIST *Node;
BOOLEAN Found;
//
// assert for NULL parameter
//
ASSERT(Alias != NULL);
//
// check for the Alias
//
for ( Node = (ALIAS_LIST *)GetFirstNode(List), Found = FALSE
; !IsNull(List, &Node->Link)
; Node = (ALIAS_LIST *)GetNextNode(List, &Node->Link)
){
ASSERT(Node->CommandString != NULL);
ASSERT(Node->Alias != NULL);
if (StrCmp(Node->Alias, Alias)==0) {
FreePool(Node->CommandString);
Node->CommandString = NULL;
Node->CommandString = StrnCatGrow(&Node->CommandString, NULL, CommandString, 0);
Found = TRUE;
break;
}
}
if (!Found) {
Node = AllocateZeroPool(sizeof(ALIAS_LIST));
ASSERT(Node->Alias == NULL);
Node->Alias = StrnCatGrow(&Node->Alias, NULL, Alias, 0);
ASSERT(Node->CommandString == NULL);
Node->CommandString = StrnCatGrow(&Node->CommandString, NULL, CommandString, 0);
InsertTailList(List, &Node->Link);
}
}
/**
Find out if an alias is on the given list.
@param[in] Alias The alias to test for.
@param[in] List The list to search.
@retval TRUE The alias is on the list.
@retval FALSE The alias is not on the list.
**/
BOOLEAN
EFIAPI
InternalIsAliasOnList(
IN CONST CHAR16 *Alias,
IN CONST LIST_ENTRY *List
)
{
ALIAS_LIST *Node;
//
// assert for NULL parameter
//
ASSERT(Alias != NULL);
//
// check for the Alias
//
for ( Node = (ALIAS_LIST *)GetFirstNode(List)
; !IsNull(List, &Node->Link)
; Node = (ALIAS_LIST *)GetNextNode(List, &Node->Link)
){
ASSERT(Node->CommandString != NULL);
ASSERT(Node->Alias != NULL);
if (StrCmp(Node->Alias, Alias)==0) {
return (TRUE);
}
}
return (FALSE);
}
/**
Remove an alias from the given list.
@param[in] Alias The alias to remove.
@param[in,out] List The list to search.
**/
BOOLEAN
EFIAPI
InternalRemoveAliasFromList(
IN CONST CHAR16 *Alias,
IN OUT LIST_ENTRY *List
)
{
ALIAS_LIST *Node;
//
// assert for NULL parameter
//
ASSERT(Alias != NULL);
//
// check for the Alias
//
for ( Node = (ALIAS_LIST *)GetFirstNode(List)
; !IsNull(List, &Node->Link)
; Node = (ALIAS_LIST *)GetNextNode(List, &Node->Link)
){
ASSERT(Node->CommandString != NULL);
ASSERT(Node->Alias != NULL);
if (StrCmp(Node->Alias, Alias)==0) {
RemoveEntryList(&Node->Link);
FreePool(Node->Alias);
FreePool(Node->CommandString);
FreePool(Node);
return (TRUE);
}
}
return (FALSE);
}
/**
Function for 'for' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunFor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
SHELL_STATUS ShellStatus;
SCRIPT_FILE *CurrentScriptFile;
CHAR16 *ArgSet;
CHAR16 *ArgSetWalker;
UINTN ArgSize;
UINTN LoopVar;
SHELL_FOR_INFO *Info;
CHAR16 *TempString;
CHAR16 *TempSpot;
BOOLEAN FirstPass;
EFI_SHELL_FILE_INFO *Node;
EFI_SHELL_FILE_INFO *FileList;
UINTN NewSize;
ArgSet = NULL;
ArgSize = 0;
ShellStatus = SHELL_SUCCESS;
ArgSetWalker = NULL;
TempString = NULL;
FirstPass = FALSE;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
if (!gEfiShellProtocol->BatchIsActive()) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"For");
return (SHELL_UNSUPPORTED);
}
if (gEfiShellParametersProtocol->Argc < 4) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle);
return (SHELL_INVALID_PARAMETER);
}
CurrentScriptFile = ShellCommandGetCurrentScriptFile();
ASSERT(CurrentScriptFile != NULL);
if (CurrentScriptFile->CurrentCommand->Data == NULL) {
FirstPass = TRUE;
//
// Make sure that an End exists.
//
if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, TRUE, FALSE)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"EndFor", L"For", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
return (SHELL_DEVICE_ERROR);
}
//
// Process the line.
//
if (gEfiShellParametersProtocol->Argv[1][0] != L'%' || gEfiShellParametersProtocol->Argv[1][2] != CHAR_NULL
||!((gEfiShellParametersProtocol->Argv[1][1] >= L'a' && gEfiShellParametersProtocol->Argv[1][1] <= L'z')
||(gEfiShellParametersProtocol->Argv[1][1] >= L'A' && gEfiShellParametersProtocol->Argv[1][1] <= L'Z'))
) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_VAR), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[2]);
return (SHELL_INVALID_PARAMETER);
}
if (gUnicodeCollation->StriColl(
gUnicodeCollation,
L"in",
gEfiShellParametersProtocol->Argv[2]) == 0) {
for (LoopVar = 0x3 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {
ASSERT((ArgSet == NULL && ArgSize == 0) || (ArgSet != NULL));
if (ArgSet == NULL) {
// ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
} else {
ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0);
}
if (StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"*") != NULL
||StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"?") != NULL
||StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"[") != NULL
||StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"]") != NULL) {
FileList = NULL;
Status = ShellOpenFileMetaArg ((CHAR16*)gEfiShellParametersProtocol->Argv[LoopVar], EFI_FILE_MODE_READ, &FileList);
if (EFI_ERROR(Status) || FileList == NULL || IsListEmpty(&FileList->Link)) {
ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);
} else {
for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)
; !IsNull(&FileList->Link, &Node->Link)
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)
){
ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0);
ArgSet = StrnCatGrow(&ArgSet, &ArgSize, Node->FullName, 0);
ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
}
ShellCloseFileMetaArg(&FileList);
}
} else {
ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);
}
ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
}
//
// set up for an 'in' for loop
//
NewSize = StrSize(ArgSet);
NewSize += sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]);
Info = AllocateZeroPool(NewSize);
ASSERT(Info != NULL);
Info->Signature = SHELL_FOR_INFO_SIGNATURE;
CopyMem(Info->Set, ArgSet, StrSize(ArgSet));
NewSize = StrSize(gEfiShellParametersProtocol->Argv[1]);
CopyMem(Info->Set+(StrSize(ArgSet)/sizeof(Info->Set[0])), gEfiShellParametersProtocol->Argv[1], NewSize);
Info->ReplacementName = Info->Set+StrSize(ArgSet)/sizeof(Info->Set[0]);
Info->CurrentValue = (CHAR16*)Info->Set;
Info->Step = 0;
Info->Current = 0;
Info->End = 0;
if (InternalIsAliasOnList(Info->ReplacementName, &CurrentScriptFile->SubstList)) {
Info->RemoveSubstAlias = FALSE;
} else {
Info->RemoveSubstAlias = TRUE;
}
CurrentScriptFile->CurrentCommand->Data = Info;
} else if (gUnicodeCollation->StriColl(
gUnicodeCollation,
L"run",
gEfiShellParametersProtocol->Argv[2]) == 0) {
for (LoopVar = 0x3 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {
ASSERT((ArgSet == NULL && ArgSize == 0) || (ArgSet != NULL));
if (ArgSet == NULL) {
// ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
} else {
ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0);
}
ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);
// ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0);
}
//
// set up for a 'run' for loop
//
Info = AllocateZeroPool(sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]));
ASSERT(Info != NULL);
CopyMem(Info->Set, gEfiShellParametersProtocol->Argv[1], StrSize(gEfiShellParametersProtocol->Argv[1]));
Info->ReplacementName = Info->Set;
Info->CurrentValue = NULL;
ArgSetWalker = ArgSet;
if (ArgSetWalker[0] != L'(') {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ArgSetWalker++;
while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {
ArgSetWalker++;
}
if (!ShellIsValidForNumber(ArgSetWalker)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
if (ArgSetWalker[0] == L'-') {
Info->Current = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);
} else {
Info->Current = (INTN)ShellStrToUintn(ArgSetWalker);
}
ArgSetWalker = StrStr(ArgSetWalker, L" ");
while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {
ArgSetWalker++;
}
if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
if (ArgSetWalker[0] == L'-') {
Info->End = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);
} else {
Info->End = (INTN)ShellStrToUintn(ArgSetWalker);
}
if (Info->Current < Info->End) {
Info->Step = 1;
} else {
Info->Step = -1;
}
ArgSetWalker = StrStr(ArgSetWalker, L" ");
while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {
ArgSetWalker++;
}
if (ArgSetWalker != NULL && *ArgSetWalker != CHAR_NULL) {
TempSpot = StrStr(ArgSetWalker, L")");
if (TempSpot == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
*TempSpot = CHAR_NULL;
if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
if (*ArgSetWalker == L')') {
ASSERT(Info->Step == 1 || Info->Step == -1);
} else {
if (ArgSetWalker[0] == L'-') {
Info->Step = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);
} else {
Info->Step = (INTN)ShellStrToUintn(ArgSetWalker);
}
}
}
}
}
}
}
}
if (ShellStatus == SHELL_SUCCESS) {
if (InternalIsAliasOnList(Info->ReplacementName, &CurrentScriptFile->SubstList)) {
Info->RemoveSubstAlias = FALSE;
} else {
Info->RemoveSubstAlias = TRUE;
}
}
CurrentScriptFile->CurrentCommand->Data = Info;
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
ShellStatus = SHELL_INVALID_PARAMETER;
}
} else {
//
// These need to be NULL since they are used to determine if this is the first pass later on...
//
ASSERT(ArgSetWalker == NULL);
ASSERT(ArgSet == NULL);
}
Info = (SHELL_FOR_INFO*)CurrentScriptFile->CurrentCommand->Data;
if (CurrentScriptFile->CurrentCommand->Reset) {
Info->CurrentValue = (CHAR16*)Info->Set;
FirstPass = TRUE;
CurrentScriptFile->CurrentCommand->Reset = FALSE;
}
if (ShellStatus == SHELL_SUCCESS) {
ASSERT(Info != NULL);
if (Info->Step != 0) {
//
// only advance if not the first pass
//
if (!FirstPass) {
//
// sequence version of for loop...
//
Info->Current += Info->Step;
}
TempString = AllocateZeroPool(50*sizeof(CHAR16));
UnicodeSPrint(TempString, 50*sizeof(CHAR16), L"%d", Info->Current);
InternalUpdateAliasOnList(Info->ReplacementName, TempString, &CurrentScriptFile->SubstList);
FreePool(TempString);
if ((Info->Step > 0 && Info->Current > Info->End) || (Info->Step < 0 && Info->Current < Info->End)) {
CurrentScriptFile->CurrentCommand->Data = NULL;
//
// find the matching endfor (we're done with the loop)
//
if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, FALSE, FALSE)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"EndFor", L"For", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
ShellStatus = SHELL_DEVICE_ERROR;
}
if (Info->RemoveSubstAlias) {
//
// remove item from list
//
InternalRemoveAliasFromList(Info->ReplacementName, &CurrentScriptFile->SubstList);
}
FreePool(Info);
}
} else {
//
// Must be in 'in' version of for loop...
//
ASSERT(Info->Set != NULL);
if (Info->CurrentValue != NULL && *Info->CurrentValue != CHAR_NULL) {
if (Info->CurrentValue[0] == L'\"') {
Info->CurrentValue++;
}
while (Info->CurrentValue[0] == L' ') {
Info->CurrentValue++;
}
if (Info->CurrentValue[0] == L'\"') {
Info->CurrentValue++;
}
//
// do the next one of the set
//
ASSERT(TempString == NULL);
TempString = StrnCatGrow(&TempString, NULL, Info->CurrentValue, 0);
TempSpot = StrStr(TempString, L"\" \"");
if (TempSpot != NULL) {
*TempSpot = CHAR_NULL;
}
while (TempString[StrLen(TempString)-1] == L'\"') {
TempString[StrLen(TempString)-1] = CHAR_NULL;
}
InternalUpdateAliasOnList(Info->ReplacementName, TempString, &CurrentScriptFile->SubstList);
Info->CurrentValue += StrLen(TempString);
if (Info->CurrentValue[0] == L'\"') {
Info->CurrentValue++;
}
while (Info->CurrentValue[0] == L' ') {
Info->CurrentValue++;
}
if (Info->CurrentValue[0] == L'\"') {
Info->CurrentValue++;
}
FreePool(TempString);
} else {
CurrentScriptFile->CurrentCommand->Data = NULL;
//
// find the matching endfor (we're done with the loop)
//
if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, FALSE, FALSE)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"EndFor", L"For", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
ShellStatus = SHELL_DEVICE_ERROR;
}
if (Info->RemoveSubstAlias) {
//
// remove item from list
//
InternalRemoveAliasFromList(Info->ReplacementName, &CurrentScriptFile->SubstList);
}
FreePool(Info);
}
}
}
if (ArgSet != NULL) {
FreePool(ArgSet);
}
return (ShellStatus);
}

View File

@ -0,0 +1,92 @@
/** @file
Main file for goto shell level 1 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellLevel1CommandsLib.h"
/**
Function for 'goto' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunGoto (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
CHAR16 *CompareString;
UINTN Size;
ShellStatus = SHELL_SUCCESS;
CompareString = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
if (!gEfiShellProtocol->BatchIsActive()) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"Goto");
return (SHELL_UNSUPPORTED);
}
//
// parse the command line
//
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel1HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
if (ShellCommandLineGetRawValue(Package, 2) != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
Size = 0;
ASSERT((CompareString == NULL && Size == 0) || (CompareString != NULL));
CompareString = StrnCatGrow(&CompareString, &Size, L":", 0);
CompareString = StrnCatGrow(&CompareString, &Size, ShellCommandLineGetRawValue(Package, 1), 0);
//
// Check forwards and then backwards for a label...
//
if (!MoveToTag(GetNextNode, L"endfor", L"for", CompareString, ShellCommandGetCurrentScriptFile(), FALSE, FALSE, TRUE)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, CompareString, L"Goto", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
ShellStatus = SHELL_NOT_FOUND;
}
FreePool(CompareString);
}
ShellCommandLineFreeVarList (Package);
}
return (ShellStatus);
}

View File

@ -0,0 +1,962 @@
/** @file
Main file for If and else shell level 1 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellLevel1CommandsLib.h"
#include <Library/PrintLib.h>
typedef enum {
END_TAG_OR,
END_TAG_AND,
END_TAG_THEN,
END_TAG_MAX
} END_TAG_TYPE;
typedef enum {
OPERATOR_GT,
OPERATOR_LT,
OPERATOR_EQ,
OPERATOR_NE,
OPERATOR_GE,
OPERATOR_LE,
OPERATOR_UGT,
OPERATOR_ULT,
OPERATOR_UGE,
OPERATOR_ULE,
OPERATOR_MAX
} BIN_OPERATOR_TYPE;
BOOLEAN
EFIAPI
IsNextFragment (
IN CONST CHAR16 **Statement,
IN CONST CHAR16 *Fragment
)
{
CHAR16 *Tester;
Tester = NULL;
Tester = StrnCatGrow(&Tester, NULL, *Statement, StrLen(Fragment));
ASSERT(Tester != NULL);
Tester[StrLen(Fragment)] = CHAR_NULL;
if (gUnicodeCollation->StriColl(
gUnicodeCollation,
(CHAR16*)Fragment,
Tester) == 0) {
//
// increment the string pointer to the end of what we found and then chop off spaces...
//
*Statement+=StrLen(Fragment);
while (*Statement[0] == L' ') {
*Statement++;
}
FreePool(Tester);
return (TRUE);
}
FreePool(Tester);
return (FALSE);
}
BOOLEAN
EFIAPI
IsValidProfile (
IN CONST CHAR16 *String
)
{
CONST CHAR16 *ProfilesString;
CONST CHAR16 *TempLocation;
ProfilesString = ShellGetEnvironmentVariable(L"profiles");
TempLocation = StrStr(ProfilesString, String);
if ((TempLocation != NULL) && (*(TempLocation-1) == L';') && (*(TempLocation+StrLen(String)) == L';')) {
return (TRUE);
}
return (FALSE);
}
BOOLEAN
EFIAPI
TestOperation (
IN CONST CHAR16 *Compare1,
IN CONST CHAR16 *Compare2,
IN CONST BIN_OPERATOR_TYPE BinOp,
IN CONST BOOLEAN CaseInsensitive,
IN CONST BOOLEAN ForceStringCompare
)
{
INTN Cmp1;
INTN Cmp2;
//
// "Compare1 BinOp Compare2"
//
switch (BinOp) {
case OPERATOR_UGT:
case OPERATOR_GT:
if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {
//
// string compare
//
if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) > 0) || (StringCompare(&Compare1, &Compare2) > 0)) {
return (TRUE);
}
} else {
//
// numeric compare
//
if (Compare1[0] == L'-') {
Cmp1 = 0 - (INTN)StrDecimalToUintn(Compare1+1);
} else {
Cmp1 = (INTN)StrDecimalToUintn(Compare1);
}
if (Compare2[0] == L'-') {
Cmp2 = 0 - (INTN)StrDecimalToUintn(Compare2+1);
} else {
Cmp2 = (INTN)StrDecimalToUintn(Compare2);
}
if (BinOp == OPERATOR_GT) {
if (Cmp1 > Cmp2) {
return (TRUE);
}
} else {
if ((UINTN)Cmp1 > (UINTN)Cmp2) {
return (TRUE);
}
}
}
return (FALSE);
break;
case OPERATOR_ULT:
case OPERATOR_LT:
if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {
//
// string compare
//
if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) < 0) || (StringCompare(&Compare1, &Compare2) < 0)) {
return (TRUE);
}
} else {
//
// numeric compare
//
if (Compare1[0] == L'-') {
Cmp1 = 0 - (INTN)StrDecimalToUintn(Compare1+1);
} else {
Cmp1 = (INTN)StrDecimalToUintn(Compare1);
}
if (Compare2[0] == L'-') {
Cmp2 = 0 - (INTN)StrDecimalToUintn(Compare2+1);
} else {
Cmp2 = (INTN)StrDecimalToUintn(Compare2);
}
if (BinOp == OPERATOR_LT) {
if (Cmp1 < Cmp2) {
return (TRUE);
}
} else {
if ((UINTN)Cmp1 < (UINTN)Cmp2) {
return (TRUE);
}
}
}
return (FALSE);
break;
case OPERATOR_EQ:
if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {
//
// string compare
//
if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) == 0) || (StringCompare(&Compare1, &Compare2) == 0)) {
return (TRUE);
}
} else {
//
// numeric compare
//
if (Compare1[0] == L'-') {
Cmp1 = 0 - (INTN)ShellStrToUintn(Compare1+1);
} else {
Cmp1 = (INTN)ShellStrToUintn(Compare1);
}
if (Compare2[0] == L'-') {
Cmp2 = 0 - (INTN)ShellStrToUintn(Compare2+1);
} else {
Cmp2 = (INTN)ShellStrToUintn(Compare2);
}
if (Cmp1 == Cmp2) {
return (TRUE);
}
}
return (FALSE);
break;
case OPERATOR_NE:
if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {
//
// string compare
//
if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) != 0) || (StringCompare(&Compare1, &Compare2) != 0)) {
return (TRUE);
}
} else {
//
// numeric compare
//
if (Compare1[0] == L'-') {
Cmp1 = 0 - (INTN)StrDecimalToUintn(Compare1+1);
} else {
Cmp1 = (INTN)StrDecimalToUintn(Compare1);
}
if (Compare2[0] == L'-') {
Cmp2 = 0 - (INTN)StrDecimalToUintn(Compare2+1);
} else {
Cmp2 = (INTN)StrDecimalToUintn(Compare2);
}
if (Cmp1 != Cmp2) {
return (TRUE);
}
}
return (FALSE);
break;
case OPERATOR_UGE:
case OPERATOR_GE:
if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {
//
// string compare
//
if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) >= 0) || (StringCompare(&Compare1, &Compare2) >= 0)) {
return (TRUE);
}
} else {
//
// numeric compare
//
if (Compare1[0] == L'-') {
Cmp1 = 0 - (INTN)StrDecimalToUintn(Compare1+1);
} else {
Cmp1 = (INTN)StrDecimalToUintn(Compare1);
}
if (Compare2[0] == L'-') {
Cmp2 = 0 - (INTN)StrDecimalToUintn(Compare2+1);
} else {
Cmp2 = (INTN)StrDecimalToUintn(Compare2);
}
if (BinOp == OPERATOR_GE) {
if (Cmp1 >= Cmp2) {
return (TRUE);
}
} else {
if ((UINTN)Cmp1 >= (UINTN)Cmp2) {
return (TRUE);
}
}
}
return (FALSE);
break;
case OPERATOR_LE:
case OPERATOR_ULE:
if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {
//
// string compare
//
if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) <= 0) || (StringCompare(&Compare1, &Compare2) <= 0)) {
return (TRUE);
}
} else {
//
// numeric compare
//
if (Compare1[0] == L'-') {
Cmp1 = 0 - (INTN)StrDecimalToUintn(Compare1+1);
} else {
Cmp1 = (INTN)StrDecimalToUintn(Compare1);
}
if (Compare2[0] == L'-') {
Cmp2 = 0 - (INTN)StrDecimalToUintn(Compare2+1);
} else {
Cmp2 = (INTN)StrDecimalToUintn(Compare2);
}
if (BinOp == OPERATOR_LE) {
if (Cmp1 <= Cmp2) {
return (TRUE);
}
} else {
if ((UINTN)Cmp1 <= (UINTN)Cmp2) {
return (TRUE);
}
}
}
return (FALSE);
break;
}
ASSERT(FALSE);
return (FALSE);
}
EFI_STATUS
EFIAPI
ProcessStatement (
IN OUT BOOLEAN *PassingState,
IN UINTN StartParameterNumber,
IN UINTN EndParameterNumber,
IN CONST END_TAG_TYPE OperatorToUse,
IN CONST BOOLEAN CaseInsensitive,
IN CONST BOOLEAN ForceStringCompare
)
{
EFI_STATUS Status;
BOOLEAN OperationResult;
BOOLEAN NotPresent;
CHAR16 *StatementWalker;
BIN_OPERATOR_TYPE BinOp;
CHAR16 *Compare1;
CHAR16 *Compare2;
CHAR16 HexString[20];
CHAR16 *TempSpot;
ASSERT((END_TAG_TYPE)OperatorToUse != END_TAG_THEN);
Status = EFI_SUCCESS;
BinOp = OPERATOR_MAX;
OperationResult = FALSE;
StatementWalker = gEfiShellParametersProtocol->Argv[StartParameterNumber];
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"not")) {
NotPresent = TRUE;
StatementWalker = gEfiShellParametersProtocol->Argv[++StartParameterNumber];
} else {
NotPresent = FALSE;
}
//
// now check for 'boolfunc' operators
//
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"isint")) {
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && StatementWalker[StrLen(StatementWalker)-1] == L')') {
StatementWalker[StrLen(StatementWalker)-1] = CHAR_NULL;
OperationResult = ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE);
} else {
Status = EFI_INVALID_PARAMETER;
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"isint");
}
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"exists") || IsNextFragment((CONST CHAR16**)(&StatementWalker), L"exist")) {
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && StatementWalker[StrLen(StatementWalker)-1] == L')') {
StatementWalker[StrLen(StatementWalker)-1] = CHAR_NULL;
//
// is what remains a file in CWD???
//
OperationResult = (BOOLEAN)(ShellFileExists(StatementWalker)==EFI_SUCCESS);
} else if (StatementWalker[0] == CHAR_NULL && StartParameterNumber+1 == EndParameterNumber) {
OperationResult = (BOOLEAN)(ShellFileExists(gEfiShellParametersProtocol->Argv[++StartParameterNumber])==EFI_SUCCESS);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"exist(s)");
Status = EFI_INVALID_PARAMETER;
}
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"available")) {
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && StatementWalker[StrLen(StatementWalker)-1] == L')') {
StatementWalker[StrLen(StatementWalker)-1] = CHAR_NULL;
//
// is what remains a file in the CWD or path???
//
OperationResult = (BOOLEAN)(ShellIsFileInPath(StatementWalker)==EFI_SUCCESS);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"available");
Status = EFI_INVALID_PARAMETER;
}
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"profile")) {
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && StatementWalker[StrLen(StatementWalker)-1] == L')') {
//
// Chop off that ')'
//
StatementWalker[StrLen(StatementWalker)-1] = CHAR_NULL;
OperationResult = IsValidProfile(StatementWalker);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"profile");
Status = EFI_INVALID_PARAMETER;
}
} else if (StartParameterNumber+1 >= EndParameterNumber) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[StartParameterNumber]);
Status = EFI_INVALID_PARAMETER;
} else {
//
// must be 'item binop item' style
//
Compare1 = NULL;
Compare2 = NULL;
BinOp = OPERATOR_MAX;
//
// get the first item
//
StatementWalker = gEfiShellParametersProtocol->Argv[StartParameterNumber];
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"efierror")) {
TempSpot = StrStr(StatementWalker, L")");
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && TempSpot != NULL) {
*TempSpot = CHAR_NULL;
if (ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE)) {
UnicodeSPrint(HexString, sizeof(HexString), L"0x%x", ShellStrToUintn(StatementWalker)|MAX_BIT);
ASSERT(Compare1 == NULL);
Compare1 = StrnCatGrow(&Compare1, NULL, HexString, 0);
StatementWalker += StrLen(StatementWalker) + 1;
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"efierror");
Status = EFI_INVALID_PARAMETER;
}
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"efierror");
Status = EFI_INVALID_PARAMETER;
}
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"pierror")) {
TempSpot = StrStr(StatementWalker, L")");
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && TempSpot != NULL) {
*TempSpot = CHAR_NULL;
if (ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE)) {
UnicodeSPrint(HexString, sizeof(HexString), L"0x%x", ShellStrToUintn(StatementWalker)|MAX_BIT|(MAX_BIT>>2));
ASSERT(Compare1 == NULL);
Compare1 = StrnCatGrow(&Compare1, NULL, HexString, 0);
StatementWalker += StrLen(StatementWalker) + 1;
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"pierror");
Status = EFI_INVALID_PARAMETER;
}
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"pierror");
Status = EFI_INVALID_PARAMETER;
}
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"oemerror")) {
TempSpot = StrStr(StatementWalker, L")");
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && TempSpot != NULL) {
TempSpot = CHAR_NULL;
if (ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE)) {
UnicodeSPrint(HexString, sizeof(HexString), L"0x%x", ShellStrToUintn(StatementWalker)|MAX_BIT|(MAX_BIT>>1));
ASSERT(Compare1 == NULL);
Compare1 = StrnCatGrow(&Compare1, NULL, HexString, 0);
StatementWalker += StrLen(StatementWalker) + 1;
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"oemerror");
Status = EFI_INVALID_PARAMETER;
}
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"oemerror");
Status = EFI_INVALID_PARAMETER;
}
} else {
ASSERT(Compare1 == NULL);
if (EndParameterNumber - StartParameterNumber > 2) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_STARTING), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[StartParameterNumber+2]);
Status = EFI_INVALID_PARAMETER;
} else {
//
// must be a raw string
//
Compare1 = StrnCatGrow(&Compare1, NULL, StatementWalker, 0);
}
}
//
// get the operator
//
ASSERT(StartParameterNumber+1<EndParameterNumber);
StatementWalker = gEfiShellParametersProtocol->Argv[StartParameterNumber+1];
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"gt")) {
BinOp = OPERATOR_GT;
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"lt")) {
BinOp = OPERATOR_LT;
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"eq")) {
BinOp = OPERATOR_EQ;
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ne")) {
BinOp = OPERATOR_NE;
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ge")) {
BinOp = OPERATOR_GE;
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"le")) {
BinOp = OPERATOR_LE;
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"==")) {
BinOp = OPERATOR_EQ;
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ugt")) {
BinOp = OPERATOR_UGT;
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ult")) {
BinOp = OPERATOR_ULT;
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"uge")) {
BinOp = OPERATOR_UGE;
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ule")) {
BinOp = OPERATOR_ULE;
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_INVALID_BINOP), gShellLevel1HiiHandle, StatementWalker);
Status = EFI_INVALID_PARAMETER;
}
//
// get the second item
//
ASSERT(StartParameterNumber+2<=EndParameterNumber);
StatementWalker = gEfiShellParametersProtocol->Argv[StartParameterNumber+2];
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"efierror")) {
TempSpot = StrStr(StatementWalker, L")");
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && TempSpot != NULL) {
TempSpot = CHAR_NULL;
if (ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE)) {
UnicodeSPrint(HexString, sizeof(HexString), L"0x%x", ShellStrToUintn(StatementWalker)|MAX_BIT);
ASSERT(Compare2 == NULL);
Compare2 = StrnCatGrow(&Compare2, NULL, HexString, 0);
StatementWalker += StrLen(StatementWalker) + 1;
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"efierror");
Status = EFI_INVALID_PARAMETER;
}
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"efierror");
Status = EFI_INVALID_PARAMETER;
}
//
// can this be collapsed into the above?
//
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"pierror")) {
TempSpot = StrStr(StatementWalker, L")");
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && TempSpot != NULL) {
TempSpot = CHAR_NULL;
if (ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE)) {
UnicodeSPrint(HexString, sizeof(HexString), L"0x%x", ShellStrToUintn(StatementWalker)|MAX_BIT|(MAX_BIT>>2));
ASSERT(Compare2 == NULL);
Compare2 = StrnCatGrow(&Compare2, NULL, HexString, 0);
StatementWalker += StrLen(StatementWalker) + 1;
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"pierror");
Status = EFI_INVALID_PARAMETER;
}
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"pierror");
Status = EFI_INVALID_PARAMETER;
}
} else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"oemerror")) {
TempSpot = StrStr(StatementWalker, L")");
if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && TempSpot != NULL) {
TempSpot = CHAR_NULL;
if (ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE)) {
UnicodeSPrint(HexString, sizeof(HexString), L"0x%x", ShellStrToUintn(StatementWalker)|MAX_BIT|(MAX_BIT>>1));
ASSERT(Compare2 == NULL);
Compare2 = StrnCatGrow(&Compare2, NULL, HexString, 0);
StatementWalker += StrLen(StatementWalker) + 1;
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"oemerror");
Status = EFI_INVALID_PARAMETER;
}
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"oemerror");
Status = EFI_INVALID_PARAMETER;
}
} else {
//
// must be a raw string
//
ASSERT(Compare2 == NULL);
Compare2 = StrnCatGrow(&Compare2, NULL, StatementWalker, 0);
}
if (Compare1 != NULL && Compare2 != NULL && BinOp != OPERATOR_MAX) {
OperationResult = TestOperation(Compare1, Compare2, BinOp, CaseInsensitive, ForceStringCompare);
}
SHELL_FREE_NON_NULL(Compare1);
SHELL_FREE_NON_NULL(Compare2);
}
//
// done processing do result...
//
if (!EFI_ERROR(Status)) {
if (NotPresent) {
OperationResult = (BOOLEAN)(!OperationResult);
}
switch(OperatorToUse) {
case END_TAG_OR:
*PassingState = (BOOLEAN)(*PassingState || OperationResult);
break;
case END_TAG_AND:
*PassingState = (BOOLEAN)(*PassingState && OperationResult);
break;
case END_TAG_MAX:
*PassingState = (BOOLEAN)(OperationResult);
break;
default:
ASSERT(FALSE);
}
}
return (Status);
}
BOOLEAN
EFIAPI
BuildNextStatement (
IN UINTN ParameterNumber,
OUT UINTN *EndParameter,
OUT END_TAG_TYPE *EndTag
)
{
CHAR16 *Buffer;
UINTN BufferSize;
*EndTag = END_TAG_MAX;
for(Buffer = NULL, BufferSize = 0
; ParameterNumber < gEfiShellParametersProtocol->Argc
; ParameterNumber++
) {
if (gUnicodeCollation->StriColl(
gUnicodeCollation,
gEfiShellParametersProtocol->Argv[ParameterNumber],
L"or") == 0) {
*EndParameter = ParameterNumber - 1;
*EndTag = END_TAG_OR;
break;
} else if (gUnicodeCollation->StriColl(
gUnicodeCollation,
gEfiShellParametersProtocol->Argv[ParameterNumber],
L"and") == 0) {
*EndParameter = ParameterNumber - 1;
*EndTag = END_TAG_AND;
break;
} else if (gUnicodeCollation->StriColl(
gUnicodeCollation,
gEfiShellParametersProtocol->Argv[ParameterNumber],
L"then") == 0) {
*EndParameter = ParameterNumber - 1;
*EndTag = END_TAG_THEN;
break;
}
}
if (*EndTag == END_TAG_MAX) {
return (FALSE);
}
return (TRUE);
}
BOOLEAN
EFIAPI
MoveToTagSpecial (
IN SCRIPT_FILE *ScriptFile
)
{
SCRIPT_COMMAND_LIST *CommandNode;
BOOLEAN Found;
UINTN TargetCount;
CHAR16 *CommandName;
CHAR16 *CommandWalker;
CHAR16 *TempLocation;
TargetCount = 1;
Found = FALSE;
if (ScriptFile == NULL) {
return FALSE;
}
for (CommandNode = (SCRIPT_COMMAND_LIST *)GetNextNode(&ScriptFile->CommandList, &ScriptFile->CurrentCommand->Link), Found = FALSE
; !IsNull(&ScriptFile->CommandList, &CommandNode->Link) && !Found
; CommandNode = (SCRIPT_COMMAND_LIST *)GetNextNode(&ScriptFile->CommandList, &CommandNode->Link)
){
//
// get just the first part of the command line...
//
CommandName = NULL;
CommandName = StrnCatGrow(&CommandName, NULL, CommandNode->Cl, 0);
CommandWalker = CommandName;
while (CommandWalker[0] == L' ') {
CommandWalker++;
}
TempLocation = StrStr(CommandWalker, L" ");
if (TempLocation != NULL) {
*TempLocation = CHAR_NULL;
}
//
// did we find a nested item ?
//
if (gUnicodeCollation->StriColl(
gUnicodeCollation,
(CHAR16*)CommandWalker,
L"If") == 0) {
TargetCount++;
} else if (TargetCount == 1 && gUnicodeCollation->StriColl(
gUnicodeCollation,
(CHAR16*)CommandWalker,
(CHAR16*)L"else") == 0) {
//
// else can only decrement the last part... not an nested if
// hence the TargetCount compare added
//
TargetCount--;
} else if (gUnicodeCollation->StriColl(
gUnicodeCollation,
(CHAR16*)CommandWalker,
(CHAR16*)L"endif") == 0) {
TargetCount--;
}
if (TargetCount == 0) {
ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)GetNextNode(&ScriptFile->CommandList, &CommandNode->Link);
Found = TRUE;
}
//
// Free the memory for this loop...
//
SHELL_FREE_NON_NULL(CommandName);
}
return (Found);
}
EFI_STATUS
EFIAPI
PerformResultOperation (
IN CONST BOOLEAN Result
)
{
if (Result || MoveToTagSpecial(ShellCommandGetCurrentScriptFile())) {
return (EFI_SUCCESS);
}
return (EFI_NOT_FOUND);
}
/**
Function for 'if' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunIf (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
SHELL_STATUS ShellStatus;
BOOLEAN CaseInsensitive;
BOOLEAN ForceString;
UINTN CurrentParameter;
UINTN EndParameter;
BOOLEAN CurrentValue;
END_TAG_TYPE Ending;
END_TAG_TYPE PreviousEnding;
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
if (!gEfiShellProtocol->BatchIsActive()) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"If");
return (SHELL_UNSUPPORTED);
}
if (gEfiShellParametersProtocol->Argc < 3) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle);
return (SHELL_INVALID_PARAMETER);
}
//
// Make sure that an End exists.
//
if (!MoveToTag(GetNextNode, L"endif", L"if", NULL, ShellCommandGetCurrentScriptFile(), TRUE, TRUE, FALSE)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"EnfIf", L"If", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
return (SHELL_DEVICE_ERROR);
}
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
CurrentParameter = 1;
EndParameter = 0;
if (gUnicodeCollation->StriColl(
gUnicodeCollation,
gEfiShellParametersProtocol->Argv[1],
L"/i") == 0 ||
gUnicodeCollation->StriColl(
gUnicodeCollation,
gEfiShellParametersProtocol->Argv[2],
L"/i") == 0 ||
(gEfiShellParametersProtocol->Argc > 3 && gUnicodeCollation->StriColl(
gUnicodeCollation,
gEfiShellParametersProtocol->Argv[3],
L"/i") == 0)) {
CaseInsensitive = TRUE;
CurrentParameter++;
} else {
CaseInsensitive = FALSE;
}
if (gUnicodeCollation->StriColl(
gUnicodeCollation,
gEfiShellParametersProtocol->Argv[1],
L"/s") == 0 ||
gUnicodeCollation->StriColl(
gUnicodeCollation,
gEfiShellParametersProtocol->Argv[2],
L"/s") == 0 ||
(gEfiShellParametersProtocol->Argc > 3 && gUnicodeCollation->StriColl(
gUnicodeCollation,
gEfiShellParametersProtocol->Argv[3],
L"/s") == 0)) {
ForceString = TRUE;
CurrentParameter++;
} else {
ForceString = FALSE;
}
for ( ShellStatus = SHELL_SUCCESS, CurrentValue = FALSE, Ending = END_TAG_MAX
; CurrentParameter < gEfiShellParametersProtocol->Argc && ShellStatus == SHELL_SUCCESS
; CurrentParameter++) {
if (gUnicodeCollation->StriColl(
gUnicodeCollation,
gEfiShellParametersProtocol->Argv[CurrentParameter],
L"then") == 0) {
//
// we are at the then
//
if (CurrentParameter+1 != gEfiShellParametersProtocol->Argc) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TEXT_AFTER_THEN), gShellLevel1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
Status = PerformResultOperation(CurrentValue);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_AFTER_BAD), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[CurrentParameter]);
ShellStatus = SHELL_INVALID_PARAMETER;
}
}
} else {
PreviousEnding = Ending;
//
// build up the next statement for analysis
//
if (!BuildNextStatement(CurrentParameter, &EndParameter, &Ending)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"Then", L"If", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// Analyze the statement
//
Status = ProcessStatement(&CurrentValue, CurrentParameter, EndParameter, PreviousEnding, CaseInsensitive, ForceString);
if (EFI_ERROR(Status)) {
// ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_STARTING), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[CurrentParameter]);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// Optomize to get out of the loop early...
//
if ((Ending == END_TAG_OR && CurrentValue) || (Ending == END_TAG_AND && !CurrentValue)) {
Status = PerformResultOperation(CurrentValue);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_AFTER_BAD), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[CurrentParameter]);
ShellStatus = SHELL_INVALID_PARAMETER;
}
break;
}
}
}
if (ShellStatus == SHELL_SUCCESS){
CurrentParameter = EndParameter;
//
// Skip over the or or and parameter.
//
if (Ending == END_TAG_OR || Ending == END_TAG_AND) {
CurrentParameter++;
}
}
}
}
return (ShellStatus);
}
/**
Function for 'else' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunElse (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
ASSERT_EFI_ERROR(CommandInit());
if (gEfiShellParametersProtocol->Argc > 1) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle);
return (SHELL_INVALID_PARAMETER);
}
if (!gEfiShellProtocol->BatchIsActive()) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"Else");
return (SHELL_UNSUPPORTED);
}
if (!MoveToTag(GetPreviousNode, L"if", L"endif", NULL, ShellCommandGetCurrentScriptFile(), FALSE, TRUE, FALSE)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"If", L"Else", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
return (SHELL_DEVICE_ERROR);
}
if (!MoveToTag(GetPreviousNode, L"if", L"else", NULL, ShellCommandGetCurrentScriptFile(), FALSE, TRUE, FALSE)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"If", L"Else", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
return (SHELL_DEVICE_ERROR);
}
if (!MoveToTag(GetNextNode, L"endif", L"if", NULL, ShellCommandGetCurrentScriptFile(), FALSE, FALSE, FALSE)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"EndIf", "Else", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
return (SHELL_DEVICE_ERROR);
}
return (SHELL_SUCCESS);
}
/**
Function for 'endif' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunEndIf (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
ASSERT_EFI_ERROR(CommandInit());
if (gEfiShellParametersProtocol->Argc > 1) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle);
return (SHELL_INVALID_PARAMETER);
}
if (!gEfiShellProtocol->BatchIsActive()) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"Endif");
return (SHELL_UNSUPPORTED);
}
if (!MoveToTag(GetPreviousNode, L"if", L"endif", NULL, ShellCommandGetCurrentScriptFile(), FALSE, TRUE, FALSE)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"If", L"EndIf", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);
return (SHELL_DEVICE_ERROR);
}
return (SHELL_SUCCESS);
}

View File

@ -0,0 +1,40 @@
/** @file
Main file for else and endif shell level 1 functions. Does nothing really...
Copyright (c) 2009-2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellLevel1CommandsLib.h"
SHELL_STATUS
EFIAPI
ShellCommandRunNoOpScriptCommand (
VOID *RESERVED
)
{
EFI_STATUS Status;
//
// ASSERT that we can init...
//
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
//
// We best be in a script...
//
ASSERT(gEfiShellProtocol->BatchIsActive());
//
// Do nothing...
//
return (SHELL_SUCCESS);
}

View File

@ -0,0 +1,63 @@
/** @file
Main file for Shift shell level 1 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellLevel1CommandsLib.h"
/**
Function for 'shift' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunShift (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
SCRIPT_FILE *CurrentScriptFile;
UINTN LoopVar;
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
if (!gEfiShellProtocol->BatchIsActive()) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"Shift");
return (SHELL_UNSUPPORTED);
}
CurrentScriptFile = ShellCommandGetCurrentScriptFile();
ASSERT(CurrentScriptFile != NULL);
if (CurrentScriptFile->Argc < 2) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle);
return (SHELL_UNSUPPORTED);
}
for (LoopVar = 0 ; LoopVar < CurrentScriptFile->Argc ; LoopVar++) {
if (LoopVar == 0) {
SHELL_FREE_NON_NULL(CurrentScriptFile->Argv[LoopVar]);
}
if (LoopVar < CurrentScriptFile->Argc -1) {
CurrentScriptFile->Argv[LoopVar] = CurrentScriptFile->Argv[LoopVar+1];
} else {
CurrentScriptFile->Argv[LoopVar] = NULL;
}
}
CurrentScriptFile->Argc--;
return (SHELL_SUCCESS);
}

View File

@ -0,0 +1,251 @@
/** @file
Main file for NULL named library for level 1 shell command functions.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellLevel1CommandsLib.h"
STATIC CONST CHAR16 mFileName[] = L"ShellCommands";
EFI_HANDLE gShellLevel1HiiHandle = NULL;
CONST EFI_GUID gShellLevel1HiiGuid = \
{ \
0xdec5daa4, 0x6781, 0x4820, { 0x9c, 0x63, 0xa7, 0xb0, 0xe4, 0xf1, 0xdb, 0x31 }
};
CONST CHAR16*
EFIAPI
ShellCommandGetManFileNameLevel1 (
VOID
)
{
return (mFileName);
}
/**
Constructor for the Shell Level 1 Commands library.
Install the handlers for level 1 UEFI Shell 2.0 commands.
@param ImageHandle the image handle of the process
@param SystemTable the EFI System Table pointer
@retval EFI_SUCCESS the shell command handlers were installed sucessfully
@retval EFI_UNSUPPORTED the shell level required was not found.
**/
EFI_STATUS
EFIAPI
ShellLevel1CommandsLibConstructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
//
// if shell level is less than 2 do nothing
//
if (PcdGet8(PcdShellSupportLevel) < 1) {
return (EFI_UNSUPPORTED);
}
gShellLevel1HiiHandle = HiiAddPackages (&gShellLevel1HiiGuid, gImageHandle, UefiShellLevel1CommandsLibStrings, NULL);
if (gShellLevel1HiiHandle == NULL) {
return (EFI_DEVICE_ERROR);
}
//
// install our shell command handlers that are always installed
//
ShellCommandRegisterCommandName(L"for", ShellCommandRunFor , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_FOR) ));
ShellCommandRegisterCommandName(L"goto", ShellCommandRunGoto , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_GOTO) ));
ShellCommandRegisterCommandName(L"if", ShellCommandRunIf , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_IF) ));
ShellCommandRegisterCommandName(L"shift", ShellCommandRunShift , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_SHIFT) ));
ShellCommandRegisterCommandName(L"exit", ShellCommandRunExit , ShellCommandGetManFileNameLevel1, 1, L"", TRUE , gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_EXIT) ));
ShellCommandRegisterCommandName(L"else", ShellCommandRunElse , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ELSE) ));
ShellCommandRegisterCommandName(L"endif", ShellCommandRunEndIf , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ENDIF) ));
ShellCommandRegisterCommandName(L"endfor", ShellCommandRunEndFor , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ENDFOR)));
return (EFI_SUCCESS);
}
/**
Destructor for the library. free any resources.
**/
EFI_STATUS
EFIAPI
ShellLevel1CommandsLibDestructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
if (gShellLevel1HiiHandle != NULL) {
HiiRemovePackages(gShellLevel1HiiHandle);
}
return (EFI_SUCCESS);
}
BOOLEAN
EFIAPI
TestNodeForMove (
IN CONST LIST_MANIP_FUNC Function,
IN CONST CHAR16 *DecrementerTag,
IN CONST CHAR16 *IncrementerTag,
IN CONST CHAR16 *Label OPTIONAL,
IN SCRIPT_FILE *ScriptFile,
IN CONST BOOLEAN MovePast,
IN CONST BOOLEAN FindOnly,
IN CONST SCRIPT_COMMAND_LIST *CommandNode,
IN UINTN *TargetCount
)
{
BOOLEAN Found;
CHAR16 *CommandName;
CHAR16 *CommandNameWalker;
CHAR16 *TempLocation;
Found = FALSE;
//
// get just the first part of the command line...
//
CommandName = NULL;
CommandName = StrnCatGrow(&CommandName, NULL, CommandNode->Cl, 0);
CommandNameWalker = CommandName;
while(CommandNameWalker[0] == L' ') {
CommandNameWalker++;
}
TempLocation = StrStr(CommandNameWalker, L" ");
if (TempLocation != NULL) {
*TempLocation = CHAR_NULL;
}
//
// did we find a nested item ?
//
if (gUnicodeCollation->StriColl(
gUnicodeCollation,
(CHAR16*)CommandNameWalker,
(CHAR16*)IncrementerTag) == 0) {
(*TargetCount)++;
} else if (gUnicodeCollation->StriColl(
gUnicodeCollation,
(CHAR16*)CommandNameWalker,
(CHAR16*)DecrementerTag) == 0) {
if (*TargetCount > 0) {
(*TargetCount)--;
}
}
//
// did we find the matching one...
//
if (Label == NULL) {
if (*TargetCount == 0) {
Found = TRUE;
if (!FindOnly) {
if (MovePast) {
ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)(*Function)(&ScriptFile->CommandList, &CommandNode->Link);
} else {
ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)CommandNode;
}
}
}
} else {
if (gUnicodeCollation->StriColl(
gUnicodeCollation,
(CHAR16*)CommandNameWalker,
(CHAR16*)Label) == 0
&& (*TargetCount) == 0) {
Found = TRUE;
if (!FindOnly) {
//
// we found the target label without loops
//
if (MovePast) {
ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)(*Function)(&ScriptFile->CommandList, &CommandNode->Link);
} else {
ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)CommandNode;
}
}
}
}
//
// Free the memory for this loop...
//
FreePool(CommandName);
return (Found);
}
BOOLEAN
EFIAPI
MoveToTag (
IN CONST LIST_MANIP_FUNC Function,
IN CONST CHAR16 *DecrementerTag,
IN CONST CHAR16 *IncrementerTag,
IN CONST CHAR16 *Label OPTIONAL,
IN SCRIPT_FILE *ScriptFile,
IN CONST BOOLEAN MovePast,
IN CONST BOOLEAN FindOnly,
IN CONST BOOLEAN WrapAroundScript
)
{
SCRIPT_COMMAND_LIST *CommandNode;
BOOLEAN Found;
UINTN TargetCount;
if (Label == NULL) {
TargetCount = 1;
} else {
TargetCount = 0;
}
if (ScriptFile == NULL) {
return FALSE;
}
for (CommandNode = (SCRIPT_COMMAND_LIST *)(*Function)(&ScriptFile->CommandList, &ScriptFile->CurrentCommand->Link), Found = FALSE
; !IsNull(&ScriptFile->CommandList, &CommandNode->Link)&& !Found
; CommandNode = (SCRIPT_COMMAND_LIST *)(*Function)(&ScriptFile->CommandList, &CommandNode->Link)
){
Found = TestNodeForMove(
Function,
DecrementerTag,
IncrementerTag,
Label,
ScriptFile,
MovePast,
FindOnly,
CommandNode,
&TargetCount);
}
if (WrapAroundScript && !Found) {
for (CommandNode = (SCRIPT_COMMAND_LIST *)GetFirstNode(&ScriptFile->CommandList), Found = FALSE
; CommandNode != ScriptFile->CurrentCommand && !Found
; CommandNode = (SCRIPT_COMMAND_LIST *)(*Function)(&ScriptFile->CommandList, &CommandNode->Link)
){
Found = TestNodeForMove(
Function,
DecrementerTag,
IncrementerTag,
Label,
ScriptFile,
MovePast,
FindOnly,
CommandNode,
&TargetCount);
}
}
return (Found);
}

View File

@ -0,0 +1,182 @@
/** @file
Main file for NULL named library for level 1 shell command functions.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 <ShellBase.h>
#include <Protocol/EfiShell.h>
#include <Protocol/EfiShellParameters.h>
#include <Protocol/DevicePath.h>
#include <Protocol/LoadedImage.h>
#include <Protocol/UnicodeCollation.h>
#include <Protocol/DevicePathToText.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
#include <Library/ShellCommandLib.h>
#include <Library/ShellLib.h>
#include <Library/SortLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/HiiLib.h>
#include <Library/FileHandleLib.h>
extern EFI_HANDLE gShellLevel1HiiHandle;
extern CONST EFI_GUID gShellLevel1HiiGuid;
/**
Function for 'exit' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunExit (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'endif' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunEndIf (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'for' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunFor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'endfor' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunEndFor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'if' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunIf (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'goto' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunGoto (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'shift' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunShift (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'else' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunElse (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
///
/// Function prototype for BOTH GetNextNode and GetPreviousNode...
/// This is used to control the MoveToTag function direction...
///
typedef
LIST_ENTRY *
(EFIAPI *LIST_MANIP_FUNC)(
IN CONST LIST_ENTRY *List,
IN CONST LIST_ENTRY *Node
);
/**
Function to move to a spacified tag in a script file structure.
@param[in] Function The pointer to the function to move with.
@param[in] DecrementerTag The pointer to a string to decrement upon finding.
@param[in] IncrementerTag The pointer to a string to increment upon finding.
@param[in] Label A Label to look for.
@param[in] ScriptFile The script file structure to look in.
@param[in] MovePast TRUE to go to the element just after the found one. FALSE otherwise.
@param[in] FindOnly FALSE to change the execution point in the script file structure. TRUE otherwise.
@param[in] WrapAroundScript TRUE to go to begining when end is hit, or vise versa. FALSE otherwise.
**/
BOOLEAN
EFIAPI
MoveToTag (
IN CONST LIST_MANIP_FUNC Function,
IN CONST CHAR16 *DecrementerTag,
IN CONST CHAR16 *IncrementerTag,
IN CONST CHAR16 *Label OPTIONAL,
IN SCRIPT_FILE *ScriptFile,
IN CONST BOOLEAN MovePast,
IN CONST BOOLEAN FindOnly,
IN CONST BOOLEAN WrapAroundScript
);

View File

@ -0,0 +1,54 @@
## @file
# Provides shell level 1 functions
#
# Copyright (c) 2009-2010, Intel Corporation. All rights reserved. <BR>
#
# 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 = UefiShellLevel1CommandsLib
FILE_GUID = 50cb6037-1102-47af-b2dd-9944b6eb1abe
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = NULL|UEFI_APPLICATION UEFI_DRIVER
CONSTRUCTOR = ShellLevel1CommandsLibConstructor
DESTRUCTOR = ShellLevel1CommandsLibDestructor
[Sources.common]
UefiShellLevel1CommandsLib.c
UefiShellLevel1CommandsLib.h
UefiShellLevel1CommandsLib.uni
Exit.c
Goto.c
If.c
For.c
Shift.c
[Packages]
MdePkg/MdePkg.dec
ShellPkg/ShellPkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
MemoryAllocationLib
BaseLib
BaseMemoryLib
DebugLib
ShellCommandLib
ShellLib
UefiLib
UefiRuntimeServicesTableLib
UefiBootServicesTableLib
SortLib
PrintLib
[Pcd.common]
gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel # ALWAYS_CONSUMED

View File

@ -0,0 +1,271 @@
/** @file
Main file for attrib shell level 2 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellLevel2CommandsLib.h"
STATIC CONST CHAR16 AllFiles[] = L"*";
STATIC CONST SHELL_PARAM_ITEM AttribParamList[] = {
{L"-a", TypeFlag},
{L"+a", TypeFlag},
{L"-s", TypeFlag},
{L"+s", TypeFlag},
{L"-h", TypeFlag},
{L"+h", TypeFlag},
{L"-r", TypeFlag},
{L"+r", TypeFlag},
{NULL, TypeMax}
};
/**
Function for 'attrib' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunAttrib (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
UINT64 FileAttributesToAdd;
UINT64 FileAttributesToRemove;
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
UINTN ParamNumberCount;
CONST CHAR16 *FileName;
EFI_SHELL_FILE_INFO *ListOfFiles;
EFI_SHELL_FILE_INFO *FileNode;
EFI_FILE_INFO *FileInfo;
ListOfFiles = NULL;
ShellStatus = SHELL_SUCCESS;
ProblemParam = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (AttribParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
} else {
FileAttributesToAdd = 0;
FileAttributesToRemove = 0;
//
// apply or remove each flag
//
if (ShellCommandLineGetFlag(Package, L"+a")) {
FileAttributesToAdd |= EFI_FILE_ARCHIVE;
}
if (ShellCommandLineGetFlag(Package, L"-a")) {
FileAttributesToRemove |= EFI_FILE_ARCHIVE;
}
if (ShellCommandLineGetFlag(Package, L"+s")) {
FileAttributesToAdd |= EFI_FILE_SYSTEM;
}
if (ShellCommandLineGetFlag(Package, L"-s")) {
FileAttributesToRemove |= EFI_FILE_SYSTEM;
}
if (ShellCommandLineGetFlag(Package, L"+h")) {
FileAttributesToAdd |= EFI_FILE_HIDDEN;
}
if (ShellCommandLineGetFlag(Package, L"-h")) {
FileAttributesToRemove |= EFI_FILE_HIDDEN;
}
if (ShellCommandLineGetFlag(Package, L"+r")) {
FileAttributesToAdd |= EFI_FILE_READ_ONLY;
}
if (ShellCommandLineGetFlag(Package, L"-r")) {
FileAttributesToRemove |= EFI_FILE_READ_ONLY;
}
if (FileAttributesToRemove == 0 && FileAttributesToAdd == 0) {
//
// Do display as we have no attributes to change
//
for ( ParamNumberCount = 1
;
; ParamNumberCount++
){
FileName = ShellCommandLineGetRawValue(Package, ParamNumberCount);
// if we dont have anything left, move on...
if (FileName == NULL && ParamNumberCount == 1) {
FileName = (CHAR16*)AllFiles;
} else if (FileName == NULL) {
break;
}
ASSERT(ListOfFiles == NULL);
Status = ShellOpenFileMetaArg((CHAR16*)FileName, EFI_FILE_MODE_READ, &ListOfFiles);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamNumberCount));
ShellStatus = SHELL_NOT_FOUND;
} else {
for (FileNode = (EFI_SHELL_FILE_INFO*)GetFirstNode(&ListOfFiles->Link)
; !IsNull(&ListOfFiles->Link, &FileNode->Link)
; FileNode = (EFI_SHELL_FILE_INFO*)GetNextNode(&ListOfFiles->Link, &FileNode->Link)
){
ShellPrintHiiEx(
-1,
-1,
NULL,
STRING_TOKEN (STR_ATTRIB_OUTPUT_LINE),
gShellLevel2HiiHandle,
FileNode->Info->Attribute&EFI_FILE_DIRECTORY? L'D':L' ',
FileNode->Info->Attribute&EFI_FILE_ARCHIVE? L'A':L' ',
FileNode->Info->Attribute&EFI_FILE_SYSTEM? L'S':L' ',
FileNode->Info->Attribute&EFI_FILE_HIDDEN? L'H':L' ',
FileNode->Info->Attribute&EFI_FILE_READ_ONLY? L'R':L' ',
FileNode->FileName
);
}
Status = ShellCloseFileMetaArg(&ListOfFiles);
ListOfFiles = NULL;
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_CLOSE_FAIL), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamNumberCount));
ShellStatus = SHELL_NOT_FOUND;
}
} // for loop for handling wildcard filenames
} // for loop for printing out the info
} else if ((FileAttributesToRemove & FileAttributesToAdd) != 0) {
//
// fail as we have conflcting params.
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// enumerate through all the files/directories and apply the attributes
//
for ( ParamNumberCount = 1
;
; ParamNumberCount++
){
FileName = ShellCommandLineGetRawValue(Package, ParamNumberCount);
// if we dont have anything left, move on...
if (FileName == NULL) {
//
// make sure we are not failing on the first one we do... if yes that's an error...
//
if (ParamNumberCount == 1) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
}
break;
}
//
// OpenFileByName / GetFileInfo / Change attributes / SetFileInfo / CloseFile / free memory
// for each file or directory on the line.
//
//
// Open the file(s)
//
ASSERT(ListOfFiles == NULL);
Status = ShellOpenFileMetaArg((CHAR16*)FileName, EFI_FILE_MODE_READ, &ListOfFiles);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamNumberCount));
ShellStatus = SHELL_NOT_FOUND;
} else {
for (FileNode = (EFI_SHELL_FILE_INFO*)GetFirstNode(&ListOfFiles->Link)
; !IsNull(&ListOfFiles->Link, &FileNode->Link)
; FileNode = (EFI_SHELL_FILE_INFO*)GetNextNode(&ListOfFiles->Link, &FileNode->Link)
){
//
// skip the directory traversing stuff...
//
if (StrCmp(FileNode->FileName, L".") == 0 || StrCmp(FileNode->FileName, L"..") == 0) {
continue;
}
FileInfo = gEfiShellProtocol->GetFileInfo(FileNode->Handle);
//
// if we are removing Read-Only we need to do that alone
//
if ((FileAttributesToRemove & EFI_FILE_READ_ONLY) == EFI_FILE_READ_ONLY) {
FileInfo->Attribute &= ~EFI_FILE_READ_ONLY;
//
// SetFileInfo
//
Status = ShellSetFileInfo(FileNode->Handle, FileInfo);
if (EFI_ERROR(Status)) {;
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_AD), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamNumberCount));
ShellStatus = SHELL_ACCESS_DENIED;
}
}
//
// change the attribute
//
FileInfo->Attribute &= ~FileAttributesToRemove;
FileInfo->Attribute |= FileAttributesToAdd;
//
// SetFileInfo
//
Status = ShellSetFileInfo(FileNode->Handle, FileInfo);
if (EFI_ERROR(Status)) {;
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_AD), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamNumberCount));
ShellStatus = SHELL_ACCESS_DENIED;
}
SHELL_FREE_NON_NULL(FileInfo);
}
Status = ShellCloseFileMetaArg(&ListOfFiles);
ListOfFiles = NULL;
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_CLOSE_FAIL), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamNumberCount));
ShellStatus = SHELL_NOT_FOUND;
}
} // for loop for handling wildcard filenames
}
}
}
}
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
//
// return the status
//
return (ShellStatus);
}

View File

@ -0,0 +1,218 @@
/** @file
Main file for attrib shell level 2 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellLevel2CommandsLib.h"
/**
Function for 'cd' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunCd (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CONST CHAR16 *Directory;
CHAR16 *Path;
CHAR16 *Drive;
UINTN DriveSize;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
SHELL_FILE_HANDLE Handle;
CONST CHAR16 *Param1;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
Drive = NULL;
DriveSize = 0;
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
}
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
} else if (ShellCommandLineGetRawValue(Package, 2) != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// remember that param 0 is the command name
// If there are 0 value parameters, then print the current directory
// else If there are 2 value parameters, then print the error message
// else If there is 1 value paramerer , then change the directory
//
Param1 = ShellCommandLineGetRawValue(Package, 1);
if (Param1 == NULL) {
//
// display the current directory
//
Directory = ShellGetCurrentDir(NULL);
if (Directory != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_PRINT), gShellLevel2HiiHandle, Directory);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
ShellStatus = SHELL_NOT_FOUND;
}
} else {
if (StrCmp(Param1, L".") == 0) {
//
// nothing to do... change to current directory
//
} else if (StrCmp(Param1, L"..") == 0) {
//
// Change up one directory...
//
Directory = ShellGetCurrentDir(NULL);
if (Directory == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
ShellStatus = SHELL_NOT_FOUND;
} else {
Drive = GetFullyQualifiedPath(Directory);
ChopLastSlash(Drive);
}
if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {
//
// change directory on current drive letter
//
Status = gEfiShellProtocol->SetCurDir(NULL, Drive);
if (Status == EFI_NOT_FOUND) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);
ShellStatus = SHELL_NOT_FOUND;
}
}
} else if (StrCmp(Param1, L"\\") == 0) {
//
// Move to root of current drive
//
Directory = ShellGetCurrentDir(NULL);
if (Directory == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
ShellStatus = SHELL_NOT_FOUND;
} else {
Drive = GetFullyQualifiedPath(Directory);
while (ChopLastSlash(Drive)) ;
}
if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {
//
// change directory on current drive letter
//
Status = gEfiShellProtocol->SetCurDir(NULL, Drive);
if (Status == EFI_NOT_FOUND) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);
ShellStatus = SHELL_NOT_FOUND;
}
}
} else if (StrStr(Param1, L":") == NULL) {
if (ShellGetCurrentDir(NULL) == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
ShellStatus = SHELL_NOT_FOUND;
} else {
ASSERT((Drive == NULL && DriveSize == 0) || (Drive != NULL));
Drive = StrnCatGrow(&Drive, &DriveSize, ShellGetCurrentDir(NULL), 0);
if (*Param1 == L'\\') {
while (ChopLastSlash(Drive)) ;
Drive = StrnCatGrow(&Drive, &DriveSize, Param1+1, 0);
} else {
Drive = StrnCatGrow(&Drive, &DriveSize, Param1, 0);
}
//
// Verify that this is a valid directory
//
Status = gEfiShellProtocol->OpenFileByName(Drive, &Handle, EFI_FILE_MODE_READ);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Drive);
ShellStatus = SHELL_NOT_FOUND;
} else if (EFI_ERROR(FileHandleIsDirectory(Handle))) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, Drive);
ShellStatus = SHELL_NOT_FOUND;
}
if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {
//
// change directory on current drive letter
//
Status = gEfiShellProtocol->SetCurDir(NULL, Drive);
if (Status == EFI_NOT_FOUND) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);
ShellStatus = SHELL_NOT_FOUND;
}
}
if (Handle != NULL) {
gEfiShellProtocol->CloseFile(Handle);
DEBUG_CODE(Handle = NULL;);
}
}
} else {
//
// change directory on other drive letter
//
Drive = AllocateZeroPool(StrSize(Param1));
Drive = StrCpy(Drive, Param1);
Path = StrStr(Drive, L":");
*(++Path) = CHAR_NULL;
Status = gEfiShellProtocol->SetCurDir(Drive, ++Path);
if (Status == EFI_NOT_FOUND) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);
Status = SHELL_NOT_FOUND;
} else if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Param1);
Status = SHELL_NOT_FOUND;
}
}
}
}
if (Drive != NULL) {
FreePool(Drive);
}
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
//
// return the status
//
return (ShellStatus);
}

View File

@ -0,0 +1,599 @@
/** @file
Main file for cp shell level 2 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellLevel2CommandsLib.h"
// this is later in the file.
SHELL_STATUS
EFIAPI
ValidateAndCopyFiles(
IN CONST EFI_SHELL_FILE_INFO *FileList,
IN CONST CHAR16 *DestDir,
IN BOOLEAN SilentMode,
IN BOOLEAN RecursiveMode,
IN VOID **Resp
);
/**
Function to Copy one file to another location
If the destination exists the user will be prompted and the result put into *resp
@param[in] Source pointer to source file name
@param[in] Dest pointer to destination file name
@param[out] Resp pointer to response from question. Pass back on looped calling
@param[in] SilentMode whether to run in quiet mode or not
@retval SHELL_SUCCESS The source file was copied to the destination
**/
SHELL_STATUS
EFIAPI
CopySingleFile(
IN CONST CHAR16 *Source,
IN CONST CHAR16 *Dest,
OUT VOID **Resp,
IN BOOLEAN SilentMode
)
{
VOID *Response;
UINTN ReadSize;
SHELL_FILE_HANDLE SourceHandle;
SHELL_FILE_HANDLE DestHandle;
EFI_STATUS Status;
VOID *Buffer;
CHAR16 *TempName;
UINTN Size;
EFI_SHELL_FILE_INFO *List;
SHELL_STATUS ShellStatus;
ASSERT(Resp != NULL);
SourceHandle = NULL;
DestHandle = NULL;
Response = *Resp;
List = NULL;
ReadSize = PcdGet16(PcdShellFileOperationSize);
// Why bother copying a file to itself
if (StrCmp(Source, Dest) == 0) {
return (SHELL_SUCCESS);
}
//
// Open destination file without create
//
Status = ShellOpenFileByName(Dest, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
//
// close file
//
if (DestHandle != NULL) {
ShellCloseFile(&DestHandle);
DestHandle = NULL;
}
//
// if the destination file existed check response and possibly prompt user
//
if (!EFI_ERROR(Status)) {
if (Response == NULL && !SilentMode) {
Status = ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_CP_PROMPT), gShellLevel2HiiHandle, &Response);
}
//
// possibly return based on response
//
if (!SilentMode) {
switch (*(SHELL_PROMPT_RESPONSE*)Response) {
case ShellPromptResponseNo:
//
// return success here so we dont stop the process
//
return (SHELL_SUCCESS);
case ShellPromptResponseCancel:
*Resp = Response;
//
// indicate to stop everything
//
return (SHELL_ABORTED);
case ShellPromptResponseAll:
*Resp = Response;
case ShellPromptResponseYes:
break;
}
}
}
if (ShellIsDirectory(Source) == EFI_SUCCESS) {
Status = ShellCreateDirectory(Dest, &DestHandle);
if (EFI_ERROR(Status)) {
return (SHELL_ACCESS_DENIED);
}
//
// Now copy all the files under the directory...
//
TempName = NULL;
Size = 0;
StrnCatGrow(&TempName, &Size, Source, 0);
StrnCatGrow(&TempName, &Size, L"\\*", 0);
ShellOpenFileMetaArg((CHAR16*)TempName, EFI_FILE_MODE_READ, &List);
TempName = NULL;
StrnCatGrow(&TempName, &Size, Dest, 0);
StrnCatGrow(&TempName, &Size, L"\\", 0);
ShellStatus = ValidateAndCopyFiles(List, TempName, SilentMode, TRUE, Resp);
ShellCloseFileMetaArg(&List);
FreePool(TempName);
Size = 0;
} else {
//
// open file with create enabled
//
Status = ShellOpenFileByName(Dest, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
if (EFI_ERROR(Status)) {
return (SHELL_ACCESS_DENIED);
}
//
// open source file
//
Status = ShellOpenFileByName(Source, &SourceHandle, EFI_FILE_MODE_READ, 0);
ASSERT_EFI_ERROR(Status);
//
// copy data between files
//
Buffer = AllocateZeroPool(ReadSize);
ASSERT(Buffer != NULL);
while (ReadSize == PcdGet16(PcdShellFileOperationSize) && !EFI_ERROR(Status)) {
Status = ShellReadFile(SourceHandle, &ReadSize, Buffer);
ASSERT_EFI_ERROR(Status);
Status = ShellWriteFile(DestHandle, &ReadSize, Buffer);
}
}
//
// close files
//
if (DestHandle != NULL) {
ShellCloseFile(&DestHandle);
DestHandle = NULL;
}
if (SourceHandle != NULL) {
ShellCloseFile(&SourceHandle);
SourceHandle = NULL;
}
//
// return
//
return (SHELL_SUCCESS);
}
/**
function to take a list of files to copy and a destination location and do
the verification and copying of those files to that location. This function
will report any errors to the user and halt.
The key is to have this function called ONLY once. this allows for the parameter
verification to happen correctly.
@param[in] FileList A LIST_ENTRY* based list of files to move
@param[in] DestDir the destination location
@retval SHELL_SUCCESS the files were all moved.
@retval SHELL_INVALID_PARAMETER a parameter was invalid
@retval SHELL_SECURITY_VIOLATION a security violation ocurred
@retval SHELL_WRITE_PROTECTED the destination was write protected
@retval SHELL_OUT_OF_RESOURCES a memory allocation failed
**/
SHELL_STATUS
EFIAPI
ValidateAndCopyFiles(
IN CONST EFI_SHELL_FILE_INFO *FileList,
IN CONST CHAR16 *DestDir,
IN BOOLEAN SilentMode,
IN BOOLEAN RecursiveMode,
IN VOID **Resp
)
{
CHAR16 *HiiOutput;
CHAR16 *HiiResultOk;
CONST EFI_SHELL_FILE_INFO *Node;
SHELL_STATUS ShellStatus;
CHAR16 *DestPath;
VOID *Response;
UINTN PathLen;
CONST CHAR16 *Cwd;
CONST CHAR16 *TempLocation;
UINTN NewSize;
if (Resp == NULL) {
Response = NULL;
} else {
Response = *Resp;
}
DestPath = NULL;
ShellStatus = SHELL_SUCCESS;
PathLen = 0;
Cwd = ShellGetCurrentDir(NULL);
ASSERT(FileList != NULL);
ASSERT(DestDir != NULL);
//
// If we are trying to copy multiple files... make sure we got a directory for the target...
//
if (EFI_ERROR(ShellIsDirectory(DestDir)) && FileList->Link.ForwardLink != FileList->Link.BackLink) {
//
// Error for destination not a directory
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, DestDir);
return (SHELL_INVALID_PARAMETER);
}
for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)
; !IsNull(&FileList->Link, &Node->Link)
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)
){
//
// skip the directory traversing stuff...
//
if (StrCmp(Node->FileName, L".") == 0 || StrCmp(Node->FileName, L"..") == 0) {
continue;
}
NewSize = StrSize(DestDir);
NewSize += StrSize(Node->FileName);
NewSize += StrSize(Cwd);
if (NewSize > PathLen) {
PathLen = NewSize;
}
//
// Make sure got -r if required
//
if (!RecursiveMode && !EFI_ERROR(ShellIsDirectory(Node->FullName))) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DIR_REQ), gShellLevel2HiiHandle);
return (SHELL_INVALID_PARAMETER);
}
//
// make sure got dest as dir if needed
//
if (!EFI_ERROR(ShellIsDirectory(Node->FullName)) && EFI_ERROR(ShellIsDirectory(DestDir))) {
//
// Error for destination not a directory
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, DestDir);
return (SHELL_INVALID_PARAMETER);
}
}
HiiOutput = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_CP_OUTPUT), NULL);
HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);
DestPath = AllocatePool(PathLen);
//
// Go through the list of files to copy...
//
for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)
; !IsNull(&FileList->Link, &Node->Link)
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)
){
if (ShellGetExecutionBreakFlag()) {
break;
}
ASSERT(Node->FileName != NULL);
ASSERT(Node->FullName != NULL);
//
// skip the directory traversing stuff...
//
if (StrCmp(Node->FileName, L".") == 0 || StrCmp(Node->FileName, L"..") == 0) {
continue;
}
if (FileList->Link.ForwardLink == FileList->Link.BackLink // 1 item
&& EFI_ERROR(ShellIsDirectory(DestDir)) // not an existing directory
) {
ASSERT(StrStr(DestDir, L":") == NULL);
//
// simple copy of a single file
//
StrCpy(DestPath, Cwd);
if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
StrCat(DestPath, L"\\");
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
}
StrCat(DestPath, DestDir);
} else {
//
// we have multiple files or a directory in the DestDir
//
if (StrStr(DestDir, L":") == NULL) {
StrCpy(DestPath, Cwd);
if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
StrCat(DestPath, L"\\");
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
}
StrCat(DestPath, DestDir);
if (DestDir[StrLen(DestDir)-1] != L'\\' && Node->FileName[0] != L'\\') {
StrCat(DestPath, L"\\");
} else if (DestDir[StrLen(DestDir)-1] == L'\\' && Node->FileName[0] == L'\\') {
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
}
StrCat(DestPath, Node->FileName);
} else {
StrCpy(DestPath, DestDir);
if (DestDir[StrLen(DestDir)-1] != L'\\' && Node->FileName[0] != L'\\') {
StrCat(DestPath, L"\\");
} else if (DestDir[StrLen(DestDir)-1] == L'\\' && Node->FileName[0] == L'\\') {
((CHAR16*)DestDir)[StrLen(DestDir)-1] = CHAR_NULL;
}
StrCat(DestPath, Node->FileName);
}
}
//
// Make sure the path exists
//
if (EFI_ERROR(VerifyIntermediateDirectories(DestPath))) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DIR_WNF), gShellLevel2HiiHandle);
ShellStatus = SHELL_DEVICE_ERROR;
break;
}
if ( !EFI_ERROR(ShellIsDirectory(Node->FullName))
&& !EFI_ERROR(ShellIsDirectory(DestPath))
&& StrniCmp(Node->FullName, DestPath, StrLen(DestPath)) == NULL
){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_PARENT), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
break;
}
if (StringNoCaseCompare(&Node->FullName, &DestPath) == 0) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_SAME), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
break;
}
if ((TempLocation = StrniCmp(Node->FullName, DestPath, StrLen(Node->FullName))) == 0
&& (DestPath[StrLen(Node->FullName)] == CHAR_NULL || DestPath[StrLen(Node->FullName)] == L'\\')
) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_SAME), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
break;
}
CleanPath(DestPath);
ShellPrintEx(-1, -1, HiiOutput, Node->FullName, DestPath);
//
// copy single file...
//
ShellStatus = CopySingleFile(Node->FullName, DestPath, &Response, SilentMode);
if (ShellStatus != SHELL_SUCCESS) {
break;
}
}
if (ShellStatus == SHELL_SUCCESS && Resp == NULL) {
ShellPrintEx(-1, -1, L"%s", HiiResultOk);
}
SHELL_FREE_NON_NULL(DestPath);
SHELL_FREE_NON_NULL(HiiOutput);
SHELL_FREE_NON_NULL(HiiResultOk);
if (Resp != NULL) {
SHELL_FREE_NON_NULL(Response);
}
return (ShellStatus);
}
SHELL_STATUS
EFIAPI
ProcessValidateAndCopyFiles(
IN EFI_SHELL_FILE_INFO *FileList,
IN CONST CHAR16 *DestDir,
IN BOOLEAN SilentMode,
IN BOOLEAN RecursiveMode
)
{
SHELL_STATUS ShellStatus;
EFI_SHELL_FILE_INFO *List;
EFI_STATUS Status;
EFI_FILE_INFO *FileInfo;
List = NULL;
Status = ShellOpenFileMetaArg((CHAR16*)DestDir, EFI_FILE_MODE_READ, &List);
if (List != NULL && List->Link.ForwardLink != List->Link.BackLink) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_MARG_ERROR), gShellLevel2HiiHandle, DestDir);
ShellStatus = SHELL_INVALID_PARAMETER;
ShellCloseFileMetaArg(&List);
} else if (List != NULL) {
ASSERT(List != NULL);
ASSERT(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink) != NULL);
ASSERT(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName != NULL);
FileInfo = NULL;
FileInfo = gEfiShellProtocol->GetFileInfo(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->Handle);
ASSERT(FileInfo != NULL);
if ((FileInfo->Attribute & EFI_FILE_READ_ONLY) == 0) {
ShellStatus = ValidateAndCopyFiles(FileList, ((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName, SilentMode, RecursiveMode, NULL);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_ERROR), gShellLevel2HiiHandle);
ShellStatus = SHELL_ACCESS_DENIED;
}
SHELL_FREE_NON_NULL(FileInfo);
ShellCloseFileMetaArg(&List);
} else {
ShellStatus = ValidateAndCopyFiles(FileList, DestDir, SilentMode, RecursiveMode, NULL);
}
return (ShellStatus);
}
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{L"-r", TypeFlag},
{L"-q", TypeFlag},
{NULL, TypeMax}
};
/**
Function for 'cp' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunCp (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
UINTN ParamCount;
UINTN LoopCounter;
EFI_SHELL_FILE_INFO *FileList;
BOOLEAN SilentMode;
BOOLEAN RecursiveMode;
CONST CHAR16 *Cwd;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
ParamCount = 0;
FileList = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
}
//
// Initialize SilentMode and RecursiveMode
//
if (gEfiShellProtocol->BatchIsActive()) {
SilentMode = TRUE;
} else {
SilentMode = ShellCommandLineGetFlag(Package, L"-q");
}
RecursiveMode = ShellCommandLineGetFlag(Package, L"-r");
switch (ParamCount = ShellCommandLineGetCount(Package)) {
case 0:
case 1:
//
// we have insufficient parameters
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
break;
case 2:
//
// must have valid CWD for single parameter...
//
Cwd = ShellGetCurrentDir(NULL);
if (Cwd == NULL){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, 1), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
if (FileList == NULL || IsListEmpty(&FileList->Link) || EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));
ShellStatus = SHELL_NOT_FOUND;
} else {
ShellStatus = ProcessValidateAndCopyFiles(FileList, Cwd, SilentMode, RecursiveMode);
}
}
break;
default:
//
// Make a big list of all the files...
//
for (ParamCount--, LoopCounter = 1 ; LoopCounter < ParamCount && ShellStatus == SHELL_SUCCESS ; LoopCounter++) {
if (ShellGetExecutionBreakFlag()) {
break;
}
Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, LoopCounter), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
if (EFI_ERROR(Status) || FileList == NULL || IsListEmpty(&FileList->Link)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));
ShellStatus = SHELL_NOT_FOUND;
}
}
//
// now copy them all...
//
if (FileList != NULL && !IsListEmpty(&FileList->Link)) {
ShellStatus = ProcessValidateAndCopyFiles(FileList, ShellCommandCleanPath((CHAR16*)ShellCommandLineGetRawValue(Package, ParamCount)), SilentMode, RecursiveMode);
Status = ShellCloseFileMetaArg(&FileList);
if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1), ShellStatus|MAX_BIT);
ShellStatus = SHELL_ACCESS_DENIED;
}
}
break;
} // switch on parameter count
if (FileList != NULL) {
ShellCloseFileMetaArg(&FileList);
}
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
}
if (ShellGetExecutionBreakFlag()) {
return (SHELL_ABORTED);
}
return (ShellStatus);
}

View File

@ -0,0 +1,282 @@
/** @file
Main file for attrib shell level 2 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellLevel2CommandsLib.h"
// This function was from from the BdsLib implementation in
// IntelFrameworkModulePkg\Library\GenericBdsLib\BdsConnect.c
// function name: BdsLibConnectAllEfi
/**
This function will connect all current system handles recursively. The
connection will finish until every handle's child handle created if it have.
@retval EFI_SUCCESS All handles and it's child handle have been
connected
@retval EFI_STATUS Return the status of gBS->LocateHandleBuffer().
**/
EFI_STATUS
EFIAPI
ConnectAllEfi (
VOID
)
{
EFI_STATUS Status;
UINTN HandleCount;
EFI_HANDLE *HandleBuffer;
UINTN Index;
Status = gBS->LocateHandleBuffer (
AllHandles,
NULL,
NULL,
&HandleCount,
&HandleBuffer
);
if (EFI_ERROR (Status)) {
return Status;
}
for (Index = 0; Index < HandleCount; Index++) {
Status = gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
}
if (HandleBuffer != NULL) {
FreePool (HandleBuffer);
}
return EFI_SUCCESS;
}
/**
function to load a .EFI driver into memory and possible connect the driver.
if FileName is NULL then ASSERT.
@param[in] FileName FileName of the driver to load
@param[in] Connect Whether to connect or not
@retval EFI_SUCCESS the driver was loaded and if Connect was
true then connect was attempted. Connection may
have failed.
@retval EFI_OUT_OF_RESOURCES there was insufficient memory
**/
EFI_STATUS
EFIAPI
LoadDriver(
IN CONST CHAR16 *FileName,
IN CONST BOOLEAN Connect
)
{
EFI_HANDLE LoadedDriverHandle;
EFI_STATUS Status;
EFI_DEVICE_PATH_PROTOCOL *Node;
EFI_DEVICE_PATH_PROTOCOL *FilePath;
EFI_LOADED_IMAGE_PROTOCOL *LoadedDriverImage;
LoadedDriverImage = NULL;
FilePath = NULL;
Node = NULL;
LoadedDriverHandle = NULL;
Status = EFI_SUCCESS;
ASSERT (FileName != NULL);
//
// Fix local copies of the protocol pointers
//
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
//
// Convert to DEVICE_PATH
//
FilePath = gEfiShellProtocol->GetDevicePathFromFilePath(FileName);
if (FilePath == NULL) {
ASSERT(FALSE);
return (EFI_INVALID_PARAMETER);
}
//
// Use LoadImage to get it into memory
//
Status = gBS->LoadImage(
FALSE,
gImageHandle,
FilePath,
NULL,
0,
&LoadedDriverHandle);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOAD_NOT_IMAGE), gShellLevel2HiiHandle, FileName, Status);
} else {
//
// Make sure it is a driver image
//
Status = gBS->HandleProtocol (LoadedDriverHandle, &gEfiLoadedImageProtocolGuid, (VOID *) &LoadedDriverImage);
ASSERT (LoadedDriverImage != NULL);
if ( EFI_ERROR(Status)
|| ( LoadedDriverImage->ImageCodeType != EfiBootServicesCode
&& LoadedDriverImage->ImageCodeType != EfiRuntimeServicesCode)
){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOAD_NOT_DRIVER), gShellLevel2HiiHandle, FileName);
//
// Exit and unload the non-driver image
//
gBS->Exit(LoadedDriverHandle, EFI_INVALID_PARAMETER, 0, NULL);
Status = EFI_INVALID_PARAMETER;
}
}
if (!EFI_ERROR(Status)) {
//
// Start the image
//
Status = gBS->StartImage(LoadedDriverHandle, NULL, NULL);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOAD_ERROR), gShellLevel2HiiHandle, FileName, Status);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOAD_LOADED), gShellLevel2HiiHandle, FileName, LoadedDriverImage->ImageBase, Status);
}
}
if (!EFI_ERROR(Status) && Connect) {
//
// Connect it...
//
Status = ConnectAllEfi();
}
//
// clean up memory...
//
if (FilePath != NULL) {
FreePool(FilePath);
}
return (Status);
}
STATIC CONST SHELL_PARAM_ITEM LoadParamList[] = {
{L"-nc", TypeFlag},
{NULL, TypeMax}
};
/**
Function for 'load' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunLoad (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
UINTN ParamCount;
EFI_SHELL_FILE_INFO *ListHead;
EFI_SHELL_FILE_INFO *Node;
ListHead = NULL;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (LoadParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
} else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
//
// we didnt get a single file to load parameter
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
for ( ParamCount = 1
; ShellCommandLineGetRawValue(Package, ParamCount) != NULL
; ParamCount++
){
Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, ParamCount), EFI_FILE_MODE_READ, &ListHead);
if (!EFI_ERROR(Status)) {
for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link)
; !IsNull(&ListHead->Link, &Node->Link)
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)
){
//
// once we have an error preserve that value, but finish the loop.
//
if (EFI_ERROR(Status)) {
LoadDriver(Node->FullName, ShellCommandLineGetFlag(Package, L"-nc"));
} else {
Status = LoadDriver(Node->FullName, ShellCommandLineGetFlag(Package, L"-nc"));
}
} // for loop for multi-open
if (EFI_ERROR(Status)) {
ShellCloseFileMetaArg(&ListHead);
} else {
Status = ShellCloseFileMetaArg(&ListHead);;
}
} else {
//
// no files found.
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, (CHAR16*)ShellCommandLineGetRawValue(Package, ParamCount));
ShellStatus = SHELL_NOT_FOUND;
}
} // for loop for params
}
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
}
if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) {
ShellStatus = SHELL_DEVICE_ERROR;
}
return (ShellStatus);
}

View File

@ -0,0 +1,564 @@
/** @file
Main file for ls shell level 2 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellLevel2CommandsLib.h"
#include <Guid/FileSystemInfo.h>
/**
print out the list of files and directories from the LS command
@param[in] Rec TRUE to automatically recurse into each found directory
FALSE to only list the specified directory.
@param[in] Attribs List of required Attribute for display.
If 0 then all non-system and non-hidden files will be printed.
@param[in] Sfo TRUE to use Standard Format Output, FALSE otherwise
@param[in] Path String with starting path.
@param[in] First TRUE for the original and FALSE for any recursion spawned instances.
@param[in] Count The count of bits enabled in Attribs.
@param[in] TimeZone The current time zone offset.
@retval SHELL_SUCCESS the printing was sucessful.
**/
SHELL_STATUS
EFIAPI
PrintLsOutput(
IN CONST BOOLEAN Rec,
IN CONST UINT64 Attribs,
IN CONST BOOLEAN Sfo,
IN CONST CHAR16 *Path,
IN CONST BOOLEAN First,
IN CONST UINTN Count,
IN CONST INT16 TimeZone
)
{
EFI_STATUS Status;
EFI_SHELL_FILE_INFO *ListHead;
EFI_SHELL_FILE_INFO *Node;
SHELL_STATUS ShellStatus;
UINT64 FileCount;
UINT64 DirCount;
UINT64 FileSize;
CHAR16 *DirectoryName;
UINTN LongestPath;
EFI_FILE_SYSTEM_INFO *SysInfo;
UINTN SysInfoSize;
SHELL_FILE_HANDLE ShellFileHandle;
CHAR16 *CorrectedPath;
EFI_FILE_PROTOCOL *EfiFpHandle;
FileCount = 0;
DirCount = 0;
FileSize = 0;
ListHead = NULL;
ShellStatus = SHELL_SUCCESS;
LongestPath = 0;
CorrectedPath = NULL;
CorrectedPath = StrnCatGrow(&CorrectedPath, NULL, Path, 0);
ASSERT(CorrectedPath != NULL);
ShellCommandCleanPath(CorrectedPath);
Status = ShellOpenFileMetaArg((CHAR16*)CorrectedPath, EFI_FILE_MODE_READ, &ListHead);
if (EFI_ERROR(Status)) {
return (SHELL_DEVICE_ERROR);
}
if (ListHead == NULL || IsListEmpty(&ListHead->Link)) {
//
// On the first one only we expect to find something...
// do we find the . and .. directories otherwise?
//
if (First) {
return (SHELL_NOT_FOUND);
}
return (SHELL_SUCCESS);
}
if (Sfo && First) {
//
// Get the first valid handle (directories)
//
for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link)
; !IsNull(&ListHead->Link, &Node->Link) && Node->Handle == NULL
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)
);
if (Node->Handle == NULL) {
DirectoryName = GetFullyQualifiedPath(((EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link))->FullName);
//
// We need to open something up to get system information
//
Status = gEfiShellProtocol->OpenFileByName(
DirectoryName,
&ShellFileHandle,
EFI_FILE_MODE_READ);
ASSERT_EFI_ERROR(Status);
FreePool(DirectoryName);
//
// Get the Volume Info from ShellFileHandle
//
SysInfo = NULL;
SysInfoSize = 0;
EfiFpHandle = ConvertShellHandleToEfiFileProtocol(ShellFileHandle);
Status = EfiFpHandle->GetInfo(
EfiFpHandle,
&gEfiFileSystemInfoGuid,
&SysInfoSize,
SysInfo);
if (Status == EFI_BUFFER_TOO_SMALL) {
SysInfo = AllocateZeroPool(SysInfoSize);
Status = EfiFpHandle->GetInfo(
EfiFpHandle,
&gEfiFileSystemInfoGuid,
&SysInfoSize,
SysInfo);
}
ASSERT_EFI_ERROR(Status);
gEfiShellProtocol->CloseFile(ShellFileHandle);
} else {
//
// Get the Volume Info from Node->Handle
//
SysInfo = NULL;
SysInfoSize = 0;
EfiFpHandle = ConvertShellHandleToEfiFileProtocol(Node->Handle);
Status = EfiFpHandle->GetInfo(
EfiFpHandle,
&gEfiFileSystemInfoGuid,
&SysInfoSize,
SysInfo);
if (Status == EFI_BUFFER_TOO_SMALL) {
SysInfo = AllocateZeroPool(SysInfoSize);
Status = EfiFpHandle->GetInfo(
EfiFpHandle,
&gEfiFileSystemInfoGuid,
&SysInfoSize,
SysInfo);
}
ASSERT_EFI_ERROR(Status);
}
ShellPrintHiiEx (
-1,
-1,
NULL,
STRING_TOKEN (STR_GEN_SFO_HEADER),
gShellLevel2HiiHandle,
L"ls");
//
// print VolumeInfo table
//
ASSERT(SysInfo != NULL);
ShellPrintHiiEx (
0,
gST->ConOut->Mode->CursorRow,
NULL,
STRING_TOKEN (STR_LS_SFO_VOLINFO),
gShellLevel2HiiHandle,
SysInfo->VolumeLabel,
SysInfo->VolumeSize,
SysInfo->ReadOnly?L"TRUE":L"FALSE",
SysInfo->FreeSpace,
SysInfo->BlockSize
);
if (SysInfo != NULL) {
FreePool(SysInfo);
}
}
if (!Sfo) {
//
// get directory name from path...
//
DirectoryName = GetFullyQualifiedPath(CorrectedPath);
//
// print header
//
ShellPrintHiiEx (
0,
gST->ConOut->Mode->CursorRow,
NULL,
STRING_TOKEN (STR_LS_HEADER_LINE1),
gShellLevel2HiiHandle,
DirectoryName
);
FreePool(DirectoryName);
}
for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link)
; !IsNull(&ListHead->Link, &Node->Link)
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)
){
ASSERT(Node != NULL);
if (LongestPath < StrSize(Node->FullName)) {
LongestPath = StrSize(Node->FullName);
}
ASSERT(Node->Info != NULL);
ASSERT((Node->Info->Attribute & EFI_FILE_VALID_ATTR) == Node->Info->Attribute);
if (Attribs == 0) {
//
// NOT system & NOT hidden
//
if ( (Node->Info->Attribute & EFI_FILE_SYSTEM)
|| (Node->Info->Attribute & EFI_FILE_HIDDEN)
){
continue;
}
} else if (Attribs != EFI_FILE_VALID_ATTR) {
if (Count == 1) {
//
// the bit must match
//
if ( (Node->Info->Attribute & Attribs) != Attribs) {
continue;
}
} else {
//
// exact match on all bits
//
if ( Node->Info->Attribute != Attribs) {
continue;
}
}
}
if (Sfo) {
//
// Print the FileInfo Table
//
ShellPrintHiiEx (
0,
gST->ConOut->Mode->CursorRow,
NULL,
STRING_TOKEN (STR_LS_SFO_FILEINFO),
gShellLevel2HiiHandle,
Node->FullName,
Node->Info->FileSize,
Node->Info->PhysicalSize,
(Node->Info->Attribute & EFI_FILE_ARCHIVE) != 0?L"a":L"",
(Node->Info->Attribute & EFI_FILE_DIRECTORY) != 0?L"d":L"",
(Node->Info->Attribute & EFI_FILE_HIDDEN) != 0?L"h":L"",
(Node->Info->Attribute & EFI_FILE_READ_ONLY) != 0?L"r":L"",
(Node->Info->Attribute & EFI_FILE_SYSTEM) != 0?L"s":L"",
Node->Info->CreateTime.Hour,
Node->Info->CreateTime.Minute,
Node->Info->CreateTime.Second,
Node->Info->CreateTime.Day,
Node->Info->CreateTime.Month,
Node->Info->CreateTime.Year,
Node->Info->LastAccessTime.Hour,
Node->Info->LastAccessTime.Minute,
Node->Info->LastAccessTime.Second,
Node->Info->LastAccessTime.Day,
Node->Info->LastAccessTime.Month,
Node->Info->LastAccessTime.Year,
Node->Info->ModificationTime.Hour,
Node->Info->ModificationTime.Minute,
Node->Info->ModificationTime.Second,
Node->Info->ModificationTime.Day,
Node->Info->ModificationTime.Month,
Node->Info->ModificationTime.Year
);
} else {
//
// print this one out...
// first print the universal start, next print the type specific name format, last print the CRLF
//
ShellPrintHiiEx (
-1,
-1,
NULL,
STRING_TOKEN (STR_LS_LINE_START_ALL),
gShellLevel2HiiHandle,
&Node->Info->ModificationTime,
(Node->Info->Attribute & EFI_FILE_DIRECTORY) != 0?L"<DIR>":L"",
(Node->Info->Attribute & EFI_FILE_READ_ONLY) != 0?L'r':L' ',
Node->Info->FileSize
);
if (Node->Info->Attribute & EFI_FILE_DIRECTORY) {
DirCount++;
ShellPrintHiiEx (
-1,
-1,
NULL,
STRING_TOKEN (STR_LS_LINE_END_DIR),
gShellLevel2HiiHandle,
Node->FileName
);
} else {
FileCount++;
FileSize += Node->Info->FileSize;
if ( (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)L".nsh", (CHAR16*)&(Node->FileName[StrLen (Node->FileName) - 4])) == 0)
|| (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)L".efi", (CHAR16*)&(Node->FileName[StrLen (Node->FileName) - 4])) == 0)
){
ShellPrintHiiEx (
-1,
-1,
NULL,
STRING_TOKEN (STR_LS_LINE_END_EXE),
gShellLevel2HiiHandle,
Node->FileName
);
} else {
ShellPrintHiiEx (
-1,
-1,
NULL,
STRING_TOKEN (STR_LS_LINE_END_FILE),
gShellLevel2HiiHandle,
Node->FileName
);
}
}
}
}
if (!Sfo) {
//
// print footer
//
ShellPrintHiiEx (
-1,
-1,
NULL,
STRING_TOKEN (STR_LS_FOOTER_LINE),
gShellLevel2HiiHandle,
FileCount,
FileSize,
DirCount
);
}
if (Rec){
DirectoryName = AllocatePool(LongestPath + 2*sizeof(CHAR16));
for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link)
; !IsNull(&ListHead->Link, &Node->Link)
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)
){
//
// recurse on any directory except the traversing ones...
//
if (((Node->Info->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY)
&& StrCmp(Node->FileName, L".") != 0
&& StrCmp(Node->FileName, L"..") != 0
){
StrCpy(DirectoryName, Node->FullName);
StrCat(DirectoryName, L"\\*");
PrintLsOutput(
Rec,
Attribs,
Sfo,
DirectoryName,
FALSE,
Count,
TimeZone);
}
}
FreePool(DirectoryName);
}
FreePool(CorrectedPath);
ShellCloseFileMetaArg(&ListHead);
FreePool(ListHead);
return (ShellStatus);
}
STATIC CONST SHELL_PARAM_ITEM LsParamList[] = {
{L"-r", TypeFlag},
{L"-a", TypeStart},
{L"-sfo", TypeFlag},
{NULL, TypeMax}
};
/**
Function for 'ls' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunLs (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
CONST CHAR16 *Attribs;
SHELL_STATUS ShellStatus;
UINT64 RequiredAttributes;
CONST CHAR16 *PathName;
CONST CHAR16 *CurDir;
UINTN Count;
CHAR16 *FullPath;
UINTN Size;
EFI_TIME theTime;
BOOLEAN SfoMode;
Size = 0;
FullPath = NULL;
ProblemParam = NULL;
Attribs = NULL;
ShellStatus = SHELL_SUCCESS;
RequiredAttributes = 0;
PathName = NULL;
CurDir = NULL;
Count = 0;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
//
// Fix local copies of the protocol pointers
//
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (LsParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
}
if (ShellCommandLineGetCount(Package) > 2) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// check for -a
//
if (ShellCommandLineGetFlag(Package, L"-a")) {
for ( Attribs = ShellCommandLineGetValue(Package, L"-a")
; Attribs != NULL && *Attribs != CHAR_NULL && ShellStatus == SHELL_SUCCESS
; Attribs++
){
switch (*Attribs) {
case L'a':
case L'A':
RequiredAttributes |= EFI_FILE_ARCHIVE;
Count++;
continue;
case L's':
case L'S':
RequiredAttributes |= EFI_FILE_SYSTEM;
Count++;
continue;
case L'h':
case L'H':
RequiredAttributes |= EFI_FILE_HIDDEN;
Count++;
continue;
case L'r':
case L'R':
RequiredAttributes |= EFI_FILE_READ_ONLY;
Count++;
continue;
case L'd':
case L'D':
RequiredAttributes |= EFI_FILE_DIRECTORY;
Count++;
continue;
default:
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ATTRIBUTE), gShellLevel2HiiHandle, ShellCommandLineGetValue(Package, L"-a"));
ShellStatus = SHELL_INVALID_PARAMETER;
break;
} // switch
} // for loop
//
// if nothing is specified all are specified
//
if (RequiredAttributes == 0) {
RequiredAttributes = EFI_FILE_VALID_ATTR;
}
} // if -a present
if (ShellStatus == SHELL_SUCCESS) {
PathName = ShellCommandLineGetRawValue(Package, 1);
if (PathName == NULL) {
CurDir = gEfiShellProtocol->GetCurDir(NULL);
if (CurDir == NULL) {
ShellStatus = SHELL_NOT_FOUND;
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
}
}
if (PathName != NULL) {
ASSERT((FullPath == NULL && Size == 0) || (FullPath != NULL));
StrnCatGrow(&FullPath, &Size, PathName, 0);
if (ShellIsDirectory(PathName) == EFI_SUCCESS) {
StrnCatGrow(&FullPath, &Size, L"\\*", 0);
}
} else {
ASSERT(FullPath == NULL);
StrnCatGrow(&FullPath, NULL, L"*", 0);
}
Status = gRT->GetTime(&theTime, NULL);
ASSERT_EFI_ERROR(Status);
SfoMode = ShellCommandLineGetFlag(Package, L"-sfo");
if (ShellStatus == SHELL_SUCCESS) {
ShellStatus = PrintLsOutput(
ShellCommandLineGetFlag(Package, L"-r"),
RequiredAttributes,
SfoMode,
FullPath,
TRUE,
Count,
(INT16)(theTime.TimeZone==2047?0:theTime.TimeZone)
);
if (ShellStatus == SHELL_NOT_FOUND) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_FILES), gShellLevel2HiiHandle);
} else if (ShellStatus == SHELL_INVALID_PARAMETER) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle);
} else if (ShellStatus != SHELL_SUCCESS) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle);
}
}
}
}
}
if (FullPath != NULL) {
FreePool(FullPath);
}
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
return (ShellStatus);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,128 @@
/** @file
Main file for attrib shell level 2 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellLevel2CommandsLib.h"
/**
Function for 'mkdir' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunMkDir (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
CONST CHAR16 *NewDirName;
UINTN DirCreateCount;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_FILE_HANDLE FileHandle;
SHELL_STATUS ShellStatus;
ShellStatus = SHELL_SUCCESS;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
}
//
// create a set of directories
//
if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
//
// we didnt get a single parameter
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
for ( DirCreateCount = 1
;
; DirCreateCount++
){
//
// loop through each directory specified
//
NewDirName = ShellCommandLineGetRawValue(Package, DirCreateCount);
if (NewDirName == NULL) {
break;
}
//
// check if that already exists... if yes fail
//
FileHandle = NULL;
Status = ShellOpenFileByName(NewDirName,
&FileHandle,
EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE,
EFI_FILE_DIRECTORY
);
if (!EFI_ERROR(Status)) {
ShellCloseFile(&FileHandle);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MKDIR_ALREADY), gShellLevel2HiiHandle, NewDirName);
ShellStatus = SHELL_INVALID_PARAMETER;
break;
} else {
ASSERT(FileHandle == NULL);
//
// create the directory named NewDirName
//
Status = ShellCreateDirectory(NewDirName, &FileHandle);
if (FileHandle != NULL) {
gEfiShellProtocol->CloseFile(FileHandle);
}
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MKDIR_CREATEFAIL), gShellLevel2HiiHandle, NewDirName);
ShellStatus = SHELL_ACCESS_DENIED;
break;
}
}
}
}
}
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
return (ShellStatus);
}

View File

@ -0,0 +1,478 @@
/** @file
Main file for mv shell level 2 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellLevel2CommandsLib.h"
/**
Function to validate that moving a specific file (FileName) to a specific
location (DestPath) is valid.
This function will verify that the destination is not a subdirectory of
FullName, that the Current working Directory is not being moved, and that
the directory is not read only.
if the move is invalid this function will report the error to StdOut.
@param FullName [in] The name of the file to move.
@param Cwd [in] The current working directory
@param DestPath [in] The target location to move to
@param Attribute[in] The Attribute of the file
@retval TRUE The move is valid
@retval FALSE The move is not
**/
BOOLEAN
EFIAPI
IsValidMove(
IN CONST CHAR16 *FullName,
IN CONST CHAR16 *Cwd,
IN CONST CHAR16 *DestPath,
IN CONST UINT64 Attribute
)
{
CHAR16 *Test;
CHAR16 *Test1;
CHAR16 *TestWalker;
UINTN Result;
UINTN TempLen;
if (Cwd != NULL && StrCmp(FullName, Cwd) == 0) {
//
// Invalid move
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_CWD), gShellLevel2HiiHandle);
return (FALSE);
}
Test = NULL;
Test = StrnCatGrow(&Test, NULL, DestPath, 0);
TestWalker = Test;
ASSERT(TestWalker != NULL);
while(*TestWalker == L'\\') {
TestWalker++;
}
while(TestWalker != NULL && TestWalker[StrLen(TestWalker)-1] == L'\\') {
TestWalker[StrLen(TestWalker)-1] = CHAR_NULL;
}
ASSERT(TestWalker != NULL);
ASSERT(FullName != NULL);
if (StrStr(FullName, TestWalker) != 0) {
TempLen = StrLen(FullName);
if (StrStr(FullName, TestWalker) != FullName // not the first items... (could below it)
&& TempLen <= (StrLen(TestWalker) + 1)
&& StrStr(FullName+StrLen(TestWalker) + 1, L"\\") == NULL) {
//
// Invalid move
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_SUB), gShellLevel2HiiHandle);
FreePool(Test);
return (FALSE);
}
}
FreePool(Test);
if (StrStr(DestPath, FullName) != 0 && StrStr(DestPath, FullName) != DestPath) {
//
// Invalid move
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_SUB), gShellLevel2HiiHandle);
return (FALSE);
}
if ((Attribute & EFI_FILE_READ_ONLY) != 0) {
//
// invalid to move read only
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_RO), gShellLevel2HiiHandle);
return (FALSE);
}
Test = StrStr(FullName, L":");
Test1 = StrStr(DestPath, L":");
if (Test1 != NULL && Test != NULL) {
*Test = CHAR_NULL;
*Test1 = CHAR_NULL;
Result = StringNoCaseCompare(&FullName, &DestPath);
*Test = L':';
*Test1 = L':';
if (Result != 0) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_FS), gShellLevel2HiiHandle);
return (FALSE);
}
}
return (TRUE);
}
/**
Function to take a destination path that might contain wildcards and verify
that there is only a single possible target (IE we cant have wildcards that
have 2 possible destination).
if the result is sucessful the caller must free *DestPathPointer.
@param[in] DestDir The original path to the destination
@param[in,out] DestPathPointer a pointer to the callee allocated final path.
@retval EFI_INVALID_PARAMETR the DestDir could not be resolved to a location
@retval EFI_INVALID_PARAMETR the DestDir could be resolved to more than 1 location
@retval EFI_SUCCESS the operation was sucessful
**/
SHELL_STATUS
EFIAPI
GetDestinationLocation(
IN CONST CHAR16 *DestDir,
IN OUT CHAR16 **DestPathPointer,
IN CONST CHAR16 *Cwd
)
{
EFI_SHELL_FILE_INFO *DestList;
EFI_SHELL_FILE_INFO *Node;
EFI_STATUS Status;
CHAR16 *DestPath;
CHAR16 *TempLocation;
UINTN NewSize;
DestList = NULL;
DestPath = NULL;
//
// get the destination path
//
Status = ShellOpenFileMetaArg((CHAR16*)DestDir, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE, &DestList);
if (DestList == NULL || IsListEmpty(&DestList->Link)) {
//
// Not existing... must be renaming
//
if ((TempLocation = StrStr(DestDir, L":")) == NULL) {
NewSize = StrSize(Cwd);
NewSize += StrSize(DestDir);
DestPath = AllocateZeroPool(NewSize);
StrCpy(DestPath, Cwd);
if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
StrCat(DestPath, L"\\");
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
}
StrCat(DestPath, DestDir);
} else {
ASSERT(DestPath == NULL);
DestPath = StrnCatGrow(&DestPath, NULL, DestDir, 0);
}
} else {
Node = (EFI_SHELL_FILE_INFO*)GetFirstNode(&DestList->Link);
//
// Make sure there is only 1 node in the list.
//
if (!IsNodeAtEnd(&DestList->Link, &Node->Link)) {
ShellCloseFileMetaArg(&DestList);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_MARG_ERROR), gShellLevel2HiiHandle, DestDir);
return (SHELL_INVALID_PARAMETER);
}
if (ShellIsDirectory(Node->FullName)==EFI_SUCCESS) {
DestPath = AllocateZeroPool(StrSize(Node->FullName)+sizeof(CHAR16));
StrCpy(DestPath, Node->FullName);
StrCat(DestPath, L"\\");
} else {
//
// cant move onto another file.
//
ShellCloseFileMetaArg(&DestList);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_ERROR), gShellLevel2HiiHandle, DestDir);
return (SHELL_INVALID_PARAMETER);
}
}
*DestPathPointer = DestPath;
ShellCloseFileMetaArg(&DestList);
return (SHELL_SUCCESS);
}
/**
function to take a list of files to move and a destination location and do
the verification and moving of those files to that location. This function
will report any errors to the user and continue to move the rest of the files.
@param[in] FileList A LIST_ENTRY* based list of files to move
@param[in] DestDir the destination location
@retval SHELL_SUCCESS the files were all moved.
@retval SHELL_INVALID_PARAMETER a parameter was invalid
@retval SHELL_SECURITY_VIOLATION a security violation ocurred
@retval SHELL_WRITE_PROTECTED the destination was write protected
@retval SHELL_OUT_OF_RESOURCES a memory allocation failed
**/
SHELL_STATUS
EFIAPI
ValidateAndMoveFiles(
IN CONST EFI_SHELL_FILE_INFO *FileList,
IN CONST CHAR16 *DestDir
)
{
EFI_STATUS Status;
CHAR16 *HiiOutput;
CHAR16 *HiiResultOk;
CHAR16 *DestPath;
CONST CHAR16 *Cwd;
SHELL_STATUS ShellStatus;
CONST EFI_SHELL_FILE_INFO *Node;
EFI_FILE_INFO *NewFileInfo;
CHAR16 *TempLocation;
UINTN NewSize;
ASSERT(FileList != NULL);
ASSERT(DestDir != NULL);
DestPath = NULL;
Cwd = ShellGetCurrentDir(NULL);
//
// Get and validate the destination location
//
ShellStatus = GetDestinationLocation(DestDir, &DestPath, Cwd);
if (ShellStatus != SHELL_SUCCESS) {
return (ShellStatus);
}
HiiOutput = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_MV_OUTPUT), NULL);
HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);
ASSERT (DestPath != NULL);
ASSERT (HiiResultOk != NULL);
ASSERT (HiiOutput != NULL);
// ASSERT (Cwd != NULL);
//
// Go through the list of files and directories to move...
//
for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)
; !IsNull(&FileList->Link, &Node->Link)
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)
){
if (ShellGetExecutionBreakFlag()) {
break;
}
ASSERT(Node->FileName != NULL);
ASSERT(Node->FullName != NULL);
//
// skip the directory traversing stuff...
//
if (StrCmp(Node->FileName, L".") == 0 || StrCmp(Node->FileName, L"..") == 0) {
continue;
}
//
// Validate that the move is valid
//
if (!IsValidMove(Node->FullName, Cwd, DestPath, Node->Info->Attribute)) {
ShellStatus = SHELL_INVALID_PARAMETER;
continue;
}
//
// Chop off map info from "DestPath"
//
if ((TempLocation = StrStr(DestPath, L":")) != NULL) {
CopyMem(DestPath, TempLocation+1, StrSize(TempLocation+1));
}
//
// construct the new file info block
//
NewSize = StrSize(DestPath);
NewSize += StrSize(Node->FileName) + sizeof(EFI_FILE_INFO) + sizeof(CHAR16);
NewFileInfo = AllocateZeroPool(NewSize);
ASSERT(NewFileInfo != NULL);
CopyMem(NewFileInfo, Node->Info, sizeof(EFI_FILE_INFO));
if (DestPath[0] != L'\\') {
StrCpy(NewFileInfo->FileName, L"\\");
StrCat(NewFileInfo->FileName, DestPath);
} else {
StrCpy(NewFileInfo->FileName, DestPath);
}
if (NewFileInfo->FileName[StrLen(NewFileInfo->FileName)-1] == L'\\') {
if (Node->FileName[0] == L'\\') {
//
// Don't allow for double slashes. Eliminate one of them.
//
NewFileInfo->FileName[StrLen(NewFileInfo->FileName)-1] = CHAR_NULL;
}
StrCat(NewFileInfo->FileName, Node->FileName);
}
NewFileInfo->Size = sizeof(EFI_FILE_INFO) + StrSize(NewFileInfo->FileName);
ShellPrintEx(-1, -1, HiiOutput, Node->FullName, NewFileInfo->FileName);
//
// Perform the move operation
//
Status = ShellSetFileInfo(Node->Handle, NewFileInfo);
//
// Free the info object we used...
//
ASSERT (NewFileInfo != NULL);
FreePool(NewFileInfo);
//
// Check our result
//
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);
//
// move failed
//
switch(Status){
default:
ShellStatus = SHELL_INVALID_PARAMETER;
case EFI_SECURITY_VIOLATION:
ShellStatus = SHELL_SECURITY_VIOLATION;
case EFI_WRITE_PROTECTED:
ShellStatus = SHELL_WRITE_PROTECTED;
case EFI_OUT_OF_RESOURCES:
ShellStatus = SHELL_OUT_OF_RESOURCES;
case EFI_DEVICE_ERROR:
ShellStatus = SHELL_DEVICE_ERROR;
case EFI_ACCESS_DENIED:
ShellStatus = SHELL_ACCESS_DENIED;
} // switch
} else {
ShellPrintEx(-1, -1, L"%s", HiiResultOk);
}
} // for loop
FreePool(DestPath);
FreePool(HiiOutput);
FreePool(HiiResultOk);
return (ShellStatus);
}
SHELL_STATUS
EFIAPI
ShellCommandRunMv (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
UINTN ParamCount;
UINTN LoopCounter;
EFI_SHELL_FILE_INFO *FileList;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
ParamCount = 0;
FileList = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
}
switch (ParamCount = ShellCommandLineGetCount(Package)) {
case 0:
case 1:
//
// we have insufficient parameters
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
break;
case 2:
//
// must have valid CWD for single parameter...
//
if (ShellGetCurrentDir(NULL) == NULL){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, 1), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
if (FileList == NULL || IsListEmpty(&FileList->Link) || EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));
ShellStatus = SHELL_NOT_FOUND;
} else {
//
// ValidateAndMoveFiles will report errors to the screen itself
//
ShellStatus = ValidateAndMoveFiles(FileList, ShellGetCurrentDir(NULL));
}
}
break;
default:
///@todo make sure this works with error half way through and continues...
for (ParamCount--, LoopCounter = 1 ; LoopCounter < ParamCount && ShellStatus == SHELL_SUCCESS ; LoopCounter++) {
if (ShellGetExecutionBreakFlag()) {
break;
}
Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, LoopCounter), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
if (FileList == NULL || IsListEmpty(&FileList->Link) || EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));
ShellStatus = SHELL_NOT_FOUND;
} else {
//
// ValidateAndMoveFiles will report errors to the screen itself
// Only change ShellStatus if it's sucessful
//
if (ShellStatus == SHELL_SUCCESS) {
ShellStatus = ValidateAndMoveFiles(FileList, ShellCommandLineGetRawValue(Package, ParamCount));
} else {
ValidateAndMoveFiles(FileList, ShellCommandLineGetRawValue(Package, ParamCount));
}
}
if (FileList != NULL && !IsListEmpty(&FileList->Link)) {
Status = ShellCloseFileMetaArg(&FileList);
if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) {
ShellStatus = SHELL_ACCESS_DENIED;
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1), ShellStatus|MAX_BIT);
}
}
}
break;
} // switch on parameter count
if (FileList != NULL) {
ShellCloseFileMetaArg(&FileList);
}
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
}
if (ShellGetExecutionBreakFlag()) {
return (SHELL_ABORTED);
}
return (ShellStatus);
}

View File

@ -0,0 +1,190 @@
/** @file
Main file for Parse shell level 2 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellLevel2CommandsLib.h"
SHELL_STATUS
EFIAPI
PerformParsing(
IN CONST CHAR16 *FileName,
IN CONST CHAR16 *TableName,
IN CONST UINTN ColumnIndex,
IN CONST UINTN TableNameInstance,
IN CONST UINTN ShellCommandInstance
)
{
SHELL_FILE_HANDLE FileHandle;
EFI_STATUS Status;
BOOLEAN Ascii;
UINTN LoopVariable;
UINTN ColumnLoop;
CHAR16 *TempLine;
CHAR16 *ColumnPointer;
SHELL_STATUS ShellStatus;
CHAR16 *TempSpot;
ASSERT(FileName != NULL);
ASSERT(TableName != NULL);
ShellStatus = SHELL_SUCCESS;
Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ, 0);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel2HiiHandle, FileName);
ShellStatus = SHELL_NOT_FOUND;
} else {
for (LoopVariable = 0 ; LoopVariable < ShellCommandInstance && !ShellFileHandleEof(FileHandle);) {
TempLine = ShellFileHandleReturnLine(FileHandle, &Ascii);
if (TempLine == NULL) {
break;
}
if (StrStr(TempLine, L"ShellCommand, \"") == TempLine) {
LoopVariable++;
}
SHELL_FREE_NON_NULL(TempLine);
}
if (LoopVariable == ShellCommandInstance) {
LoopVariable = 0;
while(1) {
TempLine = ShellFileHandleReturnLine(FileHandle, &Ascii);
if ( TempLine == NULL
|| *TempLine == CHAR_NULL
|| StrStr(TempLine, L"ShellCommand, \"") == TempLine
){
SHELL_FREE_NON_NULL(TempLine);
break;
}
if (StrStr(TempLine, TableName) == TempLine) {
LoopVariable++;
}
if ( LoopVariable == TableNameInstance
|| (TableNameInstance == (UINTN)-1 && StrStr(TempLine, TableName) == TempLine)
){
for (ColumnLoop = 1, ColumnPointer = TempLine; ColumnLoop < ColumnIndex && ColumnPointer != NULL && *ColumnPointer != CHAR_NULL; ColumnLoop++) {
ColumnPointer = StrStr(ColumnPointer, L",");
if (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL){
ColumnPointer++;
}
}
if (ColumnLoop == ColumnIndex) {
ASSERT(ColumnPointer != NULL);
TempSpot = StrStr(ColumnPointer, L",");
if (TempSpot != NULL) {
*TempSpot = CHAR_NULL;
}
while (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL && ColumnPointer[0] == L' '){
ColumnPointer++;
}
if (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL && ColumnPointer[0] == L'\"'){
ColumnPointer++;
}
if (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL && ColumnPointer[StrLen(ColumnPointer)-1] == L'\"'){
ColumnPointer[StrLen(ColumnPointer)-1] = CHAR_NULL;
}
ShellPrintEx(-1, -1, L"%s\r\n", ColumnPointer);
}
}
SHELL_FREE_NON_NULL(TempLine);
}
}
}
return (ShellStatus);
}
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{L"-i", TypeValue},
{L"-s", TypeValue},
{NULL, TypeMax}
};
/**
Function for 'parse' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunParse (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
CONST CHAR16 *FileName;
CONST CHAR16 *TableName;
CONST CHAR16 *ColumnString;
SHELL_STATUS ShellStatus;
UINTN ShellCommandInstance;
UINTN TableNameInstance;
ShellStatus = SHELL_SUCCESS;
ProblemParam = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
if (ShellCommandLineGetCount(Package) < 4) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else if (ShellCommandLineGetCount(Package) > 4) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
FileName = ShellCommandLineGetRawValue(Package, 1);
TableName = ShellCommandLineGetRawValue(Package, 2);
ColumnString = ShellCommandLineGetRawValue(Package, 3);
if (ShellCommandLineGetValue(Package, L"-i") == NULL) {
TableNameInstance = (UINTN)-1;
} else {
TableNameInstance = ShellStrToUintn(ShellCommandLineGetValue(Package, L"-i"));
}
if (ShellCommandLineGetValue(Package, L"-s") == NULL) {
ShellCommandInstance = 1;
} else {
ShellCommandInstance = ShellStrToUintn(ShellCommandLineGetValue(Package, L"-s"));
}
ShellStatus = PerformParsing(FileName, TableName, ShellStrToUintn(ColumnString), TableNameInstance, ShellCommandInstance);
}
}
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
return (ShellStatus);
}

View File

@ -0,0 +1,131 @@
/** @file
Main file for attrib shell level 2 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellLevel2CommandsLib.h"
STATIC CONST SHELL_PARAM_ITEM ResetParamList[] = {
{L"-w", TypeValue},
{L"-s", TypeValue},
{L"-c", TypeValue},
{NULL, TypeMax}
};
/**
Function for 'reset' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunReset (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CONST CHAR16 *String;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
ShellStatus = SHELL_SUCCESS;
ProblemParam = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (ResetParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
FreePool(ProblemParam);
return (SHELL_INVALID_PARAMETER);
} else {
ASSERT(FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
} else if (ShellCommandLineGetRawValue(Package, 1) != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// check for cold reset flag, then shutdown reset flag, then warm (default) reset flag
//
if (ShellCommandLineGetFlag(Package, L"-c")) {
if (ShellCommandLineGetFlag(Package, L"-s") || ShellCommandLineGetFlag(Package, L"-w")) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
String = ShellCommandLineGetValue(Package, L"-c");
if (String != NULL) {
gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, StrSize(String), (VOID*)String);
} else {
gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);
}
}
} else if (ShellCommandLineGetFlag(Package, L"-s")) {
if (ShellCommandLineGetFlag(Package, L"-w")) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
String = ShellCommandLineGetValue(Package, L"-s");
DEBUG_CODE(ShellPrintEx(-1,-1,L"Reset with %s (%d bytes)", String, String!=NULL?StrSize(String):0););
if (String != NULL) {
gRT->ResetSystem(EfiResetShutdown, EFI_SUCCESS, StrSize(String), (VOID*)String);
} else {
gRT->ResetSystem(EfiResetShutdown, EFI_SUCCESS, 0, NULL);
}
}
} else {
//
// this is default so dont worry about flag...
//
String = ShellCommandLineGetValue(Package, L"-w");
if (String != NULL) {
gRT->ResetSystem(EfiResetWarm, EFI_SUCCESS, StrSize(String), (VOID*)String);
} else {
gRT->ResetSystem(EfiResetWarm, EFI_SUCCESS, 0, NULL);
}
}
}
}
//
// we should never get here... so the free and return are for formality more than use
// as the ResetSystem function should not return...
//
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
//
// return the status
//
return (ShellStatus);
}

View File

@ -0,0 +1,296 @@
/** @file
Main file for attrib shell level 2 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellLevel2CommandsLib.h"
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{L"-q", TypeFlag},
{NULL, TypeMax}
};
BOOLEAN
EFIAPI
IsDirectoryEmpty (
IN EFI_HANDLE FileHandle
)
{
EFI_STATUS Status;
EFI_FILE_INFO *FileInfo;
BOOLEAN NoFile;
BOOLEAN RetVal;
RetVal = TRUE;
NoFile = FALSE;
for (Status = FileHandleFindFirstFile(FileHandle, &FileInfo)
; !NoFile
; Status = FileHandleFindNextFile(FileHandle, FileInfo, &NoFile)
){
if (StrStr(FileInfo->FileName, L".") != FileInfo->FileName
&&StrStr(FileInfo->FileName, L"..") != FileInfo->FileName) {
RetVal = FALSE;
}
}
return (RetVal);
}
SHELL_STATUS
EFIAPI
CascadeDelete(
IN EFI_SHELL_FILE_INFO *Node,
IN CONST BOOLEAN Quiet
)
{
SHELL_STATUS ShellStatus;
EFI_SHELL_FILE_INFO *List;
EFI_SHELL_FILE_INFO *Node2;
EFI_STATUS Status;
SHELL_PROMPT_RESPONSE *Resp;
Resp = NULL;
ShellStatus = SHELL_SUCCESS;
List = NULL;
Status = EFI_SUCCESS;
if ((Node->Info->Attribute & EFI_FILE_READ_ONLY) == EFI_FILE_READ_ONLY) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DETELE_RO), gShellLevel2HiiHandle, Node->FullName);
return (SHELL_ACCESS_DENIED);
}
if ((Node->Info->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) {
if (!IsDirectoryEmpty(Node->Handle)) {
if (!Quiet) {
Status = ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_RM_LOG_DELETE_CONF), gShellLevel2HiiHandle, Node->FullName);
Status = ShellPromptForResponse(ShellPromptResponseTypeYesNo, NULL, (VOID**)&Resp);
ASSERT_EFI_ERROR(Status);
ASSERT(Resp != NULL);
if (EFI_ERROR(Status) || *Resp != ShellPromptResponseYes) {
SHELL_FREE_NON_NULL(Resp);
return (SHELL_ABORTED);
}
SHELL_FREE_NON_NULL(Resp);
}
//
// empty out the directory
//
Status = gEfiShellProtocol->FindFilesInDir(Node->Handle, &List);
if (EFI_ERROR(Status)) {
if (List!=NULL) {
gEfiShellProtocol->FreeFileList(&List);
}
return (SHELL_DEVICE_ERROR);
}
for (Node2 = (EFI_SHELL_FILE_INFO *)GetFirstNode(&List->Link)
; !IsNull(&List->Link, &Node2->Link)
; Node2 = (EFI_SHELL_FILE_INFO *)GetNextNode(&List->Link, &Node2->Link)
){
//
// skip the directory traversing stuff...
//
if (StrCmp(Node2->FileName, L".") == 0 || StrCmp(Node2->FileName, L"..") == 0) {
continue;
}
Node2->Status = gEfiShellProtocol->OpenFileByName (Node2->FullName, &Node2->Handle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE);
ShellStatus = CascadeDelete(Node2, Quiet);
if (ShellStatus != SHELL_SUCCESS) {
if (List!=NULL) {
gEfiShellProtocol->FreeFileList(&List);
}
return (ShellStatus);
}
}
if (List!=NULL) {
gEfiShellProtocol->FreeFileList(&List);
}
}
}
if (!(StrCmp(Node->FileName, L".") == 0 || StrCmp(Node->FileName, L"..") == 0)) {
//
// now delete the current node...
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE), gShellLevel2HiiHandle, Node->FullName);
Status = gEfiShellProtocol->DeleteFile(Node->Handle);
Node->Handle = NULL;
}
//
// We cant allow for the warning here!
//
if (Status != EFI_SUCCESS){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_ERR), gShellLevel2HiiHandle, Status);
return (SHELL_ACCESS_DENIED);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_COMP), gShellLevel2HiiHandle);
return (SHELL_SUCCESS);
}
}
BOOLEAN
EFIAPI
IsValidDeleteTarget(
IN CONST EFI_SHELL_FILE_INFO *List,
IN CONST EFI_SHELL_FILE_INFO *Node,
IN CONST LIST_ENTRY *Package
)
{
CONST CHAR16 *TempLocation;
CHAR16 *Temp2;
UINTN Size;
TempLocation = StrStr(Node->FullName, L":");
if (StrLen(TempLocation) == 2) {
//
// Deleting the root directory is invalid.
//
return (FALSE);
}
TempLocation = ShellGetCurrentDir(NULL);
Size = 0;
Temp2 = NULL;
StrnCatGrow(&Temp2, &Size, TempLocation, 0);
if (StrStr(Temp2, Node->FullName) != NULL) {
FreePool(Temp2);
return (FALSE);
}
FreePool(Temp2);
return (TRUE);
}
/**
Function for 'rm' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunRm (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
CONST CHAR16 *Param;
SHELL_STATUS ShellStatus;
UINTN ParamCount;
EFI_SHELL_FILE_INFO *FileList;
EFI_SHELL_FILE_INFO *Node;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
ParamCount = 0;
FileList = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
}
if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
//
// we insufficient parameters
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// get a list with each file specified by parameters
// if parameter is a directory then add all the files below it to the list
//
for ( ParamCount = 1, Param = ShellCommandLineGetRawValue(Package, ParamCount)
; Param != NULL
; ParamCount++, Param = ShellCommandLineGetRawValue(Package, ParamCount)
){
Status = ShellOpenFileMetaArg((CHAR16*)Param, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
if (EFI_ERROR(Status) || FileList == NULL || IsListEmpty(&FileList->Link)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, (CHAR16*)Param);
ShellStatus = SHELL_NOT_FOUND;
break;
}
}
if (ShellStatus == SHELL_SUCCESS){
//
// loop through the list and make sure we are not aborting...
//
for ( Node = (EFI_SHELL_FILE_INFO*)GetFirstNode(&FileList->Link)
; !IsNull(&FileList->Link, &Node->Link) && !ShellGetExecutionBreakFlag()
; Node = (EFI_SHELL_FILE_INFO*)GetNextNode(&FileList->Link, &Node->Link)
){
//
// skip the directory traversing stuff...
//
if (StrCmp(Node->FileName, L".") == 0 || StrCmp(Node->FileName, L"..") == 0) {
continue;
}
//
// do the deleting of nodes
//
if (EFI_ERROR(Node->Status)){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_ERR2), gShellLevel2HiiHandle, Node->Status);
ShellStatus = SHELL_ACCESS_DENIED;
break;
}
if (!IsValidDeleteTarget(FileList, Node, Package)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_ERR3), gShellLevel2HiiHandle, Node->FullName);
ShellStatus = SHELL_INVALID_PARAMETER;
break;
}
ShellStatus = CascadeDelete(Node, ShellCommandLineGetFlag(Package, L"-q"));
}
}
//
// Free the fileList
//
if (FileList != NULL) {
Status = ShellCloseFileMetaArg(&FileList);
}
FileList = NULL;
}
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
}
return (ShellStatus);
}

View File

@ -0,0 +1,169 @@
/** @file
Main file for attrib shell level 2 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellLevel2CommandsLib.h"
/**
Print out each environment variable registered with the Shell 2.0 GUID.
If you spawn a pre 2.0 shell from the Shell 2.0 the environment variable may not carry through.
@retval STATUS_SUCCESS the printout was sucessful
@return any return code from GetNextVariableName except EFI_NOT_FOUND
**/
SHELL_STATUS
EFIAPI
PrintAllShellEnvVars(
VOID
)
{
CONST CHAR16 *Value;
CONST CHAR16 *ConstEnvNameList;
ConstEnvNameList = gEfiShellProtocol->GetEnv(NULL);
if (ConstEnvNameList == NULL) {
return (SHELL_SUCCESS);
}
while (*ConstEnvNameList != CHAR_NULL){
Value = gEfiShellProtocol->GetEnv(ConstEnvNameList);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_DISP), gShellLevel2HiiHandle, ConstEnvNameList, Value);
ConstEnvNameList += StrLen(ConstEnvNameList)+1;
}
return (SHELL_SUCCESS);
}
STATIC CONST SHELL_PARAM_ITEM SetParamList[] = {
{L"-d", TypeValue},
{L"-v", TypeFlag},
{NULL, TypeMax}
};
/**
Function for 'set' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunSet (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CONST CHAR16 *KeyName;
CONST CHAR16 *Value;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
//
// Make sure globals are good...
//
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (SetParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
FreePool(ProblemParam);
return (SHELL_INVALID_PARAMETER);
} else {
ASSERT(FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
} else if (ShellCommandLineGetRawValue(Package, 3) != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else if (ShellCommandLineGetRawValue(Package, 1) != NULL && ShellCommandLineGetFlag(Package, L"-d")) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else if (ShellCommandLineGetFlag(Package, L"-d")) {
//
// delete a environment variable
//
KeyName = ShellCommandLineGetValue(Package, L"-d");
if (KeyName == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellLevel2HiiHandle, L"-d");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
Status = ShellSetEnvironmentVariable(KeyName, L"", ShellCommandLineGetFlag(Package, L"-v"));
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_ND), gShellLevel2HiiHandle, KeyName, Status);
ShellStatus = SHELL_DEVICE_ERROR;
}
}
} else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
//
// print out all current environment variables
//
return(PrintAllShellEnvVars());
} else {
//
// we are either printing one or assigning one
//
KeyName = ShellCommandLineGetRawValue(Package, 1);
Value = ShellCommandLineGetRawValue(Package, 2);
if (KeyName != NULL && Value != NULL) {
//
// assigning one
//
Status = ShellSetEnvironmentVariable(KeyName, Value, ShellCommandLineGetFlag(Package, L"-v"));
} else {
if (KeyName != NULL) {
//
// print out value for this one only.
//
Value = ShellGetEnvironmentVariable(KeyName);
if (Value == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_NF), gShellLevel2HiiHandle, KeyName);
ShellStatus = SHELL_SUCCESS;
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_DISP), gShellLevel2HiiHandle, KeyName, Value);
ShellStatus = SHELL_SUCCESS;
}
} else {
ASSERT(FALSE);
}
}
}
}
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
return (ShellStatus);
}

View File

@ -0,0 +1,772 @@
/** @file
Main file for time, timezone, and date shell level 2 and shell level 3 functions.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellLevel2CommandsLib.h"
INT16
EFIAPI
AbsVal(
INT16 v
)
{
if (v>0) {
return (v);
}
return ((INT16)(-v));
}
BOOLEAN
EFIAPI
InternalIsTimeLikeString (
IN CONST CHAR16 *String,
IN CONST CHAR16 Char,
IN CONST UINTN Min,
IN CONST UINTN Max,
IN CONST BOOLEAN MinusOk
)
{
UINTN Count;
Count = 0;
if (MinusOk) {
//
// A single minus is ok.
//
if (*String == L'-') {
String++;
}
}
//
// the first char must be numeric.
//
if (!ShellIsDecimalDigitCharacter(*String)) {
return (FALSE);
}
//
// loop through the characters and use the lib function
//
for ( ; String != NULL && *String != CHAR_NULL ; String++){
if (*String == Char) {
Count++;
if (Count > Max) {
return (FALSE);
}
continue;
}
if (!ShellIsDecimalDigitCharacter(*String)) {
return (FALSE);
}
}
if (Count < Min) {
return (FALSE);
}
return (TRUE);
}
SHELL_STATUS
EFIAPI
CheckAndSetDate (
IN CONST CHAR16 *DateString
)
{
EFI_TIME TheTime;
EFI_STATUS Status;
CONST CHAR16 *Walker;
if (!InternalIsTimeLikeString(DateString, L'/', 2, 2, FALSE)) {
return (SHELL_INVALID_PARAMETER);
}
Status = gRT->GetTime(&TheTime, NULL);
ASSERT_EFI_ERROR(Status);
Walker = DateString;
TheTime.Month = 0xFF;
TheTime.Day = 0xFF;
TheTime.Year = 0xFFFF;
TheTime.Month = (UINT8)StrDecimalToUintn (Walker);
Walker = StrStr(Walker, L"/");
if (Walker != NULL && *Walker == L'/') {
Walker = Walker + 1;
}
if (Walker != NULL && Walker[0] != CHAR_NULL) {
TheTime.Day = (UINT8)StrDecimalToUintn (Walker);
Walker = StrStr(Walker, L"/");
if (Walker != NULL && *Walker == L'/') {
Walker = Walker + 1;
}
if (Walker != NULL && Walker[0] != CHAR_NULL) {
TheTime.Year = (UINT16)StrDecimalToUintn (Walker);
}
}
if (TheTime.Year < 100) {
if (TheTime.Year >= 98) {
TheTime.Year = (UINT16)(1900 + TheTime.Year);
} else {
TheTime.Year = (UINT16)(2000 + TheTime.Year);
}
}
Status = gRT->SetTime(&TheTime);
if (!EFI_ERROR(Status)){
return (SHELL_SUCCESS);
}
return (SHELL_INVALID_PARAMETER);
}
/**
Function for 'date' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunDate (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
EFI_TIME TheTime;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
ShellStatus = SHELL_SUCCESS;
ProblemParam = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (SfoParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
} else if (ShellCommandLineGetRawValue(Package, 2) != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// If there are 0 value parameters, then print the current date
// else If there are any value paramerers, then print error
//
if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
//
// get the current date
//
Status = gRT->GetTime(&TheTime, NULL);
ASSERT_EFI_ERROR(Status);
//
// ShellPrintEx the date in SFO or regular format
//
if (ShellCommandLineGetFlag(Package, L"-sfo")) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DATE_SFO_FORMAT), gShellLevel2HiiHandle, TheTime.Month, TheTime.Day, TheTime.Year);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DATE_FORMAT), gShellLevel2HiiHandle, TheTime.Month, TheTime.Day, TheTime.Year);
}
} else {
if (PcdGet8(PcdShellSupportLevel) == 2) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// perform level 3 operation here.
//
ShellStatus = CheckAndSetDate(ShellCommandLineGetRawValue(Package, 1));
if (ShellStatus != SHELL_SUCCESS) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));
ShellStatus = SHELL_INVALID_PARAMETER;
}
}
}
}
}
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
//
// return the status
//
return (ShellStatus);
}
//
// Note "-tz" is invalid for this (non-interactive) version of 'time'.
//
STATIC CONST SHELL_PARAM_ITEM TimeParamList2[] = {
{L"-d", TypeValue},
{NULL, TypeMax}
};
STATIC CONST SHELL_PARAM_ITEM TimeParamList3[] = {
{L"-d", TypeValue},
{L"-tz", TypeValue},
{NULL, TypeMax}
};
SHELL_STATUS
EFIAPI
CheckAndSetTime (
IN CONST CHAR16 *TimeString,
IN CONST INT16 Tz,
IN CONST UINT8 Daylight
)
{
EFI_TIME TheTime;
EFI_STATUS Status;
CONST CHAR16 *Walker;
if (TimeString != NULL && !InternalIsTimeLikeString(TimeString, L':', 1, 2, FALSE)) {
return (SHELL_INVALID_PARAMETER);
}
Status = gRT->GetTime(&TheTime, NULL);
ASSERT_EFI_ERROR(Status);
if (TimeString != NULL) {
Walker = TimeString;
TheTime.Hour = 0xFF;
TheTime.Minute = 0xFF;
TheTime.Hour = (UINT8)StrDecimalToUintn (Walker);
Walker = StrStr(Walker, L":");
if (Walker != NULL && *Walker == L':') {
Walker = Walker + 1;
}
if (Walker != NULL && Walker[0] != CHAR_NULL) {
TheTime.Minute = (UINT8)StrDecimalToUintn (Walker);
Walker = StrStr(Walker, L":");
if (Walker != NULL && *Walker == L':') {
Walker = Walker + 1;
}
if (Walker != NULL && Walker[0] != CHAR_NULL) {
TheTime.Second = (UINT8)StrDecimalToUintn (Walker);
}
}
}
if ((Tz >= -1440 && Tz <= 1440)||(Tz == 2047)) {
TheTime.TimeZone = Tz;
}
if (Daylight <= 3 && Daylight != 2) {
TheTime.Daylight = Daylight;
}
Status = gRT->SetTime(&TheTime);
if (!EFI_ERROR(Status)){
return (SHELL_SUCCESS);
}
return (SHELL_INVALID_PARAMETER);
}
/**
Function for 'time' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunTime (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *Message;
EFI_TIME TheTime;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
INT16 Tz;
UINT8 Daylight;
CONST CHAR16 *TempLocation;
UINTN TzMinutes;
ShellStatus = SHELL_SUCCESS;
ProblemParam = NULL;
//
// Initialize variables
//
Message = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
if (PcdGet8(PcdShellSupportLevel) == 2) {
Status = ShellCommandLineParseEx (TimeParamList2, &Package, &ProblemParam, TRUE, TRUE);
} else {
ASSERT(PcdGet8(PcdShellSupportLevel) == 3);
Status = ShellCommandLineParseEx (TimeParamList3, &Package, &ProblemParam, TRUE, TRUE);
}
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
//
// check for "-?"
//
Status = gRT->GetTime(&TheTime, NULL);
ASSERT_EFI_ERROR(Status);
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
} else if (ShellCommandLineGetRawValue(Package, 2) != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// If there are no parameters, then print the current time
//
if (ShellCommandLineGetRawValue(Package, 1) == NULL
&& !ShellCommandLineGetFlag(Package, L"-d")
&& !ShellCommandLineGetFlag(Package, L"-tz")) {
//
// ShellPrintEx the current time
//
if (TheTime.TimeZone == 2047) {
TzMinutes = 0;
} else {
TzMinutes = AbsVal(TheTime.TimeZone) % 60;
}
ShellPrintHiiEx (
-1,
-1,
NULL,
STRING_TOKEN (STR_TIME_FORMAT),
gShellLevel2HiiHandle,
TheTime.Hour,
TheTime.Minute,
TheTime.Second,
TheTime.TimeZone==2047?L" ":(TheTime.TimeZone > 0?L"-":L"+"),
TheTime.TimeZone==2047?0:AbsVal(TheTime.TimeZone) / 60,
TzMinutes
);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CRLF), gShellLevel2HiiHandle);
} else if (ShellCommandLineGetFlag(Package, L"-d") && ShellCommandLineGetValue(Package, L"-d") == NULL) {
if (TheTime.TimeZone == 2047) {
TzMinutes = 0;
} else {
TzMinutes = AbsVal(TheTime.TimeZone) % 60;
}
ShellPrintHiiEx (
-1,
-1,
NULL,
STRING_TOKEN (STR_TIME_FORMAT),
gShellLevel2HiiHandle,
TheTime.Hour,
TheTime.Minute,
TheTime.Second,
TheTime.TimeZone==2047?L" ":(TheTime.TimeZone > 0?L"-":L"+"),
TheTime.TimeZone==2047?0:AbsVal(TheTime.TimeZone) / 60,
TzMinutes
);
switch (TheTime.Daylight) {
case 0:
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DSTNA), gShellLevel2HiiHandle);
break;
case EFI_TIME_ADJUST_DAYLIGHT:
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DSTST), gShellLevel2HiiHandle);
break;
case EFI_TIME_IN_DAYLIGHT:
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DSTDT), gShellLevel2HiiHandle);
break;
default:
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_ERROR), gShellLevel2HiiHandle, L"gRT->GetTime", L"TheTime.Daylight", TheTime.Daylight);
}
} else {
if (PcdGet8(PcdShellSupportLevel) == 2) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// perform level 3 operation here.
//
if ((TempLocation = ShellCommandLineGetValue(Package, L"-tz")) != NULL) {
if (TempLocation[0] == L'-') {
Tz = (INT16)(0 - StrDecimalToUintn(++TempLocation));
} else {
Tz = (INT16)StrDecimalToUintn(TempLocation);
}
if (!(Tz >= -1440 && Tz <= 1440) && Tz != 2047) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"-d");
ShellStatus = SHELL_INVALID_PARAMETER;
}
} else {
//
// intentionally out of bounds value will prevent changing it...
//
Tz = 1441;
}
TempLocation = ShellCommandLineGetValue(Package, L"-d");
if (TempLocation != NULL) {
Daylight = (UINT8)StrDecimalToUintn(TempLocation);
if (Daylight != 0 && Daylight != 1 && Daylight != 3) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"-d");
ShellStatus = SHELL_INVALID_PARAMETER;
}
} else {
//
// invalid = will not use
//
Daylight = 0xFF;
}
if (ShellStatus == SHELL_SUCCESS) {
ShellStatus = CheckAndSetTime(ShellCommandLineGetRawValue(Package, 1), Tz, Daylight);
if (ShellStatus != SHELL_SUCCESS) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));
ShellStatus = SHELL_INVALID_PARAMETER;
}
}
}
}
}
}
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
//
// return the status
//
return (ShellStatus);
}
typedef struct {
INT16 TimeZone;
EFI_STRING_ID StringId;
} TIME_ZONE_ITEM;
STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList2[] = {
{L"-l", TypeFlag},
{L"-f", TypeFlag},
{NULL, TypeMax}
};
STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList3[] = {
{L"-l", TypeFlag},
{L"-f", TypeFlag},
{L"-s", TypeValue},
{NULL, TypeMax}
};
STATIC CONST TIME_ZONE_ITEM TimeZoneList[] = {
{720, STRING_TOKEN (STR_TIMEZONE_M12)},
{660, STRING_TOKEN (STR_TIMEZONE_M11)},
{600, STRING_TOKEN (STR_TIMEZONE_M10)},
{540, STRING_TOKEN (STR_TIMEZONE_M9)},
{480, STRING_TOKEN (STR_TIMEZONE_M8)},
{420, STRING_TOKEN (STR_TIMEZONE_M7)},
{360, STRING_TOKEN (STR_TIMEZONE_M6)},
{300, STRING_TOKEN (STR_TIMEZONE_M5)},
{270, STRING_TOKEN (STR_TIMEZONE_M430)},
{240, STRING_TOKEN (STR_TIMEZONE_M4)},
{210, STRING_TOKEN (STR_TIMEZONE_M330)},
{180, STRING_TOKEN (STR_TIMEZONE_M3)},
{120, STRING_TOKEN (STR_TIMEZONE_M2)},
{60 , STRING_TOKEN (STR_TIMEZONE_M1)},
{0 , STRING_TOKEN (STR_TIMEZONE_0)},
{-60 , STRING_TOKEN (STR_TIMEZONE_P1)},
{-120 , STRING_TOKEN (STR_TIMEZONE_P2)},
{-180 , STRING_TOKEN (STR_TIMEZONE_P3)},
{-210 , STRING_TOKEN (STR_TIMEZONE_P330)},
{-240 , STRING_TOKEN (STR_TIMEZONE_P4)},
{-270 , STRING_TOKEN (STR_TIMEZONE_P430)},
{-300 , STRING_TOKEN (STR_TIMEZONE_P5)},
{-330 , STRING_TOKEN (STR_TIMEZONE_P530)},
{-345 , STRING_TOKEN (STR_TIMEZONE_P545)},
{-360 , STRING_TOKEN (STR_TIMEZONE_P6)},
{-390 , STRING_TOKEN (STR_TIMEZONE_P630)},
{-420 , STRING_TOKEN (STR_TIMEZONE_P7)},
{-480 , STRING_TOKEN (STR_TIMEZONE_P8)},
{-540 , STRING_TOKEN (STR_TIMEZONE_P9)},
{-570 , STRING_TOKEN (STR_TIMEZONE_P930)},
{-600 , STRING_TOKEN (STR_TIMEZONE_P10)},
{-660 , STRING_TOKEN (STR_TIMEZONE_P11)},
{-720 , STRING_TOKEN (STR_TIMEZONE_P12)},
{-780 , STRING_TOKEN (STR_TIMEZONE_P13)},
{-840 , STRING_TOKEN (STR_TIMEZONE_P14)}
};
SHELL_STATUS
EFIAPI
CheckAndSetTimeZone (
IN CONST CHAR16 *TimeZoneString
)
{
EFI_TIME TheTime;
EFI_STATUS Status;
CONST CHAR16 *Walker;
UINTN LoopVar;
if (TimeZoneString == NULL) {
return (SHELL_INVALID_PARAMETER);
}
if (TimeZoneString != NULL && !InternalIsTimeLikeString(TimeZoneString, L':', 1, 1, TRUE)) {
return (SHELL_INVALID_PARAMETER);
}
Status = gRT->GetTime(&TheTime, NULL);
ASSERT_EFI_ERROR(Status);
Walker = TimeZoneString;
if (*Walker == L'-') {
TheTime.TimeZone = (INT16)((StrDecimalToUintn (++Walker)) * 60);
} else {
TheTime.TimeZone = (INT16)((StrDecimalToUintn (Walker)) * -60);
}
Walker = StrStr(Walker, L":");
if (Walker != NULL && *Walker == L':') {
Walker = Walker + 1;
}
if (Walker != NULL && Walker[0] != CHAR_NULL) {
if (TheTime.TimeZone < 0) {
TheTime.TimeZone = (INT16)(TheTime.TimeZone - (UINT8)StrDecimalToUintn (Walker));
} else {
TheTime.TimeZone = (INT16)(TheTime.TimeZone + (UINT8)StrDecimalToUintn (Walker));
}
}
Status = EFI_INVALID_PARAMETER;
for ( LoopVar = 0
; LoopVar < sizeof(TimeZoneList) / sizeof(TimeZoneList[0])
; LoopVar++
){
if (TheTime.TimeZone == TimeZoneList[LoopVar].TimeZone) {
Status = gRT->SetTime(&TheTime);
break;
}
}
if (!EFI_ERROR(Status)){
return (SHELL_SUCCESS);
}
return (SHELL_INVALID_PARAMETER);
}
/**
Function for 'timezone' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunTimeZone (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
//
// non interactive
//
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
UINT8 LoopVar;
EFI_TIME TheTime;
BOOLEAN Found;
UINTN TzMinutes;
ShellStatus = SHELL_SUCCESS;
ProblemParam = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
if (PcdGet8(PcdShellSupportLevel) == 2) {
Status = ShellCommandLineParse (TimeZoneParamList2, &Package, &ProblemParam, FALSE);
} else {
ASSERT(PcdGet8(PcdShellSupportLevel) == 3);
Status = ShellCommandLineParseEx (TimeZoneParamList3, &Package, &ProblemParam, FALSE, TRUE);
}
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetCount(Package) > 1) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
} else if (ShellCommandLineGetFlag(Package, L"-s")) {
if ((ShellCommandLineGetFlag(Package, L"-l")) || (ShellCommandLineGetFlag(Package, L"-f"))) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"-l or -f");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(PcdGet8(PcdShellSupportLevel) == 3);
if (ShellCommandLineGetValue(Package, L"-s") == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellLevel2HiiHandle, L"-s");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// Set the time zone
//
ShellStatus = CheckAndSetTimeZone(ShellCommandLineGetValue(Package, L"-s"));
if (ShellStatus != SHELL_SUCCESS) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ShellCommandLineGetValue(Package, L"-s"));
ShellStatus = SHELL_INVALID_PARAMETER;
}
}
}
} else if (ShellCommandLineGetFlag(Package, L"-l")) {
//
// Print a list of all time zones
//
for ( LoopVar = 0
; LoopVar < sizeof(TimeZoneList) / sizeof(TimeZoneList[0])
; LoopVar++
){
ShellPrintHiiEx (-1, -1, NULL, TimeZoneList[LoopVar].StringId, gShellLevel2HiiHandle);
}
} else {
//
// Get Current Time Zone Info
//
Status = gRT->GetTime(&TheTime, NULL);
ASSERT_EFI_ERROR(Status);
if (TheTime.TimeZone != 2047) {
Found = FALSE;
for ( LoopVar = 0
; LoopVar < sizeof(TimeZoneList) / sizeof(TimeZoneList[0])
; LoopVar++
){
if (TheTime.TimeZone == TimeZoneList[LoopVar].TimeZone) {
if (ShellCommandLineGetFlag(Package, L"-f")) {
//
// Print all info about current time zone
//
ShellPrintHiiEx (-1, -1, NULL, TimeZoneList[LoopVar].StringId, gShellLevel2HiiHandle);
} else {
//
// Print basic info only
//
if (TheTime.TimeZone == 2047) {
TzMinutes = 0;
} else {
TzMinutes = AbsVal(TheTime.TimeZone) % 60;
}
ShellPrintHiiEx (
-1,
-1,
NULL,
STRING_TOKEN(STR_TIMEZONE_SIMPLE),
gShellLevel2HiiHandle,
TheTime.TimeZone==2047?0:(TheTime.TimeZone > 0?L"-":L"+"),
TheTime.TimeZone==2047?0:AbsVal(TheTime.TimeZone) / 60,
TzMinutes);
}
Found = TRUE;
break;
}
}
if (!Found) {
//
// Print basic info only
//
if (TheTime.TimeZone == 2047) {
TzMinutes = 0;
} else {
TzMinutes = AbsVal(TheTime.TimeZone) % 60;
}
ShellPrintHiiEx (
-1,
-1,
NULL,
STRING_TOKEN(STR_TIMEZONE_SIMPLE),
gShellLevel2HiiHandle,
TheTime.TimeZone==2047?0:(TheTime.TimeZone > 0?L"-":L"+"),
TheTime.TimeZone==2047?0:AbsVal(TheTime.TimeZone) / 60,
TzMinutes);
if (ShellCommandLineGetFlag(Package, L"-f")) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN(STR_TIMEZONE_NI), gShellLevel2HiiHandle);
}
}
} else {
//
// TimeZone was 2047 (unknown) from GetTime()
//
}
}
}
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
return (ShellStatus);
}

View File

@ -0,0 +1,329 @@
/** @file
Main file for NULL named library for level 2 shell command functions.
these functions are:
attrib,
cd,
cp,
date*,
time*,
load,
ls,
map,
mkdir,
mv,
parse,
rm,
reset,
set,
timezone*
* functions are non-interactive only
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellLevel2CommandsLib.h"
CONST CHAR16 mFileName[] = L"ShellCommands";
EFI_HANDLE gShellLevel2HiiHandle = NULL;
CONST EFI_GUID gShellLevel2HiiGuid = \
{ \
0xf95a7ccc, 0x4c55, 0x4426, { 0xa7, 0xb4, 0xdc, 0x89, 0x61, 0x95, 0xb, 0xae } \
};
CONST CHAR16*
EFIAPI
ShellCommandGetManFileNameLevel2 (
VOID
)
{
return (mFileName);
}
/**
Constructor for the Shell Level 2 Commands library.
Install the handlers for level 2 UEFI Shell 2.0 commands.
@param ImageHandle the image handle of the process
@param SystemTable the EFI System Table pointer
@retval EFI_SUCCESS the shell command handlers were installed sucessfully
@retval EFI_UNSUPPORTED the shell level required was not found.
**/
EFI_STATUS
EFIAPI
ShellLevel2CommandsLibConstructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
//
// if shell level is less than 2 do nothing
//
if (PcdGet8(PcdShellSupportLevel) < 2) {
return (EFI_UNSUPPORTED);
}
gShellLevel2HiiHandle = HiiAddPackages (&gShellLevel2HiiGuid, gImageHandle, UefiShellLevel2CommandsLibStrings, NULL);
if (gShellLevel2HiiHandle == NULL) {
return (EFI_DEVICE_ERROR);
}
//
// install our shell command handlers that are always installed
//
ShellCommandRegisterCommandName(L"attrib", ShellCommandRunAttrib , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_ATTRIB) );
ShellCommandRegisterCommandName(L"cd", ShellCommandRunCd , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_CD) );
ShellCommandRegisterCommandName(L"cp", ShellCommandRunCp , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_CP) );
ShellCommandRegisterCommandName(L"load", ShellCommandRunLoad , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_LOAD) );
ShellCommandRegisterCommandName(L"map", ShellCommandRunMap , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_MAP) );
ShellCommandRegisterCommandName(L"mkdir", ShellCommandRunMkDir , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_MKDIR) );
ShellCommandRegisterCommandName(L"mv", ShellCommandRunMv , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_MV) );
ShellCommandRegisterCommandName(L"parse", ShellCommandRunParse , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_PARSE) );
ShellCommandRegisterCommandName(L"reset", ShellCommandRunReset , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_RESET) );
ShellCommandRegisterCommandName(L"set", ShellCommandRunSet , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_SET) );
ShellCommandRegisterCommandName(L"ls", ShellCommandRunLs , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_LS) );
ShellCommandRegisterCommandName(L"rm", ShellCommandRunRm , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_RM) );
//
// support for permenant (built in) aliases
//
ShellCommandRegisterAlias(L"rm", L"del");
ShellCommandRegisterAlias(L"ls", L"dir");
ShellCommandRegisterAlias(L"cp", L"copy");
ShellCommandRegisterAlias(L"mkdir", L"md");
ShellCommandRegisterAlias(L"cd ..", L"cd..");
ShellCommandRegisterAlias(L"cd \\", L"cd\\");
//
// These are installed in level 2 or 3...
//
if (PcdGet8(PcdShellSupportLevel) == 2 || PcdGet8(PcdShellSupportLevel) == 3) {
ShellCommandRegisterCommandName(L"date", ShellCommandRunDate , ShellCommandGetManFileNameLevel2, PcdGet8(PcdShellSupportLevel), L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_DATE) );
ShellCommandRegisterCommandName(L"time", ShellCommandRunTime , ShellCommandGetManFileNameLevel2, PcdGet8(PcdShellSupportLevel), L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_TIME) );
ShellCommandRegisterCommandName(L"timezone", ShellCommandRunTimeZone, ShellCommandGetManFileNameLevel2, PcdGet8(PcdShellSupportLevel), L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_TIMEZONE));
} else {
DEBUG_CODE_BEGIN();
//
// we want to be able to test these so install them under a different name in debug mode...
//
ShellCommandRegisterCommandName(L"l2date", ShellCommandRunDate , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_DATE) );
ShellCommandRegisterCommandName(L"l2time", ShellCommandRunTime , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_TIME) );
ShellCommandRegisterCommandName(L"l2timezone", ShellCommandRunTimeZone, ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_TIMEZONE));
DEBUG_CODE_END();
}
return (EFI_SUCCESS);
}
/**
Destructor for the library. free any resources.
@param ImageHandle The image handle of the process.
@param SystemTable The EFI System Table pointer.
@retval EFI_SUCCESS Always returned.
**/
EFI_STATUS
EFIAPI
ShellLevel2CommandsLibDestructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
if (gShellLevel2HiiHandle != NULL) {
HiiRemovePackages(gShellLevel2HiiHandle);
}
return (EFI_SUCCESS);
}
/**
Function to clean up paths. Removes the following items:
single periods in the path (no need for the current directory tag)
double periods in the path and removes a single parent directory.
This will be done inline and the resultant string may be be 'too big'.
@param[in] PathToReturn The pointer to the string containing the path.
@return PathToReturn is always returned.
**/
CHAR16*
EFIAPI
CleanPath(
IN CHAR16 *PathToReturn
)
{
CHAR16 *TempString;
UINTN TempSize;
if (PathToReturn==NULL) {
return(NULL);
}
//
// Fix up the directory name
//
while ((TempString = StrStr(PathToReturn, L"\\..\\")) != NULL) {
*TempString = CHAR_NULL;
TempString += 4;
ChopLastSlash(PathToReturn);
TempSize = StrSize(TempString);
CopyMem(PathToReturn+StrLen(PathToReturn), TempString, TempSize);
}
if ((TempString = StrStr(PathToReturn, L"\\..")) != NULL && *(TempString + 3) == CHAR_NULL) {
*TempString = CHAR_NULL;
ChopLastSlash(PathToReturn);
}
while ((TempString = StrStr(PathToReturn, L"\\.\\")) != NULL) {
*TempString = CHAR_NULL;
TempString += 2;
TempSize = StrSize(TempString);
CopyMem(PathToReturn+StrLen(PathToReturn), TempString, TempSize);
}
if ((TempString = StrStr(PathToReturn, L"\\.")) != NULL && *(TempString + 2) == CHAR_NULL) {
*TempString = CHAR_NULL;
}
return (PathToReturn);
}
/**
returns a fully qualified directory (contains a map drive at the begining)
path from a unknown directory path.
If Path is already fully qualified this will return a duplicat otherwise this
will use get the current directory and use that to build the fully qualified
version.
if the return value is not NULL it must be caller freed.
@param[in] Path The unknown Path Value
@retval NULL A memory allocation failed
@retval NULL a fully qualified path could not be discovered.
@retval other pointer to a fuly qualified path.
**/
CHAR16*
EFIAPI
GetFullyQualifiedPath(
IN CONST CHAR16* Path
)
{
CHAR16 *PathToReturn;
UINTN Size;
CONST CHAR16 *CurDir;
PathToReturn = NULL;
Size = 0;
ASSERT((PathToReturn == NULL && Size == 0) || (PathToReturn != NULL));
//
// convert a local path to an absolute path
//
if (StrStr(Path, L":") == NULL) {
CurDir = gEfiShellProtocol->GetCurDir(NULL);
StrnCatGrow(&PathToReturn, &Size, CurDir, 0);
if (*Path == L'\\') {
Path++;
}
}
StrnCatGrow(&PathToReturn, &Size, Path, 0);
CleanPath(PathToReturn);
while (PathToReturn[StrLen(PathToReturn)-1] == L'*') {
PathToReturn[StrLen(PathToReturn)-1] = CHAR_NULL;
}
return (PathToReturn);
}
/**
Function to verify all intermediate directories in the path.
@param[in] Path The pointer to the path to fix.
@retval EFI_SUCCESS The operation was successful.
**/
EFI_STATUS
EFIAPI
VerifyIntermediateDirectories (
IN CONST CHAR16 *Path
)
{
EFI_STATUS Status;
CHAR16 *PathCopy;
CHAR16 *TempSpot;
SHELL_FILE_HANDLE FileHandle;
ASSERT(Path != NULL);
Status = EFI_SUCCESS;
PathCopy = NULL;
PathCopy = StrnCatGrow(&PathCopy, NULL, Path, 0);
FileHandle = NULL;
for (TempSpot = &PathCopy[StrLen(PathCopy)-1] ; *TempSpot != CHAR_NULL && *TempSpot != L'\\' ; TempSpot = &PathCopy[StrLen(PathCopy)-1]){
*TempSpot = CHAR_NULL;
}
if (*TempSpot == L'\\') {
*TempSpot = CHAR_NULL;
}
if (PathCopy != NULL && *PathCopy != CHAR_NULL) {
Status = VerifyIntermediateDirectories(PathCopy);
if (PathCopy[StrLen(PathCopy)-1] != L':') {
if (!EFI_ERROR(Status)) {
Status = ShellOpenFileByName(PathCopy, &FileHandle, EFI_FILE_MODE_READ, 0);
if (FileHandle != NULL) {
ShellCloseFile(&FileHandle);
}
}
}
}
SHELL_FREE_NON_NULL(PathCopy);
return (Status);
}
// be lazy and borrow from baselib.
CHAR16
EFIAPI
InternalCharToUpper (
IN CONST CHAR16 Char
);
CONST CHAR16*
EFIAPI
StrniCmp(
IN CONST CHAR16 *Source,
IN CONST CHAR16 *Target,
IN CONST UINTN Count
)
{
UINTN LoopCount;
CHAR16 Char1;
CHAR16 Char2;
ASSERT(Source != NULL);
ASSERT(Target != NULL);
for (LoopCount = 0 ; LoopCount < Count ; LoopCount++) {
Char1 = InternalCharToUpper(Source[LoopCount]);
Char2 = InternalCharToUpper(Target[LoopCount]);
if (Char1 != Char2) {
return (&Source[LoopCount]);
}
}
return (NULL);
}

View File

@ -0,0 +1,297 @@
/** @file
Main file for NULL named library for level 2 shell command functions.
these functions are:
attrib, cd, cp, date*, time*, rm, reset,
load, ls, map, mkdir, mv, parse, set, timezone*
* functions are non-interactive only
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 <ShellBase.h>
#include <Protocol/EfiShell.h>
#include <Protocol/EfiShellParameters.h>
#include <Protocol/DevicePath.h>
#include <Protocol/LoadedImage.h>
#include <Protocol/UnicodeCollation.h>
#include <Protocol/DevicePathToText.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
#include <Library/ShellCommandLib.h>
#include <Library/ShellLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/HiiLib.h>
#include <Library/SortLib.h>
#include <Library/FileHandleLib.h>
extern CONST CHAR16 mFileName[];
extern EFI_HANDLE gShellLevel2HiiHandle;
extern CONST EFI_GUID gShellLevel2HiiGuid;
/**
Function for 'attrib' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunAttrib (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'date' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunDate (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'time' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunTime (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'load' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunLoad (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'ls' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunLs (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'map' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunMap (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'reset' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunReset (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'timezone' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunTimeZone (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'set' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunSet (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'mkdir' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunMkDir (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'cd' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunCd (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'cp' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunCp (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'parse' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunParse (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'rm' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunRm (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'mv' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunMv (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
returns a fully qualified directory (contains a map drive at the begining)
path from a unknown directory path.
If Path is already fully qualified this will return a duplicat otherwise this
will use get the current directory and use that to build the fully qualified
version.
if the return value is not NULL it must be caller freed.
@param[in] Path The unknown Path Value
@retval NULL A memory allocation failed
@retval NULL a fully qualified path could not be discovered.
@retval other pointer to a fuly qualified path.
**/
CHAR16*
EFIAPI
GetFullyQualifiedPath(
IN CONST CHAR16* Path
);
/**
Function to verify all intermediate directories in the path.
@param[in] Path The pointer to the path to fix.
@retval EFI_SUCCESS The operation was successful.
**/
EFI_STATUS
EFIAPI
VerifyIntermediateDirectories (
IN CONST CHAR16 *Path
);
/**
CaseInsensitive length limited string comparison.
@param[in] Source Pointer to first string.
@param[in] Target Pointer to second string.
@param[in] Count Number of characters to compare.
@retval 0 The strings are the same.
@return non-zero if the strings are different.
**/
CONST CHAR16*
EFIAPI
StrniCmp(
IN CONST CHAR16 *Source,
IN CONST CHAR16 *Target,
IN CONST UINTN Count
);

View File

@ -0,0 +1,82 @@
## @file
# Provides shell level 2 functions
#
# Copyright (c) 2009, Intel Corporation.All rights reserved. <BR>
#
# 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 = UefiShellLevel2CommandsLib
FILE_GUID = CBF3931C-A2DF-40e5-B77E-CCA9555E9755
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = NULL|UEFI_APPLICATION UEFI_DRIVER
CONSTRUCTOR = ShellLevel2CommandsLibConstructor
DESTRUCTOR = ShellLevel2CommandsLibDestructor
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources.common]
UefiShellLevel2CommandsLib.c
UefiShellLevel2CommandsLib.h
UefiShellLevel2CommandsLib.uni
TimeDate.c
Load.c
Ls.c
Map.c
Reset.c
Set.c
MkDir.c
Cd.c
Cp.c
Parse.c
Rm.c
Mv.c
Attrib.c
[Packages]
MdePkg/MdePkg.dec
ShellPkg/ShellPkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
MemoryAllocationLib
BaseLib
BaseMemoryLib
DebugLib
ShellCommandLib
ShellLib
UefiLib
UefiRuntimeServicesTableLib
UefiBootServicesTableLib
PcdLib
HiiLib
HandleParsingLib
[Protocols]
gEfiUnicodeCollation2ProtocolGuid # ALWAYS_CONSUMED
gEfiShellProtocolGuid # ALWAYS_CONSUMED
gEfiShellParametersProtocolGuid # ALWAYS_CONSUMED
gEfiDevicePathProtocolGuid # ALWAYS_CONSUMED
gEfiLoadedImageProtocolGuid # ALWAYS_CONSUMED
gEfiSimpleFileSystemProtocolGuid # ALWAYS_CONSUMED
gEfiDevicePathToTextProtocolGuid # ALWAYS_CONSUMED
[Pcd.common]
gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel # ALWAYS_CONSUMED
gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize # ALWAYS_CONSUMED
[Guids]
gEfiFileSystemInfoGuid
gEfiFileInfoGuid

View File

@ -0,0 +1,162 @@
/** @file
Main file for Alias shell level 3 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
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 "UefiShellLevel3CommandsLib.h"
#include <Library/ShellLib.h>
/**
Print out each alias registered with the Shell.
@retval STATUS_SUCCESS the printout was sucessful
@return any return code from GetNextVariableName except EFI_NOT_FOUND
**/
SHELL_STATUS
EFIAPI
PrintAllShellAlias(
VOID
)
{
CONST CHAR16 *ConstAllAliasList;
CHAR16 *Alias;
CONST CHAR16 *Command;
CHAR16 *Walker;
BOOLEAN Volatile;
Volatile = FALSE;
ConstAllAliasList = gEfiShellProtocol->GetAlias(NULL, NULL);
if (ConstAllAliasList == NULL) {
return (SHELL_SUCCESS);
}
Alias = AllocateZeroPool(StrSize(ConstAllAliasList));
Walker = (CHAR16*)ConstAllAliasList;
do {
CopyMem(Alias, Walker, StrSize(Walker));
Walker = StrStr(Alias, L";");
if (Walker != NULL) {
Walker[0] = CHAR_NULL;
Walker = Walker + 1;
}
Command = gEfiShellProtocol->GetAlias(Alias, &Volatile);
if (ShellCommandIsOnAliasList(Alias)) {
Volatile = FALSE;
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_ALIAS_OUTPUT), gShellLevel3HiiHandle, !Volatile?L' ':L'*', Alias, Command);
} while (Walker != NULL && Walker[0] != CHAR_NULL);
FreePool(Alias);
return (SHELL_SUCCESS);
}
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{L"-v", TypeFlag},
{L"-d", TypeFlag},
{NULL, TypeMax}
};
/**
Function for 'alias' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunAlias (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
CONST CHAR16 *Param1;
CONST CHAR16 *Param2;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
Param1 = ShellCommandLineGetRawValue(Package, 1);
Param2 = ShellCommandLineGetRawValue(Package, 2);
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
}
if (ShellCommandLineGetCount(Package) == 1) {
//
// print out alias'
//
Status = PrintAllShellAlias();
} else if (ShellCommandLineGetFlag(Package, L"-d")) {
//
// delete an alias
//
Status = gEfiShellProtocol->SetAlias(Param1, NULL, TRUE, FALSE);
} else if (ShellCommandLineGetCount(Package) == 3) {
//
// must be adding an alias
//
Status = gEfiShellProtocol->SetAlias(Param2, Param1, FALSE, ShellCommandLineGetFlag(Package, L"-v"));
if (EFI_ERROR(Status)) {
if (Status == EFI_ACCESS_DENIED) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellLevel3HiiHandle);
ShellStatus = SHELL_ACCESS_DENIED;
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel3HiiHandle, Status);
ShellStatus = SHELL_DEVICE_ERROR;
}
}
} else if (ShellCommandLineGetCount(Package) == 2) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel3HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
}
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
}
return (ShellStatus);
}

View File

@ -0,0 +1,135 @@
/** @file
Main file for attrib shell level 2 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
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 "UefiShellLevel3CommandsLib.h"
/**
Function for 'cls' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunCls (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *Message;
UINTN Background;
UINTN ForeColor;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
CONST CHAR16 *Param1;
ShellStatus = SHELL_SUCCESS;
ProblemParam = NULL;
Background = 0;
//
// Initialize variables
//
Message = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
} else {
//
// If there are 0 value parameters, clear sceen
//
Param1 = ShellCommandLineGetRawValue(Package, 1);
if (Param1 == NULL) {
//
// clear screen
//
gST->ConOut->ClearScreen (gST->ConOut);
} else if (ShellCommandLineGetCount(Package) > 2) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
if (StrDecimalToUintn(Param1) > 7 || StrLen(Param1) > 1 || !ShellIsDecimalDigitCharacter(*Param1)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, Param1);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
switch (StrDecimalToUintn(Param1)) {
case 0:
Background = EFI_BACKGROUND_BLACK;
break;
case 1:
Background = EFI_BACKGROUND_BLUE;
break;
case 2:
Background = EFI_BACKGROUND_GREEN;
break;
case 3:
Background = EFI_BACKGROUND_CYAN;
break;
case 4:
Background = EFI_BACKGROUND_RED;
break;
case 5:
Background = EFI_BACKGROUND_MAGENTA;
break;
case 6:
Background = EFI_BACKGROUND_BROWN;
break;
case 7:
Background = EFI_BACKGROUND_LIGHTGRAY;
break;
}
ForeColor = (~StrDecimalToUintn(Param1)) & 0xF;
Status = gST->ConOut->SetAttribute (gST->ConOut, ForeColor | Background);
ASSERT_EFI_ERROR(Status);
Status = gST->ConOut->ClearScreen (gST->ConOut);
ASSERT_EFI_ERROR(Status);
}
}
}
}
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
//
// return the status
//
return (ShellStatus);
}

View File

@ -0,0 +1,116 @@
/** @file
Main file for Echo shell level 3 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
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 "UefiShellLevel3CommandsLib.h"
#include <Library/ShellLib.h>
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{L"-on", TypeFlag},
{L"-off", TypeFlag},
{NULL, TypeMax}
};
/**
Function for 'echo' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunEcho (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
// CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
UINTN ParamCount;
// ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParseEx (ParamList, &Package, NULL, TRUE, TRUE);
// if (EFI_ERROR(Status)) {
// if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
// ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);
// FreePool(ProblemParam);
// ShellStatus = SHELL_INVALID_PARAMETER;
// } else {
// ASSERT(FALSE);
// }
// } else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
}
if (ShellCommandLineGetFlag(Package, L"-on")) {
//
// Turn it on
//
ShellCommandSetEchoState(TRUE);
} else if (ShellCommandLineGetFlag(Package, L"-off")) {
//
// turn it off
//
ShellCommandSetEchoState(FALSE);
} else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
//
// output its current state
//
if (ShellCommandGetEchoState()) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_ECHO_ON), gShellLevel3HiiHandle);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_ECHO_OFF), gShellLevel3HiiHandle);
}
} else {
//
// print the line
//
for ( ParamCount = 1
; ShellCommandLineGetRawValue(Package, ParamCount) != NULL
; ParamCount++
) {
if (ShellCommandLineGetRawValue(Package, ParamCount+1) != NULL) {
ShellPrintEx(-1, -1, L"%s ", ShellCommandLineGetRawValue(Package, ParamCount));
} else {
ShellPrintEx(-1, -1, L"%s", ShellCommandLineGetRawValue(Package, ParamCount));
}
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CRLF), gShellLevel3HiiHandle);
}
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
// }
return (ShellStatus);
}

View File

@ -0,0 +1,101 @@
/** @file
Main file for GetMtc shell level 3 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
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 "UefiShellLevel3CommandsLib.h"
#include <Library/ShellLib.h>
/**
Function for 'getmtc' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunGetMtc (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
UINT64 Mtc;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
} else if (ShellCommandLineGetRawValue(Package, 1) != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// Get the monotonic counter count
//
Status = gBS->GetNextMonotonicCount(&Mtc);
switch(Status) {
case EFI_DEVICE_ERROR:
ShellStatus = SHELL_DEVICE_ERROR;
break;
case EFI_SECURITY_VIOLATION:
ShellStatus = SHELL_SECURITY_VIOLATION;
break;
default:
if (EFI_ERROR(Status)) {
ShellStatus = SHELL_DEVICE_ERROR;
}
}
//
// print it...
//
if (ShellStatus == SHELL_SUCCESS) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GET_MTC_OUTPUT), gShellLevel3HiiHandle, Mtc);
}
}
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
}
return (ShellStatus);
}

View File

@ -0,0 +1,183 @@
/** @file
Main file for Help shell level 3 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
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 "UefiShellLevel3CommandsLib.h"
#include <Library/ShellLib.h>
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{L"-usage", TypeFlag},
{L"-section", TypeValue},
{L"-verbose", TypeFlag},
{L"-v", TypeFlag},
{NULL, TypeMax}
};
/**
Function for 'help' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunHelp (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
CHAR16 *OutText;
CONST COMMAND_LIST *CommandList;
CONST COMMAND_LIST *Node;
CHAR16 *CommandToGetHelpOn;
CHAR16 *SectionToGetHelpOn;
CHAR16 *HiiString;
BOOLEAN Found;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
OutText = NULL;
CommandToGetHelpOn = NULL;
SectionToGetHelpOn = NULL;
Found = FALSE;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
//
// Check for conflicting parameters.
//
if (ShellCommandLineGetFlag(Package, L"-usage")
&&ShellCommandLineGetFlag(Package, L"-section")
&&(ShellCommandLineGetFlag(Package, L"-verbose") || ShellCommandLineGetFlag(Package, L"-v"))
){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellLevel3HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else if (ShellCommandLineGetRawValue(Package, 2) != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// Get the command name we are getting help on
//
ASSERT(CommandToGetHelpOn == NULL);
StrnCatGrow(&CommandToGetHelpOn, NULL, ShellCommandLineGetRawValue(Package, 1), 0);
if (CommandToGetHelpOn == NULL && ShellCommandLineGetFlag(Package, L"-?")) {
//
// If we dont have a command and we got a simple -?
// we are looking for help on help command.
//
StrnCatGrow(&CommandToGetHelpOn, NULL, L"help", 0);
}
if (CommandToGetHelpOn == NULL) {
StrnCatGrow(&CommandToGetHelpOn, NULL, L"*", 0);
ASSERT(SectionToGetHelpOn == NULL);
StrnCatGrow(&SectionToGetHelpOn, NULL, L"NAME", 0);
} else {
ASSERT(SectionToGetHelpOn == NULL);
//
// Get the section name for the given command name
//
if (ShellCommandLineGetFlag(Package, L"-section")) {
StrnCatGrow(&SectionToGetHelpOn, NULL, ShellCommandLineGetValue(Package, L"-section"), 0);
} else if (ShellCommandLineGetFlag(Package, L"-usage")) {
StrnCatGrow(&SectionToGetHelpOn, NULL, L"NAME,SYNOPSIS", 0);
} else if (ShellCommandLineGetFlag(Package, L"-verbose") || ShellCommandLineGetFlag(Package, L"-v")) {
} else {
StrnCatGrow(&SectionToGetHelpOn, NULL, L"NAME", 0);
}
}
if (gUnicodeCollation->StriColl(gUnicodeCollation, CommandToGetHelpOn, L"special") == 0) {
//
// we need info on the special characters
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_SC_HEADER), gShellLevel3HiiHandle);
HiiString = HiiGetString(gShellLevel3HiiHandle, STRING_TOKEN(STR_HELP_SC_DATA), NULL);
ShellPrintEx(-1, -1, L"%s", HiiString);
FreePool(HiiString);
Found = TRUE;
} else {
CommandList = ShellCommandGetCommandList();
ASSERT(CommandList != NULL);
for ( Node = (COMMAND_LIST*)GetFirstNode(&CommandList->Link)
; CommandList != NULL && !IsListEmpty(&CommandList->Link) && !IsNull(&CommandList->Link, &Node->Link)
; Node = (COMMAND_LIST*)GetNextNode(&CommandList->Link, &Node->Link)
){
if (gUnicodeCollation->MetaiMatch(gUnicodeCollation, Node->CommandString, CommandToGetHelpOn)) {
//
// We have a command to look for help on.
//
Status = gEfiShellProtocol->GetHelpText(Node->CommandString, SectionToGetHelpOn, &OutText);
if (EFI_ERROR(Status) || OutText == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_NF), gShellLevel3HiiHandle, Node->CommandString);
ShellStatus = SHELL_NOT_FOUND;
} else {
while (OutText[StrLen(OutText)-1] == L'\r' || OutText[StrLen(OutText)-1] == L'\n' || OutText[StrLen(OutText)-1] == L' ') {
OutText[StrLen(OutText)-1] = CHAR_NULL;
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_COMMAND), gShellLevel3HiiHandle, Node->CommandString, OutText);
FreePool(OutText);
OutText = NULL;
Found = TRUE;
}
}
}
}
if (!Found && ShellStatus == SHELL_SUCCESS) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_NF), gShellLevel3HiiHandle, CommandToGetHelpOn);
ShellStatus = SHELL_NOT_FOUND;
}
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
}
}
if (CommandToGetHelpOn != NULL) {
FreePool(CommandToGetHelpOn);
}
if (SectionToGetHelpOn != NULL) {
FreePool(SectionToGetHelpOn);
}
return (ShellStatus);
}

View File

@ -0,0 +1,106 @@
/** @file
Main file for Pause shell level 3 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
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 "UefiShellLevel3CommandsLib.h"
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{L"-q", TypeFlag},
{NULL, TypeMax}
};
/**
Function for 'pause' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunPause (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
SHELL_PROMPT_RESPONSE *Resp;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
if (!gEfiShellProtocol->BatchIsActive()) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_SCRIPT_ONLY), gShellLevel3HiiHandle);
return (SHELL_UNSUPPORTED);
}
//
// parse the command line
//
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
} else if (ShellCommandLineGetRawValue(Package, 1) != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
if (!ShellCommandLineGetFlag(Package, L"-q")) {
Status = ShellPromptForResponseHii(ShellPromptResponseTypeQuitContinue, STRING_TOKEN (STR_PAUSE_PROMPT), gShellLevel3HiiHandle, (VOID**)&Resp);
} else {
Status = ShellPromptForResponse(ShellPromptResponseTypeQuitContinue, NULL, (VOID**)&Resp);
}
ASSERT_EFI_ERROR(Status);
if (Resp == NULL || *Resp == ShellPromptResponseQuit) {
ShellCommandRegisterExit(TRUE);
ShellStatus = SHELL_ABORTED;
}
if (Resp != NULL) {
FreePool(Resp);
}
}
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
}
return (ShellStatus);
}

View File

@ -0,0 +1,265 @@
/** @file
Main file for Touch shell level 3 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
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 "UefiShellLevel3CommandsLib.h"
#include <Library/ShellLib.h>
EFI_STATUS
EFIAPI
TouchFileByHandle (
IN EFI_HANDLE Handle
)
{
EFI_STATUS Status;
EFI_FILE_INFO *FileInfo;
FileInfo = gEfiShellProtocol->GetFileInfo(Handle);
if ((FileInfo->Attribute & EFI_FILE_READ_ONLY) != 0){
return (EFI_ACCESS_DENIED);
}
Status = gRT->GetTime(&FileInfo->ModificationTime, NULL);
ASSERT_EFI_ERROR(Status);
CopyMem(&FileInfo->LastAccessTime, &FileInfo->ModificationTime, sizeof(EFI_TIME));
Status = gEfiShellProtocol->SetFileInfo(Handle, FileInfo);
FreePool(FileInfo);
return (Status);
}
EFI_STATUS
EFIAPI
DoTouchByHandle (
IN CONST CHAR16 *Name,
IN CHAR16 *FS,
IN SHELL_FILE_HANDLE Handle,
IN BOOLEAN Rec
)
{
EFI_STATUS Status;
EFI_SHELL_FILE_INFO *FileList;
EFI_SHELL_FILE_INFO *Walker;
CHAR16 *TempSpot;
Status = EFI_SUCCESS;
FileList = NULL;
Walker = NULL;
if (FS == NULL) {
FS = StrnCatGrow(&FS, NULL, Name, 0);
TempSpot = StrStr(FS, L"\\");
if (TempSpot != NULL) {
*TempSpot = CHAR_NULL;
}
}
//
// do it
//
Status = TouchFileByHandle(Handle);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NO_OPEN), gShellLevel3HiiHandle, Name, Status);
return (Status);
}
//
// if it's a directory recurse...
//
if (FileHandleIsDirectory(Handle) == EFI_SUCCESS && Rec) {
//
// get each file under this directory
//
if (EFI_ERROR(gEfiShellProtocol->FindFilesInDir(Handle, &FileList))) {
Status = EFI_INVALID_PARAMETER;
}
//
// recurse on each
//
for (Walker = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)
; FileList != NULL && !IsNull(&FileList->Link, &Walker->Link) && !EFI_ERROR(Status)
; Walker = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Walker->Link)
){
if ( (StrCmp(Walker->FileName, L".") != 0)
&& (StrCmp(Walker->FileName, L"..") != 0)
){
//
// Open the file since we need that handle.
//
Status = gEfiShellProtocol->OpenFileByName (Walker->FullName, &Walker->Handle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NO_OPEN), gShellLevel3HiiHandle, Walker->FullName, Status);
Status = EFI_ACCESS_DENIED;
} else {
Status = DoTouchByHandle(Walker->FullName, FS, Walker->Handle, TRUE);
gEfiShellProtocol->CloseFile(Walker->Handle);
Walker->Handle = NULL;
}
}
}
//
// free stuff
//
if (FileList != NULL && EFI_ERROR(gEfiShellProtocol->FreeFileList(&FileList))) {
Status = EFI_INVALID_PARAMETER;
}
}
return (Status);
}
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{L"-r", TypeFlag},
{NULL, TypeMax}
};
/**
Function for 'touch' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunTouch (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
CONST CHAR16 *Param;
SHELL_STATUS ShellStatus;
UINTN ParamCount;
EFI_SHELL_FILE_INFO *FileList;
EFI_SHELL_FILE_INFO *Node;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
ParamCount = 0;
FileList = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
}
if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
//
// we insufficient parameters
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel3HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// get a list with each file specified by parameters
// if parameter is a directory then add all the files below it to the list
//
for ( ParamCount = 1, Param = ShellCommandLineGetRawValue(Package, ParamCount)
; Param != NULL
; ParamCount++, Param = ShellCommandLineGetRawValue(Package, ParamCount)
){
Status = ShellOpenFileMetaArg((CHAR16*)Param, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, &FileList);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, (CHAR16*)Param);
ShellStatus = SHELL_NOT_FOUND;
break;
}
//
// make sure we completed the param parsing sucessfully...
// Also make sure that any previous action was sucessful
//
if (ShellStatus == SHELL_SUCCESS) {
//
// check that we have at least 1 file
//
if (FileList == NULL || IsListEmpty(&FileList->Link)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel3HiiHandle, Param);
continue;
} else {
//
// loop through the list and make sure we are not aborting...
//
for ( Node = (EFI_SHELL_FILE_INFO*)GetFirstNode(&FileList->Link)
; !IsNull(&FileList->Link, &Node->Link) && !ShellGetExecutionBreakFlag()
; Node = (EFI_SHELL_FILE_INFO*)GetNextNode(&FileList->Link, &Node->Link)
){
//
// make sure the file opened ok
//
if (EFI_ERROR(Node->Status)){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NO_OPEN), gShellLevel3HiiHandle, Node->FileName, Node->Status);
ShellStatus = SHELL_NOT_FOUND;
continue;
}
Status = DoTouchByHandle(Node->FullName, NULL, Node->Handle, ShellCommandLineGetFlag(Package, L"-r"));
if (EFI_ERROR(Status) && Status != EFI_ACCESS_DENIED) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NO_OPEN), gShellLevel3HiiHandle, Node->FileName, Status);
ShellStatus = SHELL_NOT_FOUND;
}
}
}
}
//
// Free the fileList
//
if (FileList != NULL && !IsListEmpty(&FileList->Link)) {
Status = ShellCloseFileMetaArg(&FileList);
ASSERT_EFI_ERROR(Status);
}
FileList = NULL;
}
}
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
}
if (ShellGetExecutionBreakFlag()) {
return (SHELL_ABORTED);
}
return (ShellStatus);
}

View File

@ -0,0 +1,239 @@
/** @file
Main file for Type shell level 3 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
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 "UefiShellLevel3CommandsLib.h"
#include <Library/ShellLib.h>
EFI_STATUS
EFIAPI
TypeFileByHandle (
IN EFI_HANDLE Handle,
BOOLEAN Ascii,
BOOLEAN UCS2
)
{
UINTN ReadSize;
VOID *Buffer;
EFI_STATUS Status;
UINTN LoopVar;
CHAR16 AsciiChar;
ReadSize = PcdGet16(PcdShellFileOperationSize);
Buffer = AllocatePool(ReadSize);
if (Buffer == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
Status = ShellSetFilePosition(Handle, 0);
ASSERT_EFI_ERROR(Status);
while (ReadSize == ((UINTN)PcdGet16(PcdShellFileOperationSize))){
ZeroMem(Buffer, ReadSize);
Status = ShellReadFile(Handle, &ReadSize, Buffer);
if (EFI_ERROR(Status)){
break;
}
if (!(Ascii|UCS2)){
if (*(UINT16*)Buffer == UnicodeFileTag) {
UCS2 = TRUE;
Buffer = ((UINT16*)Buffer) + 1;
} else {
Ascii = TRUE;
}
}
//
// We want to use plain Print function here! (no color support for files)
//
if (Ascii){
for (LoopVar = 0 ; LoopVar < ReadSize ; LoopVar++) {
AsciiChar = CHAR_NULL;
AsciiChar = ((CHAR8*)Buffer)[LoopVar];
if (AsciiChar == CHAR_NULL) {
AsciiChar = '.';
}
Print(L"%c", AsciiChar);
}
} else {
Print(L"%s", Buffer);
}
}
Status = Print(L"\r\n", Buffer);
return (Status);
}
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{L"-a", TypeFlag},
{L"-u", TypeFlag},
{NULL, TypeMax}
};
/**
Function for 'type' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunType (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
CONST CHAR16 *Param;
SHELL_STATUS ShellStatus;
UINTN ParamCount;
EFI_SHELL_FILE_INFO *FileList;
EFI_SHELL_FILE_INFO *Node;
BOOLEAN AsciiMode;
BOOLEAN UnicodeMode;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
ParamCount = 0;
FileList = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
}
AsciiMode = ShellCommandLineGetFlag(Package, L"-a");
UnicodeMode = ShellCommandLineGetFlag(Package, L"-u");
if (AsciiMode && UnicodeMode) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, L"-a & -u");
ShellStatus = SHELL_INVALID_PARAMETER;
} else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
//
// we insufficient parameters
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel3HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// get a list with each file specified by parameters
// if parameter is a directory then add all the files below it to the list
//
for ( ParamCount = 1, Param = ShellCommandLineGetRawValue(Package, ParamCount)
; Param != NULL
; ParamCount++, Param = ShellCommandLineGetRawValue(Package, ParamCount)
){
Status = ShellOpenFileMetaArg((CHAR16*)Param, EFI_FILE_MODE_READ, &FileList);
if (EFI_ERROR(Status)) {
ShellStatus = SHELL_NOT_FOUND;
break;
}
//
// make sure we completed the param parsing sucessfully...
// Also make sure that any previous action was sucessful
//
if (ShellStatus == SHELL_SUCCESS) {
//
// check that we have at least 1 file
//
if (FileList == NULL || IsListEmpty(&FileList->Link)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel3HiiHandle, Param);
continue;
} else {
//
// loop through the list and make sure we are not aborting...
//
for ( Node = (EFI_SHELL_FILE_INFO*)GetFirstNode(&FileList->Link)
; !IsNull(&FileList->Link, &Node->Link) && !ShellGetExecutionBreakFlag()
; Node = (EFI_SHELL_FILE_INFO*)GetNextNode(&FileList->Link, &Node->Link)
){
//
// make sure the file opened ok
//
if (EFI_ERROR(Node->Status)){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NO_OPEN), gShellLevel3HiiHandle, Node->FileName, Node->Status);
ShellStatus = SHELL_NOT_FOUND;
continue;
}
//
// make sure its not a directory
//
if (FileHandleIsDirectory(Node->Handle) == EFI_SUCCESS) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_IS_DIR), gShellLevel3HiiHandle, Node->FileName);
ShellStatus = SHELL_NOT_FOUND;
continue;
}
//
// do it
//
Status = TypeFileByHandle(Node->Handle, AsciiMode, UnicodeMode);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TYP_ERROR), gShellLevel3HiiHandle, Node->FileName, Status);
ShellStatus = SHELL_INVALID_PARAMETER;
}
ASSERT(ShellStatus == SHELL_SUCCESS);
}
}
}
//
// Free the fileList
//
if (FileList != NULL && !IsListEmpty(&FileList->Link)) {
Status = ShellCloseFileMetaArg(&FileList);
}
ASSERT_EFI_ERROR(Status);
FileList = NULL;
}
}
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
}
if (ShellGetExecutionBreakFlag()) {
return (SHELL_ABORTED);
}
return (ShellStatus);
}

View File

@ -0,0 +1,94 @@
/** @file
Main file for NULL named library for level 3 shell command functions.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
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 "UefiShellLevel3CommandsLib.h"
CONST CHAR16 gShellLevel3FileName[] = L"ShellCommands";
EFI_HANDLE gShellLevel3HiiHandle = NULL;
STATIC CONST EFI_GUID gShellLevel3HiiGuid = \
{ \
0x4344558d, 0x4ef9, 0x4725, { 0xb1, 0xe4, 0x33, 0x76, 0xe8, 0xd6, 0x97, 0x4f } \
};
CONST CHAR16*
EFIAPI
ShellCommandGetManFileNameLevel3 (
VOID
)
{
return (gShellLevel3FileName);
}
/**
Constructor for the Shell Level 3 Commands library.
Install the handlers for level 3 UEFI Shell 2.0 commands.
@param ImageHandle the image handle of the process
@param SystemTable the EFI System Table pointer
@retval EFI_SUCCESS the shell command handlers were installed sucessfully
@retval EFI_UNSUPPORTED the shell level required was not found.
**/
EFI_STATUS
EFIAPI
ShellLevel3CommandsLibConstructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
gShellLevel3HiiHandle = NULL;
//
// if shell level is less than 3 do nothing
//
if (PcdGet8(PcdShellSupportLevel) < 3) {
return (EFI_UNSUPPORTED);
}
gShellLevel3HiiHandle = HiiAddPackages (&gShellLevel3HiiGuid, gImageHandle, UefiShellLevel3CommandsLibStrings, NULL);
if (gShellLevel3HiiHandle == NULL) {
return (EFI_DEVICE_ERROR);
}
//
// install our shell command handlers that are always installed
//
// Note: that Time, Timezone, and Date are part of level 2 library
//
ShellCommandRegisterCommandName(L"type", ShellCommandRunType , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_TYPE));
ShellCommandRegisterCommandName(L"touch", ShellCommandRunTouch , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_TOUCH));
ShellCommandRegisterCommandName(L"ver", ShellCommandRunVer , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_VER));
ShellCommandRegisterCommandName(L"alias", ShellCommandRunAlias , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_ALIAS));
ShellCommandRegisterCommandName(L"cls", ShellCommandRunCls , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_CLS));
ShellCommandRegisterCommandName(L"echo", ShellCommandRunEcho , ShellCommandGetManFileNameLevel3, 3, L"", FALSE, gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_ECHO));
ShellCommandRegisterCommandName(L"pause", ShellCommandRunPause , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_PAUSE));
ShellCommandRegisterCommandName(L"getmtc", ShellCommandRunGetMtc , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_GETMTC));
ShellCommandRegisterCommandName(L"help", ShellCommandRunHelp , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_HELP));
return (EFI_SUCCESS);
}
/**
Destructor for the library. free any resources.
**/
EFI_STATUS
EFIAPI
ShellLevel3CommandsLibDestructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
if (gShellLevel3HiiHandle != NULL) {
HiiRemovePackages(gShellLevel3HiiHandle);
}
return (EFI_SUCCESS);
}

View File

@ -0,0 +1,156 @@
/** @file
header file for NULL named library for level 3 shell command functions.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
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 <ShellBase.h>
#include <Protocol/EfiShell.h>
#include <Protocol/EfiShellParameters.h>
#include <Protocol/DevicePath.h>
#include <Protocol/LoadedImage.h>
#include <Protocol/UnicodeCollation.h>
#include <Protocol/DevicePathToText.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
#include <Library/ShellCommandLib.h>
#include <Library/ShellLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/HiiLib.h>
#include <Library/FileHandleLib.h>
extern EFI_HANDLE gShellLevel3HiiHandle;
/**
Function for 'type' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunType (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'touch' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunTouch (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'ver' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunVer (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'alias' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunAlias (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'cls' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunCls (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'echo' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunEcho (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'pause' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunPause (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'getmtc' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunGetMtc (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
/**
Function for 'help' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunHelp (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);

View File

@ -0,0 +1,68 @@
## @file
# Provides shell level 3 functions
# Note that the interactive versions of the time, date, and timezone functions are handled in the level 2 library.
#
# Copyright (c) 2009-2010, Intel Corporation. All rights reserved. <BR>
#
# 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 = UefiShellLevel3CommandsLib
FILE_GUID = 71374B42-85D7-4753-AD17-AA84C3A0EB93
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = NULL|UEFI_APPLICATION UEFI_DRIVER
CONSTRUCTOR = ShellLevel3CommandsLibConstructor
DESTRUCTOR = ShellLevel3CommandsLibDestructor
[Sources.common]
# note that time, timezone, and date are part of the level 2 library
Type.c
Touch.c
Ver.c
UefiShellLevel3CommandsLib.uni
UefiShellLevel3CommandsLib.c
UefiShellLevel3CommandsLib.h
Cls.c
Alias.c
Echo.c
Pause.c
GetMtc.c
Help.c
[Packages]
MdePkg/MdePkg.dec
ShellPkg/ShellPkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
MemoryAllocationLib
BaseLib
BaseMemoryLib
DebugLib
ShellCommandLib
ShellLib
UefiLib
UefiRuntimeServicesTableLib
UefiBootServicesTableLib
PcdLib
HiiLib
FileHandleLib
[Guids]
gEfiFileInfoGuid
[Pcd.common]
gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel
gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize

View File

@ -0,0 +1,145 @@
/** @file
Main file for Ver shell level 3 function.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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 "UefiShellLevel3CommandsLib.h"
#include <Library/ShellLib.h>
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{L"-s", TypeFlag},
{L"-terse", TypeFlag},
{L"-t", TypeFlag},
{L"-_pa", TypeFlag},
{NULL, TypeMax}
};
/**
Function for 'ver' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunVer (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
UINT8 Level;
Level = PcdGet8(PcdShellSupportLevel);
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
}
if (ShellCommandLineGetRawValue(Package, 1) != NULL) {
//
// we have too many parameters
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
if (ShellCommandLineGetFlag(Package, L"-s")) {
ShellPrintHiiEx (
0,
gST->ConOut->Mode->CursorRow,
NULL,
STRING_TOKEN (STR_VER_OUTPUT_SIMPLE),
gShellLevel3HiiHandle,
gEfiShellProtocol->MajorVersion,
gEfiShellProtocol->MinorVersion
);
} else {
ShellPrintHiiEx (
0,
gST->ConOut->Mode->CursorRow,
NULL,
STRING_TOKEN (STR_VER_OUTPUT_SHELL),
gShellLevel3HiiHandle,
SupportLevel[Level],
gEfiShellProtocol->MajorVersion,
gEfiShellProtocol->MinorVersion
);
if (!ShellCommandLineGetFlag(Package, L"-terse") && !ShellCommandLineGetFlag(Package, L"-t")){
ShellPrintHiiEx(
-1,
-1,
NULL,
STRING_TOKEN (STR_VER_EXTRA_STRING),
gShellLevel3HiiHandle
);
ShellPrintHiiEx (
-1,
-1,
NULL,
STRING_TOKEN (STR_VER_OUTPUT_UEFI),
gShellLevel3HiiHandle,
(gST->Hdr.Revision&0xffff0000)>>16,
(gST->Hdr.Revision&0x0000ffff),
gST->FirmwareVendor,
gST->FirmwareRevision
);
}
}
//
// implementation specific support for displaying processor architecture
//
if (ShellCommandLineGetFlag(Package, L"-_pa")) {
ShellPrintEx(-1, -1, L"%d\r\n", sizeof(UINTN)==sizeof(UINT64)?64:32);
}
}
//
// free the command line package
//
ShellCommandLineFreeVarList (Package);
}
return (ShellStatus);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
## @file
## @file
# Provides interface to shell functionality for shell commands and applications.
#
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved. <BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@ -27,7 +27,7 @@
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
[Sources.common]
UefiShellLib.c
UefiShellLib.h
@ -63,6 +63,6 @@
gEfiFileInfoGuid # ALWAYS_CONSUMED
gEfiShellEnvironment2ExtGuid # ALWAYS_CONSUMED
[Pcd]
[Pcd.common]
gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize # ALWAYS_CONSUMED
gEfiShellPkgTokenSpaceGuid.PcdShellPrintBufferSize # ALWAYS_CONSUMED

View File

@ -1,7 +1,7 @@
/** @file
Library used for sorting routines.
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
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
@ -71,7 +71,7 @@ QuickSortWorker (
if ( Count < 2
|| ElementSize < 1
){
){
return;
}
@ -89,7 +89,7 @@ QuickSortWorker (
for ( LoopCount = 0
; LoopCount < Count -1
; LoopCount++
){
){
//
// if the element is less than the pivot
//
@ -291,3 +291,24 @@ StringNoCaseCompare (
}
/**
Function to compare 2 strings.
@param[in] Buffer1 Pointer to String to compare (CHAR16**).
@param[in] Buffer2 Pointer to second String to compare (CHAR16**).
@retval 0 Buffer1 equal to Buffer2.
@return < 0 Buffer1 is less than Buffer2.
@return > 0 Buffer1 is greater than Buffer2.
**/
INTN
EFIAPI
StringCompare (
IN CONST VOID *Buffer1,
IN CONST VOID *Buffer2
)
{
return (StrCmp(
*(CHAR16**)Buffer1,
*(CHAR16**)Buffer2));
}

View File

@ -1,7 +1,7 @@
## @file
## @file
# Library used for sorting routines.
#
# Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2009, Intel Corporation. All rights reserved. <BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@ -19,13 +19,13 @@
FILE_GUID = 4264A823-45A3-42db-B92C-AA078555CBD3
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = SORTLib|UEFI_APPLICATION UEFI_DRIVER
LIBRARY_CLASS = SortLib|UEFI_APPLICATION UEFI_DRIVER UEFI_DRIVER
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
[Sources.common]
UefiSortLib.c
[Packages]
@ -46,4 +46,4 @@
[Guids]
[Pcd]
[Pcd.common]

View File

@ -1,9 +1,10 @@
## @file ShellPkg.dec
## @file ShellPkg.dec
#
# This Package provides all definitions for EFI and UEFI Shell
#
# Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 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
@ -19,37 +20,40 @@
DEC_SPECIFICATION = 0x00010005
PACKAGE_NAME = ShellPkg
PACKAGE_GUID = 9FB7587C-93F7-40a7-9C04-FD7BA94EE646
PACKAGE_VERSION = 0.2
PACKAGE_VERSION = 0.40
[Includes]
[Includes.common]
Include
[LibraryClasses]
## @libraryclass Provides most Shell APIs.
# Only available for Shell applications
##
[LibraryClasses.common]
## @libraryclass Provides most Shell APIs. Only available for Shell applications
ShellLib|Include/Library/ShellLib.h
## @libraryclass provides EFI_FILE_HANDLE services
## used by Shell and ShellLib
##
## @libraryclass Provides shell internal support Only available for shell internal commands
ShellCommandLib|Include/Library/ShellCommandLib.h
## @libraryclass provides EFI_FILE_HANDLE services used by Shell and ShellLib
FileHandleLib|Include/Library/FileHandleLib.h
## @libraryclass Allows for a shell application to have a C style entry point
##
ShellCEntryLib|Include/Library/ShellCEntryLib.h
## @libraryclass Provides sorting functions
##
SortLib|Include/Library/Sortlib.h
SortLib|Include/Library/SortLib.h
## @libraryclass Provides advanced parsing functions
HandleParsingLib|Include/Library/HandleParsingLib.h
[Guids]
[Guids.common]
gEfiShellEnvironment2ExtGuid = {0xd2c18636, 0x40e5, 0x4eb5, {0xa3, 0x1b, 0x36, 0x69, 0x5f, 0xd4, 0x2c, 0x87}}
gEfiShellPkgTokenSpaceGuid = {0x171e9188, 0x31d3, 0x40f5, {0xb1, 0x0c, 0x53, 0x9b, 0x2d, 0xb9, 0x40, 0xcd}}
gEfiShellPkgTokenSpaceGuid = {0x171e9188, 0x31d3, 0x40f5, {0xb1, 0x0c, 0x53, 0x9b, 0x2d, 0xb9, 0x40, 0xcd}}
gShellVariableGuid = {0x158def5a, 0xf656, 0x419c, {0xb0, 0x27, 0x7a, 0x31, 0x92, 0xc0, 0x79, 0xd2}}
gShellMapGuid = {0x51271e13, 0x7de3, 0x43af, {0x8b, 0xc2, 0x71, 0xad, 0x3b, 0x82, 0x43, 0x25}}
gShellAliasGuid = {0x0053d9d6, 0x2659, 0x4599, {0xa2, 0x6b, 0xef, 0x45, 0x36, 0xe6, 0x31, 0xa9}}
[Protocols]
[Protocols.common]
gEfiShellProtocolGuid = {0x6302d008, 0x7f9b, 0x4f30, {0x87, 0xac, 0x60, 0xc9, 0xfe, 0xf5, 0xda, 0x4e}}
gEfiShellParametersProtocolGuid = {0x752f3136, 0x4e16, 0x4fdc, {0xa2, 0x2a, 0xe5, 0xf4, 0x68, 0x12, 0xf4, 0xca}}
gEfiShellEnvironment2Guid = {0x47c7b221, 0xc42a, 0x11d2, {0x8e, 0x57, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}
@ -57,10 +61,54 @@
[PcdsFixedAtBuild]
## This flag is used to control initialization of the shell library
## This should be FALSE for compiling the shell application itself only.
# This should be FALSE for compiling the shell application itself only.
gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|TRUE|BOOLEAN|0x00000005
## This is the max buffer for ShellLib printings.
gEfiShellPkgTokenSpaceGuid.PcdShellPrintBufferSize|8000|UINT16|0x0000000C
## This is the max buffer for ShellLib, FileHandleLib, and internal Shell printings.
gEfiShellPkgTokenSpaceGuid.PcdShellPrintBufferSize|16000|UINT16|0x0000000C
## This flag is used to control the commands available in the shell
gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel|3|UINT8|0x00000001
## This flag is used to control the profiles available in the shell
# don't forget to update the text file if you change this.
# bit 0 = Drivers1
# bit 1 = Debug1
# bit 2 = Install1
# bit 3 = Network1
gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask|0xFF|UINT8|0x0000000D
## This is the character count for allocation for consistent mappings
gEfiShellPkgTokenSpaceGuid.PcdShellMapNameLength|50|UINT8|0x00000009
## This determins how many bytes are read out of files at a time for file operations (type, copy, etc...)
gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize|1000|UINT16|0x0000000A
[PcdsFeatureFlag]
## This flag is used to control whether the shell includes NT32 platform Guids
# and thereby prevents dependancy on that Pkg
gEfiShellPkgTokenSpaceGuid.PcdShellIncludeNtGuids|TRUE|BOOLEAN|0x0000000E
## This flag is used to control HII required by the shell
gEfiShellPkgTokenSpaceGuid.PcdShellRequireHiiPlatform|TRUE|BOOLEAN|0x00000003
## This flag is used to control HII required by the shell
gEfiShellPkgTokenSpaceGuid.PcdShellSupportFrameworkHii|FALSE|BOOLEAN|0x00000004
## This flag forces the shell to present a user console. Allows for earlier debugging of platforms.
gEfiShellPkgTokenSpaceGuid.PcdShellForceConsole|FALSE|BOOLEAN|0x0000000F
[PcdsFixedAtBuild,PcdsPatchableInModule,PcdsDynamic]
## This flag is used to control the protocols produced by the shell
# If TRUE the shell will produce EFI_SHELL_ENVIRONMENT2 and EFI_SHELL_INTERFACE
gEfiShellPkgTokenSpaceGuid.PcdShellSupportOldProtocols|FALSE|BOOLEAN|0x00000002
## this flag determins whether Page Break (-b) defaults to on or off in the shell
gEfiShellPkgTokenSpaceGuid.PcdShellPageBreakDefault|FALSE|BOOLEAN|0x00000006
## this flag determins whether insert mode for typing is default (FALSE means typeover)
gEfiShellPkgTokenSpaceGuid.PcdShellInsertModeDefault|TRUE|BOOLEAN|0x00000007
## this flag determins the default number of screens kept for history log.
# the spec defines 3 as the minimum
gEfiShellPkgTokenSpaceGuid.PcdShellScreenLogCount|3|UINT8|0x00000008

Some files were not shown because too many files have changed in this diff Show More