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