X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellLevel2CommandsLib%2FUefiShellLevel2CommandsLib.c;h=36bc3552b57936313c36e1ba85e84f326d4010fc;hp=7fe5a1102cab3fd3099d7226d847ca32709b264c;hb=2d70c90d2e8bf4405c5c16c0c7ea5b2446d1517a;hpb=a405b86d274d32b92f69842bfb9a1ab143128f57 diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c index 7fe5a1102c..36bc3552b5 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c @@ -16,12 +16,13 @@ rm, reset, set, - timezone* + timezone*, + vol * functions are non-interactive only - - Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
+ Copyright (c) 2014 Hewlett-Packard Development Company, L.P. + Copyright (c) 2009 - 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 @@ -35,11 +36,12 @@ CONST CHAR16 mFileName[] = L"ShellCommands"; EFI_HANDLE gShellLevel2HiiHandle = NULL; -CONST EFI_GUID gShellLevel2HiiGuid = \ - { \ - 0xf95a7ccc, 0x4c55, 0x4426, { 0xa7, 0xb4, 0xdc, 0x89, 0x61, 0x95, 0xb, 0xae } \ - }; +/** + Get the filename to get help text from if not using HII. + + @retval The filename. +**/ CONST CHAR16* EFIAPI ShellCommandGetManFileNameLevel2 ( @@ -71,7 +73,7 @@ ShellLevel2CommandsLibConstructor ( // if shell level is less than 2 do nothing // if (PcdGet8(PcdShellSupportLevel) < 2) { - return (EFI_UNSUPPORTED); + return (EFI_SUCCESS); } gShellLevel2HiiHandle = HiiAddPackages (&gShellLevel2HiiGuid, gImageHandle, UefiShellLevel2CommandsLibStrings, NULL); @@ -91,12 +93,13 @@ ShellLevel2CommandsLibConstructor ( ShellCommandRegisterCommandName(L"mv", ShellCommandRunMv , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_MV) ); ShellCommandRegisterCommandName(L"parse", ShellCommandRunParse , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_PARSE) ); ShellCommandRegisterCommandName(L"reset", ShellCommandRunReset , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_RESET) ); - ShellCommandRegisterCommandName(L"set", ShellCommandRunSet , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_SET) ); + ShellCommandRegisterCommandName(L"set", ShellCommandRunSet , ShellCommandGetManFileNameLevel2, 2, L"",FALSE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_SET) ); ShellCommandRegisterCommandName(L"ls", ShellCommandRunLs , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_LS) ); ShellCommandRegisterCommandName(L"rm", ShellCommandRunRm , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_RM) ); + ShellCommandRegisterCommandName(L"vol", ShellCommandRunVol , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_VOL) ); // - // support for permenant (built in) aliases + // support for permanent (built in) aliases // ShellCommandRegisterAlias(L"rm", L"del"); ShellCommandRegisterAlias(L"ls", L"dir"); @@ -104,6 +107,9 @@ ShellLevel2CommandsLibConstructor ( ShellCommandRegisterAlias(L"mkdir", L"md"); ShellCommandRegisterAlias(L"cd ..", L"cd.."); ShellCommandRegisterAlias(L"cd \\", L"cd\\"); + ShellCommandRegisterAlias(L"mv", L"ren"); + ShellCommandRegisterAlias(L"mv", L"move"); + ShellCommandRegisterAlias(L"map", L"mount"); // // These are installed in level 2 or 3... // @@ -146,54 +152,6 @@ ShellLevel2CommandsLibDestructor ( return (EFI_SUCCESS); } -/** - Function to clean up paths. Removes the following items: - single periods in the path (no need for the current directory tag) - double periods in the path and removes a single parent directory. - - This will be done inline and the resultant string may be be 'too big'. - - @param[in] PathToReturn The pointer to the string containing the path. - - @return PathToReturn is always returned. -**/ -CHAR16* -EFIAPI -CleanPath( - IN CHAR16 *PathToReturn - ) -{ - CHAR16 *TempString; - UINTN TempSize; - if (PathToReturn==NULL) { - return(NULL); - } - // - // Fix up the directory name - // - while ((TempString = StrStr(PathToReturn, L"\\..\\")) != NULL) { - *TempString = CHAR_NULL; - TempString += 4; - ChopLastSlash(PathToReturn); - TempSize = StrSize(TempString); - CopyMem(PathToReturn+StrLen(PathToReturn), TempString, TempSize); - } - if ((TempString = StrStr(PathToReturn, L"\\..")) != NULL && *(TempString + 3) == CHAR_NULL) { - *TempString = CHAR_NULL; - ChopLastSlash(PathToReturn); - } - while ((TempString = StrStr(PathToReturn, L"\\.\\")) != NULL) { - *TempString = CHAR_NULL; - TempString += 2; - TempSize = StrSize(TempString); - CopyMem(PathToReturn+StrLen(PathToReturn), TempString, TempSize); - } - if ((TempString = StrStr(PathToReturn, L"\\.")) != NULL && *(TempString + 2) == CHAR_NULL) { - *TempString = CHAR_NULL; - } - return (PathToReturn); -} - /** returns a fully qualified directory (contains a map drive at the begining) path from a unknown directory path. @@ -207,11 +165,10 @@ CleanPath( @param[in] Path The unknown Path Value @retval NULL A memory allocation failed - @retval NULL a fully qualified path could not be discovered. - @retval other pointer to a fuly qualified path. + @retval NULL A fully qualified path could not be discovered. + @retval other An allocated pointer to a fuly qualified path. **/ CHAR16* -EFIAPI GetFullyQualifiedPath( IN CONST CHAR16* Path ) @@ -230,13 +187,18 @@ GetFullyQualifiedPath( if (StrStr(Path, L":") == NULL) { CurDir = gEfiShellProtocol->GetCurDir(NULL); StrnCatGrow(&PathToReturn, &Size, CurDir, 0); + StrnCatGrow(&PathToReturn, &Size, L"\\", 0); if (*Path == L'\\') { Path++; } } StrnCatGrow(&PathToReturn, &Size, Path, 0); - CleanPath(PathToReturn); + PathCleanUpDirectories(PathToReturn); + + if (PathToReturn == NULL) { + return NULL; + } while (PathToReturn[StrLen(PathToReturn)-1] == L'*') { PathToReturn[StrLen(PathToReturn)-1] = CHAR_NULL; @@ -253,7 +215,6 @@ GetFullyQualifiedPath( @retval EFI_SUCCESS The operation was successful. **/ EFI_STATUS -EFIAPI VerifyIntermediateDirectories ( IN CONST CHAR16 *Path ) @@ -270,6 +231,10 @@ VerifyIntermediateDirectories ( PathCopy = StrnCatGrow(&PathCopy, NULL, Path, 0); FileHandle = NULL; + if (PathCopy == NULL) { + return (EFI_OUT_OF_RESOURCES); + } + for (TempSpot = &PathCopy[StrLen(PathCopy)-1] ; *TempSpot != CHAR_NULL && *TempSpot != L'\\' ; TempSpot = &PathCopy[StrLen(PathCopy)-1]){ *TempSpot = CHAR_NULL; } @@ -295,35 +260,91 @@ VerifyIntermediateDirectories ( return (Status); } -// be lazy and borrow from baselib. -CHAR16 -EFIAPI -InternalCharToUpper ( - IN CONST CHAR16 Char - ); +/** + String comparison without regard to case for a limited number of characters. -CONST CHAR16* -EFIAPI + @param[in] Source The first item to compare. + @param[in] Target The second item to compare. + @param[in] Count How many characters to compare. + + @retval 0 Source and Target are identical strings without regard to case. + @retval !=0 Source is not identical to Target. + +**/ +INTN StrniCmp( IN CONST CHAR16 *Source, IN CONST CHAR16 *Target, IN CONST UINTN Count ) { - UINTN LoopCount; - CHAR16 Char1; - CHAR16 Char2; - - ASSERT(Source != NULL); - ASSERT(Target != NULL); - - for (LoopCount = 0 ; LoopCount < Count ; LoopCount++) { - Char1 = InternalCharToUpper(Source[LoopCount]); - Char2 = InternalCharToUpper(Target[LoopCount]); - if (Char1 != Char2) { - return (&Source[LoopCount]); + CHAR16 *SourceCopy; + CHAR16 *TargetCopy; + UINTN SourceLength; + UINTN TargetLength; + INTN Result; + + if (Count == 0) { + return 0; + } + + SourceLength = StrLen (Source); + TargetLength = StrLen (Target); + SourceLength = MIN (SourceLength, Count); + TargetLength = MIN (TargetLength, Count); + SourceCopy = AllocateCopyPool ((SourceLength + 1) * sizeof (CHAR16), Source); + if (SourceCopy == NULL) { + return -1; + } + TargetCopy = AllocateCopyPool ((TargetLength + 1) * sizeof (CHAR16), Target); + if (TargetCopy == NULL) { + FreePool (SourceCopy); + return -1; + } + + SourceCopy[SourceLength] = L'\0'; + TargetCopy[TargetLength] = L'\0'; + Result = gUnicodeCollation->StriColl (gUnicodeCollation, SourceCopy, TargetCopy); + FreePool (SourceCopy); + FreePool (TargetCopy); + return Result; +} + + +/** + 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 + by caller. + + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +ShellLevel2StripQuotes ( + IN CONST CHAR16 *OriginalString, + OUT CHAR16 **CleanString + ) +{ + CHAR16 *Walker; + + if (OriginalString == NULL || CleanString == NULL) { + return EFI_INVALID_PARAMETER; + } + + *CleanString = AllocateCopyPool (StrSize (OriginalString), OriginalString); + if (*CleanString == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + for (Walker = *CleanString; Walker != NULL && *Walker != CHAR_NULL ; Walker++) { + if (*Walker == L'\"') { + CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0])); } } - return (NULL); + + return EFI_SUCCESS; } +