X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellLib%2FUefiShellLib.c;h=18c3be4a8bc7da6b9df473c7495f803e2dc023f3;hp=6cef8b7d4cd03d6d05e6457482923a7d545b3663;hb=15d8fe1fee188cd7a9ce1b0e32cbe34cc93f1097;hpb=bab9f949bf1a72f33f89331bbffa9362de254945 diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Library/UefiShellLib/UefiShellLib.c index 6cef8b7d4c..18c3be4a8b 100644 --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c @@ -1,7 +1,9 @@ /** @file Provides interface to shell functionality for shell commands and applications. - Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+ (C) Copyright 2016 Hewlett Packard Enterprise Development LP
+ Copyright 2016 Dell Inc. + Copyright (c) 2006 - 2018, 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 @@ -13,10 +15,8 @@ **/ #include "UefiShellLib.h" -#include #include - -#define FIND_XXXXX_FILE_BUFFER_SIZE (SIZE_OF_EFI_FILE_INFO + MAX_FILE_NAME_LEN) +#include // // globals... @@ -34,6 +34,7 @@ EFI_SHELL_PROTOCOL *gEfiShellProtocol; EFI_SHELL_PARAMETERS_PROTOCOL *gEfiShellParametersProtocol; EFI_HANDLE mEfiShellEnvironment2Handle; FILE_HANDLE_FUNCTION_MAP FileFunctionMap; +EFI_UNICODE_COLLATION_PROTOCOL *mUnicodeCollationProtocol; /** Check if a Unicode character is a hexadecimal character. @@ -88,7 +89,6 @@ ShellIsDecimalDigitCharacter ( @retval EFI_OUT_OF_RESOURCES Memory allocation failed. **/ EFI_STATUS -EFIAPI ShellFindSE2 ( IN EFI_HANDLE ImageHandle ) @@ -172,7 +172,6 @@ ShellFindSE2 ( @retval EFI_SUCCESS The operationw as successful. **/ EFI_STATUS -EFIAPI ShellLibConstructorWorker ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable @@ -180,43 +179,48 @@ ShellLibConstructorWorker ( { EFI_STATUS Status; - // - // UEFI 2.0 shell interfaces (used preferentially) - // - Status = gBS->OpenProtocol( - ImageHandle, - &gEfiShellProtocolGuid, - (VOID **)&gEfiShellProtocol, - ImageHandle, - NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - if (EFI_ERROR(Status)) { + if (gEfiShellProtocol == NULL) { // - // Search for the shell protocol + // UEFI 2.0 shell interfaces (used preferentially) // - Status = gBS->LocateProtocol( + Status = gBS->OpenProtocol ( + ImageHandle, &gEfiShellProtocolGuid, + (VOID **)&gEfiShellProtocol, + ImageHandle, NULL, - (VOID **)&gEfiShellProtocol - ); - if (EFI_ERROR(Status)) { - gEfiShellProtocol = NULL; + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + // + // Search for the shell protocol + // + Status = gBS->LocateProtocol ( + &gEfiShellProtocolGuid, + NULL, + (VOID **)&gEfiShellProtocol + ); + if (EFI_ERROR (Status)) { + gEfiShellProtocol = NULL; + } } } - Status = gBS->OpenProtocol( - ImageHandle, - &gEfiShellParametersProtocolGuid, - (VOID **)&gEfiShellParametersProtocol, - ImageHandle, - NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - if (EFI_ERROR(Status)) { - gEfiShellParametersProtocol = NULL; + + if (gEfiShellParametersProtocol == NULL) { + Status = gBS->OpenProtocol ( + ImageHandle, + &gEfiShellParametersProtocolGuid, + (VOID **)&gEfiShellParametersProtocol, + ImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + gEfiShellParametersProtocol = NULL; + } } - if (gEfiShellParametersProtocol == NULL || gEfiShellProtocol == NULL) { + if (gEfiShellProtocol == NULL) { // // Moved to seperate function due to complexity // @@ -239,10 +243,14 @@ ShellLibConstructorWorker ( } // - // only success getting 2 of either the old or new, but no 1/2 and 1/2 + // Getting either EDK Shell's ShellEnvironment2 and ShellInterface protocol + // or UEFI Shell's Shell protocol. + // When ShellLib is linked to a driver producing DynamicCommand protocol, + // ShellParameters protocol is set by DynamicCommand.Handler(). // - if ((mEfiShellEnvironment2 != NULL && mEfiShellInterface != NULL) || - (gEfiShellProtocol != NULL && gEfiShellParametersProtocol != NULL) ) { + if ((mEfiShellEnvironment2 != NULL && mEfiShellInterface != NULL) || + (gEfiShellProtocol != NULL) + ) { if (gEfiShellProtocol != NULL) { FileFunctionMap.GetFileInfo = gEfiShellProtocol->GetFileInfo; FileFunctionMap.SetFileInfo = gEfiShellProtocol->SetFileInfo; @@ -293,6 +301,7 @@ ShellLibConstructor ( gEfiShellParametersProtocol = NULL; mEfiShellInterface = NULL; mEfiShellEnvironment2Handle = NULL; + mUnicodeCollationProtocol = NULL; // // verify that auto initialize is not set false @@ -320,35 +329,45 @@ ShellLibDestructor ( IN EFI_SYSTEM_TABLE *SystemTable ) { + EFI_STATUS Status; + if (mEfiShellEnvironment2 != NULL) { - gBS->CloseProtocol(mEfiShellEnvironment2Handle==NULL?ImageHandle:mEfiShellEnvironment2Handle, + Status = gBS->CloseProtocol(mEfiShellEnvironment2Handle==NULL?ImageHandle:mEfiShellEnvironment2Handle, &gEfiShellEnvironment2Guid, ImageHandle, NULL); - mEfiShellEnvironment2 = NULL; + if (!EFI_ERROR (Status)) { + mEfiShellEnvironment2 = NULL; + mEfiShellEnvironment2Handle = NULL; + } } if (mEfiShellInterface != NULL) { - gBS->CloseProtocol(ImageHandle, + Status = gBS->CloseProtocol(ImageHandle, &gEfiShellInterfaceGuid, ImageHandle, NULL); - mEfiShellInterface = NULL; + if (!EFI_ERROR (Status)) { + mEfiShellInterface = NULL; + } } if (gEfiShellProtocol != NULL) { - gBS->CloseProtocol(ImageHandle, + Status = gBS->CloseProtocol(ImageHandle, &gEfiShellProtocolGuid, ImageHandle, NULL); - gEfiShellProtocol = NULL; + if (!EFI_ERROR (Status)) { + gEfiShellProtocol = NULL; + } } if (gEfiShellParametersProtocol != NULL) { - gBS->CloseProtocol(ImageHandle, + Status = gBS->CloseProtocol(ImageHandle, &gEfiShellParametersProtocolGuid, ImageHandle, NULL); - gEfiShellParametersProtocol = NULL; + if (!EFI_ERROR (Status)) { + gEfiShellParametersProtocol = NULL; + } } - mEfiShellEnvironment2Handle = NULL; return (EFI_SUCCESS); } @@ -369,8 +388,11 @@ ShellLibDestructor ( EFI_STATUS EFIAPI ShellInitialize ( + VOID ) { + EFI_STATUS Status; + // // if auto initialize is not false then skip // @@ -381,7 +403,8 @@ ShellInitialize ( // // deinit the current stuff // - ASSERT_EFI_ERROR(ShellLibDestructor(gImageHandle, gST)); + Status = ShellLibDestructor (gImageHandle, gST); + ASSERT_EFI_ERROR (Status); // // init the new stuff @@ -449,7 +472,6 @@ ShellSetFileInfo ( @param FilePath on input the device path to the file. On output the remaining device path. - @param DeviceHandle pointer to the system device handle. @param FileHandle pointer to the file handle. @param OpenMode the mode to open the file with. @param Attributes the file's file attributes. @@ -475,7 +497,6 @@ EFI_STATUS EFIAPI ShellOpenFileByDevicePath( IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath, - OUT EFI_HANDLE *DeviceHandle, OUT SHELL_FILE_HANDLE *FileHandle, IN UINT64 OpenMode, IN UINT64 Attributes @@ -488,8 +509,9 @@ ShellOpenFileByDevicePath( EFI_FILE_PROTOCOL *Handle2; CHAR16 *FnafPathName; UINTN PathLen; + EFI_HANDLE DeviceHandle; - if (FilePath == NULL || FileHandle == NULL || DeviceHandle == NULL) { + if (FilePath == NULL || FileHandle == NULL) { return (EFI_INVALID_PARAMETER); } @@ -515,11 +537,11 @@ ShellOpenFileByDevicePath( // Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, FilePath, - DeviceHandle); + &DeviceHandle); if (EFI_ERROR (Status)) { return Status; } - Status = gBS->OpenProtocol(*DeviceHandle, + Status = gBS->OpenProtocol(DeviceHandle, &gEfiSimpleFileSystemProtocolGuid, (VOID**)&EfiSimpleFileSystemProtocol, gImageHandle, @@ -667,10 +689,11 @@ ShellOpenFileByName( IN UINT64 Attributes ) { - EFI_HANDLE DeviceHandle; EFI_DEVICE_PATH_PROTOCOL *FilePath; EFI_STATUS Status; EFI_FILE_INFO *FileInfo; + CHAR16 *FileNameCopy; + EFI_STATUS Status2; // // ASSERT if FileName is NULL @@ -682,21 +705,61 @@ ShellOpenFileByName( } if (gEfiShellProtocol != NULL) { - if ((OpenMode & EFI_FILE_MODE_CREATE) == EFI_FILE_MODE_CREATE && (Attributes & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) { - return ShellCreateDirectory(FileName, FileHandle); + if ((OpenMode & EFI_FILE_MODE_CREATE) == EFI_FILE_MODE_CREATE) { + + // + // Create only a directory + // + if ((Attributes & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) { + return ShellCreateDirectory(FileName, FileHandle); + } + + // + // Create the directory to create the file in + // + FileNameCopy = AllocateCopyPool (StrSize (FileName), FileName); + if (FileNameCopy == NULL) { + return (EFI_OUT_OF_RESOURCES); + } + PathCleanUpDirectories (FileNameCopy); + if (PathRemoveLastItem (FileNameCopy)) { + if (!EFI_ERROR(ShellCreateDirectory (FileNameCopy, FileHandle))) { + ShellCloseFile (FileHandle); + } + } + SHELL_FREE_NON_NULL (FileNameCopy); } + // - // Use UEFI Shell 2.0 method + // Use UEFI Shell 2.0 method to create the file // Status = gEfiShellProtocol->OpenFileByName(FileName, FileHandle, OpenMode); - if (StrCmp(FileName, L"NUL") != 0 && !EFI_ERROR(Status) && ((OpenMode & EFI_FILE_MODE_CREATE) != 0)){ + if (EFI_ERROR(Status)) { + return Status; + } + + if (mUnicodeCollationProtocol == NULL) { + Status = gBS->LocateProtocol (&gEfiUnicodeCollation2ProtocolGuid, NULL, (VOID**)&mUnicodeCollationProtocol); + if (EFI_ERROR (Status)) { + gEfiShellProtocol->CloseFile (*FileHandle); + return Status; + } + } + + if ((mUnicodeCollationProtocol->StriColl (mUnicodeCollationProtocol, (CHAR16*)FileName, L"NUL") != 0) && + (mUnicodeCollationProtocol->StriColl (mUnicodeCollationProtocol, (CHAR16*)FileName, L"NULL") != 0) && + !EFI_ERROR(Status) && ((OpenMode & EFI_FILE_MODE_CREATE) != 0)){ FileInfo = FileFunctionMap.GetFileInfo(*FileHandle); ASSERT(FileInfo != NULL); FileInfo->Attribute = Attributes; - Status = FileFunctionMap.SetFileInfo(*FileHandle, FileInfo); + Status2 = FileFunctionMap.SetFileInfo(*FileHandle, FileInfo); FreePool(FileInfo); + if (EFI_ERROR (Status2)) { + gEfiShellProtocol->CloseFile(*FileHandle); + } + Status = Status2; } return (Status); } @@ -709,7 +772,6 @@ ShellOpenFileByName( FilePath = mEfiShellEnvironment2->NameToPath ((CHAR16*)FileName); if (FilePath != NULL) { return (ShellOpenFileByDevicePath(&FilePath, - &DeviceHandle, FileHandle, OpenMode, Attributes)); @@ -1252,6 +1314,8 @@ ShellExecute ( name. If the DeviceName is not NULL, it returns the current directory name on specified drive. + Note that the current directory string should exclude the tailing backslash character. + @param DeviceName the name of the drive to get directory on @retval NULL the directory does not exist @@ -1371,7 +1435,6 @@ typedef struct { @retval the resultant head of the double linked new format list; **/ LIST_ENTRY* -EFIAPI InternalShellConvertFileListType ( IN LIST_ENTRY *FileList, IN OUT LIST_ENTRY *ListHead @@ -1684,14 +1747,15 @@ ShellFindFilePath ( Path = ShellGetEnvironmentVariable(L"cwd"); if (Path != NULL) { - Size = StrSize(Path); + Size = StrSize(Path) + sizeof(CHAR16); Size += StrSize(FileName); TestPath = AllocateZeroPool(Size); if (TestPath == NULL) { return (NULL); } - StrnCpy(TestPath, Path, Size/sizeof(CHAR16) - 1); - StrnCat(TestPath, FileName, Size/sizeof(CHAR16) - 1 - StrLen(TestPath)); + StrCpyS(TestPath, Size/sizeof(CHAR16), Path); + StrCatS(TestPath, Size/sizeof(CHAR16), L"\\"); + StrCatS(TestPath, Size/sizeof(CHAR16), FileName); Status = ShellOpenFileByName(TestPath, &Handle, EFI_FILE_MODE_READ, 0); if (!EFI_ERROR(Status)){ if (FileHandleIsDirectory(Handle) != EFI_SUCCESS) { @@ -1723,12 +1787,12 @@ ShellFindFilePath ( *TempChar = CHAR_NULL; } if (TestPath[StrLen(TestPath)-1] != L'\\') { - StrnCat(TestPath, L"\\", Size/sizeof(CHAR16) - 1 - StrLen(TestPath)); + StrCatS(TestPath, Size/sizeof(CHAR16), L"\\"); } if (FileName[0] == L'\\') { FileName++; } - StrnCat(TestPath, FileName, Size/sizeof(CHAR16) - 1 - StrLen(TestPath)); + StrCatS(TestPath, Size/sizeof(CHAR16), FileName); if (StrStr(Walker, L";") != NULL) { Walker = StrStr(Walker, L";") + 1; } else { @@ -1797,9 +1861,9 @@ ShellFindFilePathEx ( return (NULL); } for (ExtensionWalker = FileExtension, TempChar2 = (CHAR16*)FileExtension; TempChar2 != NULL ; ExtensionWalker = TempChar2 + 1){ - StrnCpy(TestPath, FileName, Size/sizeof(CHAR16) - 1); + StrCpyS(TestPath, Size/sizeof(CHAR16), FileName); if (ExtensionWalker != NULL) { - StrnCat(TestPath, ExtensionWalker, Size/sizeof(CHAR16) - 1 - StrLen(TestPath)); + StrCatS(TestPath, Size/sizeof(CHAR16), ExtensionWalker); } TempChar = StrStr(TestPath, L";"); if (TempChar != NULL) { @@ -1840,7 +1904,6 @@ typedef struct { @retval FALSE the Parameter was not found. Type is not valid. **/ BOOLEAN -EFIAPI InternalIsOnCheckList ( IN CONST CHAR16 *Name, IN CONST SHELL_PARAM_ITEM *CheckList, @@ -1909,7 +1972,6 @@ InternalIsOnCheckList ( @retval FALSE the Parameter not a flag. **/ BOOLEAN -EFIAPI InternalIsFlag ( IN CONST CHAR16 *Name, IN CONST BOOLEAN AlwaysAllowNumbers, @@ -1966,7 +2028,6 @@ InternalIsFlag ( ProblemParam if provided. **/ EFI_STATUS -EFIAPI InternalCommandLineParse ( IN CONST SHELL_PARAM_ITEM *CheckList, OUT LIST_ENTRY **CheckPackage, @@ -1985,6 +2046,7 @@ InternalCommandLineParse ( UINTN Count; CONST CHAR16 *TempPointer; UINTN CurrentValueSize; + CHAR16 *NewValue; CurrentItemPackage = NULL; GetItemValue = 0; @@ -2078,41 +2140,37 @@ InternalCommandLineParse ( ASSERT(GetItemValue == 0); break; } - } else if (GetItemValue != 0 && CurrentItemPackage != NULL && !InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers, (CONST BOOLEAN)(CurrentItemPackage->Type == TypeTimeValue))) { - ASSERT(CurrentItemPackage != NULL); + } else if (GetItemValue != 0 && CurrentItemPackage != NULL && !InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers, (BOOLEAN)(CurrentItemPackage->Type == TypeTimeValue))) { // // get the item VALUE for a previous flag // - if (StrStr(Argv[LoopCounter], L" ") == NULL) { - CurrentValueSize = ValueSize + StrSize(Argv[LoopCounter]) + sizeof(CHAR16); - CurrentItemPackage->Value = ReallocatePool(ValueSize, CurrentValueSize, CurrentItemPackage->Value); - ASSERT(CurrentItemPackage->Value != NULL); - if (ValueSize == 0) { - StrnCpy(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1); - } else { - StrnCat(CurrentItemPackage->Value, L" ", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value)); - StrnCat(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value)); - } - ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16); + CurrentValueSize = ValueSize + StrSize(Argv[LoopCounter]) + sizeof(CHAR16); + NewValue = ReallocatePool(ValueSize, CurrentValueSize, CurrentItemPackage->Value); + if (NewValue == NULL) { + SHELL_FREE_NON_NULL (CurrentItemPackage->Value); + SHELL_FREE_NON_NULL (CurrentItemPackage); + ShellCommandLineFreeVarList (*CheckPackage); + *CheckPackage = NULL; + return EFI_OUT_OF_RESOURCES; + } + CurrentItemPackage->Value = NewValue; + if (ValueSize == 0) { + StrCpyS( CurrentItemPackage->Value, + CurrentValueSize/sizeof(CHAR16), + Argv[LoopCounter] + ); } else { - // - // the parameter has spaces. must be quoted. - // - CurrentValueSize = ValueSize + StrSize(Argv[LoopCounter]) + sizeof(CHAR16) + sizeof(CHAR16) + sizeof(CHAR16); - CurrentItemPackage->Value = ReallocatePool(ValueSize, CurrentValueSize, CurrentItemPackage->Value); - ASSERT(CurrentItemPackage->Value != NULL); - if (ValueSize == 0) { - StrnCpy(CurrentItemPackage->Value, L"\"", CurrentValueSize/sizeof(CHAR16) - 1); - StrnCat(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value)); - StrnCat(CurrentItemPackage->Value, L"\"", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value)); - } else { - StrnCat(CurrentItemPackage->Value, L" ", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value)); - StrnCat(CurrentItemPackage->Value, L"\"", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value)); - StrnCat(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value)); - StrnCat(CurrentItemPackage->Value, L"\"", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value)); - } - ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16); + StrCatS( CurrentItemPackage->Value, + CurrentValueSize/sizeof(CHAR16), + L" " + ); + StrCatS( CurrentItemPackage->Value, + CurrentValueSize/sizeof(CHAR16), + Argv[LoopCounter] + ); } + ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16); + GetItemValue--; if (GetItemValue == 0) { InsertHeadList(*CheckPackage, &CurrentItemPackage->Link); @@ -2509,7 +2567,7 @@ ShellCommandLineGetCount( } /** - Determins if a parameter is duplicated. + Determines if a parameter is duplicated. If Param is not NULL then it will point to a callee allocated string buffer with the parameter value if a duplicate is found. @@ -2632,14 +2690,14 @@ ShellCopySearchAndReplace( FreePool(Replace); return (EFI_BUFFER_TOO_SMALL); } - StrnCat(NewString, Replace, NewSize/sizeof(CHAR16) - 1 - StrLen(NewString)); + StrCatS(NewString, NewSize/sizeof(CHAR16), Replace); } else { Size = StrSize(NewString); if (Size + sizeof(CHAR16) > NewSize) { FreePool(Replace); return (EFI_BUFFER_TOO_SMALL); } - StrnCat(NewString, SourceString, 1); + StrnCatS(NewString, NewSize/sizeof(CHAR16), SourceString, 1); SourceString++; } } @@ -2658,7 +2716,6 @@ ShellCopySearchAndReplace( @retval !EFI_SUCCESS The operation failed. **/ EFI_STATUS -EFIAPI InternalPrintTo ( IN CONST CHAR16 *String ) @@ -2672,10 +2729,10 @@ InternalPrintTo ( return (gEfiShellProtocol->WriteFile(gEfiShellParametersProtocol->StdOut, &Size, (VOID*)String)); } if (mEfiShellInterface != NULL) { - if (mEfiShellInterface->RedirArgc == 0) { + if (mEfiShellInterface->RedirArgc == 0) { // // Divide in half for old shell. Must be string length not size. - // + // Size /=2; // Divide in half only when no redirection. } return (mEfiShellInterface->StdOut->Write(mEfiShellInterface->StdOut, &Size, (VOID*)String)); @@ -2714,7 +2771,6 @@ InternalPrintTo ( @return EFI_DEVICE_ERROR The console device reported an error. **/ EFI_STATUS -EFIAPI InternalShellPrintWorker( IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, @@ -2787,7 +2843,7 @@ InternalShellPrintWorker( // update the attribute // if (ResumeLocation != NULL) { - if (*(ResumeLocation-1) == L'^') { + if ((ResumeLocation != mPostReplaceFormat2) && (*(ResumeLocation-1) == L'^')) { // // Move cursor back 1 position to overwrite the ^ // @@ -2810,10 +2866,10 @@ InternalShellPrintWorker( gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_WHITE, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4))); break; case (L'B'): - gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_BLUE, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4))); + gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_LIGHTBLUE, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4))); break; case (L'V'): - gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_GREEN, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4))); + gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_LIGHTGREEN, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4))); break; default: // @@ -2943,13 +2999,14 @@ ShellPrintHiiEx( CHAR16 *HiiFormatString; EFI_STATUS RetVal; + RetVal = EFI_DEVICE_ERROR; + VA_START (Marker, HiiFormatHandle); HiiFormatString = HiiGetString(HiiFormatHandle, HiiFormatStringId, Language); - ASSERT(HiiFormatString != NULL); - - RetVal = InternalShellPrintWorker(Col, Row, HiiFormatString, Marker); - - SHELL_FREE_NON_NULL(HiiFormatString); + if (HiiFormatString != NULL) { + RetVal = InternalShellPrintWorker (Col, Row, HiiFormatString, Marker); + SHELL_FREE_NON_NULL (HiiFormatString); + } VA_END(Marker); return (RetVal); @@ -3113,7 +3170,7 @@ ShellHexStrToUintn( if (!EFI_ERROR(ShellConvertStringToUint64(String, &RetVal, TRUE, TRUE))) { return ((UINTN)RetVal); } - + return ((UINTN)(-1)); } @@ -3242,7 +3299,8 @@ StrnCatGrow ( *CurrentSize = NewSize; } } else { - *Destination = AllocateZeroPool((Count+1)*sizeof(CHAR16)); + NewSize = (Count+1)*sizeof(CHAR16); + *Destination = AllocateZeroPool(NewSize); } // @@ -3251,14 +3309,16 @@ StrnCatGrow ( if (*Destination == NULL) { return (NULL); } - return StrnCat(*Destination, Source, Count); + + StrnCatS(*Destination, NewSize/sizeof(CHAR16), Source, Count); + return *Destination; } /** Prompt the user and return the resultant answer to the requestor. This function will display the requested question on the shell prompt and then - wait for an apropriate answer to be input from the console. + wait for an appropriate answer to be input from the console. if the SHELL_PROMPT_REQUEST_TYPE is SHELL_PROMPT_REQUEST_TYPE_YESNO, ShellPromptResponseTypeQuitContinue or SHELL_PROMPT_REQUEST_TYPE_YESNOCANCEL then *Response is of type SHELL_PROMPT_RESPONSE. @@ -3358,7 +3418,8 @@ ShellPromptForResponse ( break; } } - break; case ShellPromptResponseTypeYesNoAllCancel: + break; + case ShellPromptResponseTypeYesNoAllCancel: if (Prompt != NULL) { ShellPrintEx(-1, -1, L"%s", Prompt); } @@ -3376,7 +3437,11 @@ ShellPromptForResponse ( if (EFI_ERROR(Status)) { break; } - ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar); + + if (Key.UnicodeChar <= 127 && Key.UnicodeChar >= 32) { + ShellPrintEx (-1, -1, L"%c", Key.UnicodeChar); + } + switch (Key.UnicodeChar) { case L'Y': case L'y': @@ -3560,7 +3625,6 @@ ShellPromptForResponseHii ( @retval FALSE There is a non-numeric character. **/ BOOLEAN -EFIAPI InternalShellIsHexOrDecimalNumber ( IN CONST CHAR16 *String, IN CONST BOOLEAN ForceHex, @@ -3569,29 +3633,36 @@ InternalShellIsHexOrDecimalNumber ( ) { BOOLEAN Hex; + BOOLEAN LeadingZero; + + if (String == NULL) { + return FALSE; + } // // chop off a single negative sign // - if (String != NULL && *String == L'-') { + if (*String == L'-') { String++; } - if (String == NULL) { - return (FALSE); + if (*String == CHAR_NULL) { + return FALSE; } // // chop leading zeroes // - while(String != NULL && *String == L'0'){ + LeadingZero = FALSE; + while(*String == L'0'){ String++; + LeadingZero = TRUE; } // // allow '0x' or '0X', but not 'x' or 'X' // - if (String != NULL && (*String == L'x' || *String == L'X')) { - if (*(String-1) != L'0') { + if (*String == L'x' || *String == L'X') { + if (!LeadingZero) { // // we got an x without a preceeding 0 // @@ -3608,7 +3679,7 @@ InternalShellIsHexOrDecimalNumber ( // // loop through the remaining characters and use the lib function // - for ( ; String != NULL && *String != CHAR_NULL && !(StopAtSpace && *String == L' ') ; String++){ + for ( ; *String != CHAR_NULL && !(StopAtSpace && *String == L' ') ; String++){ if (TimeNumbers && (String[0] == L':')) { continue; } @@ -3673,7 +3744,6 @@ ShellFileExists( **/ CHAR16 -EFIAPI InternalShellCharToUpper ( IN CHAR16 Char ) @@ -3699,7 +3769,6 @@ InternalShellCharToUpper ( **/ UINTN -EFIAPI InternalShellHexCharToUintn ( IN CHAR16 Char ) @@ -3708,13 +3777,13 @@ InternalShellHexCharToUintn ( return Char - L'0'; } - return (UINTN) (10 + InternalShellCharToUpper (Char) - L'A'); + return (10 + InternalShellCharToUpper (Char) - L'A'); } /** Convert a Null-terminated Unicode hexadecimal string to a value of type UINT64. - This function returns a value of type UINTN by interpreting the contents + This function returns a value of type UINT64 by interpreting the contents of the Unicode string specified by String as a hexadecimal number. The format of the input Unicode string String is: @@ -3742,7 +3811,6 @@ InternalShellHexCharToUintn ( @retval EFI_DEVICE_ERROR An overflow occured. **/ EFI_STATUS -EFIAPI InternalShellStrHexToUint64 ( IN CONST CHAR16 *String, OUT UINT64 *Value, @@ -3782,16 +3850,16 @@ InternalShellStrHexToUint64 ( Result = 0; // - // Skip spaces if requested + // there is a space where there should't be // - while (StopAtSpace && *String == L' ') { - String++; + if (*String == L' ') { + return (EFI_INVALID_PARAMETER); } while (ShellIsHexaDecimalDigitCharacter (*String)) { // // If the Hex Number represented by String overflows according - // to the range defined by UINTN, then ASSERT(). + // to the range defined by UINT64, then return EFI_DEVICE_ERROR. // if (!(Result <= (RShiftU64((((UINT64) ~0) - InternalShellHexCharToUintn (*String)), 4)))) { // if (!(Result <= ((((UINT64) ~0) - InternalShellHexCharToUintn (*String)) >> 4))) { @@ -3844,7 +3912,6 @@ InternalShellStrHexToUint64 ( @retval EFI_DEVICE_ERROR An overflow occured. **/ EFI_STATUS -EFIAPI InternalShellStrDecimalToUint64 ( IN CONST CHAR16 *String, OUT UINT64 *Value, @@ -3874,15 +3941,18 @@ InternalShellStrDecimalToUint64 ( Result = 0; // - // Skip spaces if requested + // Stop upon space if requested + // (if the whole value was 0) // - while (StopAtSpace && *String == L' ') { - String++; + if (StopAtSpace && *String == L' ') { + *Value = Result; + return (EFI_SUCCESS); } + while (ShellIsDecimalDigitCharacter (*String)) { // // If the number represented by String overflows according - // to the range defined by UINT64, then ASSERT(). + // to the range defined by UINT64, then return EFI_DEVICE_ERROR. // if (!(Result <= (DivU64x32((((UINT64) ~0) - (*String - L'0')),10)))) { @@ -4043,6 +4113,9 @@ ShellFileHandleReturnLine( Status = ShellFileHandleReadLine(Handle, RetVal, &Size, FALSE, Ascii); } + if (Status == EFI_END_OF_FILE && RetVal != NULL && *RetVal != CHAR_NULL) { + Status = EFI_SUCCESS; + } if (EFI_ERROR(Status) && (RetVal != NULL)) { FreePool(RetVal); RetVal = NULL; @@ -4056,9 +4129,20 @@ ShellFileHandleReturnLine( If the position upon start is 0, then the Ascii Boolean will be set. This should be maintained and not changed for all operations with the same file. + NOTE: LINES THAT ARE RETURNED BY THIS FUNCTION ARE UCS2, EVEN IF THE FILE BEING READ + IS IN ASCII FORMAT. + @param[in] Handle SHELL_FILE_HANDLE to read from. - @param[in, out] Buffer The pointer to buffer to read into. - @param[in, out] Size The pointer to number of bytes in Buffer. + @param[in, out] Buffer The pointer to buffer to read into. If this function + returns EFI_SUCCESS, then on output Buffer will + contain a UCS2 string, even if the file being + read is ASCII. + @param[in, out] Size On input, pointer to number of bytes in Buffer. + On output, unchanged unless Buffer is too small + to contain the next line of the file. In that + case Size is set to the number of bytes needed + to hold the next line of the file (as a UCS2 + string, even if it is an ASCII file). @param[in] Truncate If the buffer is large enough, this has no effect. If the buffer is is too small and Truncate is TRUE, the line will be truncated. @@ -4070,6 +4154,7 @@ ShellFileHandleReturnLine( @retval EFI_SUCCESS The operation was successful. The line is stored in Buffer. + @retval EFI_END_OF_FILE There are no more lines in the file. @retval EFI_INVALID_PARAMETER Handle was NULL. @retval EFI_INVALID_PARAMETER Size was NULL. @retval EFI_BUFFER_TOO_SMALL Size was not large enough to store the line. @@ -4115,19 +4200,22 @@ ShellFileHandleReadLine( } } + if (*Ascii) { + CharSize = sizeof(CHAR8); + } else { + CharSize = sizeof(CHAR16); + } for (CountSoFar = 0;;CountSoFar++){ CharBuffer = 0; - if (*Ascii) { - CharSize = sizeof(CHAR8); - } else { - CharSize = sizeof(CHAR16); - } Status = gEfiShellProtocol->ReadFile(Handle, &CharSize, &CharBuffer); if ( EFI_ERROR(Status) || CharSize == 0 || (CharBuffer == L'\n' && !(*Ascii)) || (CharBuffer == '\n' && *Ascii) ){ + if (CharSize == 0) { + Status = EFI_END_OF_FILE; + } break; } // @@ -4164,7 +4252,7 @@ ShellFileHandleReadLine( @param[in] CommandToGetHelpOn Pointer to a string containing the command name of help file to be printed. @param[in] SectionToGetHelpOn Pointer to the section specifier(s). - @param[in] PrintCommandText If TRUE, prints the command followed by the help content, otherwise prints + @param[in] PrintCommandText If TRUE, prints the command followed by the help content, otherwise prints the help content only. @retval EFI_DEVICE_ERROR The help data format was incorrect. @retval EFI_NOT_FOUND The help data could not be found. @@ -4178,33 +4266,33 @@ ShellPrintHelp ( IN BOOLEAN PrintCommandText ) { - EFI_STATUS Status; - CHAR16 *OutText; - - OutText = NULL; - + EFI_STATUS Status; + CHAR16 *OutText; + + OutText = NULL; + // // Get the string to print based // - Status = gEfiShellProtocol->GetHelpText (CommandToGetHelpOn, SectionToGetHelpOn, &OutText); - + Status = gEfiShellProtocol->GetHelpText (CommandToGetHelpOn, SectionToGetHelpOn, &OutText); + // // make sure we got a valid string // if (EFI_ERROR(Status)){ return Status; - } + } if (OutText == NULL || StrLen(OutText) == 0) { - return EFI_NOT_FOUND; - } - + return EFI_NOT_FOUND; + } + // // Chop off trailing stuff we dont need // while (OutText[StrLen(OutText)-1] == L'\r' || OutText[StrLen(OutText)-1] == L'\n' || OutText[StrLen(OutText)-1] == L' ') { OutText[StrLen(OutText)-1] = CHAR_NULL; } - + // // Print this out to the console // @@ -4213,17 +4301,17 @@ ShellPrintHelp ( } else { ShellPrintEx(-1, -1, L"%N%s\r\n", OutText); } - + SHELL_FREE_NON_NULL(OutText); - return EFI_SUCCESS; + return EFI_SUCCESS; } /** Function to delete a file by name - + @param[in] FileName Pointer to file name to delete. - + @retval EFI_SUCCESS the file was deleted sucessfully @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not deleted @@ -4250,39 +4338,38 @@ ShellDeleteFileByName( { EFI_STATUS Status; SHELL_FILE_HANDLE FileHandle; - + Status = ShellFileExists(FileName); - + if (Status == EFI_SUCCESS){ Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0x0); if (Status == EFI_SUCCESS){ Status = ShellDeleteFile(&FileHandle); } - } + } return(Status); - + } /** Cleans off all the quotes in the string. @param[in] OriginalString pointer to the string to be cleaned. - @param[out] CleanString The new string with all quotes removed. - Memory allocated in the function and free + @param[out] CleanString The new string with all quotes removed. + Memory allocated in the function and free by caller. @retval EFI_SUCCESS The operation was successful. **/ EFI_STATUS -EFIAPI InternalShellStripQuotes ( IN CONST CHAR16 *OriginalString, OUT CHAR16 **CleanString ) { CHAR16 *Walker; - + if (OriginalString == NULL || CleanString == NULL) { return EFI_INVALID_PARAMETER; }