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