]>
Commit | Line | Data |
---|---|---|
a405b86d | 1 | /** @file\r |
2 | Provides interface to shell internal functions for shell commands.\r | |
3 | \r | |
4 | This library is for use ONLY by shell commands linked into the shell application.\r | |
268d3445 | 5 | This library will not function if it is used for UEFI Shell 2.0 Applications.\r |
a405b86d | 6 | \r |
ba0014b9 | 7 | Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r |
b464d7ed RN |
8 | (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r |
9 | (C) Copyright 2013-2014 Hewlett-Packard Development Company, L.P.<BR>\r | |
56ba3746 | 10 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
a405b86d | 11 | \r |
12 | **/\r | |
13 | \r | |
14 | #ifndef _SHELL_COMMAND_LIB_\r | |
15 | #define _SHELL_COMMAND_LIB_\r | |
16 | \r | |
17 | #include <Uefi.h>\r | |
a405b86d | 18 | \r |
28165f24 RN |
19 | #include <Protocol/Shell.h>\r |
20 | #include <Protocol/ShellParameters.h>\r | |
a405b86d | 21 | #include <Protocol/UnicodeCollation.h>\r |
a405b86d | 22 | #include <Protocol/SimpleFileSystem.h>\r |
23 | \r | |
24 | #include <Library/UefiBootServicesTableLib.h>\r | |
25 | \r | |
26 | //\r | |
27 | // The extern global protocol poionters.\r | |
28 | //\r | |
47d20b54 MK |
29 | extern EFI_UNICODE_COLLATION_PROTOCOL *gUnicodeCollation;\r |
30 | extern CONST CHAR16 *SupportLevel[];\r | |
a405b86d | 31 | \r |
32 | //\r | |
33 | // The map list objects.\r | |
34 | //\r | |
35 | typedef struct {\r | |
47d20b54 MK |
36 | LIST_ENTRY Link;\r |
37 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
38 | CHAR16 *MapName;\r | |
39 | CHAR16 *CurrentDirectoryPath;\r | |
40 | UINT64 Flags;\r | |
a405b86d | 41 | } SHELL_MAP_LIST;\r |
42 | /// List of Mappings - DeviceName and Drive Letter(ism).\r | |
47d20b54 | 43 | extern SHELL_MAP_LIST gShellMapList;\r |
a405b86d | 44 | /// Pointer to node of current directory in the mMapList.\r |
47d20b54 | 45 | extern SHELL_MAP_LIST *gShellCurMapping;\r |
a405b86d | 46 | \r |
47 | /**\r | |
48 | Returns the help MAN fileName for a given shell command.\r | |
49 | \r | |
50 | @retval !NULL The unicode string of the MAN filename.\r | |
51 | @retval NULL An error ocurred.\r | |
52 | \r | |
53 | **/\r | |
54 | typedef\r | |
55 | CONST CHAR16 *\r | |
56 | (EFIAPI *SHELL_GET_MAN_FILENAME)(\r | |
57 | VOID\r | |
58 | );\r | |
59 | \r | |
60 | /**\r | |
61 | Runs a shell command on a given command line.\r | |
62 | \r | |
63 | The specific operation of a given shell command is specified in the UEFI Shell\r | |
64 | Specification 2.0, or in the source of the given command.\r | |
65 | \r | |
66 | Upon completion of the command run the shell protocol and environment variables\r | |
67 | may have been updated due to the operation.\r | |
68 | \r | |
69 | @param[in] ImageHandle The ImageHandle to the app, or NULL if\r | |
70 | the command built into shell.\r | |
71 | @param[in] SystemTable The pointer to the system table.\r | |
72 | \r | |
73 | @retval RETURN_SUCCESS The shell command was sucessful.\r | |
74 | @retval RETURN_UNSUPPORTED The command is not supported.\r | |
75 | **/\r | |
76 | typedef\r | |
77 | SHELL_STATUS\r | |
78 | (EFIAPI *SHELL_RUN_COMMAND)(\r | |
79 | IN EFI_HANDLE ImageHandle,\r | |
80 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
81 | );\r | |
82 | \r | |
83 | /**\r | |
84 | Registers the handlers of type SHELL_RUN_COMMAND and\r | |
85 | SHELL_GET_MAN_FILENAME for each shell command.\r | |
86 | \r | |
87 | If the ShellSupportLevel is greater than the value of\r | |
88 | PcdShellSupportLevel, then return RETURN_UNSUPPORTED.\r | |
89 | \r | |
90 | Registers the the handlers specified by GetHelpInfoHandler and CommandHandler\r | |
91 | with the command specified by CommandString. If the command named by\r | |
92 | CommandString has already been registered, then return\r | |
93 | RETURN_ALREADY_STARTED.\r | |
94 | \r | |
95 | If there are not enough resources available to register the handlers, then\r | |
96 | RETURN_OUT_OF_RESOURCES is returned.\r | |
97 | \r | |
98 | If CommandString is NULL, then ASSERT().\r | |
99 | If GetHelpInfoHandler is NULL, then ASSERT().\r | |
100 | If CommandHandler is NULL, then ASSERT().\r | |
101 | If ProfileName is NULL, then ASSERT().\r | |
102 | \r | |
103 | @param[in] CommandString The pointer to the command name. This is the\r | |
104 | name to look for on the command line in\r | |
105 | the shell.\r | |
106 | @param[in] CommandHandler The pointer to a function that runs the\r | |
107 | specified command.\r | |
108 | @param[in] GetManFileName The pointer to a function that provides man\r | |
109 | filename.\r | |
110 | @param[in] ShellMinSupportLevel The minimum Shell Support Level which has this\r | |
111 | function.\r | |
112 | @param[in] ProfileName The profile name to require for support of this\r | |
113 | function.\r | |
114 | @param[in] CanAffectLE Indicates whether this command's return value\r | |
115 | can change the LASTERROR environment variable.\r | |
116 | @param[in] HiiHandle The handle of this command's HII entry.\r | |
117 | @param[in] ManFormatHelp The HII locator for the help text.\r | |
118 | \r | |
119 | @retval RETURN_SUCCESS The handlers were registered.\r | |
120 | @retval RETURN_OUT_OF_RESOURCES There are not enough resources available to\r | |
121 | register the shell command.\r | |
122 | @retval RETURN_UNSUPPORTED The ShellMinSupportLevel was higher than the\r | |
123 | currently allowed support level.\r | |
124 | @retval RETURN_ALREADY_STARTED The CommandString represents a command that\r | |
125 | is already registered. Only one handler set for\r | |
126 | a given command is allowed.\r | |
127 | @sa SHELL_GET_MAN_FILENAME\r | |
128 | @sa SHELL_RUN_COMMAND\r | |
129 | **/\r | |
130 | RETURN_STATUS\r | |
131 | EFIAPI\r | |
132 | ShellCommandRegisterCommandName (\r | |
47d20b54 MK |
133 | IN CONST CHAR16 *CommandString,\r |
134 | IN SHELL_RUN_COMMAND CommandHandler,\r | |
135 | IN SHELL_GET_MAN_FILENAME GetManFileName,\r | |
136 | IN UINT32 ShellMinSupportLevel,\r | |
137 | IN CONST CHAR16 *ProfileName,\r | |
138 | IN CONST BOOLEAN CanAffectLE,\r | |
139 | IN CONST EFI_HII_HANDLE HiiHandle,\r | |
140 | IN CONST EFI_STRING_ID ManFormatHelp\r | |
a405b86d | 141 | );\r |
142 | \r | |
143 | /**\r | |
144 | Checks if a command string has been registered for CommandString, and if so, it runs\r | |
145 | the previously registered handler for that command with the command line.\r | |
146 | \r | |
147 | If CommandString is NULL, then ASSERT().\r | |
148 | \r | |
149 | If Sections is specified, then each section name listed will be compared in a case sensitive\r | |
150 | manner to the section names described in Appendix B UEFI Shell 2.0 Specification. If the section exists,\r | |
151 | it is appended to the returned help text. If the section does not exist, no\r | |
152 | information is returned. If Sections is NULL, then all help text information\r | |
153 | available is returned.\r | |
154 | \r | |
4ff7e37b ED |
155 | @param[in] CommandString The pointer to the command name. This is the name\r |
156 | found on the command line in the shell.\r | |
157 | @param[in, out] RetVal The pointer to the return value from the command handler.\r | |
a405b86d | 158 | \r |
4ff7e37b ED |
159 | @param[in, out] CanAffectLE Indicates whether this command's return value\r |
160 | needs to be placed into LASTERROR environment variable.\r | |
a405b86d | 161 | \r |
162 | @retval RETURN_SUCCESS The handler was run.\r | |
163 | @retval RETURN_NOT_FOUND The CommandString did not match a registered\r | |
164 | command name.\r | |
165 | @sa SHELL_RUN_COMMAND\r | |
166 | **/\r | |
167 | RETURN_STATUS\r | |
168 | EFIAPI\r | |
169 | ShellCommandRunCommandHandler (\r | |
47d20b54 MK |
170 | IN CONST CHAR16 *CommandString,\r |
171 | IN OUT SHELL_STATUS *RetVal,\r | |
172 | IN OUT BOOLEAN *CanAffectLE OPTIONAL\r | |
a405b86d | 173 | );\r |
174 | \r | |
175 | /**\r | |
176 | Checks if a command string has been registered for CommandString, and if so, it\r | |
177 | returns the MAN filename specified for that command.\r | |
178 | \r | |
179 | If CommandString is NULL, then ASSERT().\r | |
180 | \r | |
181 | @param[in] CommandString The pointer to the command name. This is the name\r | |
182 | found on the command line in the shell.\r | |
183 | \r | |
184 | @retval NULL The CommandString was not a registered command.\r | |
185 | @retval other The name of the MAN file.\r | |
186 | @sa SHELL_GET_MAN_FILENAME\r | |
187 | **/\r | |
47d20b54 | 188 | CONST CHAR16 *\r |
a405b86d | 189 | EFIAPI\r |
190 | ShellCommandGetManFileNameHandler (\r | |
47d20b54 | 191 | IN CONST CHAR16 *CommandString\r |
a405b86d | 192 | );\r |
193 | \r | |
a405b86d | 194 | typedef struct {\r |
47d20b54 MK |
195 | LIST_ENTRY Link;\r |
196 | CHAR16 *CommandString;\r | |
a405b86d | 197 | } COMMAND_LIST;\r |
198 | \r | |
199 | /**\r | |
200 | Get the list of all available shell internal commands. This is a linked list,\r | |
201 | via the LIST_ENTRY structure. Enumerate through it using the BaseLib linked\r | |
202 | list functions. Do not modify the values.\r | |
203 | \r | |
4bbdc0e1 | 204 | @param[in] Sort TRUE to alphabetically sort the values first. FALSE otherwise.\r |
205 | \r | |
a405b86d | 206 | @return A linked list of all available shell commands.\r |
207 | **/\r | |
47d20b54 | 208 | CONST COMMAND_LIST *\r |
a405b86d | 209 | EFIAPI\r |
210 | ShellCommandGetCommandList (\r | |
47d20b54 | 211 | IN CONST BOOLEAN Sort\r |
a405b86d | 212 | );\r |
213 | \r | |
214 | typedef struct {\r | |
47d20b54 MK |
215 | LIST_ENTRY Link;\r |
216 | CHAR16 *CommandString;\r | |
217 | CHAR16 *Alias;\r | |
a405b86d | 218 | } ALIAS_LIST;\r |
219 | \r | |
220 | /**\r | |
221 | Registers aliases to be set as part of the initialization of the shell application.\r | |
222 | \r | |
223 | If Command is NULL, then ASSERT().\r | |
224 | If Alias is NULL, then ASSERT().\r | |
225 | \r | |
226 | @param[in] Command The pointer to the Command.\r | |
227 | @param[in] Alias The pointer to Alias.\r | |
228 | \r | |
229 | @retval RETURN_SUCCESS The handlers were registered.\r | |
230 | @retval RETURN_OUT_OF_RESOURCES There are not enough resources available to\r | |
231 | register the shell command.\r | |
232 | **/\r | |
233 | RETURN_STATUS\r | |
234 | EFIAPI\r | |
235 | ShellCommandRegisterAlias (\r | |
47d20b54 MK |
236 | IN CONST CHAR16 *Command,\r |
237 | IN CONST CHAR16 *Alias\r | |
a405b86d | 238 | );\r |
239 | \r | |
240 | /**\r | |
241 | Get the list of all shell alias commands. This is a linked list,\r | |
242 | via LIST_ENTRY structure. Enumerate through it using the BaseLib linked\r | |
243 | list functions. Do not modify the values.\r | |
244 | \r | |
245 | @return A linked list of all requested shell aliases.\r | |
246 | **/\r | |
47d20b54 | 247 | CONST ALIAS_LIST *\r |
a405b86d | 248 | EFIAPI\r |
249 | ShellCommandGetInitAliasList (\r | |
250 | VOID\r | |
251 | );\r | |
252 | \r | |
253 | /**\r | |
254 | Determine if a given alias is on the list of built in aliases.\r | |
255 | \r | |
256 | @param[in] Alias The alias to test for.\r | |
257 | \r | |
258 | @retval TRUE The alias is a built in alias.\r | |
259 | @retval FALSE The alias is not a built in alias.\r | |
260 | **/\r | |
261 | BOOLEAN\r | |
262 | EFIAPI\r | |
263 | ShellCommandIsOnAliasList (\r | |
47d20b54 | 264 | IN CONST CHAR16 *Alias\r |
a405b86d | 265 | );\r |
266 | \r | |
267 | /**\r | |
268 | Checks if a command is already on the list.\r | |
269 | \r | |
270 | @param[in] CommandString The command string to check for on the list.\r | |
271 | \r | |
272 | @retval TRUE CommandString represents a registered command.\r | |
273 | @retval FALSE CommandString does not represent a registered command.\r | |
274 | **/\r | |
275 | BOOLEAN\r | |
276 | EFIAPI\r | |
277 | ShellCommandIsCommandOnList (\r | |
47d20b54 | 278 | IN CONST CHAR16 *CommandString\r |
a405b86d | 279 | );\r |
280 | \r | |
281 | /**\r | |
282 | Get the help text for a command.\r | |
283 | \r | |
284 | @param[in] CommandString The command name.\r | |
285 | \r | |
286 | @retval NULL No help text was found.\r | |
287 | @return The string of the help text. The caller required to free.\r | |
288 | **/\r | |
47d20b54 | 289 | CHAR16 *\r |
a405b86d | 290 | EFIAPI\r |
291 | ShellCommandGetCommandHelp (\r | |
47d20b54 | 292 | IN CONST CHAR16 *CommandString\r |
a405b86d | 293 | );\r |
294 | \r | |
295 | /**\r | |
296 | Function to make sure that the above pointers are valid.\r | |
297 | **/\r | |
298 | EFI_STATUS\r | |
299 | EFIAPI\r | |
300 | CommandInit (\r | |
301 | VOID\r | |
302 | );\r | |
303 | \r | |
304 | /**\r | |
305 | Function to determine current state of ECHO. Echo determines if lines from scripts\r | |
306 | and ECHO commands are enabled.\r | |
307 | \r | |
308 | @retval TRUE Echo is currently enabled.\r | |
309 | @retval FALSE Echo is currently disabled.\r | |
310 | **/\r | |
311 | BOOLEAN\r | |
312 | EFIAPI\r | |
313 | ShellCommandGetEchoState (\r | |
314 | VOID\r | |
315 | );\r | |
316 | \r | |
317 | /**\r | |
318 | Function to set current state of ECHO. Echo determines if lines from scripts\r | |
319 | and ECHO commands are enabled.\r | |
320 | \r | |
321 | @param[in] State TRUE to enable Echo, FALSE otherwise.\r | |
322 | **/\r | |
323 | VOID\r | |
324 | EFIAPI\r | |
325 | ShellCommandSetEchoState (\r | |
47d20b54 | 326 | IN BOOLEAN State\r |
a405b86d | 327 | );\r |
328 | \r | |
a405b86d | 329 | /**\r |
330 | Indicate that the current shell or script should exit.\r | |
331 | \r | |
332 | @param[in] ScriptOnly TRUE if exiting a script; FALSE otherwise.\r | |
b6b22b13 | 333 | @param[in] ErrorCode The 64 bit error code to return.\r |
a405b86d | 334 | **/\r |
335 | VOID\r | |
336 | EFIAPI\r | |
337 | ShellCommandRegisterExit (\r | |
47d20b54 MK |
338 | IN BOOLEAN ScriptOnly,\r |
339 | IN CONST UINT64 ErrorCode\r | |
b6b22b13 | 340 | );\r |
341 | \r | |
342 | /**\r | |
343 | Retrieve the Exit code.\r | |
344 | \r | |
345 | @return the value passed into RegisterExit.\r | |
346 | **/\r | |
347 | UINT64\r | |
348 | EFIAPI\r | |
349 | ShellCommandGetExitCode (\r | |
350 | VOID\r | |
a405b86d | 351 | );\r |
352 | \r | |
353 | /**\r | |
354 | Retrieve the Exit indicator.\r | |
355 | \r | |
356 | @retval TRUE Exit was indicated.\r | |
357 | @retval FALSE Exit was not indicated.\r | |
358 | **/\r | |
359 | BOOLEAN\r | |
360 | EFIAPI\r | |
361 | ShellCommandGetExit (\r | |
362 | VOID\r | |
363 | );\r | |
364 | \r | |
365 | /**\r | |
366 | Retrieve the Exit script indicator.\r | |
367 | \r | |
368 | If ShellCommandGetExit returns FALSE, then the return from this is undefined.\r | |
369 | \r | |
370 | @retval TRUE ScriptOnly was indicated.\r | |
371 | @retval FALSE ScriptOnly was not indicated.\r | |
372 | **/\r | |
373 | BOOLEAN\r | |
374 | EFIAPI\r | |
375 | ShellCommandGetScriptExit (\r | |
376 | VOID\r | |
377 | );\r | |
378 | \r | |
379 | typedef struct {\r | |
47d20b54 MK |
380 | LIST_ENTRY Link; ///< List enumerator items.\r |
381 | UINTN Line; ///< What line of the script file this was on.\r | |
382 | CHAR16 *Cl; ///< The original command line.\r | |
383 | VOID *Data; ///< The data structure format dependant upon Command. (not always used)\r | |
384 | BOOLEAN Reset; ///< Reset the command (it must be treated like a initial run (but it may have data already))\r | |
a405b86d | 385 | } SCRIPT_COMMAND_LIST;\r |
386 | \r | |
387 | typedef struct {\r | |
47d20b54 MK |
388 | CHAR16 *ScriptName; ///< The filename of this script.\r |
389 | CHAR16 **Argv; ///< The parmameters to the script file.\r | |
390 | UINTN Argc; ///< The count of parameters.\r | |
391 | LIST_ENTRY CommandList; ///< The script converted to a list of commands (SCRIPT_COMMAND_LIST objects).\r | |
392 | SCRIPT_COMMAND_LIST *CurrentCommand; ///< The command currently being operated. If !=NULL must be a member of CommandList.\r | |
393 | LIST_ENTRY SubstList; ///< A list of current script loop alias' (ALIAS_LIST objects) (Used for the for %-based replacement).\r | |
a405b86d | 394 | } SCRIPT_FILE;\r |
395 | \r | |
396 | /**\r | |
397 | Function to return a pointer to the currently running script file object.\r | |
398 | \r | |
399 | @retval NULL A script file is not currently running.\r | |
400 | @return A pointer to the current script file object.\r | |
401 | **/\r | |
47d20b54 | 402 | SCRIPT_FILE *\r |
a405b86d | 403 | EFIAPI\r |
404 | ShellCommandGetCurrentScriptFile (\r | |
405 | VOID\r | |
406 | );\r | |
407 | \r | |
408 | /**\r | |
409 | Function to set a new script as the currently running one.\r | |
410 | \r | |
411 | This function will correctly stack and unstack nested scripts.\r | |
412 | \r | |
413 | @param[in] Script The pointer to new script information structure. If NULL,\r | |
414 | it removes and de-allocates the topmost Script structure.\r | |
415 | \r | |
416 | @return A pointer to the current running script file after this\r | |
417 | change. It is NULL if removing the final script.\r | |
418 | **/\r | |
47d20b54 | 419 | SCRIPT_FILE *\r |
a405b86d | 420 | EFIAPI\r |
421 | ShellCommandSetNewScript (\r | |
47d20b54 | 422 | IN SCRIPT_FILE *Script OPTIONAL\r |
a405b86d | 423 | );\r |
424 | \r | |
0ab85bef | 425 | /**\r |
426 | Function to cleanup all memory from a SCRIPT_FILE structure.\r | |
427 | \r | |
428 | @param[in] Script The pointer to the structure to cleanup.\r | |
429 | **/\r | |
430 | VOID\r | |
431 | EFIAPI\r | |
432 | DeleteScriptFileStruct (\r | |
47d20b54 | 433 | IN SCRIPT_FILE *Script\r |
0ab85bef | 434 | );\r |
435 | \r | |
a405b86d | 436 | /**\r |
437 | Function to get the current Profile string.\r | |
438 | \r | |
439 | This is used to retrieve what profiles were installed.\r | |
440 | \r | |
441 | @retval NULL There are no installed profiles.\r | |
442 | @return A semicolon-delimited list of profiles.\r | |
443 | **/\r | |
444 | CONST CHAR16 *\r | |
445 | EFIAPI\r | |
446 | ShellCommandGetProfileList (\r | |
447 | VOID\r | |
448 | );\r | |
449 | \r | |
450 | typedef enum {\r | |
451 | MappingTypeFileSystem,\r | |
452 | MappingTypeBlockIo,\r | |
453 | MappingTypeMax\r | |
454 | } SHELL_MAPPING_TYPE;\r | |
455 | \r | |
456 | /**\r | |
457 | Function to generate the next default mapping name.\r | |
458 | \r | |
459 | If the return value is not NULL then it must be callee freed.\r | |
460 | \r | |
461 | @param Type What kind of mapping name to make.\r | |
462 | \r | |
463 | @retval NULL a memory allocation failed.\r | |
464 | @return a new map name string\r | |
465 | **/\r | |
47d20b54 | 466 | CHAR16 *\r |
a405b86d | 467 | EFIAPI\r |
47d20b54 MK |
468 | ShellCommandCreateNewMappingName (\r |
469 | IN CONST SHELL_MAPPING_TYPE Type\r | |
a405b86d | 470 | );\r |
471 | \r | |
472 | /**\r | |
473 | Function to initialize the table for creating consistent map names.\r | |
474 | \r | |
475 | @param[out] Table The pointer to pointer to pointer to DevicePathProtocol object.\r | |
476 | \r | |
477 | @retval EFI_SUCCESS The table was created successfully.\r | |
478 | **/\r | |
479 | EFI_STATUS\r | |
480 | EFIAPI\r | |
481 | ShellCommandConsistMappingInitialize (\r | |
47d20b54 | 482 | EFI_DEVICE_PATH_PROTOCOL ***Table\r |
a405b86d | 483 | );\r |
484 | \r | |
485 | /**\r | |
486 | Function to uninitialize the table for creating consistent map names.\r | |
487 | \r | |
488 | The parameter must have been received from ShellCommandConsistMappingInitialize.\r | |
489 | \r | |
490 | @param[out] Table The pointer to pointer to DevicePathProtocol object.\r | |
491 | \r | |
492 | @retval EFI_SUCCESS The table was deleted successfully.\r | |
493 | **/\r | |
494 | EFI_STATUS\r | |
495 | EFIAPI\r | |
496 | ShellCommandConsistMappingUnInitialize (\r | |
47d20b54 | 497 | EFI_DEVICE_PATH_PROTOCOL **Table\r |
a405b86d | 498 | );\r |
499 | \r | |
500 | /**\r | |
ba0014b9 | 501 | Create a consistent mapped name for the device specified by DevicePath\r |
a405b86d | 502 | based on the Table.\r |
503 | \r | |
ba0014b9 | 504 | This must be called after ShellCommandConsistMappingInitialize() and\r |
a405b86d | 505 | before ShellCommandConsistMappingUnInitialize() is called.\r |
506 | \r | |
4bbdc0e1 | 507 | @param[in] DevicePath The pointer to the dev path for the device.\r |
a405b86d | 508 | @param[in] Table The Table of mapping information.\r |
509 | \r | |
510 | @retval NULL A consistent mapped name could not be created.\r | |
511 | @return A pointer to a string allocated from pool with the device name.\r | |
512 | **/\r | |
47d20b54 | 513 | CHAR16 *\r |
a405b86d | 514 | EFIAPI\r |
515 | ShellCommandConsistMappingGenMappingName (\r | |
47d20b54 MK |
516 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r |
517 | IN EFI_DEVICE_PATH_PROTOCOL **Table\r | |
a405b86d | 518 | );\r |
519 | \r | |
520 | /**\r | |
521 | Function to search the list of mappings for the first matching node on the\r | |
522 | list based on the MapKey.\r | |
523 | \r | |
524 | @param[in] MapKey The pointer to the string key to search for in the map.\r | |
525 | \r | |
526 | @return the node on the list.\r | |
527 | **/\r | |
47d20b54 | 528 | SHELL_MAP_LIST *\r |
a405b86d | 529 | EFIAPI\r |
530 | ShellCommandFindMapItem (\r | |
47d20b54 | 531 | IN CONST CHAR16 *MapKey\r |
a405b86d | 532 | );\r |
533 | \r | |
534 | /**\r | |
535 | Function to add a map node to the list of map items and update the "path" environment variable (optionally).\r | |
536 | \r | |
537 | If Path is TRUE (during initialization only), the path environment variable will also be updated to include\r | |
538 | default paths on the new map name...\r | |
539 | \r | |
540 | Path should be FALSE when this function is called from the protocol SetMap function.\r | |
541 | \r | |
542 | @param[in] Name The human readable mapped name.\r | |
543 | @param[in] DevicePath The Device Path for this map.\r | |
544 | @param[in] Flags The Flags attribute for this map item.\r | |
545 | @param[in] Path TRUE to update path, FALSE to skip this step (should only be TRUE during initialization).\r | |
546 | \r | |
547 | @retval EFI_SUCCESS The addition was sucessful.\r | |
548 | @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r | |
549 | @retval EFI_INVALID_PARAMETER A parameter was invalid.\r | |
550 | **/\r | |
551 | EFI_STATUS\r | |
552 | EFIAPI\r | |
47d20b54 MK |
553 | ShellCommandAddMapItemAndUpdatePath (\r |
554 | IN CONST CHAR16 *Name,\r | |
555 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r | |
556 | IN CONST UINT64 Flags,\r | |
557 | IN CONST BOOLEAN Path\r | |
a405b86d | 558 | );\r |
559 | \r | |
560 | /**\r | |
561 | Creates the default map names for each device path in the system with\r | |
562 | a protocol depending on the Type.\r | |
563 | \r | |
564 | Also sets up the default path environment variable if Type is FileSystem.\r | |
565 | \r | |
566 | @retval EFI_SUCCESS All map names were created sucessfully.\r | |
567 | @retval EFI_NOT_FOUND No protocols were found in the system.\r | |
568 | @return Error returned from gBS->LocateHandle().\r | |
569 | \r | |
570 | @sa LocateHandle\r | |
571 | **/\r | |
572 | EFI_STATUS\r | |
573 | EFIAPI\r | |
47d20b54 | 574 | ShellCommandCreateInitialMappingsAndPaths (\r |
a405b86d | 575 | VOID\r |
576 | );\r | |
577 | \r | |
e71cb452 TS |
578 | /**\r |
579 | Add mappings for any devices without one. Do not change any existing maps.\r | |
580 | \r | |
581 | @retval EFI_SUCCESS The operation was successful.\r | |
582 | **/\r | |
583 | EFI_STATUS\r | |
584 | EFIAPI\r | |
585 | ShellCommandUpdateMapping (\r | |
586 | VOID\r | |
587 | );\r | |
588 | \r | |
a405b86d | 589 | /**\r |
590 | Converts a SHELL_FILE_HANDLE to an EFI_FILE_PROTOCOL*.\r | |
591 | \r | |
592 | @param[in] Handle The SHELL_FILE_HANDLE to convert.\r | |
593 | \r | |
594 | @return a EFI_FILE_PROTOCOL* representing the same file.\r | |
595 | **/\r | |
47d20b54 | 596 | EFI_FILE_PROTOCOL *\r |
a405b86d | 597 | EFIAPI\r |
47d20b54 MK |
598 | ConvertShellHandleToEfiFileProtocol (\r |
599 | IN CONST SHELL_FILE_HANDLE Handle\r | |
a405b86d | 600 | );\r |
601 | \r | |
602 | /**\r | |
603 | Remove a SHELL_FILE_HANDLE frmo the list of SHELL_FILE_HANDLES.\r | |
604 | \r | |
605 | @param[in] Handle The SHELL_FILE_HANDLE to remove.\r | |
606 | \r | |
607 | @retval TRUE The item was removed.\r | |
608 | @retval FALSE The item was not found.\r | |
609 | **/\r | |
610 | BOOLEAN\r | |
611 | EFIAPI\r | |
47d20b54 MK |
612 | ShellFileHandleRemove (\r |
613 | IN CONST SHELL_FILE_HANDLE Handle\r | |
a405b86d | 614 | );\r |
615 | \r | |
616 | /**\r | |
617 | Converts a EFI_FILE_PROTOCOL* to an SHELL_FILE_HANDLE.\r | |
618 | \r | |
619 | @param[in] Handle The pointer to EFI_FILE_PROTOCOL to convert.\r | |
620 | @param[in] Path The path to the file for verification.\r | |
621 | \r | |
622 | @return a SHELL_FILE_HANDLE representing the same file.\r | |
623 | **/\r | |
624 | SHELL_FILE_HANDLE\r | |
625 | EFIAPI\r | |
47d20b54 MK |
626 | ConvertEfiFileProtocolToShellHandle (\r |
627 | IN CONST EFI_FILE_PROTOCOL *Handle,\r | |
628 | IN CONST CHAR16 *Path\r | |
a405b86d | 629 | );\r |
630 | \r | |
631 | /**\r | |
632 | Find the path that was logged with the specified SHELL_FILE_HANDLE.\r | |
633 | \r | |
634 | @param[in] Handle The SHELL_FILE_HANDLE to query on.\r | |
635 | \r | |
636 | @return A pointer to the path for the file.\r | |
637 | **/\r | |
47d20b54 | 638 | CONST CHAR16 *\r |
a405b86d | 639 | EFIAPI\r |
47d20b54 MK |
640 | ShellFileHandleGetPath (\r |
641 | IN CONST SHELL_FILE_HANDLE Handle\r | |
a405b86d | 642 | );\r |
643 | \r | |
a405b86d | 644 | /**\r |
645 | Function to determine if a SHELL_FILE_HANDLE is at the end of the file.\r | |
646 | \r | |
647 | This will NOT work on directories.\r | |
648 | \r | |
649 | If Handle is NULL, then ASSERT.\r | |
650 | \r | |
651 | @param[in] Handle the file handle\r | |
652 | \r | |
653 | @retval TRUE the position is at the end of the file\r | |
654 | @retval FALSE the position is not at the end of the file\r | |
655 | **/\r | |
656 | BOOLEAN\r | |
657 | EFIAPI\r | |
47d20b54 MK |
658 | ShellFileHandleEof (\r |
659 | IN SHELL_FILE_HANDLE Handle\r | |
a405b86d | 660 | );\r |
661 | \r | |
a405b86d | 662 | typedef struct {\r |
663 | LIST_ENTRY Link;\r | |
664 | void *Buffer;\r | |
665 | } BUFFER_LIST;\r | |
666 | \r | |
667 | /**\r | |
668 | Frees any BUFFER_LIST defined type.\r | |
669 | \r | |
670 | @param[in] List The pointer to the list head.\r | |
671 | **/\r | |
672 | VOID\r | |
673 | EFIAPI\r | |
674 | FreeBufferList (\r | |
47d20b54 | 675 | IN BUFFER_LIST *List\r |
a405b86d | 676 | );\r |
677 | \r | |
3bd89603 LE |
678 | /**\r |
679 | Function printing hex output to the console.\r | |
680 | \r | |
681 | @param[in] Indent Number of spaces to indent.\r | |
682 | @param[in] Offset Offset to start with.\r | |
683 | @param[in] DataSize Length of data.\r | |
684 | @param[in] UserData Pointer to some data.\r | |
685 | **/\r | |
686 | VOID\r | |
667d7146 | 687 | EFIAPI\r |
3bd89603 | 688 | DumpHex (\r |
47d20b54 MK |
689 | IN UINTN Indent,\r |
690 | IN UINTN Offset,\r | |
691 | IN UINTN DataSize,\r | |
692 | IN VOID *UserData\r | |
3bd89603 LE |
693 | );\r |
694 | \r | |
b464d7ed RN |
695 | /**\r |
696 | Dump HEX data into buffer.\r | |
697 | \r | |
698 | @param[in] Buffer HEX data to be dumped in Buffer.\r | |
699 | @param[in] Indent How many spaces to indent the output.\r | |
700 | @param[in] Offset The offset of the printing.\r | |
701 | @param[in] DataSize The size in bytes of UserData.\r | |
702 | @param[in] UserData The data to print out.\r | |
703 | **/\r | |
47d20b54 | 704 | CHAR16 *\r |
667d7146 | 705 | EFIAPI\r |
b464d7ed RN |
706 | CatSDumpHex (\r |
707 | IN CHAR16 *Buffer,\r | |
708 | IN UINTN Indent,\r | |
709 | IN UINTN Offset,\r | |
710 | IN UINTN DataSize,\r | |
711 | IN VOID *UserData\r | |
712 | );\r | |
101c55ac LE |
713 | \r |
714 | //\r | |
715 | // Determines the ordering operation for ShellSortFileList().\r | |
716 | //\r | |
717 | typedef enum {\r | |
718 | //\r | |
719 | // Sort the EFI_SHELL_FILE_INFO objects by the FileName field, in increasing\r | |
720 | // order, using gUnicodeCollation->StriColl().\r | |
721 | //\r | |
722 | ShellSortFileListByFileName,\r | |
723 | //\r | |
724 | // Sort the EFI_SHELL_FILE_INFO objects by the FullName field, in increasing\r | |
725 | // order, using gUnicodeCollation->StriColl().\r | |
726 | //\r | |
727 | ShellSortFileListByFullName,\r | |
728 | ShellSortFileListMax\r | |
729 | } SHELL_SORT_FILE_LIST;\r | |
730 | \r | |
731 | /**\r | |
732 | Sort an EFI_SHELL_FILE_INFO list, optionally moving duplicates to a separate\r | |
733 | list.\r | |
734 | \r | |
735 | @param[in,out] FileList The list of EFI_SHELL_FILE_INFO objects to sort.\r | |
736 | \r | |
737 | If FileList is NULL on input, then FileList is\r | |
738 | considered an empty, hence already sorted, list.\r | |
739 | \r | |
740 | Otherwise, if (*FileList) is NULL on input, then\r | |
741 | EFI_INVALID_PARAMETER is returned.\r | |
742 | \r | |
743 | Otherwise, the caller is responsible for having\r | |
744 | initialized (*FileList)->Link with\r | |
745 | InitializeListHead(). No other fields in the\r | |
746 | (**FileList) head element are accessed by this\r | |
747 | function.\r | |
748 | \r | |
749 | On output, (*FileList) is sorted according to Order.\r | |
750 | If Duplicates is NULL on input, then duplicate\r | |
751 | elements are preserved, sorted stably, on\r | |
752 | (*FileList). If Duplicates is not NULL on input,\r | |
753 | then duplicates are moved (stably sorted) to the\r | |
754 | new, dynamically allocated (*Duplicates) list.\r | |
755 | \r | |
756 | @param[out] Duplicates If Duplicates is NULL on input, (*FileList) will be\r | |
757 | a monotonically ordered list on output, with\r | |
758 | duplicates stably sorted.\r | |
759 | \r | |
760 | If Duplicates is not NULL on input, (*FileList) will\r | |
761 | be a strictly monotonically oredered list on output,\r | |
762 | with duplicates separated (stably sorted) to\r | |
763 | (*Duplicates). All fields except Link will be\r | |
764 | zero-initialized in the (**Duplicates) head element.\r | |
765 | If no duplicates exist, then (*Duplicates) is set to\r | |
766 | NULL on output.\r | |
767 | \r | |
768 | @param[in] Order Determines the comparison operation between\r | |
769 | EFI_SHELL_FILE_INFO objects.\r | |
770 | \r | |
771 | @retval EFI_INVALID_PARAMETER (UINTN)Order is greater than or equal to\r | |
772 | (UINTN)ShellSortFileListMax. Neither the\r | |
773 | (*FileList) nor the (*Duplicates) list has\r | |
774 | been modified.\r | |
775 | \r | |
776 | @retval EFI_INVALID_PARAMETER (*FileList) was NULL on input. Neither the\r | |
777 | (*FileList) nor the (*Duplicates) list has\r | |
778 | been modified.\r | |
779 | \r | |
780 | @retval EFI_OUT_OF_RESOURCES Memory allocation failed. Neither the\r | |
781 | (*FileList) nor the (*Duplicates) list has\r | |
782 | been modified.\r | |
783 | \r | |
784 | @retval EFI_SUCCESS Sorting successful, including the case when\r | |
785 | FileList is NULL on input.\r | |
786 | **/\r | |
787 | EFI_STATUS\r | |
788 | EFIAPI\r | |
789 | ShellSortFileList (\r | |
47d20b54 MK |
790 | IN OUT EFI_SHELL_FILE_INFO **FileList,\r |
791 | OUT EFI_SHELL_FILE_INFO **Duplicates OPTIONAL,\r | |
792 | IN SHELL_SORT_FILE_LIST Order\r | |
101c55ac | 793 | );\r |
47d20b54 | 794 | \r |
a405b86d | 795 | #endif //_SHELL_COMMAND_LIB_\r |