/** @file
Provides interface to shell internal functions for shell commands.
Copyright (c) 2009 - 2011, 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
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 "UefiShellCommandLib.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 {
};
// STATIC local variables
// global variables required by library class.
L"Minimal",
L"Scripting",
L"Basic",
L"Interactive"
};
/**
Function to make sure that the global protocol pointers are valid.
must be called after constructor before accessing the pointers.
**/
)
{
if (gUnicodeCollation == NULL) {
return (EFI_DEVICE_ERROR);
}
}
if (gDevPathToText == NULL) {
return (EFI_DEVICE_ERROR);
}
}
return (EFI_SUCCESS);
}
/**
Constructor for the Shell Command library.
Initialize the library and determine if the underlying is a UEFI Shell 2.0 or an EFI shell.
@param ImageHandle the image handle of the process
@param SystemTable the EFI System Table pointer
@retval EFI_SUCCESS the initialization was complete sucessfully
**/
)
{
mEchoState = TRUE;
mExitScript = FALSE;
mProfileListSize = 0;
mProfileList = NULL;
if (gUnicodeCollation == NULL) {
return (EFI_DEVICE_ERROR);
}
}
return (RETURN_SUCCESS);
}
/**
Destructor for the library. free any resources.
@param ImageHandle the image handle of the process
@param SystemTable the EFI System Table pointer
@retval RETURN_SUCCESS this function always returns success
**/
)
{
//
// enumerate throught the list and free all the memory
//
}
//
// enumerate through the init command list and free all memory
//
}
//
// enumerate throught the list and free all the memory
//
}
//
// enumerate throught the mappings list and free all the memory
//
){
}
}
}
if (mProfileList != NULL) {
}
gShellCurDir = NULL;
return (RETURN_SUCCESS);
}
/**
Checks if a command is already on the list.
@param[in] CommandString The command string to check for on the list.
**/
)
{
//
// assert for NULL parameter
//
//
// check for the command
//
){
if (gUnicodeCollation->StriColl(
Node->CommandString) == 0
){
return (TRUE);
}
}
return (FALSE);
}
/**
Get the help text for a command.
@param[in] CommandString The command name.
@retval NULL No help text was found.
@return String of help text. Caller reuiqred to free.
**/
)
{
//
// assert for NULL parameter
//
//
// check for the command
//
){
if (gUnicodeCollation->StriColl(
Node->CommandString) == 0
){
}
}
return (NULL);
}
/**
Registers handlers of type SHELL_RUN_COMMAND and
SHELL_GET_MAN_FILENAME for each shell command.
If the ShellSupportLevel is greater than the value of the
PcdShellSupportLevel then return RETURN_UNSUPPORTED.
Registers 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 Pointer to the command name. This is the
name to look for on the command line in
the shell.
@param[in] CommandHandler Pointer to a function that runs the
specified command.
@param[in] GetManFileName Pointer to a function that provides man
filename.
@param[in] ShellMinSupportLevel minimum Shell Support Level which has this
function.
@param[in] ProfileName 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 Handle of this command's HII entry.
@param[in] ManFormatHelp 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 1 handler set for
a given command is allowed.
@sa SHELL_GET_MAN_FILENAME
@sa SHELL_RUN_COMMAND
**/
)
{
//
// ASSERTs for NULL parameters
//
//
// check for shell support level
//
return (RETURN_UNSUPPORTED);
}
//
// check for already on the list
//
return (RETURN_ALREADY_STARTED);
}
//
// allocate memory for new struct
//
//
// populate the new struct
//
if ( StrLen(ProfileName)>0
&& ((mProfileList != NULL
){
if (mProfileList == NULL) {
//
// If this is the first make a leading ';'
//
}
}
//
// add the new struct to the list
//
return (RETURN_SUCCESS);
}
/**
Function to get the current Profile string.
@retval NULL There are no installed profiles.
@return A semi-colon delimited list of profiles.
**/
)
{
return (mProfileList);
}
/**
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 casesensitive
manner, to the section names described in Appendix B UEFI Shell 2.0 spec. 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[in] CommandString Pointer to the command name. This is the name
found on the command line in the shell.
@param[in, out] RetVal Pointer to the return vaule 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
**/
)
{
//
// assert for NULL parameters
//
//
// check for the command
//
){
if (gUnicodeCollation->StriColl(
Node->CommandString) == 0
){
if (CanAffectLE != NULL) {
}
} else {
}
return (RETURN_SUCCESS);
}
}
return (RETURN_NOT_FOUND);
}
/**
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 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.
@return other the name of the MAN file.
@sa SHELL_GET_MAN_FILENAME
**/
)
{
//
// assert for NULL parameters
//
//
// check for the command
//
){
if (gUnicodeCollation->StriColl(
Node->CommandString) == 0
){
return (Node->GetManFileName());
}
}
return (NULL);
}
/**
Get the list of all available shell internal commands. This is a linked list
(via LIST_ENTRY structure). enumerate through it using the BaseLib linked
list functions. do not modify the values.
@param[in] Sort TRUE to alphabetically sort the values first. FALSE otherwise.
@return a Linked list of all available shell commands.
**/
)
{
// if (!Sort) {
// return ((COMMAND_LIST*)(&mCommandList));
// }
return ((COMMAND_LIST*)(&mCommandList));
}
/**
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 Pointer to the Command
@param[in] Alias 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.
**/
)
{
//
// Asserts for NULL
//
//
// allocate memory for new struct
//
//
// populate the new struct
//
//
// add the new struct to the list
//
return (RETURN_SUCCESS);
}
/**
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 alias'.
**/
)
{
return (&mAliasList);
}
/**
Determine if a given alias is on the list of built in alias'.
@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
**/
)
{
//
// assert for NULL parameter
//
//
// check for the Alias
//
){
if (gUnicodeCollation->StriColl(
Node->CommandString) == 0
){
return (TRUE);
}
if (gUnicodeCollation->StriColl(
){
return (TRUE);
}
}
return (FALSE);
}
/**
Function to determine current state of ECHO. Echo determins if lines from scripts
and ECHO commands are enabled.
@retval TRUE Echo is currently enabled
@retval FALSE Echo is currently disabled
**/
)
{
return (mEchoState);
}
/**
Function to set current state of ECHO. Echo determins if lines from scripts
and ECHO commands are enabled.
If State is TRUE, Echo will be enabled.
If State is FALSE, Echo will be disabled.
@param[in] State How to set echo.
**/
)
{
mEchoState = State;
}
/**
Indicate that the current shell or script should exit.
@param[in] ScriptOnly TRUE if exiting a script; FALSE otherwise.
@param[in] ErrorCode The 64 bit error code to return.
**/
)
{
if (mExitRequested) {
} else {
mExitScript = FALSE;
}
}
/**
Retrieve the Exit indicator.
@retval TRUE Exit was indicated.
@retval FALSE Exis was not indicated.
**/
)
{
return (mExitRequested);
}
/**
Retrieve the Exit code.
If ShellCommandGetExit returns FALSE than the return from this is undefined.
@return the value passed into RegisterExit.
**/
)
{
return (mExitCode);
}
/**
Retrieve the Exit script indicator.
If ShellCommandGetExit returns FALSE than the return from this is undefined.
@retval TRUE ScriptOnly was indicated.
@retval FALSE ScriptOnly was not indicated.
**/
)
{
return (mExitScript);
}
/**
Function to cleanup all memory from a SCRIPT_FILE structure.
@param[in] Script The pointer to the structure to cleanup.
**/
)
{
return;
}
}
}
}
}
}
}
}
/**
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.
**/
)
{
return (NULL);
}
}
/**
Function to set a new script as the currently running one.
This function will correctly stack and unstack nested scripts.
@param[in] Script Pointer to new script information structure. if NULL
will remove and de-allocate the top-most Script structure.
@return A pointer to the current running script file after this
change. NULL if removing the final script.
**/
)
{
return (NULL);
}
} else {
return (NULL);
}
}
return (ShellCommandGetCurrentScriptFile());
}
/**
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
**/
)
{
return (String);
}
/**
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.
**/
)
{
NewPathSize = 0;
OriginalPath = NULL;
if (MapListNode == NULL) {
} else {
} else {
}
}
if (MapListNode != NULL) {
}
}
}
} else if (Path) {
//
// Since there was no error and Path was TRUE
// Now add the correct path for that mapping
//
if (OriginalPath != NULL) {
} else {
}
}
return (Status);
}
/**
Creates the default map names for each device path in the system with
a protocol depending on the Type.
Creates the consistent map names for each device path in the system with
a protocol depending on the Type.
Note: This will reset all mappings in the system("map -r").
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
**/
)
{
HandleList = NULL;
//
// Reset the static members back to zero
//
mFsMaxCount = 0;
mBlkMaxCount = 0;
//
// First empty out the existing list.
//
){
} // for loop
}
//
// Find each handle with Simple File System
//
if (HandleList != NULL) {
//
// Do a count of the handles
//
//
// Get all Device Paths
//
}
//
// Sort all DevicePaths
//
//
// Assign new Mappings to all...
//
//
// Get default name first
//
//
// Now do consistent name
//
NewConsistName = ShellCommandConsistMappingGenMappingName(DevicePathList[Count], ConsistMappingTable);
if (NewConsistName != NULL) {
}
}
HandleList = NULL;
} else {
}
//
// Find each handle with Block Io
//
if (HandleList != NULL) {
//
// Get all Device Paths
//
}
//
// Sort all DevicePaths
//
//
// Assign new Mappings to all...
//
//
// Get default name first
//
}
return (EFI_NOT_FOUND);
}
return (EFI_SUCCESS);
}
/**
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.
**/
)
{
return ((EFI_FILE_PROTOCOL*)(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.
@retval NULL There was not enough memory.
**/
)
{
return (NULL);
}
return (NULL);
}
return (NULL);
}
}
return ((SHELL_FILE_HANDLE)(Handle));
}
/**
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.
**/
)
{
){
}
}
return (NULL);
}
/**
Remove a SHELL_FILE_HANDLE from 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.
**/
)
{
){
return (TRUE);
}
}
return (FALSE);
}
/**
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
**/
)
{
//
// ASSERT if Handle is NULL
//
return (FALSE);
}
} else {
}
return (RetVal);
}
/**
Frees any BUFFER_LIST defined type.
@param[in] List The BUFFER_LIST object to free.
**/
)
{
return;
}
//
// enumerate through the buffer list and free all memory
//
){
}
}
}