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