summaryrefslogtreecommitdiff
path: root/ShellPkg/Application
diff options
context:
space:
mode:
Diffstat (limited to 'ShellPkg/Application')
-rw-r--r--ShellPkg/Application/Shell/ConsoleLogger.c108
-rw-r--r--ShellPkg/Application/Shell/ConsoleWrappers.c12
-rw-r--r--ShellPkg/Application/Shell/ConsoleWrappers.h6
-rw-r--r--ShellPkg/Application/Shell/FileHandleWrappers.c283
-rw-r--r--ShellPkg/Application/Shell/Shell.c173
-rw-r--r--ShellPkg/Application/Shell/Shell.h6
-rw-r--r--ShellPkg/Application/Shell/Shell.unibin4142 -> 4388 bytes
-rw-r--r--ShellPkg/Application/Shell/ShellEnvVar.c12
-rw-r--r--ShellPkg/Application/Shell/ShellManParser.c41
-rw-r--r--ShellPkg/Application/Shell/ShellParametersProtocol.c176
-rw-r--r--ShellPkg/Application/Shell/ShellProtocol.c175
-rw-r--r--ShellPkg/Application/Shell/ShellProtocol.h15
12 files changed, 822 insertions, 185 deletions
diff --git a/ShellPkg/Application/Shell/ConsoleLogger.c b/ShellPkg/Application/Shell/ConsoleLogger.c
index 4b237bf6e9..58518cabe9 100644
--- a/ShellPkg/Application/Shell/ConsoleLogger.c
+++ b/ShellPkg/Application/Shell/ConsoleLogger.c
@@ -1,7 +1,7 @@
/** @file
Provides interface to shell console logger.
- Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
+ 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
@@ -39,40 +39,40 @@ ConsoleLoggerInstall(
EFI_STATUS Status;
ASSERT(ConsoleInfo != NULL);
- (*ConsoleInfo) = AllocatePool(sizeof(CONSOLE_LOGGER_PRIVATE_DATA));
+ (*ConsoleInfo) = AllocateZeroPool(sizeof(CONSOLE_LOGGER_PRIVATE_DATA));
if ((*ConsoleInfo) == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
- (*ConsoleInfo)->Signature = CONSOLE_LOGGER_PRIVATE_DATA_SIGNATURE;
- (*ConsoleInfo)->OldConOut = NULL;
- (*ConsoleInfo)->OldConHandle = NULL;
- (*ConsoleInfo)->Buffer = NULL;
- (*ConsoleInfo)->BufferSize = 0;
- (*ConsoleInfo)->OriginalStartRow = 0;
- (*ConsoleInfo)->CurrentStartRow = 0;
- (*ConsoleInfo)->RowsPerScreen = 0;
- (*ConsoleInfo)->ColsPerScreen = 0;
- (*ConsoleInfo)->Attributes = NULL;
- (*ConsoleInfo)->AttribSize = 0;
- (*ConsoleInfo)->ScreenCount = ScreensToSave;
- (*ConsoleInfo)->HistoryMode.MaxMode = 1;
- (*ConsoleInfo)->HistoryMode.Mode = 0;
- (*ConsoleInfo)->HistoryMode.Attribute = 0;
- (*ConsoleInfo)->HistoryMode.CursorColumn = 0;
- (*ConsoleInfo)->HistoryMode.CursorRow = 0;
- (*ConsoleInfo)->HistoryMode.CursorVisible = FALSE;
- (*ConsoleInfo)->OurConOut.Reset = ConsoleLoggerReset;
- (*ConsoleInfo)->OurConOut.OutputString = ConsoleLoggerOutputString;
- (*ConsoleInfo)->OurConOut.TestString = ConsoleLoggerTestString;
- (*ConsoleInfo)->OurConOut.QueryMode = ConsoleLoggerQueryMode;
- (*ConsoleInfo)->OurConOut.SetMode = ConsoleLoggerSetMode;
- (*ConsoleInfo)->OurConOut.SetAttribute = ConsoleLoggerSetAttribute;
- (*ConsoleInfo)->OurConOut.ClearScreen = ConsoleLoggerClearScreen;
+ (*ConsoleInfo)->Signature = CONSOLE_LOGGER_PRIVATE_DATA_SIGNATURE;
+ (*ConsoleInfo)->OldConOut = gST->ConOut;
+ (*ConsoleInfo)->OldConHandle = gST->ConsoleOutHandle;
+ (*ConsoleInfo)->Buffer = NULL;
+ (*ConsoleInfo)->BufferSize = 0;
+ (*ConsoleInfo)->OriginalStartRow = 0;
+ (*ConsoleInfo)->CurrentStartRow = 0;
+ (*ConsoleInfo)->RowsPerScreen = 0;
+ (*ConsoleInfo)->ColsPerScreen = 0;
+ (*ConsoleInfo)->Attributes = NULL;
+ (*ConsoleInfo)->AttribSize = 0;
+ (*ConsoleInfo)->ScreenCount = ScreensToSave;
+ (*ConsoleInfo)->HistoryMode.MaxMode = 1;
+ (*ConsoleInfo)->HistoryMode.Mode = 0;
+ (*ConsoleInfo)->HistoryMode.Attribute = 0;
+ (*ConsoleInfo)->HistoryMode.CursorColumn = 0;
+ (*ConsoleInfo)->HistoryMode.CursorRow = 0;
+ (*ConsoleInfo)->HistoryMode.CursorVisible = FALSE;
+ (*ConsoleInfo)->OurConOut.Reset = ConsoleLoggerReset;
+ (*ConsoleInfo)->OurConOut.OutputString = ConsoleLoggerOutputString;
+ (*ConsoleInfo)->OurConOut.TestString = ConsoleLoggerTestString;
+ (*ConsoleInfo)->OurConOut.QueryMode = ConsoleLoggerQueryMode;
+ (*ConsoleInfo)->OurConOut.SetMode = ConsoleLoggerSetMode;
+ (*ConsoleInfo)->OurConOut.SetAttribute = ConsoleLoggerSetAttribute;
+ (*ConsoleInfo)->OurConOut.ClearScreen = ConsoleLoggerClearScreen;
(*ConsoleInfo)->OurConOut.SetCursorPosition = ConsoleLoggerSetCursorPosition;
- (*ConsoleInfo)->OurConOut.EnableCursor = ConsoleLoggerEnableCursor;
- (*ConsoleInfo)->OurConOut.Mode = NULL;
- (*ConsoleInfo)->Enabled = TRUE;
+ (*ConsoleInfo)->OurConOut.EnableCursor = ConsoleLoggerEnableCursor;
+ (*ConsoleInfo)->OurConOut.Mode = gST->ConOut->Mode;
+ (*ConsoleInfo)->Enabled = TRUE;
Status = ConsoleLoggerResetBuffers(*ConsoleInfo);
if (EFI_ERROR(Status)) {
@@ -90,11 +90,8 @@ ConsoleLoggerInstall(
return (Status);
}
- (*ConsoleInfo)->OldConOut = gST->ConOut;
- (*ConsoleInfo)->OldConHandle = gST->ConsoleOutHandle;
-
gST->ConsoleOutHandle = gImageHandle;
- gST->ConOut = &(*ConsoleInfo)->OurConOut;
+ gST->ConOut = &(*ConsoleInfo)->OurConOut;
return (Status);
}
@@ -103,7 +100,7 @@ ConsoleLoggerInstall(
Return the system to the state it was before InstallConsoleLogger
was installed.
- @param[in,out] ConsoleInfo The object from the install function.
+ @param[in] ConsoleInfo The object from the install function.
@retval EFI_SUCCESS The operation was successful
@return other The operation failed. This was from UninstallProtocolInterface.
@@ -631,7 +628,10 @@ ConsoleLoggerDoPageBreak(
}
if (*Resp == ShellPromptResponseContinue) {
FreePool(Resp);
- ShellInfoObject.ConsoleInfo->RowCounter = 0;
+ ShellInfoObject.ConsoleInfo->RowCounter = 0;
+// ShellInfoObject.ConsoleInfo->OurConOut.Mode->CursorRow = 0;
+// ShellInfoObject.ConsoleInfo->OurConOut.Mode->CursorColumn = 0;
+
return (EFI_SUCCESS);
} else if (*Resp == ShellPromptResponseQuit) {
FreePool(Resp);
@@ -660,16 +660,23 @@ ConsoleLoggerDoPageBreak(
EFI_STATUS
EFIAPI
ConsoleLoggerPrintWithPageBreak(
- IN CHAR16 *String,
+ IN CONST CHAR16 *String,
IN CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo
)
{
CONST CHAR16 *Walker;
CONST CHAR16 *LineStart;
+ CHAR16 *StringCopy;
CHAR16 TempChar;
- for ( Walker = String
- , LineStart = String
+ StringCopy = NULL;
+ StringCopy = StrnCatGrow(&StringCopy, NULL, String, 0);
+ if (StringCopy == NULL) {
+ return (EFI_OUT_OF_RESOURCES);
+ }
+
+ for ( Walker = StringCopy
+ , LineStart = StringCopy
; Walker != NULL && *Walker != CHAR_NULL
; Walker++
){
@@ -766,6 +773,7 @@ ConsoleLoggerPrintWithPageBreak(
//
// We got an error which means 'break' and halt the printing
//
+ SHELL_FREE_NON_NULL(StringCopy);
return (EFI_DEVICE_ERROR);
}
}
@@ -775,6 +783,7 @@ ConsoleLoggerPrintWithPageBreak(
ConsoleLoggerOutputStringSplit (LineStart, ConsoleInfo);
}
+ SHELL_FREE_NON_NULL(StringCopy);
return (EFI_SUCCESS);
}
@@ -803,6 +812,9 @@ ConsoleLoggerOutputString (
{
CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;
ConsoleInfo = CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(This);
+ if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleOut) {
+ return (EFI_UNSUPPORTED);
+ }
ASSERT(ShellInfoObject.ConsoleInfo == ConsoleInfo);
if (!ShellInfoObject.ConsoleInfo->Enabled) {
return (EFI_DEVICE_ERROR);
@@ -893,8 +905,8 @@ ConsoleLoggerQueryMode (
EFI_STATUS
EFIAPI
ConsoleLoggerSetMode (
- IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
- IN UINTN ModeNumber
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
+ IN UINTN ModeNumber
)
{
EFI_STATUS Status;
@@ -911,6 +923,7 @@ ConsoleLoggerSetMode (
// Check that the buffers are still correct for logging
//
if (!EFI_ERROR (Status)) {
+ ConsoleInfo->OurConOut.Mode = gST->ConOut->Mode;
ConsoleLoggerResetBuffers(ConsoleInfo);
}
@@ -981,9 +994,12 @@ ConsoleLoggerClearScreen (
INT32 *Attributes;
UINTN Row;
UINTN Column;
+ CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;
+ if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleOut) {
+ return (EFI_UNSUPPORTED);
+ }
- CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;
ConsoleInfo = CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(This);
//
@@ -1044,8 +1060,12 @@ ConsoleLoggerSetCursorPosition (
)
{
EFI_STATUS Status;
-
CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;
+
+ if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleOut) {
+ return (EFI_UNSUPPORTED);
+ }
+
ConsoleInfo = CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(This);
//
// Forward the request to the original ConOut
@@ -1154,8 +1174,6 @@ ConsoleLoggerResetBuffers(
return (EFI_OUT_OF_RESOURCES);
}
- ConsoleInfo->OurConOut.Mode = gST->ConOut->Mode;
- ConsoleInfo->OldConOut = gST->ConOut;
CopyMem (&ConsoleInfo->HistoryMode, ConsoleInfo->OldConOut->Mode, sizeof (EFI_SIMPLE_TEXT_OUTPUT_MODE));
return (EFI_SUCCESS);
diff --git a/ShellPkg/Application/Shell/ConsoleWrappers.c b/ShellPkg/Application/Shell/ConsoleWrappers.c
index 61b6a5ee52..3212af9a08 100644
--- a/ShellPkg/Application/Shell/ConsoleWrappers.c
+++ b/ShellPkg/Application/Shell/ConsoleWrappers.c
@@ -1,7 +1,7 @@
/** @file
Function definitions for shell simple text in and out on top of file handles.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
@@ -82,15 +82,15 @@ FileBasedSimpleTextInReset(
ReadKeyStroke function for the fake simple text input.
@param[in] This A pointer to the SimpleTextIn structure.
- @param[out] Key A pointer to the Key structure to fill.
+ @param[in,out] Key A pointer to the Key structure to fill.
@retval EFI_SUCCESS The read was successful.
**/
EFI_STATUS
EFIAPI
FileBasedSimpleTextInReadKeyStroke(
- IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
- IN EFI_INPUT_KEY *Key
+ IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
+ IN OUT EFI_INPUT_KEY *Key
)
{
UINTN Size;
@@ -454,14 +454,14 @@ CreateSimpleTextOutOnFile(
Function to close a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a
SHELL_FILE_HANDLE to support redirecting output from a file.
- @param[in] SimpleTextOut The pointer to the SimpleTextOUT to close.
+ @param[in] SimpleTextOut The pointer to the SimpleTextOUT to close.
@retval EFI_SUCCESS The object was closed.
**/
EFI_STATUS
EFIAPI
CloseSimpleTextOutOnFile(
- OUT EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut
)
{
EFI_STATUS Status;
diff --git a/ShellPkg/Application/Shell/ConsoleWrappers.h b/ShellPkg/Application/Shell/ConsoleWrappers.h
index 966a9225fa..572113d397 100644
--- a/ShellPkg/Application/Shell/ConsoleWrappers.h
+++ b/ShellPkg/Application/Shell/ConsoleWrappers.h
@@ -1,7 +1,7 @@
/** @file
Function definitions for shell simple text in and out on top of file handles.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
@@ -67,14 +67,14 @@ CreateSimpleTextOutOnFile(
Function to close a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a
SHELL_FILE_HANDLE to support redirecting output from a file.
- @param[in] SimpleTextOut The pointer to the SimpleTextOUT to close.
+ @param[in] SimpleTextOut The pointer to the SimpleTextOUT to close.
@retval EFI_SUCCESS The object was closed.
**/
EFI_STATUS
EFIAPI
CloseSimpleTextOutOnFile(
- OUT EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut
);
#endif //_SHELL_CONSOLE_WRAPPERS_HEADER_
diff --git a/ShellPkg/Application/Shell/FileHandleWrappers.c b/ShellPkg/Application/Shell/FileHandleWrappers.c
index ee13d0cb73..38fdb8d848 100644
--- a/ShellPkg/Application/Shell/FileHandleWrappers.c
+++ b/ShellPkg/Application/Shell/FileHandleWrappers.c
@@ -2,7 +2,7 @@
EFI_FILE_PROTOCOL wrappers for other items (Like Environment Variables,
StdIn, StdOut, StdErr, etc...).
- Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
+ 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
@@ -166,18 +166,18 @@ FileInterfaceStdOutWrite(
/**
File style interface for StdIn (Write).
- @param[in] This Ignored.
- @param[in] BufferSize Ignored.
- @param[in] Buffer Ignored.
+ @param[in] This Ignored.
+ @param[in,out] BufferSize Ignored.
+ @param[in] Buffer Ignored.
@retval EFI_UNSUPPORTED
**/
EFI_STATUS
EFIAPI
FileInterfaceStdInWrite(
- IN EFI_FILE_PROTOCOL *This,
- IN OUT UINTN *BufferSize,
- IN VOID *Buffer
+ IN EFI_FILE_PROTOCOL *This,
+ IN OUT UINTN *BufferSize,
+ IN VOID *Buffer
)
{
return (EFI_UNSUPPORTED);
@@ -232,7 +232,7 @@ FileInterfaceStdOutRead(
@param[in,out] BufferSize Ignored.
@param[out] Buffer Ignored.
- @retval EFI_UNSUPPORTED
+ @retval EFI_UNSUPPORTED Always.
**/
EFI_STATUS
EFIAPI
@@ -250,16 +250,16 @@ FileInterfaceStdErrRead(
@param[in] This Ignored.
@param[in,out] BufferSize Ignored.
- @param[in] Buffer Ignored.
+ @param[out] Buffer Ignored.
- @retval EFI_SUCCESS
+ @retval EFI_SUCCESS Always.
**/
EFI_STATUS
EFIAPI
FileInterfaceNulRead(
- IN EFI_FILE_PROTOCOL *This,
- IN OUT UINTN *BufferSize,
- OUT VOID *Buffer
+ IN EFI_FILE_PROTOCOL *This,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
)
{
return (EFI_SUCCESS);
@@ -1352,7 +1352,7 @@ FileInterfaceMemWrite(
//
// Ascii
//
- AsciiBuffer = AllocatePool(*BufferSize);
+ AsciiBuffer = AllocateZeroPool(*BufferSize);
AsciiSPrint(AsciiBuffer, *BufferSize, "%S", Buffer);
if ((UINTN)(((EFI_FILE_PROTOCOL_MEM*)This)->Position + AsciiStrSize(AsciiBuffer)) > (UINTN)(((EFI_FILE_PROTOCOL_MEM*)This)->BufferSize)) {
((EFI_FILE_PROTOCOL_MEM*)This)->Buffer = ReallocatePool((UINTN)(((EFI_FILE_PROTOCOL_MEM*)This)->BufferSize), (UINTN)(((EFI_FILE_PROTOCOL_MEM*)This)->BufferSize) + AsciiStrSize(AsciiBuffer) + 10, ((EFI_FILE_PROTOCOL_MEM*)This)->Buffer);
@@ -1475,6 +1475,224 @@ typedef struct {
} EFI_FILE_PROTOCOL_FILE;
/**
+ Set a files current position
+
+ @param This Protocol instance pointer.
+ @param Position Byte position from the start of the file.
+
+ @retval EFI_SUCCESS Data was written.
+ @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open.
+
+**/
+EFI_STATUS
+EFIAPI
+FileInterfaceFileSetPosition(
+ IN EFI_FILE_PROTOCOL *This,
+ IN UINT64 Position
+ )
+{
+ return ((EFI_FILE_PROTOCOL_FILE*)This)->Orig->SetPosition(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, Position);
+}
+
+/**
+ Get a file's current position
+
+ @param This Protocol instance pointer.
+ @param Position Byte position from the start of the file.
+
+ @retval EFI_SUCCESS Data was written.
+ @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open..
+
+**/
+EFI_STATUS
+EFIAPI
+FileInterfaceFileGetPosition(
+ IN EFI_FILE_PROTOCOL *This,
+ OUT UINT64 *Position
+ )
+{
+ return ((EFI_FILE_PROTOCOL_FILE*)This)->Orig->GetPosition(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, Position);
+}
+
+/**
+ Get information about a file.
+
+ @param This Protocol instance pointer.
+ @param InformationType Type of information to return in Buffer.
+ @param BufferSize On input size of buffer, on output amount of data in buffer.
+ @param Buffer The buffer to return data.
+
+ @retval EFI_SUCCESS Data was returned.
+ @retval EFI_UNSUPPORT InformationType is 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_BUFFER_TOO_SMALL Buffer was too small; required size returned in BufferSize.
+
+**/
+EFI_STATUS
+EFIAPI
+FileInterfaceFileGetInfo(
+ IN EFI_FILE_PROTOCOL *This,
+ IN EFI_GUID *InformationType,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
+ )
+{
+ return ((EFI_FILE_PROTOCOL_FILE*)This)->Orig->GetInfo(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, InformationType, BufferSize, Buffer);
+}
+
+/**
+ Set information about a file
+
+ @param File Protocol instance pointer.
+ @param InformationType Type of information in Buffer.
+ @param BufferSize Size of buffer.
+ @param Buffer The data to write.
+
+ @retval EFI_SUCCESS Data was returned.
+ @retval EFI_UNSUPPORT InformationType is 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.
+
+**/
+EFI_STATUS
+EFIAPI
+FileInterfaceFileSetInfo(
+ IN EFI_FILE_PROTOCOL *This,
+ IN EFI_GUID *InformationType,
+ IN UINTN BufferSize,
+ IN VOID *Buffer
+ )
+{
+ return ((EFI_FILE_PROTOCOL_FILE*)This)->Orig->SetInfo(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, InformationType, BufferSize, Buffer);
+}
+
+/**
+ Flush data back for the file handle.
+
+ @param This Protocol instance pointer.
+
+ @retval EFI_SUCCESS Data was written.
+ @retval EFI_UNSUPPORT Writes to Open directory are not supported.
+ @retval EFI_NO_MEDIA The device has no media.
+ @retval EFI_DEVICE_ERROR The device reported an error.
+ @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
+ @retval EFI_WRITE_PROTECTED The device is write protected.
+ @retval EFI_ACCESS_DENIED The file was open for read only.
+ @retval EFI_VOLUME_FULL The volume is full.
+
+**/
+EFI_STATUS
+EFIAPI
+FileInterfaceFileFlush(
+ IN EFI_FILE_PROTOCOL *This
+ )
+{
+ return ((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Flush(((EFI_FILE_PROTOCOL_FILE*)This)->Orig);
+}
+
+/**
+ Read data from the file.
+
+ @param This Protocol instance pointer.
+ @param BufferSize On input size of buffer, on output amount of data in buffer.
+ @param Buffer The buffer in which data is 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_VOLUME_CORRUPTED The file system structures are corrupted.
+ @retval EFI_BUFFER_TO_SMALL BufferSize is too small. BufferSize contains required size.
+
+**/
+EFI_STATUS
+EFIAPI
+FileInterfaceFileRead(
+ IN EFI_FILE_PROTOCOL *This,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
+ )
+{
+ CHAR8 *AsciiBuffer;
+ UINTN Size;
+ EFI_STATUS Status;
+ if (((EFI_FILE_PROTOCOL_FILE*)This)->Unicode) {
+ //
+ // Unicode
+ //
+ return (((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Read(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, BufferSize, Buffer));
+ } else {
+ //
+ // Ascii
+ //
+ AsciiBuffer = AllocateZeroPool((Size = *BufferSize));
+ Status = (((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Read(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, &Size, AsciiBuffer));
+ UnicodeSPrint(Buffer, *BufferSize, L"%a", AsciiBuffer);
+ FreePool(AsciiBuffer);
+ return (Status);
+ }
+}
+
+/**
+ Opens a new file relative to the source file's location.
+
+ @param[in] This The protocol instance pointer.
+ @param[out] NewHandle Returns File Handle for FileName.
+ @param[in] FileName Null terminated string. "\", ".", and ".." are supported.
+ @param[in] OpenMode Open mode for file.
+ @param[in] Attributes Only used for EFI_FILE_MODE_CREATE.
+
+ @retval EFI_SUCCESS The device was opened.
+ @retval EFI_NOT_FOUND The specified file could not be found on the device.
+ @retval EFI_NO_MEDIA The device has no media.
+ @retval EFI_MEDIA_CHANGED The media has changed.
+ @retval EFI_DEVICE_ERROR The device reported an error.
+ @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
+ @retval EFI_ACCESS_DENIED The service denied access to the file.
+ @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.
+ @retval EFI_VOLUME_FULL The volume is full.
+**/
+EFI_STATUS
+EFIAPI
+FileInterfaceFileOpen (
+ IN EFI_FILE_PROTOCOL *This,
+ OUT EFI_FILE_PROTOCOL **NewHandle,
+ IN CHAR16 *FileName,
+ IN UINT64 OpenMode,
+ IN UINT64 Attributes
+ )
+{
+ return ((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Open(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, NewHandle, FileName, OpenMode, Attributes);
+}
+
+/**
+ Close and delete the file handle.
+
+ @param This Protocol instance pointer.
+
+ @retval EFI_SUCCESS The device was opened.
+ @retval EFI_WARN_DELETE_FAILURE The handle was closed but the file was not deleted.
+
+**/
+EFI_STATUS
+EFIAPI
+FileInterfaceFileDelete(
+ IN EFI_FILE_PROTOCOL *This
+ )
+{
+ EFI_STATUS Status;
+ Status = ((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Delete(((EFI_FILE_PROTOCOL_FILE*)This)->Orig);
+ FreePool(This);
+ return (Status);
+}
+
+/**
File style interface for File (Close).
@param[in] This The pointer to the EFI_FILE_PROTOCOL object.
@@ -1487,9 +1705,10 @@ FileInterfaceFileClose(
IN EFI_FILE_PROTOCOL *This
)
{
- ((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Close(((EFI_FILE_PROTOCOL_FILE*)This)->Orig);
+ EFI_STATUS Status;
+ Status = ((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Close(((EFI_FILE_PROTOCOL_FILE*)This)->Orig);
FreePool(This);
- return (EFI_SUCCESS);
+ return (Status);
}
/**
@@ -1498,18 +1717,18 @@ FileInterfaceFileClose(
If the file was opened with ASCII mode the data will be processed through
AsciiSPrint before writing.
- @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
- @param[in] BufferSize Size in bytes of Buffer.
- @param[in] Buffer The pointer to the buffer to write.
+ @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
+ @param[in,out] BufferSize Size in bytes of Buffer.
+ @param[in] Buffer The pointer to the buffer to write.
@retval EFI_SUCCESS The data was written.
**/
EFI_STATUS
EFIAPI
FileInterfaceFileWrite(
- IN EFI_FILE_PROTOCOL *This,
- IN OUT UINTN *BufferSize,
- IN VOID *Buffer
+ IN EFI_FILE_PROTOCOL *This,
+ IN OUT UINTN *BufferSize,
+ IN VOID *Buffer
)
{
CHAR8 *AsciiBuffer;
@@ -1524,7 +1743,7 @@ FileInterfaceFileWrite(
//
// Ascii
//
- AsciiBuffer = AllocatePool(*BufferSize);
+ AsciiBuffer = AllocateZeroPool(*BufferSize);
AsciiSPrint(AsciiBuffer, *BufferSize, "%S", Buffer);
Size = AsciiStrSize(AsciiBuffer) - 1; // (we dont need the null terminator)
Status = (((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Write(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, &Size, AsciiBuffer));
@@ -1552,15 +1771,23 @@ CreateFileInterfaceFile(
{
EFI_FILE_PROTOCOL_FILE *NewOne;
- NewOne = AllocatePool(sizeof(EFI_FILE_PROTOCOL_FILE));
+ NewOne = AllocateZeroPool(sizeof(EFI_FILE_PROTOCOL_FILE));
if (NewOne == NULL) {
return (NULL);
}
CopyMem(NewOne, Template, sizeof(EFI_FILE_PROTOCOL_FILE));
- NewOne->Orig = (EFI_FILE_PROTOCOL *)Template;
- NewOne->Unicode = Unicode;
- NewOne->Close = FileInterfaceFileClose;
- NewOne->Write = FileInterfaceFileWrite;
+ NewOne->Orig = (EFI_FILE_PROTOCOL *)Template;
+ NewOne->Unicode = Unicode;
+ NewOne->Open = FileInterfaceFileOpen;
+ NewOne->Close = FileInterfaceFileClose;
+ NewOne->Delete = FileInterfaceFileDelete;
+ NewOne->Read = FileInterfaceFileRead;
+ NewOne->Write = FileInterfaceFileWrite;
+ NewOne->GetPosition = FileInterfaceFileGetPosition;
+ NewOne->SetPosition = FileInterfaceFileSetPosition;
+ NewOne->GetInfo = FileInterfaceFileGetInfo;
+ NewOne->SetInfo = FileInterfaceFileSetInfo;
+ NewOne->Flush = FileInterfaceFileFlush;
return ((EFI_FILE_PROTOCOL *)NewOne);
}
diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c
index 1e608cd87d..17943531db 100644
--- a/ShellPkg/Application/Shell/Shell.c
+++ b/ShellPkg/Application/Shell/Shell.c
@@ -1,7 +1,7 @@
/** @file
This is THE shell (application)
- Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
+ 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
@@ -63,6 +63,82 @@ STATIC CONST CHAR16 mExecutableExtensions[] = L".NSH;.EFI";
STATIC CONST CHAR16 mStartupScript[] = L"startup.nsh";
/**
+ Function to start monitoring for CTRL-S using SimpleTextInputEx. This
+ feature's enabled state was not known when the shell initially launched.
+
+ @retval EFI_SUCCESS The feature is enabled.
+ @retval EFI_OUT_OF_RESOURCES There is not enough mnemory available.
+**/
+EFI_STATUS
+EFIAPI
+InternalEfiShellStartCtrlSMonitor(
+ VOID
+ )
+{
+ EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx;
+ EFI_KEY_DATA KeyData;
+ EFI_STATUS Status;
+
+ Status = gBS->OpenProtocol(
+ gST->ConsoleInHandle,
+ &gEfiSimpleTextInputExProtocolGuid,
+ (VOID**)&SimpleEx,
+ gImageHandle,
+ NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+ if (EFI_ERROR(Status)) {
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_SHELL_NO_IN_EX),
+ ShellInfoObject.HiiHandle);
+ return (EFI_SUCCESS);
+ }
+
+ KeyData.KeyState.KeyToggleState = 0;
+ KeyData.Key.ScanCode = 0;
+ KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;
+ KeyData.Key.UnicodeChar = L's';
+
+ Status = SimpleEx->RegisterKeyNotify(
+ SimpleEx,
+ &KeyData,
+ NotificationFunction,
+ &ShellInfoObject.CtrlSNotifyHandle1);
+
+ KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;
+ if (!EFI_ERROR(Status)) {
+ Status = SimpleEx->RegisterKeyNotify(
+ SimpleEx,
+ &KeyData,
+ NotificationFunction,
+ &ShellInfoObject.CtrlSNotifyHandle2);
+ }
+ KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;
+ KeyData.Key.UnicodeChar = 19;
+
+ if (!EFI_ERROR(Status)) {
+ Status = SimpleEx->RegisterKeyNotify(
+ SimpleEx,
+ &KeyData,
+ NotificationFunction,
+ &ShellInfoObject.CtrlSNotifyHandle2);
+ }
+ KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;
+ if (!EFI_ERROR(Status)) {
+ Status = SimpleEx->RegisterKeyNotify(
+ SimpleEx,
+ &KeyData,
+ NotificationFunction,
+ &ShellInfoObject.CtrlSNotifyHandle2);
+ }
+ return (Status);
+}
+
+
+
+/**
The entry point for the application.
@param[in] ImageHandle The firmware allocated handle for the EFI image.
@@ -278,6 +354,13 @@ UefiMain (
Status = InernalEfiShellStartMonitor();
}
+ if (!EFI_ERROR(Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {
+ //
+ // Set up the event for CTRL-S monitoring...
+ //
+ Status = InternalEfiShellStartCtrlSMonitor();
+ }
+
if (!EFI_ERROR(Status) && PcdGet8(PcdShellSupportLevel) >= 1) {
//
// process the startup script or launch the called app.
@@ -577,6 +660,7 @@ ProcessCommandLine(
UINTN Count;
UINTN LoopVar;
CHAR16 *ProblemParam;
+ UINT64 Intermediate;
Package = NULL;
ProblemParam = NULL;
@@ -587,7 +671,7 @@ ProcessCommandLine(
Size = 0;
TempConst = ShellCommandLineGetRawValue(Package, Count++);
if (TempConst != NULL && StrLen(TempConst)) {
- ShellInfoObject.ShellInitSettings.FileName = AllocatePool(StrSize(TempConst));
+ ShellInfoObject.ShellInitSettings.FileName = AllocateZeroPool(StrSize(TempConst));
if (ShellInfoObject.ShellInitSettings.FileName == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
@@ -641,17 +725,19 @@ ProcessCommandLine(
ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoVersion = ShellCommandLineGetFlag(Package, L"-noversion");
ShellInfoObject.ShellInitSettings.BitUnion.Bits.Delay = ShellCommandLineGetFlag(Package, L"-delay");
- if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.Delay) {
+ ShellInfoObject.ShellInitSettings.Delay = 5;
+
+ if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoInterrupt) {
+ ShellInfoObject.ShellInitSettings.Delay = 0;
+ } else if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.Delay) {
TempConst = ShellCommandLineGetValue(Package, L"-delay");
- if (TempConst != NULL) {
- ShellInfoObject.ShellInitSettings.Delay = StrDecimalToUintn (TempConst);
- } else {
- ShellInfoObject.ShellInitSettings.Delay = 5;
+ if (*TempConst == L':') {
+ TempConst++;
+ }
+ if (TempConst != NULL && !EFI_ERROR(ShellConvertStringToUint64(TempConst, &Intermediate, FALSE, FALSE))) {
+ ShellInfoObject.ShellInitSettings.Delay = (UINTN)Intermediate;
}
- } else {
- ShellInfoObject.ShellInitSettings.Delay = 5;
}
-
ShellCommandLineFreeVarList(Package);
return (Status);
@@ -681,7 +767,9 @@ DoStartupScript(
EFI_DEVICE_PATH_PROTOCOL *NewPath;
EFI_DEVICE_PATH_PROTOCOL *NamePath;
CHAR16 *FileStringPath;
+ CHAR16 *TempSpot;
UINTN NewSize;
+ CONST CHAR16 *MapName;
Key.UnicodeChar = CHAR_NULL;
Key.ScanCode = 0;
@@ -723,13 +811,15 @@ DoStartupScript(
//
// print out our warning and see if they press a key
//
- for ( Status = EFI_UNSUPPORTED, Delay = (ShellInfoObject.ShellInitSettings.Delay * 10)
- ; Delay > 0 && EFI_ERROR(Status)
+ for ( Status = EFI_UNSUPPORTED, Delay = ShellInfoObject.ShellInitSettings.Delay * 10
+ ; Delay != 0 && EFI_ERROR(Status)
; Delay--
){
ShellPrintHiiEx(0, gST->ConOut->Mode->CursorRow, NULL, STRING_TOKEN (STR_SHELL_STARTUP_QUESTION), ShellInfoObject.HiiHandle, Delay/10);
gBS->Stall (100000);
- Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
+ if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {
+ Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
+ }
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_CRLF), ShellInfoObject.HiiHandle);
@@ -740,25 +830,39 @@ DoStartupScript(
return (EFI_SUCCESS);
}
- NamePath = FileDevicePath (NULL, mStartupScript);
//
- // Try the first location
+ // Try the first location (must be file system)
//
- NewPath = AppendDevicePathNode (ImagePath, NamePath);
- Status = InternalOpenFileDevicePath(NewPath, &FileHandle, EFI_FILE_MODE_READ, 0);
+ MapName = ShellInfoObject.NewEfiShellProtocol->GetMapFromDevicePath(&ImagePath);
+ if (MapName != NULL) {
+ FileStringPath = NULL;
+ NewSize = 0;
+ FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, MapName, 0);
+ TempSpot = StrStr(FileStringPath, L";");
+ if (TempSpot != NULL) {
+ *TempSpot = CHAR_NULL;
+ }
+ FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, ((FILEPATH_DEVICE_PATH*)FilePath)->PathName, 0);
+ ChopLastSlash(FileStringPath);
+ FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, mStartupScript, 0);
+ Status = ShellInfoObject.NewEfiShellProtocol->OpenFileByName(FileStringPath, &FileHandle, EFI_FILE_MODE_READ);
+ FreePool(FileStringPath);
+ }
if (EFI_ERROR(Status)) {
+ NamePath = FileDevicePath (NULL, mStartupScript);
+ NewPath = AppendDevicePathNode (ImagePath, NamePath);
+ FreePool(NamePath);
+
//
- // Try the second location
+ // Try the location
//
- FreePool(NewPath);
- NewPath = AppendDevicePathNode (FilePath , NamePath);
Status = InternalOpenFileDevicePath(NewPath, &FileHandle, EFI_FILE_MODE_READ, 0);
+ FreePool(NewPath);
}
-
//
// If we got a file, run it
//
- if (!EFI_ERROR(Status)) {
+ if (!EFI_ERROR(Status) && FileHandle != NULL) {
Status = RunScriptFileHandle (FileHandle, mStartupScript);
ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle);
} else {
@@ -775,8 +879,6 @@ DoStartupScript(
}
}
- FreePool(NamePath);
- FreePool(NewPath);
return (Status);
}
@@ -920,7 +1022,7 @@ ShellConvertAlias(
return (EFI_SUCCESS);
}
FreePool(*CommandString);
- *CommandString = AllocatePool(StrSize(NewString));
+ *CommandString = AllocateZeroPool(StrSize(NewString));
if (*CommandString == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
@@ -1185,7 +1287,7 @@ RunCommand(
UINTN PostAliasSize;
CHAR16 *PostVariableCmdLine;
CHAR16 *CommandWithPath;
- EFI_DEVICE_PATH_PROTOCOL *DevPath;
+ CONST EFI_DEVICE_PATH_PROTOCOL *DevPath;
CONST CHAR16 *TempLocation;
CONST CHAR16 *TempLocation2;
SHELL_FILE_HANDLE OriginalStdIn;
@@ -1319,7 +1421,11 @@ RunCommand(
Status = UpdateStdInStdOutStdErr(ShellInfoObject.NewShellParametersProtocol, PostVariableCmdLine, &OriginalStdIn, &OriginalStdOut, &OriginalStdErr, &OriginalSystemTableInfo);
if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_REDIR), ShellInfoObject.HiiHandle);
+ if (Status == EFI_NOT_FOUND) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_REDUNDA_REDIR), ShellInfoObject.HiiHandle);
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_REDIR), ShellInfoObject.HiiHandle);
+ }
} else {
//
// remove the < and/or > from the command line now
@@ -1452,7 +1558,6 @@ RunCommand(
SHELL_FREE_NON_NULL(CommandName);
SHELL_FREE_NON_NULL(CommandWithPath);
SHELL_FREE_NON_NULL(PostVariableCmdLine);
- SHELL_FREE_NON_NULL(DevPath);
return (Status);
}
@@ -1591,12 +1696,12 @@ RunScriptFileHandle (
//
// Now enumerate through the commands and run each one.
//
- CommandLine = AllocatePool(PcdGet16(PcdShellPrintBufferSize));
+ CommandLine = AllocateZeroPool(PcdGet16(PcdShellPrintBufferSize));
if (CommandLine == NULL) {
DeleteScriptFileStruct(NewScriptFile);
return (EFI_OUT_OF_RESOURCES);
}
- CommandLine2 = AllocatePool(PcdGet16(PcdShellPrintBufferSize));
+ CommandLine2 = AllocateZeroPool(PcdGet16(PcdShellPrintBufferSize));
if (CommandLine2 == NULL) {
FreePool(CommandLine);
DeleteScriptFileStruct(NewScriptFile);
@@ -1732,11 +1837,17 @@ RunScriptFileHandle (
}
}
- ShellCommandSetEchoState(PreScriptEchoState);
FreePool(CommandLine);
FreePool(CommandLine2);
ShellCommandSetNewScript (NULL);
+
+ //
+ // Only if this was the last script reset the state.
+ //
+ if (ShellCommandGetCurrentScriptFile()==NULL) {
+ ShellCommandSetEchoState(PreScriptEchoState);
+ }
return (EFI_SUCCESS);
}
diff --git a/ShellPkg/Application/Shell/Shell.h b/ShellPkg/Application/Shell/Shell.h
index ec32355b6c..3699fb233d 100644
--- a/ShellPkg/Application/Shell/Shell.h
+++ b/ShellPkg/Application/Shell/Shell.h
@@ -1,7 +1,7 @@
/** @file
function definitions for internal to shell functions.
- Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
+ 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
@@ -109,6 +109,10 @@ typedef struct {
EFI_HANDLE CtrlCNotifyHandle2; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
EFI_HANDLE CtrlCNotifyHandle3; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
EFI_HANDLE CtrlCNotifyHandle4; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
+ EFI_HANDLE CtrlSNotifyHandle1; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
+ EFI_HANDLE CtrlSNotifyHandle2; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
+ EFI_HANDLE CtrlSNotifyHandle3; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
+ EFI_HANDLE CtrlSNotifyHandle4; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
} SHELL_INFO;
extern SHELL_INFO ShellInfoObject;
diff --git a/ShellPkg/Application/Shell/Shell.uni b/ShellPkg/Application/Shell/Shell.uni
index e7327f3dbb..a217f746cf 100644
--- a/ShellPkg/Application/Shell/Shell.uni
+++ b/ShellPkg/Application/Shell/Shell.uni
Binary files differ
diff --git a/ShellPkg/Application/Shell/ShellEnvVar.c b/ShellPkg/Application/Shell/ShellEnvVar.c
index 519181b56d..174a783830 100644
--- a/ShellPkg/Application/Shell/ShellEnvVar.c
+++ b/ShellPkg/Application/Shell/ShellEnvVar.c
@@ -1,7 +1,7 @@
/** @file
function declarations for shell environment functions.
- Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
+ 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
@@ -56,7 +56,7 @@ IsVolatileEnv (
&Size,
Buffer);
if (Status == EFI_BUFFER_TOO_SMALL) {
- Buffer = AllocatePool(Size);
+ Buffer = AllocateZeroPool(Size);
ASSERT(Buffer != NULL);
Status = gRT->GetVariable((CHAR16*)EnvVarName,
&gShellVariableGuid,
@@ -154,7 +154,7 @@ GetEnvironmentVariableList(
}
NameSize = (UINTN)MaxVarSize;
- VariableName = AllocatePool(NameSize);
+ VariableName = AllocateZeroPool(NameSize);
if (VariableName == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
@@ -175,7 +175,7 @@ GetEnvironmentVariableList(
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);
+ VarList->Val = AllocateZeroPool(ValSize);
if (VarList->Val == NULL) {
SHELL_FREE_NON_NULL(VarList);
Status = EFI_OUT_OF_RESOURCES;
@@ -184,7 +184,7 @@ GetEnvironmentVariableList(
}
}
if (!EFI_ERROR(Status) && VarList != NULL) {
- VarList->Key = AllocatePool(StrSize(VariableName));
+ VarList->Key = AllocateZeroPool(StrSize(VariableName));
if (VarList->Key == NULL) {
SHELL_FREE_NON_NULL(VarList->Val);
SHELL_FREE_NON_NULL(VarList);
@@ -312,7 +312,7 @@ SetEnvironmentVariables(
break;
}
ASSERT(StrStr(CurrentString, L"=") != NULL);
- Node = AllocatePool(sizeof(ENV_VAR_LIST));
+ Node = AllocateZeroPool(sizeof(ENV_VAR_LIST));
ASSERT(Node != NULL);
Node->Key = AllocateZeroPool((StrStr(CurrentString, L"=") - CurrentString + 1) * sizeof(CHAR16));
ASSERT(Node->Key != NULL);
diff --git a/ShellPkg/Application/Shell/ShellManParser.c b/ShellPkg/Application/Shell/ShellManParser.c
index e184c78d4f..ab32c36b75 100644
--- a/ShellPkg/Application/Shell/ShellManParser.c
+++ b/ShellPkg/Application/Shell/ShellManParser.c
@@ -1,7 +1,7 @@
/** @file
Provides interface to shell MAN file parser.
- Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
+ 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
@@ -368,7 +368,7 @@ ManBufferFindTitleSection(
Status = EFI_SUCCESS;
- TitleString = AllocatePool((7*sizeof(CHAR16)) + StrSize(Command));
+ TitleString = AllocateZeroPool((7*sizeof(CHAR16)) + StrSize(Command));
if (TitleString == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
@@ -389,24 +389,27 @@ ManBufferFindTitleSection(
; 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);
+ if (TitleEnd == NULL) {
+ Status = EFI_DEVICE_ERROR;
+ } else {
+ 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;
+ for (CurrentLocation = TitleEnd
+ ; *CurrentLocation != L'\n'
+ ; CurrentLocation++);
+ for (
+ ; *CurrentLocation == L' ' || *CurrentLocation == L'\n' || *CurrentLocation == L'\r'
+ ; CurrentLocation++);
+ *Buffer = CurrentLocation;
+ }
}
FreePool(TitleString);
@@ -465,7 +468,7 @@ ManFileFindTitleSection(
return (EFI_OUT_OF_RESOURCES);
}
- TitleString = AllocatePool((4*sizeof(CHAR16)) + StrSize(Command));
+ TitleString = AllocateZeroPool((4*sizeof(CHAR16)) + StrSize(Command));
if (TitleString == NULL) {
FreePool(ReadLine);
return (EFI_OUT_OF_RESOURCES);
diff --git a/ShellPkg/Application/Shell/ShellParametersProtocol.c b/ShellPkg/Application/Shell/ShellParametersProtocol.c
index b594d3434f..3d138825ff 100644
--- a/ShellPkg/Application/Shell/ShellParametersProtocol.c
+++ b/ShellPkg/Application/Shell/ShellParametersProtocol.c
@@ -2,7 +2,7 @@
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>
+ 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
@@ -127,9 +127,9 @@ GetNextParameter(
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'^') {
+ }/* else if (*NextDelim == L'^') {
*NextDelim = L' ';
- }
+ }*/
}
while ((*TempParameter)[StrLen(*TempParameter)-1] == L' ') {
(*TempParameter)[StrLen(*TempParameter)-1] = CHAR_NULL;
@@ -142,7 +142,7 @@ GetNextParameter(
}
/**
- function to populate Argc and Argv.
+ 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
@@ -419,6 +419,34 @@ CleanUpShellParametersProtocol (
return (Status);
}
+EFI_STATUS
+EFIAPI
+IsUnicodeFile(
+ IN CONST CHAR16 *FileName
+ )
+{
+ SHELL_FILE_HANDLE Handle;
+ EFI_STATUS Status;
+ UINT64 OriginalFilePosition;
+ UINTN CharSize;
+ CHAR16 CharBuffer;
+
+ Status = gEfiShellProtocol->OpenFileByName(FileName, &Handle, EFI_FILE_MODE_READ);
+ if (EFI_ERROR(Status)) {
+ return (Status);
+ }
+ gEfiShellProtocol->GetFilePosition(Handle, &OriginalFilePosition);
+ gEfiShellProtocol->SetFilePosition(Handle, 0);
+ CharSize = sizeof(CHAR16);
+ Status = gEfiShellProtocol->ReadFile(Handle, &CharSize, &CharBuffer);
+ if (EFI_ERROR(Status) || CharBuffer != gUnicodeFileTag) {
+ Status = EFI_BUFFER_TOO_SMALL;
+ }
+ gEfiShellProtocol->SetFilePosition(Handle, OriginalFilePosition);
+ gEfiShellProtocol->CloseFile(Handle);
+ 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
@@ -513,41 +541,70 @@ UpdateStdInStdOutStdErr(
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>>v ")) != NULL) {
+ SetMem16(CommandLineWalker, 12, L' ');
StdErrVarName = CommandLineWalker += 6;
ErrAppend = TRUE;
+ if (StrStr(CommandLineWalker, L" 2>>v ") != NULL) {
+ Status = EFI_NOT_FOUND;
+ }
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>>v ")) != NULL) {
+ SetMem16(CommandLineWalker, 12, L' ');
StdOutVarName = CommandLineWalker += 6;
OutAppend = TRUE;
+ if (StrStr(CommandLineWalker, L" 1>>v ") != NULL) {
+ Status = EFI_NOT_FOUND;
+ }
} else if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >>v ")) != NULL) {
+ SetMem16(CommandLineWalker, 10, L' ');
StdOutVarName = CommandLineWalker += 5;
OutAppend = TRUE;
+ if (StrStr(CommandLineWalker, L" >>v ") != NULL) {
+ Status = EFI_NOT_FOUND;
+ }
} else if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >v ")) != NULL) {
+ SetMem16(CommandLineWalker, 8, L' ');
StdOutVarName = CommandLineWalker += 4;
OutAppend = FALSE;
+ if (StrStr(CommandLineWalker, L" >v ") != NULL) {
+ Status = EFI_NOT_FOUND;
+ }
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>>a ")) != NULL) {
+ SetMem16(CommandLineWalker, 12, L' ');
StdOutFileName = CommandLineWalker += 6;
OutAppend = TRUE;
OutUnicode = FALSE;
+ if (StrStr(CommandLineWalker, L" 1>>a ") != NULL) {
+ Status = EFI_NOT_FOUND;
+ }
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>> ")) != NULL) {
+ SetMem16(CommandLineWalker, 10, L' ');
if (StdOutFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdOutFileName = CommandLineWalker += 5;
OutAppend = TRUE;
}
+ if (StrStr(CommandLineWalker, L" 1>> ") != NULL) {
+ Status = EFI_NOT_FOUND;
+ }
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >> ")) != NULL) {
+ SetMem16(CommandLineWalker, 8, L' ');
if (StdOutFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdOutFileName = CommandLineWalker += 4;
OutAppend = TRUE;
}
+ if (StrStr(CommandLineWalker, L" >> ") != NULL) {
+ Status = EFI_NOT_FOUND;
+ }
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >>a ")) != NULL) {
+ SetMem16(CommandLineWalker, 10, L' ');
if (StdOutFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
@@ -555,8 +612,12 @@ UpdateStdInStdOutStdErr(
OutAppend = TRUE;
OutUnicode = FALSE;
}
+ if (StrStr(CommandLineWalker, L" >>a ") != NULL) {
+ Status = EFI_NOT_FOUND;
+ }
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>a ")) != NULL) {
+ SetMem16(CommandLineWalker, 10, L' ');
if (StdOutFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
@@ -564,8 +625,12 @@ UpdateStdInStdOutStdErr(
OutAppend = FALSE;
OutUnicode = FALSE;
}
+ if (StrStr(CommandLineWalker, L" 1>a ") != NULL) {
+ Status = EFI_NOT_FOUND;
+ }
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >a ")) != NULL) {
+ SetMem16(CommandLineWalker, 8, L' ');
if (StdOutFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
@@ -573,33 +638,49 @@ UpdateStdInStdOutStdErr(
OutAppend = FALSE;
OutUnicode = FALSE;
}
+ if (StrStr(CommandLineWalker, L" >a ") != NULL) {
+ Status = EFI_NOT_FOUND;
+ }
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>> ")) != NULL) {
+ SetMem16(CommandLineWalker, 10, L' ');
if (StdErrFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdErrFileName = CommandLineWalker += 5;
ErrAppend = TRUE;
}
+ if (StrStr(CommandLineWalker, L" 2>> ") != NULL) {
+ Status = EFI_NOT_FOUND;
+ }
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>v ")) != NULL) {
+ SetMem16(CommandLineWalker, 10, L' ');
if (StdErrVarName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdErrVarName = CommandLineWalker += 5;
ErrAppend = FALSE;
}
+ if (StrStr(CommandLineWalker, L" 2>v ") != NULL) {
+ Status = EFI_NOT_FOUND;
+ }
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>v ")) != NULL) {
+ SetMem16(CommandLineWalker, 10, L' ');
if (StdOutVarName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdOutVarName = CommandLineWalker += 5;
OutAppend = FALSE;
}
+ if (StrStr(CommandLineWalker, L" 1>v ") != NULL) {
+ Status = EFI_NOT_FOUND;
+ }
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>a ")) != NULL) {
+ SetMem16(CommandLineWalker, 10, L' ');
if (StdErrFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
@@ -607,56 +688,81 @@ UpdateStdInStdOutStdErr(
ErrAppend = FALSE;
ErrUnicode = FALSE;
}
+ if (StrStr(CommandLineWalker, L" 2>a ") != NULL) {
+ Status = EFI_NOT_FOUND;
+ }
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2> ")) != NULL) {
+ SetMem16(CommandLineWalker, 8, L' ');
if (StdErrFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdErrFileName = CommandLineWalker += 4;
ErrAppend = FALSE;
}
+ if (StrStr(CommandLineWalker, L" 2> ") != NULL) {
+ Status = EFI_NOT_FOUND;
+ }
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1> ")) != NULL) {
+ SetMem16(CommandLineWalker, 8, L' ');
if (StdOutFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdOutFileName = CommandLineWalker += 4;
OutAppend = FALSE;
}
+ if (StrStr(CommandLineWalker, L" 1> ") != NULL) {
+ Status = EFI_NOT_FOUND;
+ }
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" > ")) != NULL) {
+ SetMem16(CommandLineWalker, 6, L' ');
if (StdOutFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdOutFileName = CommandLineWalker += 3;
OutAppend = FALSE;
}
+ if (StrStr(CommandLineWalker, L" > ") != NULL) {
+ Status = EFI_NOT_FOUND;
+ }
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" < ")) != NULL) {
+ SetMem16(CommandLineWalker, 6, L' ');
if (StdInFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdInFileName = CommandLineWalker += 3;
- OutAppend = FALSE;
+ }
+ if (StrStr(CommandLineWalker, L" < ") != NULL) {
+ Status = EFI_NOT_FOUND;
}
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" <a ")) != NULL) {
+ SetMem16(CommandLineWalker, 8, L' ');
if (StdInFileName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
- StdInFileName = CommandLineWalker += 4;
- OutAppend = FALSE;
+ StdInFileName = CommandLineWalker += 4;
+ InUnicode = FALSE;
+ }
+ if (StrStr(CommandLineWalker, L" <a ") != NULL) {
+ Status = EFI_NOT_FOUND;
}
}
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" <v ")) != NULL) {
+ SetMem16(CommandLineWalker, 8, L' ');
if (StdInVarName != NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
StdInVarName = CommandLineWalker += 4;
- OutAppend = FALSE;
+ }
+ if (StrStr(CommandLineWalker, L" <v ") != NULL) {
+ Status = EFI_NOT_FOUND;
}
}
@@ -683,21 +789,52 @@ UpdateStdInStdOutStdErr(
//
// Verify not the same and not duplicating something from a split
//
- if ((StdErrFileName != NULL && StdOutFileName!= NULL && StringNoCaseCompare(&StdErrFileName, &StdOutFileName) == 0)
+ if (
+ //
+ // Check that no 2 filenames are the same
+ //
+ (StdErrFileName != NULL && StdOutFileName!= NULL && StringNoCaseCompare(&StdErrFileName, &StdOutFileName) == 0)
||(StdErrFileName != NULL && StdInFileName != NULL && StringNoCaseCompare(&StdErrFileName, &StdInFileName ) == 0)
||(StdOutFileName != NULL && StdInFileName != NULL && StringNoCaseCompare(&StdOutFileName, &StdInFileName ) == 0)
+ //
+ // Check that no 2 variable names are the same
+ //
||(StdErrVarName != NULL && StdInVarName != NULL && StringNoCaseCompare(&StdErrVarName , &StdInVarName ) == 0)
||(StdOutVarName != NULL && StdInVarName != NULL && StringNoCaseCompare(&StdOutVarName , &StdInVarName ) == 0)
||(StdErrVarName != NULL && StdOutVarName != NULL && StringNoCaseCompare(&StdErrVarName , &StdOutVarName ) == 0)
+ //
+ // When a split (using | operator) is in place some are not allowed
+ //
||(Split != NULL && Split->SplitStdIn != NULL && (StdInVarName != NULL || StdInFileName != NULL))
||(Split != NULL && Split->SplitStdOut != NULL && (StdOutVarName != NULL || StdOutFileName != NULL))
+ //
+ // Check that nothing is trying to be output to 2 locations.
+ //
||(StdErrFileName != NULL && StdErrVarName != NULL)
||(StdOutFileName != NULL && StdOutVarName != NULL)
||(StdInFileName != NULL && StdInVarName != NULL)
+ //
+ // There should not be extra > or <
+ //
+ ||(StrStr(CommandLineCopy, L"<") != NULL)
+ ||(StrStr(CommandLineCopy, L">") != NULL)
+ //
+ // Check for no volatile environment variables
+ //
||(StdErrVarName != NULL && !IsVolatileEnv(StdErrVarName))
||(StdOutVarName != NULL && !IsVolatileEnv(StdOutVarName))
+ //
+ // Cant redirect during a reconnect operation.
+ //
||(StrStr(NewCommandLine, L"connect -r") != NULL
&& (StdOutVarName != NULL || StdOutFileName != NULL || StdErrFileName != NULL || StdErrVarName != NULL))
+ //
+ // Check that filetypes (Unicode/Ascii) do not change during an append
+ //
+ ||(StdOutFileName != NULL && OutUnicode && OutAppend && (!EFI_ERROR(ShellFileExists(StdOutFileName)) && EFI_ERROR(IsUnicodeFile(StdOutFileName))))
+ ||(StdErrFileName != NULL && ErrUnicode && ErrAppend && (!EFI_ERROR(ShellFileExists(StdErrFileName)) && EFI_ERROR(IsUnicodeFile(StdErrFileName))))
+ ||(StdOutFileName != NULL && !OutUnicode && OutAppend && (!EFI_ERROR(ShellFileExists(StdOutFileName)) && !EFI_ERROR(IsUnicodeFile(StdOutFileName))))
+ ||(StdErrFileName != NULL && !ErrUnicode && ErrAppend && (!EFI_ERROR(ShellFileExists(StdErrFileName)) && !EFI_ERROR(IsUnicodeFile(StdErrFileName))))
){
Status = EFI_INVALID_PARAMETER;
} else {
@@ -716,13 +853,12 @@ UpdateStdInStdOutStdErr(
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
+ // Write out the gUnicodeFileTag
//
Size = sizeof(CHAR16);
- TagBuffer[0] = UnicodeFileTag;
+ TagBuffer[0] = gUnicodeFileTag;
TagBuffer[1] = CHAR_NULL;
ShellInfoObject.NewEfiShellProtocol->WriteFile(TempHandle, &Size, TagBuffer);
}
@@ -750,12 +886,14 @@ UpdateStdInStdOutStdErr(
if (TempHandle == NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
- if (!OutAppend && OutUnicode && !EFI_ERROR(Status)) {
+ if (StrStr(StdOutFileName, L"NUL")==StdOutFileName) {
+ //no-op
+ } else if (!OutAppend && OutUnicode && !EFI_ERROR(Status)) {
//
- // Write out the UnicodeFileTag
+ // Write out the gUnicodeFileTag
//
Size = sizeof(CHAR16);
- TagBuffer[0] = UnicodeFileTag;
+ TagBuffer[0] = gUnicodeFileTag;
TagBuffer[1] = CHAR_NULL;
ShellInfoObject.NewEfiShellProtocol->WriteFile(TempHandle, &Size, TagBuffer);
} else if (OutAppend) {
@@ -790,10 +928,6 @@ UpdateStdInStdOutStdErr(
}
TempHandle = CreateFileInterfaceEnv(StdOutVarName);
ASSERT(TempHandle != NULL);
- if (!OutUnicode) {
- TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
- ASSERT(TempHandle != NULL);
- }
ShellParameters->StdOut = TempHandle;
gST->ConOut = CreateSimpleTextOutOnFile(TempHandle, &gST->ConsoleOutHandle);
}
@@ -810,10 +944,6 @@ UpdateStdInStdOutStdErr(
}
TempHandle = CreateFileInterfaceEnv(StdErrVarName);
ASSERT(TempHandle != NULL);
- if (!ErrUnicode) {
- TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
- ASSERT(TempHandle != NULL);
- }
ShellParameters->StdErr = TempHandle;
gST->StdErr = CreateSimpleTextOutOnFile(TempHandle, &gST->StandardErrorHandle);
}
diff --git a/ShellPkg/Application/Shell/ShellProtocol.c b/ShellPkg/Application/Shell/ShellProtocol.c
index 19759cbb2b..e2da5d37ad 100644
--- a/ShellPkg/Application/Shell/ShellProtocol.c
+++ b/ShellPkg/Application/Shell/ShellProtocol.c
@@ -2,7 +2,7 @@
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>
+ 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
@@ -38,6 +38,36 @@ EfiShellClose (
}
/**
+ Internal worker to determine whether there is a BlockIo somewhere
+ upon the device path specified.
+
+ @param[in] DevicePath The device path to test.
+
+ @retval TRUE gEfiBlockIoProtocolGuid was installed on a handle with this device path
+ @retval FALSE gEfiBlockIoProtocolGuid was not found.
+**/
+BOOLEAN
+EFIAPI
+InternalShellProtocolIsBlockIoPresent(
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
+ )
+{
+ EFI_DEVICE_PATH_PROTOCOL *DevicePathCopy;
+ EFI_STATUS Status;
+ EFI_HANDLE Handle;
+
+ Handle = NULL;
+
+ DevicePathCopy = (EFI_DEVICE_PATH_PROTOCOL*)DevicePath;
+ Status = gBS->LocateDevicePath(&gEfiBlockIoProtocolGuid, &DevicePathCopy, &Handle);
+
+ if ((Handle != NULL) && (!EFI_ERROR(Status))) {
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+/**
Internal worker to determine whether there is a file system somewhere
upon the device path specified.
@@ -176,7 +206,8 @@ EfiShellSetMap(
// make sure this is a valid to add device path
//
///@todo add BlockIo to this test...
- if (!InternalShellProtocolIsSimpleFileSystemPresent(DevicePath)) {
+ if (!InternalShellProtocolIsSimpleFileSystemPresent(DevicePath)
+ && !InternalShellProtocolIsBlockIoPresent(DevicePath)) {
return (EFI_INVALID_PARAMETER);
}
@@ -496,10 +527,9 @@ EfiShellGetDevicePathFromFilePath(
NewPath = AllocateZeroPool(Size);
ASSERT(NewPath != NULL);
StrCpy(NewPath, Cwd);
- if ((Path[0] == (CHAR16)L'\\') &&
- (NewPath[StrLen(NewPath)-1] == (CHAR16)L'\\')
- ) {
- ((CHAR16*)NewPath)[StrLen(NewPath)-1] = CHAR_NULL;
+ if (*Path == L'\\') {
+ Path++;
+ while (ChopLastSlash(NewPath)) ;
}
StrCat(NewPath, Path);
DevicePathForReturn = EfiShellGetDevicePathFromFilePath(NewPath);
@@ -621,6 +651,11 @@ EfiShellGetDeviceName(
CHAR8 *Lang;
CHAR8 *TempChar;
+ UINTN ParentControllerCount;
+ EFI_HANDLE *ParentControllerBuffer;
+ UINTN ParentDriverCount;
+ EFI_HANDLE *ParentDriverBuffer;
+
if (BestDeviceName == NULL ||
DeviceHandle == NULL
){
@@ -673,7 +708,7 @@ EfiShellGetDeviceName(
continue;
}
if (Language == NULL) {
- Lang = AllocatePool(AsciiStrSize(CompName2->SupportedLanguages));
+ Lang = AllocateZeroPool(AsciiStrSize(CompName2->SupportedLanguages));
if (Lang == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
@@ -683,7 +718,7 @@ EfiShellGetDeviceName(
*TempChar = CHAR_NULL;
}
} else {
- Lang = AllocatePool(AsciiStrSize(Language));
+ Lang = AllocateZeroPool(AsciiStrSize(Language));
if (Lang == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
@@ -699,14 +734,80 @@ EfiShellGetDeviceName(
if (HandleList != NULL) {
FreePool(HandleList);
}
+
+ //
+ // Now check the parent controller using this as the child.
+ //
+ if (DeviceNameToReturn == NULL){
+ PARSE_HANDLE_DATABASE_PARENTS(DeviceHandle, &ParentControllerCount, &ParentControllerBuffer);
+ for (LoopVar = 0 ; LoopVar < ParentControllerCount ; LoopVar++) {
+ PARSE_HANDLE_DATABASE_UEFI_DRIVERS(ParentControllerBuffer[LoopVar], &ParentDriverCount, &ParentDriverBuffer);
+ for (HandleCount = 0 ; HandleCount < ParentDriverCount ; HandleCount++) {
+ //
+ // try using that driver's component name with controller and our driver as the child.
+ //
+ Status = gBS->OpenProtocol(
+ ParentDriverBuffer[HandleCount],
+ &gEfiComponentName2ProtocolGuid,
+ (VOID**)&CompName2,
+ gImageHandle,
+ NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+ if (EFI_ERROR(Status)) {
+ Status = gBS->OpenProtocol(
+ ParentDriverBuffer[HandleCount],
+ &gEfiComponentNameProtocolGuid,
+ (VOID**)&CompName2,
+ gImageHandle,
+ NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+ }
+
+ if (EFI_ERROR(Status)) {
+ continue;
+ }
+ if (Language == NULL) {
+ Lang = AllocateZeroPool(AsciiStrSize(CompName2->SupportedLanguages));
+ if (Lang == NULL) {
+ return (EFI_OUT_OF_RESOURCES);
+ }
+ AsciiStrCpy(Lang, CompName2->SupportedLanguages);
+ TempChar = AsciiStrStr(Lang, ";");
+ if (TempChar != NULL){
+ *TempChar = CHAR_NULL;
+ }
+ } else {
+ Lang = AllocateZeroPool(AsciiStrSize(Language));
+ if (Lang == NULL) {
+ return (EFI_OUT_OF_RESOURCES);
+ }
+ AsciiStrCpy(Lang, Language);
+ }
+ Status = CompName2->GetControllerName(CompName2, ParentControllerBuffer[LoopVar], DeviceHandle, Lang, &DeviceNameToReturn);
+ FreePool(Lang);
+ Lang = NULL;
+ if (!EFI_ERROR(Status) && DeviceNameToReturn != NULL) {
+ break;
+ }
+
+
+
+ }
+ SHELL_FREE_NON_NULL(ParentDriverBuffer);
+ if (!EFI_ERROR(Status) && DeviceNameToReturn != NULL) {
+ break;
+ }
+ }
+ SHELL_FREE_NON_NULL(ParentControllerBuffer);
+ }
+ //
+ // dont return on fail since we will try device path if that bit is on
+ //
if (DeviceNameToReturn != NULL){
ASSERT(BestDeviceName != NULL);
StrnCatGrow(BestDeviceName, NULL, DeviceNameToReturn, 0);
return (EFI_SUCCESS);
}
- //
- // dont return on fail since we will try device path if that bit is on
- //
}
if ((Flags & EFI_DEVICE_NAME_USE_DEVICE_PATH) != 0) {
Status = gBS->LocateProtocol(
@@ -1630,14 +1731,14 @@ InternalDuplicateShellFileInfo(
{
EFI_SHELL_FILE_INFO *NewNode;
- NewNode = AllocatePool(sizeof(EFI_SHELL_FILE_INFO));
+ NewNode = AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));
if (NewNode == NULL) {
return (NULL);
}
NewNode->FullName = AllocateZeroPool(StrSize(Node->FullName));
NewNode->FileName = AllocateZeroPool(StrSize(Node->FileName));
- NewNode->Info = AllocatePool((UINTN)Node->Info->Size);
+ NewNode->Info = AllocateZeroPool((UINTN)Node->Info->Size);
if ( NewNode->FullName == NULL
|| NewNode->FileName == NULL
|| NewNode->Info == NULL
@@ -1964,7 +2065,7 @@ ShellSearchHandle(
} else {
NewShellNode->Handle = NULL;
if (*FileList == NULL) {
- *FileList = AllocatePool(sizeof(EFI_SHELL_FILE_INFO));
+ *FileList = AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));
InitializeListHead(&((*FileList)->Link));
}
@@ -2044,7 +2145,7 @@ ShellSearchHandle(
Status = EFI_OUT_OF_RESOURCES;
}
if (*FileList == NULL) {
- *FileList = AllocatePool(sizeof(EFI_SHELL_FILE_INFO));
+ *FileList = AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));
InitializeListHead(&((*FileList)->Link));
}
@@ -2121,7 +2222,7 @@ EfiShellFindFiles(
RootDevicePath = NULL;
RootFileHandle = NULL;
MapName = NULL;
- PatternCopy = AllocatePool(StrSize(FilePattern));
+ PatternCopy = AllocateZeroPool(StrSize(FilePattern));
if (PatternCopy == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
@@ -2186,17 +2287,19 @@ EfiShellOpenFileList(
CHAR16 *Path2;
UINTN Path2Size;
CONST CHAR16 *CurDir;
+ BOOLEAN Found;
ShellCommandCleanPath(Path);
Path2Size = 0;
Path2 = NULL;
- ASSERT(FileList != NULL);
- ASSERT(*FileList != NULL);
+ if (FileList == NULL || *FileList == NULL) {
+ return (EFI_INVALID_PARAMETER);
+ }
if (*Path == L'.' && *(Path+1) == L'\\') {
- Path++;
+ Path+=2;
}
//
@@ -2208,6 +2311,7 @@ EfiShellOpenFileList(
StrnCatGrow(&Path2, &Path2Size, CurDir, 0);
if (*Path == L'\\') {
Path++;
+ while (ChopLastSlash(Path2)) ;
}
ASSERT((Path2 == NULL && Path2Size == 0) || (Path2 != NULL));
StrnCatGrow(&Path2, &Path2Size, Path, 0);
@@ -2229,6 +2333,7 @@ EfiShellOpenFileList(
return (Status);
}
+ Found = FALSE;
//
// We had no errors so open all the files (that are not already opened...)
//
@@ -2238,9 +2343,13 @@ EfiShellOpenFileList(
){
if (ShellFileListItem->Status == 0 && ShellFileListItem->Handle == NULL) {
ShellFileListItem->Status = EfiShellOpenFileByName (ShellFileListItem->FullName, &ShellFileListItem->Handle, OpenMode);
+ Found = TRUE;
}
}
+ if (!Found) {
+ return (EFI_NOT_FOUND);
+ }
return(EFI_SUCCESS);
}
@@ -3190,6 +3299,12 @@ CleanUpShellProtocol (
Status = SimpleEx->UnregisterKeyNotify(SimpleEx, ShellInfoObject.CtrlCNotifyHandle1);
Status = SimpleEx->UnregisterKeyNotify(SimpleEx, ShellInfoObject.CtrlCNotifyHandle2);
+ Status = SimpleEx->UnregisterKeyNotify(SimpleEx, ShellInfoObject.CtrlCNotifyHandle3);
+ Status = SimpleEx->UnregisterKeyNotify(SimpleEx, ShellInfoObject.CtrlCNotifyHandle4);
+ Status = SimpleEx->UnregisterKeyNotify(SimpleEx, ShellInfoObject.CtrlSNotifyHandle1);
+ Status = SimpleEx->UnregisterKeyNotify(SimpleEx, ShellInfoObject.CtrlSNotifyHandle2);
+ Status = SimpleEx->UnregisterKeyNotify(SimpleEx, ShellInfoObject.CtrlSNotifyHandle3);
+ Status = SimpleEx->UnregisterKeyNotify(SimpleEx, ShellInfoObject.CtrlSNotifyHandle4);
return (Status);
}
@@ -3207,10 +3322,26 @@ NotificationFunction(
IN EFI_KEY_DATA *KeyData
)
{
- if (ShellInfoObject.NewEfiShellProtocol->ExecutionBreak == NULL) {
- return (EFI_UNSUPPORTED);
+ EFI_INPUT_KEY Key;
+ UINTN EventIndex;
+// ShellPrintEx(-1,-1,L" <Notify> ");
+ if ((KeyData->Key.UnicodeChar == L'c' || KeyData->Key.UnicodeChar == 3) &&
+ (KeyData->KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED) || KeyData->KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED))
+ ){
+ if (ShellInfoObject.NewEfiShellProtocol->ExecutionBreak == NULL) {
+ return (EFI_UNSUPPORTED);
+ }
+ return (gBS->SignalEvent(ShellInfoObject.NewEfiShellProtocol->ExecutionBreak));
+ } else if ((KeyData->Key.UnicodeChar == L's') &&
+ (KeyData->KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED) || KeyData->KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED))
+ ){
+ //
+ // just get some key
+ //
+ gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);
+ gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
}
- return (gBS->SignalEvent(ShellInfoObject.NewEfiShellProtocol->ExecutionBreak));
+ return (EFI_SUCCESS);
}
/**
diff --git a/ShellPkg/Application/Shell/ShellProtocol.h b/ShellPkg/Application/Shell/ShellProtocol.h
index 38e71b40dc..1b809ecd29 100644
--- a/ShellPkg/Application/Shell/ShellProtocol.h
+++ b/ShellPkg/Application/Shell/ShellProtocol.h
@@ -2,7 +2,7 @@
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>
+ 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
@@ -959,5 +959,18 @@ EFIAPI
InernalEfiShellStartMonitor(
VOID
);
+
+/**
+ Notification function for keystrokes.
+
+ @param[in] KeyData The key that was pressed.
+
+ @retval EFI_SUCCESS The operation was successful.
+**/
+EFI_STATUS
+EFIAPI
+NotificationFunction(
+ IN EFI_KEY_DATA *KeyData
+ );
#endif //_SHELL_PROTOCOL_HEADER_