diff options
author | Jaben Carsey <jaben.carsey@intel.com> | 2014-01-17 17:51:09 +0000 |
---|---|---|
committer | jcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524> | 2014-01-17 17:51:09 +0000 |
commit | 2c86b6b785f50a38c52949c46fd2b1d00fc80721 (patch) | |
tree | db80ad3ecdd9046baab0dcb1610ae0b4e2f6bc0f /ShellPkg | |
parent | d91e3ba5e705907c670a0bedb6906e2165ab112d (diff) | |
download | edk2-platforms-2c86b6b785f50a38c52949c46fd2b1d00fc80721.tar.xz |
ShellPkg: Change StdIn redirection
This changes how StdIn redirection works such that the file is opened and parsed for length up front and not each time. This prevents TPL issues.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15140 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ShellPkg')
-rw-r--r-- | ShellPkg/Application/Shell/ConsoleWrappers.c | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/ShellPkg/Application/Shell/ConsoleWrappers.c b/ShellPkg/Application/Shell/ConsoleWrappers.c index 49ba6e90e7..fddf5c4ba0 100644 --- a/ShellPkg/Application/Shell/ConsoleWrappers.c +++ b/ShellPkg/Application/Shell/ConsoleWrappers.c @@ -2,7 +2,7 @@ Function definitions for shell simple text in and out on top of file handles.
Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
- Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 2014, 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
@@ -19,6 +19,7 @@ typedef struct { EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleTextIn;
SHELL_FILE_HANDLE FileHandle;
EFI_HANDLE TheHandle;
+ UINT64 RemainingBytesOfInputFile;
} SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL;
typedef struct {
@@ -43,19 +44,7 @@ ConInWaitForKey ( IN VOID *Context
)
{
- UINT64 Position;
- UINT64 Size;
- //
- // Someone is waiting on the keystroke event, if there's
- // a key pending, signal the event
- //
- // Context is the pointer to EFI_SIMPLE_TEXT_INPUT_PROTOCOL
- //
- ShellInfoObject.NewEfiShellProtocol->GetFilePosition(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)Context)->FileHandle, &Position);
- ShellInfoObject.NewEfiShellProtocol->GetFileSize (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)Context)->FileHandle, &Size );
- if (Position < Size) {
- gBS->SignalEvent (Event);
- }
+ gBS->SignalEvent (Event);
}
/**
@@ -92,10 +81,32 @@ FileBasedSimpleTextInReadKeyStroke( )
{
UINTN Size;
- Size = sizeof(CHAR16);
+
+ //
+ // Verify the parameters
+ //
if (Key == NULL || This == NULL) {
return (EFI_INVALID_PARAMETER);
}
+
+ //
+ // Check if we have any characters left in the stream.
+ //
+ if (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile == 0) {
+ return (EFI_NOT_READY);
+ }
+
+ Size = sizeof(CHAR16);
+
+ //
+ // Decrement the amount of free space by Size or set to zero (for odd length files)
+ //
+ if (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile > Size) {
+ ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile -= Size;
+ } else {
+ ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile = 0;
+ }
+
Key->ScanCode = 0;
return (ShellInfoObject.NewEfiShellProtocol->ReadFile(
((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->FileHandle,
@@ -122,6 +133,8 @@ CreateSimpleTextInOnFile( {
SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ProtocolToReturn;
EFI_STATUS Status;
+ UINT64 CurrentPosition;
+ UINT64 FileSize;
if (HandleLocation == NULL || FileHandleToUse == NULL) {
return (NULL);
@@ -131,7 +144,15 @@ CreateSimpleTextInOnFile( if (ProtocolToReturn == NULL) {
return (NULL);
}
- ProtocolToReturn->FileHandle = FileHandleToUse;
+
+ ShellGetFileSize (FileHandleToUse, &FileSize);
+ ShellGetFilePosition(FileHandleToUse, &CurrentPosition);
+
+ //
+ // Initialize the protocol members
+ //
+ ProtocolToReturn->RemainingBytesOfInputFile = FileSize - CurrentPosition;
+ ProtocolToReturn->FileHandle = FileHandleToUse;
ProtocolToReturn->SimpleTextIn.Reset = FileBasedSimpleTextInReset;
ProtocolToReturn->SimpleTextIn.ReadKeyStroke = FileBasedSimpleTextInReadKeyStroke;
|