X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ShellPkg%2FApplication%2FShell%2FShellProtocol.c;h=e1aadb845d4eb7c49a971d9ba1919efced0c84f7;hp=de7dc3cad91b08b28be628969f3a69883c2e86c3;hb=e3df6949e7e2a4578660d4079988487a147c91b7;hpb=f9125972ae96c95f284cf7faebb9ec0be8dd3a10 diff --git a/ShellPkg/Application/Shell/ShellProtocol.c b/ShellPkg/Application/Shell/ShellProtocol.c index de7dc3cad9..e1aadb845d 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 - 2011, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -14,7 +14,6 @@ **/ #include "Shell.h" -#include /** Close an open file handle. @@ -116,27 +115,19 @@ InternalShellProtocolDebugPrintMessage ( IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath ) { - EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevicePathToText; EFI_STATUS Status; CHAR16 *Temp; Status = EFI_SUCCESS; DEBUG_CODE_BEGIN(); - DevicePathToText = NULL; - Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, - NULL, - (VOID**)&DevicePathToText); if (Mapping != NULL) { DEBUG((EFI_D_INFO, "Added new map item:\"%S\"\r\n", Mapping)); } - if (!EFI_ERROR(Status)) { - if (DevicePath != NULL) { - Temp = DevicePathToText->ConvertDevicePathToText(DevicePath, TRUE, TRUE); - DEBUG((EFI_D_INFO, "DevicePath: %S\r\n", Temp)); - FreePool(Temp); - } - } + Temp = ConvertDevicePathToText(DevicePath, TRUE, TRUE); + DEBUG((EFI_D_INFO, "DevicePath: %S\r\n", Temp)); + FreePool(Temp); + DEBUG_CODE_END(); return (Status); } @@ -488,10 +479,12 @@ EfiShellGetFilePathFromDevicePath( This function converts a file system style name to a device path, by replacing any mapping references to the associated device path. - @param Path the pointer to the path + @param[in] Path The pointer to the path. - @return all The pointer of the file path. The file path is callee + @return The pointer of the file path. The file path is callee allocated and should be freed by the caller. + @retval NULL The path could not be found. + @retval NULL There was not enough available memory. **/ EFI_DEVICE_PATH_PROTOCOL * EFIAPI @@ -525,7 +518,9 @@ EfiShellGetDevicePathFromFilePath( Size = StrSize(Cwd); Size += StrSize(Path); NewPath = AllocateZeroPool(Size); - ASSERT(NewPath != NULL); + if (NewPath == NULL) { + return (NULL); + } StrCpy(NewPath, Cwd); if (*Path == L'\\') { Path++; @@ -543,8 +538,7 @@ EfiShellGetDevicePathFromFilePath( // ASSERT((MapName == NULL && Size == 0) || (MapName != NULL)); MapName = StrnCatGrow(&MapName, &Size, Path, (StrStr(Path, L":")-Path+1)); - if (MapName[StrLen(MapName)-1] != L':') { - ASSERT(FALSE); + if (MapName == NULL || MapName[StrLen(MapName)-1] != L':') { return (NULL); } @@ -564,7 +558,6 @@ EfiShellGetDevicePathFromFilePath( // DevicePathCopyForFree = DevicePathCopy = DuplicateDevicePath(DevicePath); if (DevicePathCopy == NULL) { - ASSERT(FALSE); FreePool(MapName); return (NULL); } @@ -646,7 +639,6 @@ EfiShellGetDeviceName( { EFI_STATUS Status; EFI_COMPONENT_NAME2_PROTOCOL *CompName2; - EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevicePathToText; EFI_DEVICE_PATH_PROTOCOL *DevicePath; EFI_HANDLE *HandleList; UINTN HandleCount; @@ -814,28 +806,19 @@ EfiShellGetDeviceName( } } if ((Flags & EFI_DEVICE_NAME_USE_DEVICE_PATH) != 0) { - Status = gBS->LocateProtocol( - &gEfiDevicePathToTextProtocolGuid, + Status = gBS->OpenProtocol( + DeviceHandle, + &gEfiDevicePathProtocolGuid, + (VOID**)&DevicePath, + gImageHandle, NULL, - (VOID**)&DevicePathToText); - // - // we now have the device path to text protocol - // + EFI_OPEN_PROTOCOL_GET_PROTOCOL); if (!EFI_ERROR(Status)) { - Status = gBS->OpenProtocol( - DeviceHandle, - &gEfiDevicePathProtocolGuid, - (VOID**)&DevicePath, - gImageHandle, - NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL); - if (!EFI_ERROR(Status)) { - // - // use device path to text on the device path - // - *BestDeviceName = DevicePathToText->ConvertDevicePathToText(DevicePath, TRUE, TRUE); - return (EFI_SUCCESS); - } + // + // use device path to text on the device path + // + *BestDeviceName = ConvertDevicePathToText(DevicePath, TRUE, TRUE); + return (EFI_SUCCESS); } } // @@ -993,7 +976,6 @@ InternalOpenFileDevicePath( SHELL_FILE_HANDLE ShellHandle; EFI_FILE_PROTOCOL *Handle1; EFI_FILE_PROTOCOL *Handle2; - EFI_DEVICE_PATH_PROTOCOL *DpCopy; FILEPATH_DEVICE_PATH *AlignedNode; if (FileHandle == NULL) { @@ -1003,7 +985,6 @@ InternalOpenFileDevicePath( Handle1 = NULL; Handle2 = NULL; Handle = NULL; - DpCopy = DevicePath; ShellHandle = NULL; FilePathNode = NULL; AlignedNode = NULL; @@ -1584,18 +1565,18 @@ EfiShellExecute( DevPath = AppendDevicePath (ShellInfoObject.ImageDevPath, ShellInfoObject.FileDevPath); DEBUG_CODE_BEGIN(); - Temp = gDevPathToText->ConvertDevicePathToText(ShellInfoObject.FileDevPath, TRUE, TRUE); + Temp = ConvertDevicePathToText(ShellInfoObject.FileDevPath, TRUE, TRUE); FreePool(Temp); - Temp = gDevPathToText->ConvertDevicePathToText(ShellInfoObject.ImageDevPath, TRUE, TRUE); + Temp = ConvertDevicePathToText(ShellInfoObject.ImageDevPath, TRUE, TRUE); FreePool(Temp); - Temp = gDevPathToText->ConvertDevicePathToText(DevPath, TRUE, TRUE); + Temp = ConvertDevicePathToText(DevPath, TRUE, TRUE); FreePool(Temp); DEBUG_CODE_END(); Temp = NULL; Size = 0; ASSERT((Temp == NULL && Size == 0) || (Temp != NULL)); - StrnCatGrow(&Temp, &Size, L"Shell.efi ", 0); + StrnCatGrow(&Temp, &Size, L"Shell.efi -_exit ", 0); StrnCatGrow(&Temp, &Size, CommandLine, 0); Status = InternalShellExecuteDevicePath( @@ -1797,7 +1778,7 @@ CreateAndPopulateShellFileInfo( if (ShellFileListItem == NULL) { return (NULL); } - if (Info != NULL) { + if (Info != NULL && Info->Size != 0) { ShellFileListItem->Info = AllocateZeroPool((UINTN)Info->Size); if (ShellFileListItem->Info == NULL) { FreePool(ShellFileListItem); @@ -1888,6 +1869,9 @@ EfiShellFindFilesInDir( TempString = NULL; Size = 0; TempString = StrnCatGrow(&TempString, &Size, ShellFileHandleGetPath(FileDirHandle), 0); + if (TempString == NULL) { + return (EFI_OUT_OF_RESOURCES); + } TempSpot = StrStr(TempString, L";"); if (TempSpot != NULL) { @@ -1895,6 +1879,9 @@ EfiShellFindFilesInDir( } TempString = StrnCatGrow(&TempString, &Size, BasePath, 0); + if (TempString == NULL) { + return (EFI_OUT_OF_RESOURCES); + } BasePath = TempString; } @@ -2239,8 +2226,9 @@ EfiShellFindFiles( ASSERT(MapName == NULL); MapName = StrnCatGrow(&MapName, NULL, PatternCopy, Count); - - if (!EFI_ERROR(Status)) { + if (MapName == NULL) { + Status = EFI_OUT_OF_RESOURCES; + } else { RootDevicePath = EfiShellGetDevicePathFromFilePath(PatternCopy); if (RootDevicePath == NULL) { Status = EFI_INVALID_PARAMETER; @@ -2759,7 +2747,7 @@ EfiShellSetCurDir( MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, L"\\", 0); ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL)); MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, DirectoryName, 0); - if (MapListItem->CurrentDirectoryPath[StrLen(MapListItem->CurrentDirectoryPath)-1] != L'\\') { + if (MapListItem->CurrentDirectoryPath != NULL && MapListItem->CurrentDirectoryPath[StrLen(MapListItem->CurrentDirectoryPath)-1] != L'\\') { ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL)); MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, L"\\", 0); } @@ -2884,7 +2872,6 @@ InternalEfiShellGetListAlias( UINTN NameSize; CHAR16 *RetVal; UINTN RetSize; - CHAR16 *Alias; Status = gRT->QueryVariableInfo(EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS, &MaxStorSize, &RemStorSize, &MaxVarSize); ASSERT_EFI_ERROR(Status); @@ -2910,7 +2897,6 @@ InternalEfiShellGetListAlias( break; } if (CompareGuid(&Guid, &gShellAliasGuid)){ - Alias = GetVariable(VariableName, &gShellAliasGuid); ASSERT((RetVal == NULL && RetSize == 0) || (RetVal != NULL)); RetVal = StrnCatGrow(&RetVal, &RetSize, VariableName, 0); RetVal = StrnCatGrow(&RetVal, &RetSize, L";", 0); @@ -3327,9 +3313,10 @@ NotificationFunction( IN EFI_KEY_DATA *KeyData ) { -// ShellPrintEx(-1,-1,L" "); - 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)) + EFI_INPUT_KEY Key; + if ( ((KeyData->Key.UnicodeChar == L'c') && + (KeyData->KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED) || KeyData->KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED))) || + (KeyData->Key.UnicodeChar == 3) ){ if (ShellInfoObject.NewEfiShellProtocol->ExecutionBreak == NULL) { return (EFI_UNSUPPORTED); @@ -3339,6 +3326,12 @@ NotificationFunction( (KeyData->KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED) || KeyData->KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED)) ){ ShellInfoObject.HaltOutput = TRUE; + + // + // Make sure that there are no pending keystrokes to pervent the pause. + // + gST->ConIn->Reset(gST->ConIn, FALSE); + while (gST->ConIn->ReadKeyStroke (gST->ConIn, &Key)==EFI_SUCCESS); } return (EFI_SUCCESS); }