]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Application/Shell/Shell.h
Revert "ShellPkg: Add Shell[Get|Set]RawCmdLine to ShellCommandLib"
[mirror_edk2.git] / ShellPkg / Application / Shell / Shell.h
CommitLineData
a405b86d 1/** @file\r
2 function definitions for internal to shell functions.\r
3\r
c011b6c9 4 (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>\r
8d4eec6d 5 Copyright (c) 2009 - 2016, 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
8d4eec6d 32#include <Protocol/HiiPackageList.h>\r
a405b86d 33\r
34#include <Library/BaseLib.h>\r
35#include <Library/UefiApplicationEntryPoint.h>\r
36#include <Library/UefiLib.h>\r
37#include <Library/DebugLib.h>\r
38#include <Library/MemoryAllocationLib.h>\r
39#include <Library/ShellCommandLib.h>\r
40#include <Library/UefiRuntimeServicesTableLib.h>\r
41#include <Library/UefiBootServicesTableLib.h>\r
42#include <Library/DevicePathLib.h>\r
43#include <Library/BaseMemoryLib.h>\r
44#include <Library/PcdLib.h>\r
45#include <Library/ShellLib.h>\r
46#include <Library/SortLib.h>\r
47#include <Library/HiiLib.h>\r
48#include <Library/PrintLib.h>\r
49#include <Library/HandleParsingLib.h>\r
0406a571 50#include <Library/FileHandleLib.h>\r
8d4eec6d 51#include <Library/UefiHiiServicesLib.h>\r
a405b86d 52\r
53#include "ShellParametersProtocol.h"\r
54#include "ShellProtocol.h"\r
55#include "ShellEnvVar.h"\r
56#include "ConsoleLogger.h"\r
57#include "ShellManParser.h"\r
a49f6a2f 58#include "ConsoleWrappers.h"\r
0406a571 59#include "FileHandleWrappers.h"\r
a405b86d 60\r
dcbdb8bf
QS
61extern CONST CHAR16 mNoNestingEnvVarName[];\r
62extern CONST CHAR16 mNoNestingTrue[];\r
63extern CONST CHAR16 mNoNestingFalse[];\r
64\r
a405b86d 65typedef struct {\r
66 LIST_ENTRY Link; ///< Standard linked list handler.\r
67 SHELL_FILE_HANDLE *SplitStdOut; ///< ConsoleOut for use in the split.\r
68 SHELL_FILE_HANDLE *SplitStdIn; ///< ConsoleIn for use in the split.\r
69} SPLIT_LIST;\r
70\r
71typedef struct {\r
72 UINT32 Startup:1; ///< Was "-startup" found on command line.\r
73 UINT32 NoStartup:1; ///< Was "-nostartup" found on command line.\r
74 UINT32 NoConsoleOut:1; ///< Was "-noconsoleout" found on command line.\r
75 UINT32 NoConsoleIn:1; ///< Was "-noconsolein" found on command line.\r
76 UINT32 NoInterrupt:1; ///< Was "-nointerrupt" found on command line.\r
77 UINT32 NoMap:1; ///< Was "-nomap" found on command line.\r
78 UINT32 NoVersion:1; ///< Was "-noversion" found on command line.\r
79 UINT32 Delay:1; ///< Was "-delay[:n] found on command line\r
dcbdb8bf
QS
80 UINT32 Exit:1; ///< Was "-_exit" found on command line\r
81 UINT32 NoNest:1; ///< Was "-nonest" found on command line\r
ca79c798 82 UINT32 Reserved:7; ///< Extra bits\r
a405b86d 83} SHELL_BITS;\r
84\r
85typedef union {\r
86 SHELL_BITS Bits;\r
87 UINT16 AllBits;\r
88} SHELL_BIT_UNION;\r
89\r
90typedef struct {\r
91 SHELL_BIT_UNION BitUnion;\r
92 UINTN Delay; ///< Seconds of delay default:5.\r
93 CHAR16 *FileName; ///< Filename to run upon successful initialization.\r
94 CHAR16 *FileOptions; ///< Options to pass to FileName.\r
95} SHELL_INIT_SETTINGS;\r
96\r
97typedef struct {\r
98 BUFFER_LIST CommandHistory;\r
99 UINTN VisibleRowNumber;\r
100 UINTN OriginalVisibleRowNumber;\r
101 BOOLEAN InsertMode; ///< Is the current typing mode insert (FALSE = overwrite).\r
102} SHELL_VIEWING_SETTINGS;\r
103\r
104typedef struct {\r
105 EFI_SHELL_PARAMETERS_PROTOCOL *NewShellParametersProtocol;\r
838b31a6 106 EFI_SHELL_PROTOCOL *NewEfiShellProtocol;\r
a405b86d 107 BOOLEAN PageBreakEnabled;\r
108 BOOLEAN RootShellInstance;\r
109 SHELL_INIT_SETTINGS ShellInitSettings;\r
110 BUFFER_LIST BufferToFreeList; ///< List of buffers that were returned to the user to free.\r
111 SHELL_VIEWING_SETTINGS ViewingSettings;\r
112 EFI_HII_HANDLE HiiHandle; ///< Handle from HiiLib.\r
113 UINTN LogScreenCount; ///< How many screens of log information to save.\r
114 EFI_EVENT UserBreakTimer; ///< Timer event for polling for CTRL-C.\r
115 EFI_DEVICE_PATH_PROTOCOL *ImageDevPath; ///< DevicePath for ourselves.\r
116 EFI_DEVICE_PATH_PROTOCOL *FileDevPath; ///< DevicePath for ourselves.\r
117 CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo; ///< Pointer for ConsoleInformation.\r
118 EFI_SHELL_PARAMETERS_PROTOCOL *OldShellParameters; ///< old shell parameters to reinstall upon exiting.\r
119 SHELL_PROTOCOL_HANDLE_LIST OldShellList; ///< List of other instances to reinstall when closing.\r
120 SPLIT_LIST SplitList; ///< List of Splits in FILO stack.\r
402e4a9d
RN
121 VOID *CtrlCNotifyHandle1; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
122 VOID *CtrlCNotifyHandle2; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
123 VOID *CtrlCNotifyHandle3; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
124 VOID *CtrlCNotifyHandle4; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
125 VOID *CtrlSNotifyHandle1; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
126 VOID *CtrlSNotifyHandle2; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
127 VOID *CtrlSNotifyHandle3; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
128 VOID *CtrlSNotifyHandle4; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
a49f6a2f 129 BOOLEAN HaltOutput; ///< TRUE to start a CTRL-S halt.\r
a405b86d 130} SHELL_INFO;\r
131\r
8d4eec6d
QS
132#pragma pack(1)\r
133///\r
134/// HII specific Vendor Device Path definition.\r
135///\r
136typedef struct {\r
137 VENDOR_DEVICE_PATH VendorDevicePath;\r
138 EFI_DEVICE_PATH_PROTOCOL End;\r
139} SHELL_MAN_HII_VENDOR_DEVICE_PATH;\r
140#pragma pack()\r
141\r
a405b86d 142extern SHELL_INFO ShellInfoObject;\r
143\r
6bd64463
JC
144/**\r
145 Converts the command line to it's post-processed form. this replaces variables and alias' per UEFI Shell spec.\r
146\r
147 @param[in,out] CmdLine pointer to the command line to update\r
148\r
149 @retval EFI_SUCCESS The operation was successful\r
150 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
d08a5464 151 @return some other error occurred\r
6bd64463
JC
152**/\r
153EFI_STATUS\r
154EFIAPI\r
155ProcessCommandLineToFinal(\r
156 IN OUT CHAR16 **CmdLine\r
157 );\r
158\r
159/**\r
51429264 160 Function to update the shell variable "lasterror".\r
6bd64463
JC
161\r
162 @param[in] ErrorCode the error code to put into lasterror\r
163**/\r
164EFI_STATUS\r
165EFIAPI\r
166SetLastError(\r
167 IN CONST SHELL_STATUS ErrorCode\r
168 );\r
169\r
a405b86d 170/**\r
171 Sets all the alias' that were registered with the ShellCommandLib library.\r
172\r
d08a5464 173 @retval EFI_SUCCESS all init commands were run successfully.\r
a405b86d 174**/\r
175EFI_STATUS\r
176EFIAPI\r
177SetBuiltInAlias(\r
178 VOID\r
179 );\r
180\r
181/**\r
182 This function will populate the 2 device path protocol parameters based on the\r
183 global gImageHandle. the DevPath will point to the device path for the handle that has\r
184 loaded image protocol installed on it. the FilePath will point to the device path\r
185 for the file that was loaded.\r
186\r
d08a5464
JP
187 @param[in, out] DevPath on a successful return the device path to the loaded image\r
188 @param[in, out] FilePath on a successful return the device path to the file\r
a405b86d 189\r
d08a5464 190 @retval EFI_SUCCESS the 2 device paths were successfully returned.\r
a405b86d 191 @return other a error from gBS->HandleProtocol\r
192\r
193 @sa HandleProtocol\r
194**/\r
195EFI_STATUS\r
196EFIAPI\r
197GetDevicePathsForImageAndFile (\r
198 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevPath,\r
199 IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath\r
200 );\r
201\r
202/**\r
203 Process all Uefi Shell 2.0 command line options.\r
204\r
205 see Uefi Shell 2.0 section 3.2 for full details.\r
206\r
207 the command line should resemble the following:\r
208\r
209 shell.efi [ShellOpt-options] [options] [file-name [file-name-options]]\r
210\r
211 ShellOpt options Options which control the initialization behavior of the shell.\r
212 These options are read from the EFI global variable "ShellOpt"\r
213 and are processed before options or file-name.\r
214\r
215 options Options which control the initialization behavior of the shell.\r
216\r
217 file-name The name of a UEFI shell application or script to be executed\r
218 after initialization is complete. By default, if file-name is\r
219 specified, then -nostartup is implied. Scripts are not supported\r
220 by level 0.\r
221\r
222 file-nameoptions The command-line options that are passed to file-name when it\r
223 is invoked.\r
224\r
225 This will initialize the ShellInitSettings global variable.\r
226\r
227 @retval EFI_SUCCESS the variable is initialized.\r
228**/\r
229EFI_STATUS\r
230EFIAPI\r
231ProcessCommandLine(\r
232 VOID\r
233 );\r
234\r
235/**\r
236 Handles all interaction with the default startup script.\r
237\r
238 this will check that the correct command line parameters were passed, handle the delay, and then start running the script.\r
239\r
240 @param[in] ImagePath The path to the image for shell. The first place to look for the startup script.\r
241 @param[in] FilePath The path to the file for shell. The second place to look for the startup script.\r
242\r
243 @retval EFI_SUCCESS The variable is initialized.\r
244**/\r
245EFI_STATUS\r
246EFIAPI\r
247DoStartupScript(\r
a308e058
RN
248 IN EFI_DEVICE_PATH_PROTOCOL *ImagePath,\r
249 IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r
a405b86d 250 );\r
251\r
252/**\r
253 Function to perform the shell prompt looping. It will do a single prompt,\r
254 dispatch the result, and then return. It is expected that the caller will\r
255 call this function in a loop many times.\r
256\r
257 @retval EFI_SUCCESS\r
258 @retval RETURN_ABORTED\r
259**/\r
260EFI_STATUS\r
261EFIAPI\r
262DoShellPrompt (\r
263 VOID\r
264 );\r
265\r
266/**\r
267 Add a buffer to the Buffer To Free List for safely returning buffers to other\r
268 places without risking letting them modify internal shell information.\r
269\r
270 @param Buffer Something to pass to FreePool when the shell is exiting.\r
271**/\r
272VOID*\r
273EFIAPI\r
274AddBufferToFreeList(\r
275 VOID *Buffer\r
276 );\r
277\r
278/**\r
279 Add a buffer to the Command History List.\r
280\r
281 @param Buffer[in] The line buffer to add.\r
282**/\r
283VOID\r
284EFIAPI\r
285AddLineToCommandHistory(\r
286 IN CONST CHAR16 *Buffer\r
287 );\r
288\r
289/**\r
290 Function will process and run a command line.\r
291\r
292 This will determine if the command line represents an internal shell command or dispatch an external application.\r
293\r
a308e058 294 @param[in] CmdLine the command line to parse\r
a405b86d 295\r
296 @retval EFI_SUCCESS the command was completed\r
297 @retval EFI_ABORTED the command's operation was aborted\r
298**/\r
299EFI_STATUS\r
300EFIAPI\r
301RunCommand(\r
a308e058 302 IN CONST CHAR16 *CmdLine\r
a405b86d 303 );\r
304\r
490ce43d
QS
305/**\r
306 Function will process and run a command line.\r
307\r
308 This will determine if the command line represents an internal shell \r
309 command or dispatch an external application.\r
310\r
311 @param[in] CmdLine The command line to parse.\r
312 @param[out] CommandStatus The status from the command line.\r
313\r
314 @retval EFI_SUCCESS The command was completed.\r
315 @retval EFI_ABORTED The command's operation was aborted.\r
316**/\r
317EFI_STATUS\r
318EFIAPI\r
319RunShellCommand(\r
320 IN CONST CHAR16 *CmdLine,\r
321 OUT EFI_STATUS *CommandStatus\r
322 );\r
323\r
a405b86d 324/**\r
d08a5464 325 Function determines if the CommandName COULD be a valid command. It does not determine whether\r
a405b86d 326 this is a valid command. It only checks for invalid characters.\r
327\r
328 @param[in] CommandName The name to check\r
329\r
330 @retval TRUE CommandName could be a command name\r
331 @retval FALSE CommandName could not be a valid command name\r
332**/\r
333BOOLEAN\r
334EFIAPI\r
335IsValidCommandName(\r
336 IN CONST CHAR16 *CommandName\r
337 );\r
338\r
339/**\r
340 Function to process a NSH script file via SHELL_FILE_HANDLE.\r
341\r
342 @param[in] Handle The handle to the already opened file.\r
343 @param[in] Name The name of the script file.\r
344\r
d08a5464 345 @retval EFI_SUCCESS the script completed successfully\r
a405b86d 346**/\r
347EFI_STATUS\r
348EFIAPI\r
349RunScriptFileHandle (\r
a308e058
RN
350 IN SHELL_FILE_HANDLE Handle,\r
351 IN CONST CHAR16 *Name\r
a405b86d 352 );\r
353\r
354/**\r
355 Function to process a NSH script file.\r
356\r
357 @param[in] ScriptPath Pointer to the script file name (including file system path).\r
e958b946
JC
358 @param[in] Handle the handle of the script file already opened.\r
359 @param[in] CmdLine the command line to run.\r
360 @param[in] ParamProtocol the shell parameters protocol pointer\r
a405b86d 361\r
d08a5464 362 @retval EFI_SUCCESS the script completed successfully\r
a405b86d 363**/\r
364EFI_STATUS\r
365EFIAPI\r
366RunScriptFile (\r
a308e058
RN
367 IN CONST CHAR16 *ScriptPath,\r
368 IN SHELL_FILE_HANDLE Handle OPTIONAL,\r
369 IN CONST CHAR16 *CmdLine,\r
370 IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol\r
a405b86d 371 );\r
372\r
389824ff
QS
373/**\r
374 Cleans off leading and trailing spaces and tabs.\r
375\r
376 @param[in] String pointer to the string to trim them off.\r
377**/\r
378EFI_STATUS\r
379EFIAPI\r
380TrimSpaces(\r
381 IN CHAR16 **String\r
382 );\r
383\r
14810d6b
QS
384/**\r
385 \r
386 Create a new buffer list and stores the old one to OldBufferList \r
387\r
388 @param OldBufferList The temporary list head used to store the nodes in BufferToFreeList.\r
389**/\r
390VOID\r
391SaveBufferList (\r
392 OUT LIST_ENTRY *OldBufferList\r
393 );\r
394\r
395/**\r
396 Restore previous nodes into BufferToFreeList .\r
397\r
398 @param OldBufferList The temporary list head used to store the nodes in BufferToFreeList.\r
399**/\r
400VOID\r
401RestoreBufferList (\r
402 IN OUT LIST_ENTRY *OldBufferList\r
403 );\r
404\r
405\r
406\r
a405b86d 407#endif //_SHELL_INTERNAL_HEADER_\r
408\r