Roll back check in r15180 which caused the shell always returns EFI_ABORTED no matter...
[mirror_edk2.git] / ShellPkg / Application / Shell / Shell.h
CommitLineData
a405b86d 1/** @file\r
2 function definitions for internal to shell functions.\r
3\r
838b31a6 4 (C) Copyright 2014, Hewlett-Packard Development Company, L.P.\r
e958b946 5 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
a405b86d 6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#ifndef _SHELL_INTERNAL_HEADER_\r
17#define _SHELL_INTERNAL_HEADER_\r
18\r
19#include <Uefi.h>\r
20#include <ShellBase.h>\r
21\r
22#include <Guid/ShellVariableGuid.h>\r
0406a571 23#include <Guid/ShellAliasGuid.h>\r
a405b86d 24\r
25#include <Protocol/LoadedImage.h>\r
26#include <Protocol/SimpleTextOut.h>\r
27#include <Protocol/EfiShell.h>\r
28#include <Protocol/EfiShellInterface.h>\r
29#include <Protocol/EfiShellEnvironment2.h>\r
30#include <Protocol/EfiShellParameters.h>\r
31#include <Protocol/BlockIo.h>\r
32\r
33#include <Library/BaseLib.h>\r
34#include <Library/UefiApplicationEntryPoint.h>\r
35#include <Library/UefiLib.h>\r
36#include <Library/DebugLib.h>\r
37#include <Library/MemoryAllocationLib.h>\r
38#include <Library/ShellCommandLib.h>\r
39#include <Library/UefiRuntimeServicesTableLib.h>\r
40#include <Library/UefiBootServicesTableLib.h>\r
41#include <Library/DevicePathLib.h>\r
42#include <Library/BaseMemoryLib.h>\r
43#include <Library/PcdLib.h>\r
44#include <Library/ShellLib.h>\r
45#include <Library/SortLib.h>\r
46#include <Library/HiiLib.h>\r
47#include <Library/PrintLib.h>\r
48#include <Library/HandleParsingLib.h>\r
ab94587a 49#include <Library/PathLib.h>\r
0406a571 50#include <Library/FileHandleLib.h>\r
a405b86d 51\r
52#include "ShellParametersProtocol.h"\r
53#include "ShellProtocol.h"\r
54#include "ShellEnvVar.h"\r
55#include "ConsoleLogger.h"\r
56#include "ShellManParser.h"\r
a49f6a2f 57#include "ConsoleWrappers.h"\r
0406a571 58#include "FileHandleWrappers.h"\r
a405b86d 59\r
60typedef struct {\r
61 LIST_ENTRY Link; ///< Standard linked list handler.\r
62 SHELL_FILE_HANDLE *SplitStdOut; ///< ConsoleOut for use in the split.\r
63 SHELL_FILE_HANDLE *SplitStdIn; ///< ConsoleIn for use in the split.\r
64} SPLIT_LIST;\r
65\r
66typedef struct {\r
67 UINT32 Startup:1; ///< Was "-startup" found on command line.\r
68 UINT32 NoStartup:1; ///< Was "-nostartup" found on command line.\r
69 UINT32 NoConsoleOut:1; ///< Was "-noconsoleout" found on command line.\r
70 UINT32 NoConsoleIn:1; ///< Was "-noconsolein" found on command line.\r
71 UINT32 NoInterrupt:1; ///< Was "-nointerrupt" found on command line.\r
72 UINT32 NoMap:1; ///< Was "-nomap" found on command line.\r
73 UINT32 NoVersion:1; ///< Was "-noversion" found on command line.\r
74 UINT32 Delay:1; ///< Was "-delay[:n] found on command line\r
ca79c798 75 UINT32 Exit:1; ///< Was "-_exit" found on command line\r
76 UINT32 Reserved:7; ///< Extra bits\r
a405b86d 77} SHELL_BITS;\r
78\r
79typedef union {\r
80 SHELL_BITS Bits;\r
81 UINT16 AllBits;\r
82} SHELL_BIT_UNION;\r
83\r
84typedef struct {\r
85 SHELL_BIT_UNION BitUnion;\r
86 UINTN Delay; ///< Seconds of delay default:5.\r
87 CHAR16 *FileName; ///< Filename to run upon successful initialization.\r
88 CHAR16 *FileOptions; ///< Options to pass to FileName.\r
89} SHELL_INIT_SETTINGS;\r
90\r
91typedef struct {\r
92 BUFFER_LIST CommandHistory;\r
93 UINTN VisibleRowNumber;\r
94 UINTN OriginalVisibleRowNumber;\r
95 BOOLEAN InsertMode; ///< Is the current typing mode insert (FALSE = overwrite).\r
96} SHELL_VIEWING_SETTINGS;\r
97\r
98typedef struct {\r
99 EFI_SHELL_PARAMETERS_PROTOCOL *NewShellParametersProtocol;\r
838b31a6 100 EFI_SHELL_PROTOCOL *NewEfiShellProtocol;\r
a405b86d 101 BOOLEAN PageBreakEnabled;\r
102 BOOLEAN RootShellInstance;\r
103 SHELL_INIT_SETTINGS ShellInitSettings;\r
104 BUFFER_LIST BufferToFreeList; ///< List of buffers that were returned to the user to free.\r
105 SHELL_VIEWING_SETTINGS ViewingSettings;\r
106 EFI_HII_HANDLE HiiHandle; ///< Handle from HiiLib.\r
107 UINTN LogScreenCount; ///< How many screens of log information to save.\r
108 EFI_EVENT UserBreakTimer; ///< Timer event for polling for CTRL-C.\r
109 EFI_DEVICE_PATH_PROTOCOL *ImageDevPath; ///< DevicePath for ourselves.\r
110 EFI_DEVICE_PATH_PROTOCOL *FileDevPath; ///< DevicePath for ourselves.\r
111 CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo; ///< Pointer for ConsoleInformation.\r
112 EFI_SHELL_PARAMETERS_PROTOCOL *OldShellParameters; ///< old shell parameters to reinstall upon exiting.\r
113 SHELL_PROTOCOL_HANDLE_LIST OldShellList; ///< List of other instances to reinstall when closing.\r
114 SPLIT_LIST SplitList; ///< List of Splits in FILO stack.\r
402e4a9d
RN
115 VOID *CtrlCNotifyHandle1; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
116 VOID *CtrlCNotifyHandle2; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
117 VOID *CtrlCNotifyHandle3; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
118 VOID *CtrlCNotifyHandle4; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
119 VOID *CtrlSNotifyHandle1; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
120 VOID *CtrlSNotifyHandle2; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
121 VOID *CtrlSNotifyHandle3; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
122 VOID *CtrlSNotifyHandle4; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
a49f6a2f 123 BOOLEAN HaltOutput; ///< TRUE to start a CTRL-S halt.\r
a405b86d 124} SHELL_INFO;\r
125\r
126extern SHELL_INFO ShellInfoObject;\r
127\r
6ba2921d 128typedef enum {\r
51429264
SQ
129 Internal_Command,\r
130 Script_File_Name,\r
131 Efi_Application,\r
132 File_Sys_Change,\r
133 Unknown_Invalid\r
6ba2921d
JC
134} SHELL_OPERATION_TYPES;\r
135\r
6bd64463
JC
136/**\r
137 Converts the command line to it's post-processed form. this replaces variables and alias' per UEFI Shell spec.\r
138\r
139 @param[in,out] CmdLine pointer to the command line to update\r
140\r
141 @retval EFI_SUCCESS The operation was successful\r
142 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
143 @return some other error occured\r
144**/\r
145EFI_STATUS\r
146EFIAPI\r
147ProcessCommandLineToFinal(\r
148 IN OUT CHAR16 **CmdLine\r
149 );\r
150\r
151/**\r
51429264 152 Function to update the shell variable "lasterror".\r
6bd64463
JC
153\r
154 @param[in] ErrorCode the error code to put into lasterror\r
155**/\r
156EFI_STATUS\r
157EFIAPI\r
158SetLastError(\r
159 IN CONST SHELL_STATUS ErrorCode\r
160 );\r
161\r
a405b86d 162/**\r
163 Sets all the alias' that were registered with the ShellCommandLib library.\r
164\r
165 @retval EFI_SUCCESS all init commands were run sucessfully.\r
166**/\r
167EFI_STATUS\r
168EFIAPI\r
169SetBuiltInAlias(\r
170 VOID\r
171 );\r
172\r
173/**\r
174 This function will populate the 2 device path protocol parameters based on the\r
175 global gImageHandle. the DevPath will point to the device path for the handle that has\r
176 loaded image protocol installed on it. the FilePath will point to the device path\r
177 for the file that was loaded.\r
178\r
4ff7e37b
ED
179 @param[in, out] DevPath on a sucessful return the device path to the loaded image\r
180 @param[in, out] FilePath on a sucessful return the device path to the file\r
a405b86d 181\r
182 @retval EFI_SUCCESS the 2 device paths were sucessfully returned.\r
183 @return other a error from gBS->HandleProtocol\r
184\r
185 @sa HandleProtocol\r
186**/\r
187EFI_STATUS\r
188EFIAPI\r
189GetDevicePathsForImageAndFile (\r
190 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevPath,\r
191 IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath\r
192 );\r
193\r
194/**\r
195 Process all Uefi Shell 2.0 command line options.\r
196\r
197 see Uefi Shell 2.0 section 3.2 for full details.\r
198\r
199 the command line should resemble the following:\r
200\r
201 shell.efi [ShellOpt-options] [options] [file-name [file-name-options]]\r
202\r
203 ShellOpt options Options which control the initialization behavior of the shell.\r
204 These options are read from the EFI global variable "ShellOpt"\r
205 and are processed before options or file-name.\r
206\r
207 options Options which control the initialization behavior of the shell.\r
208\r
209 file-name The name of a UEFI shell application or script to be executed\r
210 after initialization is complete. By default, if file-name is\r
211 specified, then -nostartup is implied. Scripts are not supported\r
212 by level 0.\r
213\r
214 file-nameoptions The command-line options that are passed to file-name when it\r
215 is invoked.\r
216\r
217 This will initialize the ShellInitSettings global variable.\r
218\r
219 @retval EFI_SUCCESS the variable is initialized.\r
220**/\r
221EFI_STATUS\r
222EFIAPI\r
223ProcessCommandLine(\r
224 VOID\r
225 );\r
226\r
227/**\r
228 Handles all interaction with the default startup script.\r
229\r
230 this will check that the correct command line parameters were passed, handle the delay, and then start running the script.\r
231\r
232 @param[in] ImagePath The path to the image for shell. The first place to look for the startup script.\r
233 @param[in] FilePath The path to the file for shell. The second place to look for the startup script.\r
234\r
235 @retval EFI_SUCCESS The variable is initialized.\r
236**/\r
237EFI_STATUS\r
238EFIAPI\r
239DoStartupScript(\r
a308e058
RN
240 IN EFI_DEVICE_PATH_PROTOCOL *ImagePath,\r
241 IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r
a405b86d 242 );\r
243\r
244/**\r
245 Function to perform the shell prompt looping. It will do a single prompt,\r
246 dispatch the result, and then return. It is expected that the caller will\r
247 call this function in a loop many times.\r
248\r
249 @retval EFI_SUCCESS\r
250 @retval RETURN_ABORTED\r
251**/\r
252EFI_STATUS\r
253EFIAPI\r
254DoShellPrompt (\r
255 VOID\r
256 );\r
257\r
258/**\r
259 Add a buffer to the Buffer To Free List for safely returning buffers to other\r
260 places without risking letting them modify internal shell information.\r
261\r
262 @param Buffer Something to pass to FreePool when the shell is exiting.\r
263**/\r
264VOID*\r
265EFIAPI\r
266AddBufferToFreeList(\r
267 VOID *Buffer\r
268 );\r
269\r
270/**\r
271 Add a buffer to the Command History List.\r
272\r
273 @param Buffer[in] The line buffer to add.\r
274**/\r
275VOID\r
276EFIAPI\r
277AddLineToCommandHistory(\r
278 IN CONST CHAR16 *Buffer\r
279 );\r
280\r
281/**\r
282 Function will process and run a command line.\r
283\r
284 This will determine if the command line represents an internal shell command or dispatch an external application.\r
285\r
a308e058 286 @param[in] CmdLine the command line to parse\r
a405b86d 287\r
288 @retval EFI_SUCCESS the command was completed\r
289 @retval EFI_ABORTED the command's operation was aborted\r
290**/\r
291EFI_STATUS\r
292EFIAPI\r
293RunCommand(\r
a308e058 294 IN CONST CHAR16 *CmdLine\r
a405b86d 295 );\r
296\r
297/**\r
298 Function determins if the CommandName COULD be a valid command. It does not determine whether\r
299 this is a valid command. It only checks for invalid characters.\r
300\r
301 @param[in] CommandName The name to check\r
302\r
303 @retval TRUE CommandName could be a command name\r
304 @retval FALSE CommandName could not be a valid command name\r
305**/\r
306BOOLEAN\r
307EFIAPI\r
308IsValidCommandName(\r
309 IN CONST CHAR16 *CommandName\r
310 );\r
311\r
312/**\r
313 Function to process a NSH script file via SHELL_FILE_HANDLE.\r
314\r
315 @param[in] Handle The handle to the already opened file.\r
316 @param[in] Name The name of the script file.\r
317\r
318 @retval EFI_SUCCESS the script completed sucessfully\r
319**/\r
320EFI_STATUS\r
321EFIAPI\r
322RunScriptFileHandle (\r
a308e058
RN
323 IN SHELL_FILE_HANDLE Handle,\r
324 IN CONST CHAR16 *Name\r
a405b86d 325 );\r
326\r
327/**\r
328 Function to process a NSH script file.\r
329\r
330 @param[in] ScriptPath Pointer to the script file name (including file system path).\r
e958b946
JC
331 @param[in] Handle the handle of the script file already opened.\r
332 @param[in] CmdLine the command line to run.\r
333 @param[in] ParamProtocol the shell parameters protocol pointer\r
a405b86d 334\r
335 @retval EFI_SUCCESS the script completed sucessfully\r
336**/\r
337EFI_STATUS\r
338EFIAPI\r
339RunScriptFile (\r
a308e058
RN
340 IN CONST CHAR16 *ScriptPath,\r
341 IN SHELL_FILE_HANDLE Handle OPTIONAL,\r
342 IN CONST CHAR16 *CmdLine,\r
343 IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol\r
a405b86d 344 );\r
345\r
a308e058 346\r
a405b86d 347#endif //_SHELL_INTERNAL_HEADER_\r
348\r