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