X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ShellPkg%2FApplication%2FShell%2FShellProtocol.c;h=e1aadb845d4eb7c49a971d9ba1919efced0c84f7;hp=2d587ea03b1f3838144bd61ce40f17a46841db9c;hb=e3df6949e7e2a4578660d4079988487a147c91b7;hpb=e35b53179454119ba0d8591ccdfee9f0efe5fd77 diff --git a/ShellPkg/Application/Shell/ShellProtocol.c b/ShellPkg/Application/Shell/ShellProtocol.c index 2d587ea03b..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,11 +518,13 @@ 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++; - while (ChopLastSlash(NewPath)) ; + while (PathRemoveLastItem(NewPath)) ; } StrCat(NewPath, Path); DevicePathForReturn = EfiShellGetDevicePathFromFilePath(NewPath); @@ -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); } @@ -588,7 +581,7 @@ EfiShellGetDevicePathFromFilePath( if (*(Path+StrLen(MapName)+1) == CHAR_NULL) { DevicePathForReturn = FileDevicePath(Handle, L"\\"); } else { - DevicePathForReturn = FileDevicePath(Handle, Path+StrLen(MapName)+1); + DevicePathForReturn = FileDevicePath(Handle, Path+StrLen(MapName)); } FreePool(MapName); @@ -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; } @@ -1945,8 +1932,8 @@ EfiShellFindFilesInDir( /** Updates a file name to be preceeded by the mapped drive name - @param[in] BasePath the Mapped drive name to prepend - @param[in,out] Path pointer to pointer to the file name to update. + @param[in] BasePath the Mapped drive name to prepend + @param[in, out] Path pointer to pointer to the file name to update. @retval EFI_SUCCESS @retval EFI_OUT_OF_RESOURCES @@ -2001,12 +1988,12 @@ UpdateFileName( Upon a EFI_SUCCESS return fromt he function any the caller is responsible to call FreeFileList with FileList. - @param[in] FilePattern The FilePattern to check against. - @param[in] UnicodeCollation The pointer to EFI_UNICODE_COLLATION_PROTOCOL structure - @param[in] FileHandle The FileHandle to start with - @param[in,out] FileList pointer to pointer to list of found files. - @param[in] ParentNode The node for the parent. Same file as identified by HANDLE. - @param[in] MapName The file system name this file is on. + @param[in] FilePattern The FilePattern to check against. + @param[in] UnicodeCollation The pointer to EFI_UNICODE_COLLATION_PROTOCOL structure + @param[in] FileHandle The FileHandle to start with + @param[in, out] FileList pointer to pointer to list of found files. + @param[in] ParentNode The node for the parent. Same file as identified by HANDLE. + @param[in] MapName The file system name this file is on. @retval EFI_SUCCESS all files were found and the FileList contains a list. @retval EFI_NOT_FOUND no files were found @@ -2232,15 +2219,16 @@ EfiShellFindFiles( } StrCpy(PatternCopy, FilePattern); - PatternCopy = CleanPath(PatternCopy); + PatternCopy = PathCleanUpDirectories(PatternCopy); Count = StrStr(PatternCopy, L":") - PatternCopy; Count += 2; 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; @@ -2293,7 +2281,7 @@ EfiShellOpenFileList( CONST CHAR16 *CurDir; BOOLEAN Found; - ShellCommandCleanPath(Path); + PathCleanUpDirectories(Path); Path2Size = 0; Path2 = NULL; @@ -2315,7 +2303,7 @@ EfiShellOpenFileList( StrnCatGrow(&Path2, &Path2Size, CurDir, 0); if (*Path == L'\\') { Path++; - while (ChopLastSlash(Path2)) ; + while (PathRemoveLastItem(Path2)) ; } ASSERT((Path2 == NULL && Path2Size == 0) || (Path2 != NULL)); StrnCatGrow(&Path2, &Path2Size, Path, 0); @@ -2324,7 +2312,7 @@ EfiShellOpenFileList( StrnCatGrow(&Path2, NULL, Path, 0); } - CleanPath (Path2); + PathCleanUpDirectories (Path2); // // do the search @@ -2677,7 +2665,7 @@ EfiShellSetCurDir( DirectoryName = StrnCatGrow(&DirectoryName, NULL, Dir, 0); ASSERT(DirectoryName != NULL); - CleanPath(DirectoryName); + PathCleanUpDirectories(DirectoryName); if (FileSystem == NULL) { // @@ -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); @@ -3124,7 +3110,7 @@ EFI_SHELL_PROTOCOL mShellProtocol = { This must be removed via calling CleanUpShellProtocol(). - @param[in,out] NewShell The pointer to the pointer to the structure + @param[in, out] NewShell The pointer to the pointer to the structure to install. @retval EFI_SUCCESS The operation was successful. @@ -3253,7 +3239,7 @@ CreatePopulateInstallShellProtocol ( Free all memory and restore the system to the state it was in before calling CreatePopulateInstallShellProtocol. - @param[in,out] NewShell The pointer to the new shell protocol structure. + @param[in, out] NewShell The pointer to the new shell protocol structure. @retval EFI_SUCCESS The operation was successful. **/ @@ -3301,15 +3287,16 @@ CleanUpShellProtocol ( NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); - 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); - + if (!EFI_ERROR (Status)) { + 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); } @@ -3327,10 +3314,9 @@ NotificationFunction( ) { EFI_INPUT_KEY Key; - UINTN EventIndex; -// 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)) + 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,11 +3325,13 @@ NotificationFunction( } 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)) ){ + ShellInfoObject.HaltOutput = TRUE; + // - // just get some key + // Make sure that there are no pending keystrokes to pervent the pause. // - gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex); - gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); + gST->ConIn->Reset(gST->ConIn, FALSE); + while (gST->ConIn->ReadKeyStroke (gST->ConIn, &Key)==EFI_SUCCESS); } return (EFI_SUCCESS); }