]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Application/Shell/Shell.h
ShellPkg: Clean up header file usage.
[mirror_edk2.git] / ShellPkg / Application / Shell / Shell.h
1 /** @file
2 function definitions for internal to shell functions.
3
4 Copyright (c) 2009 - 2012, 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 Reserved:8; ///< Extra bits
75 } SHELL_BITS;
76
77 typedef union {
78 SHELL_BITS Bits;
79 UINT16 AllBits;
80 } SHELL_BIT_UNION;
81
82 typedef struct {
83 SHELL_BIT_UNION BitUnion;
84 UINTN Delay; ///< Seconds of delay default:5.
85 CHAR16 *FileName; ///< Filename to run upon successful initialization.
86 CHAR16 *FileOptions; ///< Options to pass to FileName.
87 } SHELL_INIT_SETTINGS;
88
89 typedef struct {
90 BUFFER_LIST CommandHistory;
91 UINTN VisibleRowNumber;
92 UINTN OriginalVisibleRowNumber;
93 BOOLEAN InsertMode; ///< Is the current typing mode insert (FALSE = overwrite).
94 } SHELL_VIEWING_SETTINGS;
95
96 typedef struct {
97 EFI_SHELL_PARAMETERS_PROTOCOL *NewShellParametersProtocol;
98 EFI_SHELL_PROTOCOL *NewEfiShellProtocol;
99 BOOLEAN PageBreakEnabled;
100 BOOLEAN RootShellInstance;
101 SHELL_INIT_SETTINGS ShellInitSettings;
102 BUFFER_LIST BufferToFreeList; ///< List of buffers that were returned to the user to free.
103 SHELL_VIEWING_SETTINGS ViewingSettings;
104 EFI_HII_HANDLE HiiHandle; ///< Handle from HiiLib.
105 UINTN LogScreenCount; ///< How many screens of log information to save.
106 EFI_EVENT UserBreakTimer; ///< Timer event for polling for CTRL-C.
107 EFI_DEVICE_PATH_PROTOCOL *ImageDevPath; ///< DevicePath for ourselves.
108 EFI_DEVICE_PATH_PROTOCOL *FileDevPath; ///< DevicePath for ourselves.
109 CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo; ///< Pointer for ConsoleInformation.
110 EFI_SHELL_PARAMETERS_PROTOCOL *OldShellParameters; ///< old shell parameters to reinstall upon exiting.
111 SHELL_PROTOCOL_HANDLE_LIST OldShellList; ///< List of other instances to reinstall when closing.
112 SPLIT_LIST SplitList; ///< List of Splits in FILO stack.
113 VOID *CtrlCNotifyHandle1; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
114 VOID *CtrlCNotifyHandle2; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
115 VOID *CtrlCNotifyHandle3; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
116 VOID *CtrlCNotifyHandle4; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
117 VOID *CtrlSNotifyHandle1; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
118 VOID *CtrlSNotifyHandle2; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
119 VOID *CtrlSNotifyHandle3; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
120 VOID *CtrlSNotifyHandle4; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
121 BOOLEAN HaltOutput; ///< TRUE to start a CTRL-S halt.
122 } SHELL_INFO;
123
124 extern SHELL_INFO ShellInfoObject;
125
126 /**
127 Sets all the alias' that were registered with the ShellCommandLib library.
128
129 @retval EFI_SUCCESS all init commands were run sucessfully.
130 **/
131 EFI_STATUS
132 EFIAPI
133 SetBuiltInAlias(
134 VOID
135 );
136
137 /**
138 This function will populate the 2 device path protocol parameters based on the
139 global gImageHandle. the DevPath will point to the device path for the handle that has
140 loaded image protocol installed on it. the FilePath will point to the device path
141 for the file that was loaded.
142
143 @param[in, out] DevPath on a sucessful return the device path to the loaded image
144 @param[in, out] FilePath on a sucessful return the device path to the file
145
146 @retval EFI_SUCCESS the 2 device paths were sucessfully returned.
147 @return other a error from gBS->HandleProtocol
148
149 @sa HandleProtocol
150 **/
151 EFI_STATUS
152 EFIAPI
153 GetDevicePathsForImageAndFile (
154 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevPath,
155 IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath
156 );
157
158 /**
159 Process all Uefi Shell 2.0 command line options.
160
161 see Uefi Shell 2.0 section 3.2 for full details.
162
163 the command line should resemble the following:
164
165 shell.efi [ShellOpt-options] [options] [file-name [file-name-options]]
166
167 ShellOpt options Options which control the initialization behavior of the shell.
168 These options are read from the EFI global variable "ShellOpt"
169 and are processed before options or file-name.
170
171 options Options which control the initialization behavior of the shell.
172
173 file-name The name of a UEFI shell application or script to be executed
174 after initialization is complete. By default, if file-name is
175 specified, then -nostartup is implied. Scripts are not supported
176 by level 0.
177
178 file-nameoptions The command-line options that are passed to file-name when it
179 is invoked.
180
181 This will initialize the ShellInitSettings global variable.
182
183 @retval EFI_SUCCESS the variable is initialized.
184 **/
185 EFI_STATUS
186 EFIAPI
187 ProcessCommandLine(
188 VOID
189 );
190
191 /**
192 Handles all interaction with the default startup script.
193
194 this will check that the correct command line parameters were passed, handle the delay, and then start running the script.
195
196 @param[in] ImagePath The path to the image for shell. The first place to look for the startup script.
197 @param[in] FilePath The path to the file for shell. The second place to look for the startup script.
198
199 @retval EFI_SUCCESS The variable is initialized.
200 **/
201 EFI_STATUS
202 EFIAPI
203 DoStartupScript(
204 IN EFI_DEVICE_PATH_PROTOCOL *ImagePath,
205 IN EFI_DEVICE_PATH_PROTOCOL *FilePath
206 );
207
208 /**
209 Function to perform the shell prompt looping. It will do a single prompt,
210 dispatch the result, and then return. It is expected that the caller will
211 call this function in a loop many times.
212
213 @retval EFI_SUCCESS
214 @retval RETURN_ABORTED
215 **/
216 EFI_STATUS
217 EFIAPI
218 DoShellPrompt (
219 VOID
220 );
221
222 /**
223 Add a buffer to the Buffer To Free List for safely returning buffers to other
224 places without risking letting them modify internal shell information.
225
226 @param Buffer Something to pass to FreePool when the shell is exiting.
227 **/
228 VOID*
229 EFIAPI
230 AddBufferToFreeList(
231 VOID *Buffer
232 );
233
234 /**
235 Add a buffer to the Command History List.
236
237 @param Buffer[in] The line buffer to add.
238 **/
239 VOID
240 EFIAPI
241 AddLineToCommandHistory(
242 IN CONST CHAR16 *Buffer
243 );
244
245 /**
246 Function will process and run a command line.
247
248 This will determine if the command line represents an internal shell command or dispatch an external application.
249
250 @param[in] CmdLine the command line to parse
251
252 @retval EFI_SUCCESS the command was completed
253 @retval EFI_ABORTED the command's operation was aborted
254 **/
255 EFI_STATUS
256 EFIAPI
257 RunCommand(
258 IN CONST CHAR16 *CmdLine
259 );
260
261 /**
262 Function determins if the CommandName COULD be a valid command. It does not determine whether
263 this is a valid command. It only checks for invalid characters.
264
265 @param[in] CommandName The name to check
266
267 @retval TRUE CommandName could be a command name
268 @retval FALSE CommandName could not be a valid command name
269 **/
270 BOOLEAN
271 EFIAPI
272 IsValidCommandName(
273 IN CONST CHAR16 *CommandName
274 );
275
276 /**
277 Function to process a NSH script file via SHELL_FILE_HANDLE.
278
279 @param[in] Handle The handle to the already opened file.
280 @param[in] Name The name of the script file.
281
282 @retval EFI_SUCCESS the script completed sucessfully
283 **/
284 EFI_STATUS
285 EFIAPI
286 RunScriptFileHandle (
287 IN SHELL_FILE_HANDLE Handle,
288 IN CONST CHAR16 *Name
289 );
290
291 /**
292 Function to process a NSH script file.
293
294 @param[in] ScriptPath Pointer to the script file name (including file system path).
295
296 @retval EFI_SUCCESS the script completed sucessfully
297 **/
298 EFI_STATUS
299 EFIAPI
300 RunScriptFile (
301 IN CONST CHAR16 *ScriptPath
302 );
303
304
305 #endif //_SHELL_INTERNAL_HEADER_
306