+ ASSERT(StdOut == NULL);\r
+\r
+ ASSERT(StrStr(CmdLine, L"|") != NULL);\r
+\r
+ Status = EFI_SUCCESS;\r
+ NextCommandLine = NULL;\r
+ OurCommandLine = NULL;\r
+ Size1 = 0;\r
+ Size2 = 0;\r
+\r
+ NextCommandLine = StrnCatGrow(&NextCommandLine, &Size1, StrStr(CmdLine, L"|")+1, 0);\r
+ OurCommandLine = StrnCatGrow(&OurCommandLine , &Size2, CmdLine , StrStr(CmdLine, L"|") - CmdLine);\r
+\r
+ if (NextCommandLine == NULL || OurCommandLine == NULL) {\r
+ SHELL_FREE_NON_NULL(OurCommandLine);\r
+ SHELL_FREE_NON_NULL(NextCommandLine);\r
+ return (EFI_OUT_OF_RESOURCES);\r
+ } else if (StrStr(OurCommandLine, L"|") != NULL || Size1 == 0 || Size2 == 0) {\r
+ SHELL_FREE_NON_NULL(OurCommandLine);\r
+ SHELL_FREE_NON_NULL(NextCommandLine);\r
+ return (EFI_INVALID_PARAMETER);\r
+ } else if (NextCommandLine[0] == L'a' &&\r
+ (NextCommandLine[1] == L' ' || NextCommandLine[1] == CHAR_NULL)\r
+ ){\r
+ CopyMem(NextCommandLine, NextCommandLine+1, StrSize(NextCommandLine) - sizeof(NextCommandLine[0]));\r
+ while (NextCommandLine[0] == L' ') {\r
+ CopyMem(NextCommandLine, NextCommandLine+1, StrSize(NextCommandLine) - sizeof(NextCommandLine[0]));\r
+ }\r
+ if (NextCommandLine[0] == CHAR_NULL) {\r
+ SHELL_FREE_NON_NULL(OurCommandLine);\r
+ SHELL_FREE_NON_NULL(NextCommandLine);\r
+ return (EFI_INVALID_PARAMETER);\r
+ }\r
+ Unicode = FALSE;\r
+ } else {\r
+ Unicode = TRUE;\r
+ }\r
+\r
+\r
+ //\r
+ // make a SPLIT_LIST item and add to list\r
+ //\r
+ Split = AllocateZeroPool(sizeof(SPLIT_LIST));\r
+ ASSERT(Split != NULL);\r
+ Split->SplitStdIn = StdIn;\r
+ Split->SplitStdOut = ConvertEfiFileProtocolToShellHandle(CreateFileInterfaceMem(Unicode), NULL);\r
+ ASSERT(Split->SplitStdOut != NULL);\r
+ InsertHeadList(&ShellInfoObject.SplitList.Link, &Split->Link);\r
+\r
+ Status = RunCommand(OurCommandLine);\r
+\r
+ //\r
+ // move the output from the first to the in to the second.\r
+ //\r
+ TempFileHandle = Split->SplitStdOut;\r
+ if (Split->SplitStdIn == StdIn) {\r
+ Split->SplitStdOut = NULL;\r
+ } else {\r
+ Split->SplitStdOut = Split->SplitStdIn;\r
+ }\r
+ Split->SplitStdIn = TempFileHandle;\r
+ ShellInfoObject.NewEfiShellProtocol->SetFilePosition(ConvertShellHandleToEfiFileProtocol(Split->SplitStdIn), 0);\r
+\r
+ if (!EFI_ERROR(Status)) {\r
+ Status = RunCommand(NextCommandLine);\r
+ }\r
+\r
+ //\r
+ // remove the top level from the ScriptList\r
+ //\r
+ ASSERT((SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link) == Split);\r
+ RemoveEntryList(&Split->Link);\r
+\r
+ //\r
+ // Note that the original StdIn is now the StdOut...\r
+ //\r
+ if (Split->SplitStdOut != NULL && Split->SplitStdOut != StdIn) {\r
+ ShellInfoObject.NewEfiShellProtocol->CloseFile(ConvertShellHandleToEfiFileProtocol(Split->SplitStdOut));\r
+ }\r
+ if (Split->SplitStdIn != NULL) {\r
+ ShellInfoObject.NewEfiShellProtocol->CloseFile(ConvertShellHandleToEfiFileProtocol(Split->SplitStdIn));\r
+ }\r
+\r
+ FreePool(Split);\r
+ FreePool(NextCommandLine);\r
+ FreePool(OurCommandLine);\r
+\r
+ return (Status);\r
+}\r
+\r
+/**\r
+ Take the original command line, substitute any variables, free \r
+ the original string, return the modified copy.\r
+\r
+ @param[in] CmdLine pointer to the command line to update.\r
+\r
+ @retval EFI_SUCCESS the function was successful.\r
+ @retval EFI_OUT_OF_RESOURCES a memory allocation failed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ShellSubstituteVariables(\r
+ IN CHAR16 **CmdLine\r
+ )\r
+{\r
+ CHAR16 *NewCmdLine;\r
+ NewCmdLine = ShellConvertVariables(*CmdLine);\r
+ SHELL_FREE_NON_NULL(*CmdLine);\r
+ if (NewCmdLine == NULL) {\r
+ return (EFI_OUT_OF_RESOURCES);\r
+ }\r
+ *CmdLine = NewCmdLine;\r
+ return (EFI_SUCCESS);\r
+}\r
+\r
+/**\r
+ Take the original command line, substitute any alias in the first group of space delimited characters, free \r
+ the original string, return the modified copy.\r
+\r
+ @param[in] CmdLine pointer to the command line to update.\r
+\r
+ @retval EFI_SUCCESS the function was successful.\r
+ @retval EFI_OUT_OF_RESOURCES a memory allocation failed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ShellSubstituteAliases(\r
+ IN CHAR16 **CmdLine\r
+ )\r
+{\r
+ CHAR16 *NewCmdLine;\r
+ CHAR16 *CommandName;\r
+ EFI_STATUS Status;\r
+ UINTN PostAliasSize;\r
+ ASSERT(CmdLine != NULL);\r
+ ASSERT(*CmdLine!= NULL);\r
+\r
+\r
+ CommandName = NULL;\r
+ if (StrStr((*CmdLine), L" ") == NULL){\r
+ StrnCatGrow(&CommandName, NULL, (*CmdLine), 0);\r
+ } else {\r
+ StrnCatGrow(&CommandName, NULL, (*CmdLine), StrStr((*CmdLine), L" ") - (*CmdLine));\r
+ }\r
+\r
+ //\r
+ // This cannot happen 'inline' since the CmdLine can need extra space.\r
+ //\r
+ NewCmdLine = NULL;\r
+ if (!ShellCommandIsCommandOnList(CommandName)) {\r
+ //\r
+ // Convert via alias\r
+ //\r
+ Status = ShellConvertAlias(&CommandName);\r
+ if (EFI_ERROR(Status)){\r
+ return (Status);\r
+ }\r
+ PostAliasSize = 0;\r
+ NewCmdLine = StrnCatGrow(&NewCmdLine, &PostAliasSize, CommandName, 0);\r
+ if (NewCmdLine == NULL) {\r
+ SHELL_FREE_NON_NULL(CommandName);\r
+ SHELL_FREE_NON_NULL(*CmdLine);\r
+ return (EFI_OUT_OF_RESOURCES);\r
+ }\r
+ NewCmdLine = StrnCatGrow(&NewCmdLine, &PostAliasSize, StrStr((*CmdLine), L" "), 0);\r
+ if (NewCmdLine == NULL) {\r
+ SHELL_FREE_NON_NULL(CommandName);\r
+ SHELL_FREE_NON_NULL(*CmdLine);\r
+ return (EFI_OUT_OF_RESOURCES);\r
+ }\r
+ } else {\r
+ NewCmdLine = StrnCatGrow(&NewCmdLine, NULL, (*CmdLine), 0);\r
+ }\r
+\r
+ SHELL_FREE_NON_NULL(*CmdLine);\r
+ SHELL_FREE_NON_NULL(CommandName);\r
+ \r
+ //\r
+ // re-assign the passed in double pointer to point to our newly allocated buffer\r
+ //\r
+ *CmdLine = NewCmdLine;\r
+\r
+ return (EFI_SUCCESS);\r
+}\r
+\r
+/**\r
+ Takes the Argv[0] part of the command line and determine the meaning of it.\r
+\r
+ @param[in] CmdName pointer to the command line to update.\r
+ \r
+ @retval Internal_Command The name is an internal command.\r
+ @retval File_Sys_Change the name is a file system change.\r
+ @retval Script_File_Name the name is a NSH script file.\r
+ @retval Unknown_Invalid the name is unknown.\r
+ @retval Efi_Application the name is an application (.EFI).\r
+**/\r
+SHELL_OPERATION_TYPES\r
+EFIAPI\r
+GetOperationType(\r
+ IN CONST CHAR16 *CmdName\r
+ )\r
+{\r
+ CHAR16* FileWithPath;\r
+ CONST CHAR16* TempLocation;\r
+ CONST CHAR16* TempLocation2;\r
+\r
+ FileWithPath = NULL;\r
+ //\r
+ // test for an internal command.\r
+ //\r
+ if (ShellCommandIsCommandOnList(CmdName)) {\r
+ return (Internal_Command);\r
+ }\r
+\r
+ //\r
+ // Test for file system change request. anything ending with first : and cant have spaces.\r
+ //\r
+ if (CmdName[(StrLen(CmdName)-1)] == L':') {\r
+ if ( StrStr(CmdName, L" ") != NULL \r
+ || StrLen(StrStr(CmdName, L":")) > 1\r
+ ) {\r
+ return (Unknown_Invalid);\r
+ }\r
+ return (File_Sys_Change);\r
+ }\r
+\r
+ //\r
+ // Test for a file\r
+ //\r
+ if ((FileWithPath = ShellFindFilePathEx(CmdName, mExecutableExtensions)) != NULL) {\r
+ //\r
+ // See if that file has a script file extension\r
+ //\r
+ if (StrLen(FileWithPath) > 4) {\r
+ TempLocation = FileWithPath+StrLen(FileWithPath)-4;\r
+ TempLocation2 = mScriptExtension;\r
+ if (StringNoCaseCompare((VOID*)(&TempLocation), (VOID*)(&TempLocation2)) == 0) {\r
+ SHELL_FREE_NON_NULL(FileWithPath);\r
+ return (Script_File_Name);\r
+ }\r
+ }\r
+\r
+ //\r
+ // Was a file, but not a script. we treat this as an application.\r
+ //\r
+ SHELL_FREE_NON_NULL(FileWithPath);\r
+ return (Efi_Application);\r
+ }\r
+ \r
+ SHELL_FREE_NON_NULL(FileWithPath);\r
+ //\r
+ // No clue what this is... return invalid flag...\r
+ //\r
+ return (Unknown_Invalid);\r
+}\r
+\r
+/**\r
+ Determine if the first item in a command line is valid.\r
+\r
+ @param[in] CmdLine The command line to parse.\r
+\r
+ @retval EFI_SUCCESS The item is valid.\r
+ @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
+ @retval EFI_NOT_FOUND The operation type is unknown or invalid.\r
+**/\r
+EFI_STATUS \r
+EFIAPI\r
+IsValidSplit(\r
+ IN CONST CHAR16 *CmdLine\r
+ )\r
+{\r
+ CHAR16 *Temp;\r
+ CHAR16 *FirstParameter;\r
+ CHAR16 *TempWalker;\r
+ EFI_STATUS Status;\r
+\r
+ Temp = NULL;\r
+\r
+ Temp = StrnCatGrow(&Temp, NULL, CmdLine, 0);\r
+ if (Temp == NULL) {\r
+ return (EFI_OUT_OF_RESOURCES);\r
+ }\r
+\r
+ FirstParameter = StrStr(Temp, L"|");\r
+ if (FirstParameter != NULL) {\r
+ *FirstParameter = CHAR_NULL;\r
+ }\r
+\r
+ FirstParameter = NULL;\r
+\r
+ //\r
+ // Process the command line\r
+ //\r
+ Status = ProcessCommandLineToFinal(&Temp);\r
+\r
+ if (!EFI_ERROR(Status)) {\r
+ FirstParameter = AllocateZeroPool(StrSize(CmdLine));\r
+ if (FirstParameter == NULL) {\r
+ SHELL_FREE_NON_NULL(Temp);\r
+ return (EFI_OUT_OF_RESOURCES);\r
+ }\r
+ TempWalker = (CHAR16*)Temp;\r
+ if (!EFI_ERROR(GetNextParameter(&TempWalker, &FirstParameter, StrSize(CmdLine), TRUE))) {\r
+ if (GetOperationType(FirstParameter) == Unknown_Invalid) {\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r
+ SetLastError(SHELL_NOT_FOUND);\r
+ Status = EFI_NOT_FOUND;\r
+ }\r
+ }\r
+ }\r
+\r
+ SHELL_FREE_NON_NULL(Temp);\r
+ SHELL_FREE_NON_NULL(FirstParameter);\r
+ return Status;\r
+}\r
+\r
+/**\r
+ Determine if a command line contains with a split contains only valid commands.\r
+\r
+ @param[in] CmdLine The command line to parse.\r
+\r
+ @retval EFI_SUCCESS CmdLine has only valid commands, application, or has no split.\r
+ @retval EFI_ABORTED CmdLine has at least one invalid command or application.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VerifySplit(\r
+ IN CONST CHAR16 *CmdLine\r
+ )\r
+{\r
+ CONST CHAR16 *TempSpot;\r
+ EFI_STATUS Status;\r
+\r
+ //\r
+ // If this was the only item, then get out\r
+ //\r
+ if (!ContainsSplit(CmdLine)) {\r
+ return (EFI_SUCCESS);\r
+ }\r
+\r
+ //\r
+ // Verify up to the pipe or end character\r
+ //\r
+ Status = IsValidSplit(CmdLine);\r
+ if (EFI_ERROR(Status)) {\r
+ return (Status);\r
+ }\r
+\r
+ //\r
+ // recurse to verify the next item\r
+ //\r
+ TempSpot = FindFirstCharacter(CmdLine, L"|", L'^') + 1;\r
+ if (*TempSpot == L'a' && \r
+ (*(TempSpot + 1) == L' ' || *(TempSpot + 1) == CHAR_NULL)\r
+ ) {\r
+ // If it's an ASCII pipe '|a'\r
+ TempSpot += 1;\r
+ }\r
+ \r
+ return (VerifySplit(TempSpot));\r
+}\r
+\r
+/**\r
+ Process a split based operation.\r
+\r
+ @param[in] CmdLine pointer to the command line to process\r
+\r
+ @retval EFI_SUCCESS The operation was successful\r
+ @return an error occurred.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ProcessNewSplitCommandLine(\r
+ IN CONST CHAR16 *CmdLine\r
+ )\r
+{\r
+ SPLIT_LIST *Split;\r
+ EFI_STATUS Status;\r
+\r
+ Status = VerifySplit(CmdLine);\r
+ if (EFI_ERROR(Status)) {\r
+ return (Status);\r
+ }\r
+\r
+ Split = NULL;\r
+\r
+ //\r
+ // are we in an existing split???\r
+ //\r
+ if (!IsListEmpty(&ShellInfoObject.SplitList.Link)) {\r
+ Split = (SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link);\r
+ }\r
+\r
+ if (Split == NULL) {\r
+ Status = RunSplitCommand(CmdLine, NULL, NULL);\r
+ } else {\r
+ Status = RunSplitCommand(CmdLine, Split->SplitStdIn, Split->SplitStdOut);\r
+ }\r
+ if (EFI_ERROR(Status)) {\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_SPLIT), ShellInfoObject.HiiHandle, CmdLine);\r
+ }\r
+ return (Status);\r
+}\r
+\r
+/**\r
+ Handle a request to change the current file system.\r
+\r
+ @param[in] CmdLine The passed in command line.\r
+\r
+ @retval EFI_SUCCESS The operation was successful.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ChangeMappedDrive(\r
+ IN CONST CHAR16 *CmdLine\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ Status = EFI_SUCCESS;\r
+\r
+ //\r
+ // make sure we are the right operation\r
+ //\r
+ ASSERT(CmdLine[(StrLen(CmdLine)-1)] == L':' && StrStr(CmdLine, L" ") == NULL);\r
+ \r
+ //\r
+ // Call the protocol API to do the work\r
+ //\r
+ Status = ShellInfoObject.NewEfiShellProtocol->SetCurDir(NULL, CmdLine);\r
+\r
+ //\r
+ // Report any errors\r
+ //\r
+ if (EFI_ERROR(Status)) {\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_MAPPING), ShellInfoObject.HiiHandle, CmdLine);\r
+ }\r
+\r
+ return (Status);\r
+}\r
+\r
+/**\r
+ Reprocess the command line to direct all -? to the help command.\r
+\r
+ if found, will add "help" as argv[0], and move the rest later.\r
+\r
+ @param[in,out] CmdLine pointer to the command line to update\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DoHelpUpdate(\r
+ IN OUT CHAR16 **CmdLine\r
+ )\r
+{\r
+ CHAR16 *CurrentParameter;\r
+ CHAR16 *Walker;\r
+ CHAR16 *NewCommandLine;\r
+ EFI_STATUS Status;\r
+ UINTN NewCmdLineSize;\r
+\r
+ Status = EFI_SUCCESS;\r
+\r
+ CurrentParameter = AllocateZeroPool(StrSize(*CmdLine));\r
+ if (CurrentParameter == NULL) {\r
+ return (EFI_OUT_OF_RESOURCES);\r
+ }\r
+\r
+ Walker = *CmdLine;\r
+ while(Walker != NULL && *Walker != CHAR_NULL) {\r
+ if (!EFI_ERROR(GetNextParameter(&Walker, &CurrentParameter, StrSize(*CmdLine), TRUE))) {\r
+ if (StrStr(CurrentParameter, L"-?") == CurrentParameter) {\r
+ CurrentParameter[0] = L' ';\r
+ CurrentParameter[1] = L' ';\r
+ NewCmdLineSize = StrSize(L"help ") + StrSize(*CmdLine);\r
+ NewCommandLine = AllocateZeroPool(NewCmdLineSize);\r
+ if (NewCommandLine == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ break;\r
+ }\r
+\r
+ //\r
+ // We know the space is sufficient since we just calculated it.\r
+ //\r
+ StrnCpyS(NewCommandLine, NewCmdLineSize/sizeof(CHAR16), L"help ", 5);\r
+ StrnCatS(NewCommandLine, NewCmdLineSize/sizeof(CHAR16), *CmdLine, StrLen(*CmdLine));\r
+ SHELL_FREE_NON_NULL(*CmdLine);\r
+ *CmdLine = NewCommandLine;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+\r
+ SHELL_FREE_NON_NULL(CurrentParameter);\r
+\r
+ return (Status);\r
+}\r
+\r
+/**\r
+ Function to update the shell variable "lasterror".\r
+\r
+ @param[in] ErrorCode the error code to put into lasterror.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SetLastError(\r
+ IN CONST SHELL_STATUS ErrorCode\r
+ )\r
+{\r
+ CHAR16 LeString[19];\r
+ if (sizeof(EFI_STATUS) == sizeof(UINT64)) {\r
+ UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ErrorCode);\r
+ } else {\r
+ UnicodeSPrint(LeString, sizeof(LeString), L"0x%x", ErrorCode);\r
+ }\r
+ DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););\r
+ InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);\r
+\r
+ return (EFI_SUCCESS);\r
+}\r
+\r
+/**\r
+ Converts the command line to it's post-processed form. this replaces variables and alias' per UEFI Shell spec.\r
+\r
+ @param[in,out] CmdLine pointer to the command line to update\r
+\r
+ @retval EFI_SUCCESS The operation was successful\r
+ @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
+ @return some other error occurred\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ProcessCommandLineToFinal(\r
+ IN OUT CHAR16 **CmdLine\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ TrimSpaces(CmdLine);\r
+\r
+ Status = ShellSubstituteAliases(CmdLine);\r
+ if (EFI_ERROR(Status)) {\r
+ return (Status);\r
+ }\r
+\r
+ TrimSpaces(CmdLine);\r
+\r
+ Status = ShellSubstituteVariables(CmdLine);\r
+ if (EFI_ERROR(Status)) {\r
+ return (Status);\r
+ }\r
+ ASSERT (*CmdLine != NULL);\r
+\r
+ TrimSpaces(CmdLine);\r
+\r
+ //\r
+ // update for help parsing\r
+ //\r
+ if (StrStr(*CmdLine, L"?") != NULL) {\r
+ //\r
+ // This may do nothing if the ? does not indicate help.\r
+ // Save all the details for in the API below.\r
+ //\r
+ Status = DoHelpUpdate(CmdLine);\r
+ }\r
+\r
+ TrimSpaces(CmdLine);\r
+\r
+ return (EFI_SUCCESS);\r
+}\r
+\r
+/**\r
+ Run an internal shell command.\r
+\r
+ This API will update the shell's environment since these commands are libraries.\r
+ \r
+ @param[in] CmdLine the command line to run.\r
+ @param[in] FirstParameter the first parameter on the command line\r
+ @param[in] ParamProtocol the shell parameters protocol pointer\r
+ @param[out] CommandStatus the status from the command line.\r
+\r
+ @retval EFI_SUCCESS The command was completed.\r
+ @retval EFI_ABORTED The command's operation was aborted.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RunInternalCommand(\r
+ IN CONST CHAR16 *CmdLine,\r
+ IN CHAR16 *FirstParameter,\r
+ IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol,\r
+ OUT EFI_STATUS *CommandStatus\r
+)\r
+{\r
+ EFI_STATUS Status;\r
+ UINTN Argc;\r
+ CHAR16 **Argv;\r
+ SHELL_STATUS CommandReturnedStatus;\r
+ BOOLEAN LastError;\r
+ CHAR16 *Walker;\r
+ CHAR16 *NewCmdLine; \r
+\r
+ NewCmdLine = AllocateCopyPool (StrSize (CmdLine), CmdLine);\r
+ if (NewCmdLine == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ for (Walker = NewCmdLine; Walker != NULL && *Walker != CHAR_NULL ; Walker++) {\r
+ if (*Walker == L'^' && *(Walker+1) == L'#') {\r
+ CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0]));\r
+ }\r
+ }\r
+\r
+ //\r
+ // get the argc and argv updated for internal commands\r
+ //\r
+ Status = UpdateArgcArgv(ParamProtocol, NewCmdLine, Internal_Command, &Argv, &Argc);\r
+ if (!EFI_ERROR(Status)) {\r
+ //\r
+ // Run the internal command.\r
+ //\r
+ Status = ShellCommandRunCommandHandler(FirstParameter, &CommandReturnedStatus, &LastError);\r
+\r
+ if (!EFI_ERROR(Status)) {\r
+ if (CommandStatus != NULL) {\r
+ if (CommandReturnedStatus != SHELL_SUCCESS) {\r
+ *CommandStatus = (EFI_STATUS)(CommandReturnedStatus | MAX_BIT);\r
+ } else {\r
+ *CommandStatus = EFI_SUCCESS;\r
+ }\r
+ }\r
+\r
+ //\r
+ // Update last error status.\r
+ // some commands do not update last error.\r
+ //\r
+ if (LastError) {\r
+ SetLastError(CommandReturnedStatus);\r
+ }\r
+\r
+ //\r
+ // Pass thru the exitcode from the app.\r
+ //\r
+ if (ShellCommandGetExit()) {\r
+ //\r
+ // An Exit was requested ("exit" command), pass its value up.\r
+ //\r
+ Status = CommandReturnedStatus;\r
+ } else if (CommandReturnedStatus != SHELL_SUCCESS && IsScriptOnlyCommand(FirstParameter)) {\r
+ //\r
+ // Always abort when a script only command fails for any reason\r
+ //\r
+ Status = EFI_ABORTED;\r
+ } else if (ShellCommandGetCurrentScriptFile() != NULL && CommandReturnedStatus == SHELL_ABORTED) {\r
+ //\r
+ // Abort when in a script and a command aborted\r
+ //\r
+ Status = EFI_ABORTED;\r
+ }\r
+ }\r
+ }\r
+\r
+ //\r
+ // This is guaranteed to be called after UpdateArgcArgv no matter what else happened.\r
+ // This is safe even if the update API failed. In this case, it may be a no-op.\r
+ //\r
+ RestoreArgcArgv(ParamProtocol, &Argv, &Argc);\r
+\r
+ //\r
+ // If a script is running and the command is not a script only command, then\r
+ // change return value to success so the script won't halt (unless aborted).\r
+ //\r
+ // Script only commands have to be able halt the script since the script will\r
+ // not operate if they are failing.\r
+ //\r
+ if ( ShellCommandGetCurrentScriptFile() != NULL\r
+ && !IsScriptOnlyCommand(FirstParameter)\r
+ && Status != EFI_ABORTED\r
+ ) {\r
+ Status = EFI_SUCCESS;\r
+ }\r
+\r
+ FreePool (NewCmdLine);\r
+ return (Status);\r
+}\r
+\r
+/**\r
+ Function to run the command or file.\r
+\r
+ @param[in] Type the type of operation being run.\r
+ @param[in] CmdLine the command line to run.\r
+ @param[in] FirstParameter the first parameter on the command line\r
+ @param[in] ParamProtocol the shell parameters protocol pointer\r
+ @param[out] CommandStatus the status from the command line.\r
+\r
+ @retval EFI_SUCCESS The command was completed.\r
+ @retval EFI_ABORTED The command's operation was aborted.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RunCommandOrFile(\r
+ IN SHELL_OPERATION_TYPES Type,\r
+ IN CONST CHAR16 *CmdLine,\r
+ IN CHAR16 *FirstParameter,\r
+ IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol,\r
+ OUT EFI_STATUS *CommandStatus\r
+)\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_STATUS StartStatus;\r
+ CHAR16 *CommandWithPath;\r
+ EFI_DEVICE_PATH_PROTOCOL *DevPath;\r
+ SHELL_STATUS CalleeExitStatus;\r
+\r
+ Status = EFI_SUCCESS;\r
+ CommandWithPath = NULL;\r
+ DevPath = NULL;\r
+ CalleeExitStatus = SHELL_INVALID_PARAMETER;\r
+\r
+ switch (Type) {\r
+ case Internal_Command:\r
+ Status = RunInternalCommand(CmdLine, FirstParameter, ParamProtocol, CommandStatus);\r
+ break;\r
+ case Script_File_Name:\r
+ case Efi_Application:\r
+ //\r
+ // Process a fully qualified path\r
+ //\r
+ if (StrStr(FirstParameter, L":") != NULL) {\r
+ ASSERT (CommandWithPath == NULL);\r
+ if (ShellIsFile(FirstParameter) == EFI_SUCCESS) {\r
+ CommandWithPath = StrnCatGrow(&CommandWithPath, NULL, FirstParameter, 0);\r
+ }\r
+ }\r
+\r
+ //\r
+ // Process a relative path and also check in the path environment variable\r
+ //\r
+ if (CommandWithPath == NULL) {\r
+ CommandWithPath = ShellFindFilePathEx(FirstParameter, mExecutableExtensions);\r
+ }\r
+\r
+ //\r
+ // This should be impossible now.\r
+ //\r
+ ASSERT(CommandWithPath != NULL);\r
+\r
+ //\r
+ // Make sure that path is not just a directory (or not found)\r
+ //\r
+ if (!EFI_ERROR(ShellIsDirectory(CommandWithPath))) {\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r
+ SetLastError(SHELL_NOT_FOUND);\r
+ }\r
+ switch (Type) {\r
+ case Script_File_Name:\r
+ Status = RunScriptFile (CommandWithPath, NULL, CmdLine, ParamProtocol);\r
+ break;\r
+ case Efi_Application:\r
+ //\r
+ // Get the device path of the application image\r
+ //\r
+ DevPath = ShellInfoObject.NewEfiShellProtocol->GetDevicePathFromFilePath(CommandWithPath);\r
+ if (DevPath == NULL){\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ break;\r
+ }\r
+\r
+ //\r
+ // Execute the device path\r
+ //\r
+ Status = InternalShellExecuteDevicePath(\r
+ &gImageHandle,\r
+ DevPath,\r
+ CmdLine,\r
+ NULL,\r
+ &StartStatus\r
+ );\r
+\r
+ SHELL_FREE_NON_NULL(DevPath);\r
+\r
+ if(EFI_ERROR (Status)) {\r
+ CalleeExitStatus = (SHELL_STATUS) (Status & (~MAX_BIT));\r
+ } else {\r
+ CalleeExitStatus = (SHELL_STATUS) StartStatus;\r
+ }\r
+\r
+ if (CommandStatus != NULL) {\r
+ *CommandStatus = CalleeExitStatus;\r
+ }\r
+\r
+ //\r
+ // Update last error status.\r
+ //\r
+ // Status is an EFI_STATUS. Clear top bit to convert to SHELL_STATUS\r
+ SetLastError(CalleeExitStatus);\r
+ break;\r
+ default:\r
+ //\r
+ // Do nothing.\r
+ //\r
+ break;\r
+ }\r
+ break;\r
+ default:\r
+ //\r
+ // Do nothing.\r
+ //\r
+ break;\r
+ }\r
+\r
+ SHELL_FREE_NON_NULL(CommandWithPath);\r