console logger - support disabling the console out.
console wrapper - comment fixes. file handle wrappers - allow for creation of layers of file interfaces to automatically convert ASCII to UCS-2. shell - add CTRL-S support and change how searching for startup.nsh. shellenvvar - zero the memory allocations. shall man parser - input verification on the help text. shellparameters protocol - input redirection verification enhanced, leave ^ behind when not used. shell protocol - remove ASSERTs, fixed GetDeviceName, allow mapping of BlockIO devices, and enhanced key monitoring for CTRL-S (now CTRL-S and CTRL-C). git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11440 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user