]>
Commit | Line | Data |
---|---|---|
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 |
60 | typedef 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 | |
66 | typedef 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 | |
79 | typedef union {\r | |
80 | SHELL_BITS Bits;\r | |
81 | UINT16 AllBits;\r | |
82 | } SHELL_BIT_UNION;\r | |
83 | \r | |
84 | typedef 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 | |
91 | typedef 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 | |
98 | typedef 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 | |
126 | extern SHELL_INFO ShellInfoObject;\r | |
127 | \r | |
6ba2921d | 128 | typedef 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 | |
145 | EFI_STATUS\r | |
146 | EFIAPI\r | |
147 | ProcessCommandLineToFinal(\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 | |
156 | EFI_STATUS\r | |
157 | EFIAPI\r | |
158 | SetLastError(\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 | |
167 | EFI_STATUS\r | |
168 | EFIAPI\r | |
169 | SetBuiltInAlias(\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 | |
187 | EFI_STATUS\r | |
188 | EFIAPI\r | |
189 | GetDevicePathsForImageAndFile (\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 | |
221 | EFI_STATUS\r | |
222 | EFIAPI\r | |
223 | ProcessCommandLine(\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 | |
5223c121 BJ |
234 | @param[out] ExitStatus The exit code of the script. Ignored if NULL.\r |
235 | Invalid when this function returns an error.\r | |
a405b86d | 236 | \r |
237 | @retval EFI_SUCCESS The variable is initialized.\r | |
238 | **/\r | |
239 | EFI_STATUS\r | |
240 | EFIAPI\r | |
241 | DoStartupScript(\r | |
5223c121 BJ |
242 | IN EFI_DEVICE_PATH_PROTOCOL *ImagePath,\r |
243 | IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r | |
244 | OUT SHELL_STATUS *ExitStatus\r | |
a405b86d | 245 | );\r |
246 | \r | |
247 | /**\r | |
248 | Function to perform the shell prompt looping. It will do a single prompt,\r | |
249 | dispatch the result, and then return. It is expected that the caller will\r | |
250 | call this function in a loop many times.\r | |
251 | \r | |
252 | @retval EFI_SUCCESS\r | |
253 | @retval RETURN_ABORTED\r | |
254 | **/\r | |
255 | EFI_STATUS\r | |
256 | EFIAPI\r | |
257 | DoShellPrompt (\r | |
258 | VOID\r | |
259 | );\r | |
260 | \r | |
261 | /**\r | |
262 | Add a buffer to the Buffer To Free List for safely returning buffers to other\r | |
263 | places without risking letting them modify internal shell information.\r | |
264 | \r | |
265 | @param Buffer Something to pass to FreePool when the shell is exiting.\r | |
266 | **/\r | |
267 | VOID*\r | |
268 | EFIAPI\r | |
269 | AddBufferToFreeList(\r | |
270 | VOID *Buffer\r | |
271 | );\r | |
272 | \r | |
273 | /**\r | |
274 | Add a buffer to the Command History List.\r | |
275 | \r | |
276 | @param Buffer[in] The line buffer to add.\r | |
277 | **/\r | |
278 | VOID\r | |
279 | EFIAPI\r | |
280 | AddLineToCommandHistory(\r | |
281 | IN CONST CHAR16 *Buffer\r | |
282 | );\r | |
283 | \r | |
284 | /**\r | |
285 | Function will process and run a command line.\r | |
286 | \r | |
287 | This will determine if the command line represents an internal shell command or dispatch an external application.\r | |
288 | \r | |
5223c121 BJ |
289 | @param[in] CmdLine the command line to parse\r |
290 | @param[out] ExitStatus The exit status of the command. Ignored if NULL.\r | |
a405b86d | 291 | \r |
292 | @retval EFI_SUCCESS the command was completed\r | |
293 | @retval EFI_ABORTED the command's operation was aborted\r | |
294 | **/\r | |
295 | EFI_STATUS\r | |
296 | EFIAPI\r | |
297 | RunCommand(\r | |
5223c121 BJ |
298 | IN CONST CHAR16 *CmdLine,\r |
299 | OUT SHELL_STATUS *ExitStatus\r | |
a405b86d | 300 | );\r |
301 | \r | |
302 | /**\r | |
303 | Function determins if the CommandName COULD be a valid command. It does not determine whether\r | |
304 | this is a valid command. It only checks for invalid characters.\r | |
305 | \r | |
306 | @param[in] CommandName The name to check\r | |
307 | \r | |
308 | @retval TRUE CommandName could be a command name\r | |
309 | @retval FALSE CommandName could not be a valid command name\r | |
310 | **/\r | |
311 | BOOLEAN\r | |
312 | EFIAPI\r | |
313 | IsValidCommandName(\r | |
314 | IN CONST CHAR16 *CommandName\r | |
315 | );\r | |
316 | \r | |
317 | /**\r | |
318 | Function to process a NSH script file via SHELL_FILE_HANDLE.\r | |
319 | \r | |
320 | @param[in] Handle The handle to the already opened file.\r | |
321 | @param[in] Name The name of the script file.\r | |
322 | \r | |
5223c121 BJ |
323 | @param[out] ExitStatus The exit code of the script. Ignored if NULL.\r |
324 | Invalid when this function returns an error.\r | |
325 | \r | |
a405b86d | 326 | @retval EFI_SUCCESS the script completed sucessfully\r |
327 | **/\r | |
328 | EFI_STATUS\r | |
329 | EFIAPI\r | |
330 | RunScriptFileHandle (\r | |
5223c121 BJ |
331 | IN SHELL_FILE_HANDLE Handle,\r |
332 | IN CONST CHAR16 *Name,\r | |
333 | OUT SHELL_STATUS *ExitStatus\r | |
a405b86d | 334 | );\r |
335 | \r | |
336 | /**\r | |
337 | Function to process a NSH script file.\r | |
338 | \r | |
339 | @param[in] ScriptPath Pointer to the script file name (including file system path).\r | |
e958b946 JC |
340 | @param[in] Handle the handle of the script file already opened.\r |
341 | @param[in] CmdLine the command line to run.\r | |
342 | @param[in] ParamProtocol the shell parameters protocol pointer\r | |
a405b86d | 343 | \r |
5223c121 BJ |
344 | @param[out] ExitStatus The exit code of the script. Ignored if NULL.\r |
345 | Invalid when this function returns an error.\r | |
346 | \r | |
a405b86d | 347 | @retval EFI_SUCCESS the script completed sucessfully\r |
348 | **/\r | |
349 | EFI_STATUS\r | |
350 | EFIAPI\r | |
351 | RunScriptFile (\r | |
5223c121 BJ |
352 | IN CONST CHAR16 *ScriptPath,\r |
353 | IN SHELL_FILE_HANDLE Handle OPTIONAL,\r | |
354 | IN CONST CHAR16 *CmdLine,\r | |
355 | IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol,\r | |
356 | OUT SHELL_STATUS *ExitStatus\r | |
a405b86d | 357 | );\r |
358 | \r | |
a405b86d | 359 | #endif //_SHELL_INTERNAL_HEADER_\r |
360 | \r |