]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/ShellProtocol.c
ShellPkg: Removing ipf which is no longer supported from edk2.
[mirror_edk2.git] / ShellPkg / Application / Shell / ShellProtocol.c
index 04b66c5acaae349977573b93e696d0a6b7e0efa1..f2ca2029e368f61cb17e77b7c9d7fbc919a4c177 100644 (file)
@@ -4,7 +4,7 @@
 \r
   (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>\r
   (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
-  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -477,7 +477,7 @@ EfiShellGetFilePathFromDevicePath(
         //  UEFI Shell spec section 3.7)\r
         if ((PathSize != 0)                        &&\r
             (PathForReturn != NULL)                &&\r
-            (PathForReturn[PathSize - 1] != L'\\') &&\r
+            (PathForReturn[PathSize / sizeof (CHAR16) - 1] != L'\\') &&\r
             (AlignedNode->PathName[0]    != L'\\')) {\r
           PathForReturn = StrnCatGrow (&PathForReturn, &PathSize, L"\\", 1);\r
         }\r
@@ -598,7 +598,8 @@ EfiShellGetDevicePathFromFilePath(
   //\r
   // build the full device path\r
   //\r
-  if (*(Path+StrLen(MapName)+1) == CHAR_NULL) {\r
+  if ((*(Path+StrLen(MapName)) != CHAR_NULL) &&\r
+      (*(Path+StrLen(MapName)+1) == CHAR_NULL)) {\r
     DevicePathForReturn = FileDevicePath(Handle, L"\\");\r
   } else {\r
     DevicePathForReturn = FileDevicePath(Handle, Path+StrLen(MapName));\r
@@ -826,7 +827,8 @@ EfiShellGetDeviceName(
   @retval EFI_NOT_FOUND         EFI_SIMPLE_FILE_SYSTEM could not be found or the root directory\r
                                 could not be opened.\r
   @retval EFI_VOLUME_CORRUPTED  The data structures in the volume were corrupted.\r
-  @retval EFI_DEVICE_ERROR      The device had an error\r
+  @retval EFI_DEVICE_ERROR      The device had an error.\r
+  @retval Others                Error status returned from EFI_SIMPLE_FILE_SYSTEM_PROTOCOL->OpenVolume().\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -866,8 +868,12 @@ EfiShellOpenRootByHandle(
   // Open the root volume now...\r
   //\r
   Status = SimpleFileSystem->OpenVolume(SimpleFileSystem, &RealFileHandle);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
   *FileHandle = ConvertEfiFileProtocolToShellHandle(RealFileHandle, EfiShellGetMapFromDevicePath(&DevPath));\r
-  return (Status);\r
+  return (EFI_SUCCESS);\r
 }\r
 \r
 /**\r
@@ -1416,7 +1422,7 @@ EfiShellEnablePageBreak (
                                 variables with the format 'x=y', where x is the\r
                                 environment variable name and y is the value. If this\r
                                 is NULL, then the current shell environment is used.\r
-                            \r
+\r
   @param[out] StartImageStatus  Returned status from gBS->StartImage.\r
 \r
   @retval EFI_SUCCESS       The command executed successfully. The  status code\r
@@ -1454,7 +1460,7 @@ InternalShellExecuteDevicePath(
   ZeroMem(&ShellParamsProtocol, sizeof(EFI_SHELL_PARAMETERS_PROTOCOL));\r
 \r
   NewHandle = NULL;\r
-  \r
+\r
   NewCmdLine = AllocateCopyPool (StrSize (CommandLine), CommandLine);\r
   if (NewCmdLine == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
@@ -1499,8 +1505,8 @@ InternalShellExecuteDevicePath(
     //\r
     if (LoadedImage->ImageCodeType != EfiLoaderCode){\r
       ShellPrintHiiEx(\r
-        -1, \r
-        -1, \r
+        -1,\r
+        -1,\r
         NULL,\r
         STRING_TOKEN (STR_SHELL_IMAGE_NOT_APP),\r
         ShellInfoObject.HiiHandle\r
@@ -1624,7 +1630,7 @@ FreeAlloc:
                                 variables with the format 'x=y', where x is the\r
                                 environment variable name and y is the value. If this\r
                                 is NULL, then the current shell environment is used.\r
-                \r
+\r
   @param[out] StartImageStatus  Returned status from the command line.\r
 \r
   @retval EFI_SUCCESS       The command executed successfully. The  status code\r
@@ -1678,6 +1684,7 @@ InternalShellExecute(
 STATIC\r
 BOOLEAN\r
 NestingEnabled(\r
+  VOID\r
 )\r
 {\r
   EFI_STATUS  Status;\r
@@ -1781,7 +1788,7 @@ EfiShellExecute(
     Temp = NULL;\r
     Size = 0;\r
     ASSERT((Temp == NULL && Size == 0) || (Temp != NULL));\r
-    StrnCatGrow(&Temp, &Size, L"Shell.efi -_exit ", 0);\r
+    StrnCatGrow(&Temp, &Size, L"Shell.efi -exit ", 0);\r
     StrnCatGrow(&Temp, &Size, CommandLine, 0);\r
 \r
     Status = InternalShellExecuteDevicePath(\r
@@ -2203,7 +2210,7 @@ EfiShellGetGuidFromName(
   if (Guid == NULL || GuidName == NULL) {\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
\r
+\r
   Status = GetGuidFromStringName(GuidName, NULL, &NewGuid);\r
 \r
   if (!EFI_ERROR(Status)) {\r
@@ -2755,8 +2762,8 @@ EfiShellGetEnvEx(
       ; Node = (ENV_VAR_LIST*)GetNextNode(&gShellEnvVarList.Link, &Node->Link)\r
      ){\r
       ASSERT(Node->Key != NULL);\r
-      StrCpyS( CurrentWriteLocation, \r
-                (Size)/sizeof(CHAR16) - (CurrentWriteLocation - ((CHAR16*)Buffer)), \r
+      StrCpyS( CurrentWriteLocation,\r
+                (Size)/sizeof(CHAR16) - (CurrentWriteLocation - ((CHAR16*)Buffer)),\r
                 Node->Key\r
                 );\r
       CurrentWriteLocation += StrLen(CurrentWriteLocation) + 1;\r
@@ -2872,8 +2879,8 @@ InternalEfiShellSetEnv(
                );\r
     if (!EFI_ERROR (Status)) {\r
       Status = Volatile\r
-             ? SHELL_SET_ENVIRONMENT_VARIABLE_V(Name, StrSize(Value), Value)\r
-             : SHELL_SET_ENVIRONMENT_VARIABLE_NV(Name, StrSize(Value), Value);\r
+             ? SHELL_SET_ENVIRONMENT_VARIABLE_V (Name, StrSize (Value) - sizeof (CHAR16), Value)\r
+             : SHELL_SET_ENVIRONMENT_VARIABLE_NV (Name, StrSize (Value) - sizeof (CHAR16), Value);\r
       if (EFI_ERROR (Status)) {\r
         ShellRemvoeEnvVarFromList(Name);\r
       }\r
@@ -3079,10 +3086,10 @@ EfiShellSetCurDir(
       // make that the current file system mapping\r
       //\r
       if (MapListItem != NULL) {\r
-        gShellCurDir = MapListItem;\r
+        gShellCurMapping = MapListItem;\r
       }\r
     } else {\r
-      MapListItem = gShellCurDir;\r
+      MapListItem = gShellCurMapping;\r
     }\r
 \r
     if (MapListItem == NULL) {\r
@@ -3131,7 +3138,7 @@ EfiShellSetCurDir(
       FreePool (DirectoryName);\r
       return (EFI_INVALID_PARAMETER);\r
     }\r
-//    gShellCurDir = MapListItem;\r
+//    gShellCurMapping = MapListItem;\r
     if (DirectoryName != NULL) {\r
       //\r
       // change current dir on that file system\r
@@ -3157,7 +3164,7 @@ EfiShellSetCurDir(
   //\r
   // if updated the current directory then update the environment variable\r
   //\r
-  if (MapListItem == gShellCurDir) {\r
+  if (MapListItem == gShellCurMapping) {\r
     Size = 0;\r
     ASSERT((TempString == NULL && Size == 0) || (TempString != NULL));\r
     StrnCatGrow(&TempString, &Size, MapListItem->MapName, 0);\r
@@ -3226,9 +3233,9 @@ EfiShellGetHelpText(
         return EFI_OUT_OF_RESOURCES;\r
       }\r
 \r
-      StrnCpyS( FixCommand, \r
-                (StrSize(Command) - 4 * sizeof (CHAR16))/sizeof(CHAR16), \r
-                Command, \r
+      StrnCpyS( FixCommand,\r
+                (StrSize(Command) - 4 * sizeof (CHAR16))/sizeof(CHAR16),\r
+                Command,\r
                 StrLen(Command)-4\r
                 );\r
       Status = ProcessManFile(FixCommand, FixCommand, Sections, NULL, HelpText);\r
@@ -3285,9 +3292,10 @@ EfiShellIsRootShell(
 **/\r
 CHAR16 *\r
 InternalEfiShellGetListAlias(\r
+  VOID\r
   )\r
 {\r
-  \r
+\r
   EFI_STATUS        Status;\r
   EFI_GUID          Guid;\r
   CHAR16            *VariableName;\r
@@ -3322,17 +3330,17 @@ InternalEfiShellGetListAlias(
         RetVal = NULL;\r
         break;\r
       }\r
-      \r
+\r
       NameSize = NameBufferSize;\r
       Status = gRT->GetNextVariableName(&NameSize, VariableName, &Guid);\r
     }\r
-    \r
+\r
     if (EFI_ERROR (Status)) {\r
       SHELL_FREE_NON_NULL(RetVal);\r
       RetVal = NULL;\r
       break;\r
     }\r
-    \r
+\r
     if (CompareGuid(&Guid, &gShellAliasGuid)){\r
       ASSERT((RetVal == NULL && RetSize == 0) || (RetVal != NULL));\r
       RetVal = StrnCatGrow(&RetVal, &RetSize, VariableName, 0);\r
@@ -3347,10 +3355,10 @@ InternalEfiShellGetListAlias(
 /**\r
   Convert a null-terminated unicode string, in-place, to all lowercase.\r
   Then return it.\r
-  \r
+\r
   @param  Str    The null-terminated string to be converted to all lowercase.\r
-  \r
-  @return        The null-terminated string converted into all lowercase.  \r
+\r
+  @return        The null-terminated string converted into all lowercase.\r
 **/\r
 CHAR16 *\r
 ToLower (\r
@@ -3377,7 +3385,7 @@ ToLower (
   @param[out] Volatile          upon return of a single command if TRUE indicates\r
                                 this is stored in a volatile fashion.  FALSE otherwise.\r
 \r
-  @return                              If Alias is not NULL, it will return a pointer to\r
+  @return                        If Alias is not NULL, it will return a pointer to\r
                                 the NULL-terminated command for that alias.\r
                                 If Alias is NULL, ReturnedData points to a ';'\r
                                 delimited list of alias (e.g.\r
@@ -3463,40 +3471,40 @@ InternalSetAlias(
 {\r
   EFI_STATUS  Status;\r
   CHAR16      *AliasLower;\r
+  BOOLEAN     DeleteAlias;\r
 \r
-  // Convert to lowercase to make aliases case-insensitive\r
-  if (Alias != NULL) {\r
-    AliasLower = AllocateCopyPool (StrSize (Alias), Alias);\r
-    if (AliasLower == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
-    ToLower (AliasLower);\r
-  } else {\r
-    AliasLower = NULL;\r
-  }\r
-\r
-  //\r
-  // We must be trying to remove one if Alias is NULL\r
-  //\r
+  DeleteAlias = FALSE;\r
   if (Alias == NULL) {\r
     //\r
+    // We must be trying to remove one if Alias is NULL\r
     // remove an alias (but passed in COMMAND parameter)\r
     //\r
-    Status = (gRT->SetVariable((CHAR16*)Command, &gShellAliasGuid, 0, 0, NULL));\r
-  } else {\r
-    //\r
-    // Add and replace are the same\r
-    //\r
-\r
-    // We dont check the error return on purpose since the variable may not exist.\r
-    gRT->SetVariable((CHAR16*)Command, &gShellAliasGuid, 0, 0, NULL);\r
+    Alias       = Command;\r
+    DeleteAlias = TRUE;\r
+  }\r
+  ASSERT (Alias != NULL);\r
 \r
-    Status = (gRT->SetVariable((CHAR16*)Alias, &gShellAliasGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS|(Volatile?0:EFI_VARIABLE_NON_VOLATILE), StrSize(Command), (VOID*)Command));\r
+  //\r
+  // Convert to lowercase to make aliases case-insensitive\r
+  //\r
+  AliasLower = AllocateCopyPool (StrSize (Alias), Alias);\r
+  if (AliasLower == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
   }\r
+  ToLower (AliasLower);\r
 \r
-  if (Alias != NULL) {\r
-    FreePool (AliasLower);\r
+  if (DeleteAlias) {\r
+    Status = gRT->SetVariable (AliasLower, &gShellAliasGuid, 0, 0, NULL);\r
+  } else {\r
+    Status = gRT->SetVariable (\r
+                    AliasLower, &gShellAliasGuid,\r
+                    EFI_VARIABLE_BOOTSERVICE_ACCESS | (Volatile ? 0 : EFI_VARIABLE_NON_VOLATILE),\r
+                    StrSize (Command), (VOID *) Command\r
+                    );\r
   }\r
+\r
+  FreePool (AliasLower);\r
+\r
   return Status;\r
 }\r
 \r
@@ -3793,7 +3801,7 @@ CleanUpShellEnvironment (
 {\r
   EFI_STATUS                        Status;\r
   EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx;\r
-  \r
+\r
   CleanUpShellProtocol (NewShell);\r
 \r
   Status = gBS->CloseEvent(NewShell->ExecutionBreak);\r
@@ -3836,21 +3844,21 @@ NotificationFunction(
   if ( ((KeyData->Key.UnicodeChar == L'c') &&\r
         (KeyData->KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED) || KeyData->KeyState.KeyShiftState  == (EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED))) ||\r
       (KeyData->Key.UnicodeChar == 3)\r
-      ){ \r
+      ){\r
     if (ShellInfoObject.NewEfiShellProtocol->ExecutionBreak == NULL) {\r
       return (EFI_UNSUPPORTED);\r
     }\r
     return (gBS->SignalEvent(ShellInfoObject.NewEfiShellProtocol->ExecutionBreak));\r
   } else if  ((KeyData->Key.UnicodeChar == L's') &&\r
               (KeyData->KeyState.KeyShiftState  == (EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED) || KeyData->KeyState.KeyShiftState  == (EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED))\r
-              ){ \r
+              ){\r
     ShellInfoObject.HaltOutput = TRUE;\r
   }\r
   return (EFI_SUCCESS);\r
 }\r
 \r
 /**\r
-  Function to start monitoring for CTRL-C using SimpleTextInputEx.  This \r
+  Function to start monitoring for CTRL-C using SimpleTextInputEx.  This\r
   feature's enabled state was not known when the shell initially launched.\r
 \r
   @retval EFI_SUCCESS           The feature is enabled.\r
@@ -3874,8 +3882,8 @@ InernalEfiShellStartMonitor(
     EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
   if (EFI_ERROR(Status)) {\r
     ShellPrintHiiEx(\r
-      -1, \r
-      -1, \r
+      -1,\r
+      -1,\r
       NULL,\r
       STRING_TOKEN (STR_SHELL_NO_IN_EX),\r
       ShellInfoObject.HiiHandle);\r
@@ -3896,7 +3904,7 @@ InernalEfiShellStartMonitor(
     &KeyData,\r
     NotificationFunction,\r
     &ShellInfoObject.CtrlCNotifyHandle1);\r
-  \r
+\r
   KeyData.KeyState.KeyShiftState  = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;\r
   if (!EFI_ERROR(Status)) {\r
     Status = SimpleEx->RegisterKeyNotify(\r