2 Main file for NULL named library for level 2 shell command functions.
22 * functions are non-interactive only
24 Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
25 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
26 SPDX-License-Identifier: BSD-2-Clause-Patent
29 #include "UefiShellLevel2CommandsLib.h"
31 CONST CHAR16 mFileName
[] = L
"ShellCommands";
32 EFI_HII_HANDLE gShellLevel2HiiHandle
= NULL
;
35 Get the filename to get help text from if not using HII.
41 ShellCommandGetManFileNameLevel2 (
49 Constructor for the Shell Level 2 Commands library.
51 Install the handlers for level 2 UEFI Shell 2.0 commands.
53 @param ImageHandle the image handle of the process
54 @param SystemTable the EFI System Table pointer
56 @retval EFI_SUCCESS the shell command handlers were installed sucessfully
57 @retval EFI_UNSUPPORTED the shell level required was not found.
61 ShellLevel2CommandsLibConstructor (
62 IN EFI_HANDLE ImageHandle
,
63 IN EFI_SYSTEM_TABLE
*SystemTable
67 // if shell level is less than 2 do nothing
69 if (PcdGet8 (PcdShellSupportLevel
) < 2) {
73 gShellLevel2HiiHandle
= HiiAddPackages (&gShellLevel2HiiGuid
, gImageHandle
, UefiShellLevel2CommandsLibStrings
, NULL
);
74 if (gShellLevel2HiiHandle
== NULL
) {
75 return (EFI_DEVICE_ERROR
);
79 // install our shell command handlers that are always installed
81 ShellCommandRegisterCommandName (L
"attrib", ShellCommandRunAttrib
, ShellCommandGetManFileNameLevel2
, 2, L
"", TRUE
, gShellLevel2HiiHandle
, STRING_TOKEN (STR_GET_HELP_ATTRIB
));
82 ShellCommandRegisterCommandName (L
"cd", ShellCommandRunCd
, ShellCommandGetManFileNameLevel2
, 2, L
"", TRUE
, gShellLevel2HiiHandle
, STRING_TOKEN (STR_GET_HELP_CD
));
83 ShellCommandRegisterCommandName (L
"cp", ShellCommandRunCp
, ShellCommandGetManFileNameLevel2
, 2, L
"", TRUE
, gShellLevel2HiiHandle
, STRING_TOKEN (STR_GET_HELP_CP
));
84 ShellCommandRegisterCommandName (L
"load", ShellCommandRunLoad
, ShellCommandGetManFileNameLevel2
, 2, L
"", TRUE
, gShellLevel2HiiHandle
, STRING_TOKEN (STR_GET_HELP_LOAD
));
85 ShellCommandRegisterCommandName (L
"map", ShellCommandRunMap
, ShellCommandGetManFileNameLevel2
, 2, L
"", TRUE
, gShellLevel2HiiHandle
, STRING_TOKEN (STR_GET_HELP_MAP
));
86 ShellCommandRegisterCommandName (L
"mkdir", ShellCommandRunMkDir
, ShellCommandGetManFileNameLevel2
, 2, L
"", TRUE
, gShellLevel2HiiHandle
, STRING_TOKEN (STR_GET_HELP_MKDIR
));
87 ShellCommandRegisterCommandName (L
"mv", ShellCommandRunMv
, ShellCommandGetManFileNameLevel2
, 2, L
"", TRUE
, gShellLevel2HiiHandle
, STRING_TOKEN (STR_GET_HELP_MV
));
88 ShellCommandRegisterCommandName (L
"parse", ShellCommandRunParse
, ShellCommandGetManFileNameLevel2
, 2, L
"", TRUE
, gShellLevel2HiiHandle
, STRING_TOKEN (STR_GET_HELP_PARSE
));
89 ShellCommandRegisterCommandName (L
"reset", ShellCommandRunReset
, ShellCommandGetManFileNameLevel2
, 2, L
"", TRUE
, gShellLevel2HiiHandle
, STRING_TOKEN (STR_GET_HELP_RESET
));
90 ShellCommandRegisterCommandName (L
"set", ShellCommandRunSet
, ShellCommandGetManFileNameLevel2
, 2, L
"", FALSE
, gShellLevel2HiiHandle
, STRING_TOKEN (STR_GET_HELP_SET
));
91 ShellCommandRegisterCommandName (L
"ls", ShellCommandRunLs
, ShellCommandGetManFileNameLevel2
, 2, L
"", TRUE
, gShellLevel2HiiHandle
, STRING_TOKEN (STR_GET_HELP_LS
));
92 ShellCommandRegisterCommandName (L
"rm", ShellCommandRunRm
, ShellCommandGetManFileNameLevel2
, 2, L
"", TRUE
, gShellLevel2HiiHandle
, STRING_TOKEN (STR_GET_HELP_RM
));
93 ShellCommandRegisterCommandName (L
"vol", ShellCommandRunVol
, ShellCommandGetManFileNameLevel2
, 2, L
"", TRUE
, gShellLevel2HiiHandle
, STRING_TOKEN (STR_GET_HELP_VOL
));
96 // support for permanent (built in) aliases
98 ShellCommandRegisterAlias (L
"rm", L
"del");
99 ShellCommandRegisterAlias (L
"ls", L
"dir");
100 ShellCommandRegisterAlias (L
"cp", L
"copy");
101 ShellCommandRegisterAlias (L
"mkdir", L
"md");
102 ShellCommandRegisterAlias (L
"cd ..", L
"cd..");
103 ShellCommandRegisterAlias (L
"cd \\", L
"cd\\");
104 ShellCommandRegisterAlias (L
"mv", L
"ren");
105 ShellCommandRegisterAlias (L
"mv", L
"move");
106 ShellCommandRegisterAlias (L
"map", L
"mount");
108 // These are installed in level 2 or 3...
110 if ((PcdGet8 (PcdShellSupportLevel
) == 2) || (PcdGet8 (PcdShellSupportLevel
) == 3)) {
111 ShellCommandRegisterCommandName (L
"date", ShellCommandRunDate
, ShellCommandGetManFileNameLevel2
, PcdGet8 (PcdShellSupportLevel
), L
"", TRUE
, gShellLevel2HiiHandle
, STRING_TOKEN (STR_GET_HELP_DATE
));
112 ShellCommandRegisterCommandName (L
"time", ShellCommandRunTime
, ShellCommandGetManFileNameLevel2
, PcdGet8 (PcdShellSupportLevel
), L
"", TRUE
, gShellLevel2HiiHandle
, STRING_TOKEN (STR_GET_HELP_TIME
));
113 ShellCommandRegisterCommandName (L
"timezone", ShellCommandRunTimeZone
, ShellCommandGetManFileNameLevel2
, PcdGet8 (PcdShellSupportLevel
), L
"", TRUE
, gShellLevel2HiiHandle
, STRING_TOKEN (STR_GET_HELP_TIMEZONE
));
117 // we want to be able to test these so install them under a different name in debug mode...
119 ShellCommandRegisterCommandName (L
"l2date", ShellCommandRunDate
, ShellCommandGetManFileNameLevel2
, 2, L
"", TRUE
, gShellLevel2HiiHandle
, STRING_TOKEN (STR_GET_HELP_DATE
));
120 ShellCommandRegisterCommandName (L
"l2time", ShellCommandRunTime
, ShellCommandGetManFileNameLevel2
, 2, L
"", TRUE
, gShellLevel2HiiHandle
, STRING_TOKEN (STR_GET_HELP_TIME
));
121 ShellCommandRegisterCommandName (L
"l2timezone", ShellCommandRunTimeZone
, ShellCommandGetManFileNameLevel2
, 2, L
"", TRUE
, gShellLevel2HiiHandle
, STRING_TOKEN (STR_GET_HELP_TIMEZONE
));
125 return (EFI_SUCCESS
);
129 Destructor for the library. free any resources.
131 @param ImageHandle The image handle of the process.
132 @param SystemTable The EFI System Table pointer.
134 @retval EFI_SUCCESS Always returned.
138 ShellLevel2CommandsLibDestructor (
139 IN EFI_HANDLE ImageHandle
,
140 IN EFI_SYSTEM_TABLE
*SystemTable
143 if (gShellLevel2HiiHandle
!= NULL
) {
144 HiiRemovePackages (gShellLevel2HiiHandle
);
147 return (EFI_SUCCESS
);
151 returns a fully qualified directory (contains a map drive at the begining)
152 path from a unknown directory path.
154 If Path is already fully qualified this will return a duplicat otherwise this
155 will use get the current directory and use that to build the fully qualified
158 if the return value is not NULL it must be caller freed.
160 @param[in] Path The unknown Path Value
162 @retval NULL A memory allocation failed
163 @retval NULL A fully qualified path could not be discovered.
164 @retval other An allocated pointer to a fuly qualified path.
167 GetFullyQualifiedPath (
168 IN CONST CHAR16
*Path
171 CHAR16
*PathToReturn
;
173 CONST CHAR16
*CurDir
;
178 ASSERT ((PathToReturn
== NULL
&& Size
== 0) || (PathToReturn
!= NULL
));
180 // convert a local path to an absolute path
182 if (StrStr (Path
, L
":") == NULL
) {
183 CurDir
= gEfiShellProtocol
->GetCurDir (NULL
);
184 StrnCatGrow (&PathToReturn
, &Size
, CurDir
, 0);
185 StrnCatGrow (&PathToReturn
, &Size
, L
"\\", 0);
186 if (*Path
== L
'\\') {
191 StrnCatGrow (&PathToReturn
, &Size
, Path
, 0);
193 PathCleanUpDirectories (PathToReturn
);
195 if (PathToReturn
== NULL
) {
199 while (PathToReturn
[StrLen (PathToReturn
)-1] == L
'*') {
200 PathToReturn
[StrLen (PathToReturn
)-1] = CHAR_NULL
;
203 return (PathToReturn
);
207 Function to verify all intermediate directories in the path.
209 @param[in] Path The pointer to the path to fix.
211 @retval EFI_SUCCESS The operation was successful.
214 VerifyIntermediateDirectories (
215 IN CONST CHAR16
*Path
221 SHELL_FILE_HANDLE FileHandle
;
223 ASSERT (Path
!= NULL
);
225 Status
= EFI_SUCCESS
;
227 PathCopy
= StrnCatGrow (&PathCopy
, NULL
, Path
, 0);
230 if (PathCopy
== NULL
) {
231 return (EFI_OUT_OF_RESOURCES
);
234 for (TempSpot
= &PathCopy
[StrLen (PathCopy
)-1]; *TempSpot
!= CHAR_NULL
&& *TempSpot
!= L
'\\'; TempSpot
= &PathCopy
[StrLen (PathCopy
)-1]) {
235 *TempSpot
= CHAR_NULL
;
238 if (*TempSpot
== L
'\\') {
239 *TempSpot
= CHAR_NULL
;
242 if ((PathCopy
!= NULL
) && (*PathCopy
!= CHAR_NULL
)) {
243 Status
= VerifyIntermediateDirectories (PathCopy
);
245 if (PathCopy
[StrLen (PathCopy
)-1] != L
':') {
246 if (!EFI_ERROR (Status
)) {
247 Status
= ShellOpenFileByName (PathCopy
, &FileHandle
, EFI_FILE_MODE_READ
, 0);
248 if (FileHandle
!= NULL
) {
249 ShellCloseFile (&FileHandle
);
255 SHELL_FREE_NON_NULL (PathCopy
);
261 String comparison without regard to case for a limited number of characters.
263 @param[in] Source The first item to compare.
264 @param[in] Target The second item to compare.
265 @param[in] Count How many characters to compare.
267 @retval 0 Source and Target are identical strings without regard to case.
268 @retval !=0 Source is not identical to Target.
273 IN CONST CHAR16
*Source
,
274 IN CONST CHAR16
*Target
,
288 SourceLength
= StrLen (Source
);
289 TargetLength
= StrLen (Target
);
290 SourceLength
= MIN (SourceLength
, Count
);
291 TargetLength
= MIN (TargetLength
, Count
);
292 SourceCopy
= AllocateCopyPool ((SourceLength
+ 1) * sizeof (CHAR16
), Source
);
293 if (SourceCopy
== NULL
) {
297 TargetCopy
= AllocateCopyPool ((TargetLength
+ 1) * sizeof (CHAR16
), Target
);
298 if (TargetCopy
== NULL
) {
299 FreePool (SourceCopy
);
303 SourceCopy
[SourceLength
] = L
'\0';
304 TargetCopy
[TargetLength
] = L
'\0';
305 Result
= gUnicodeCollation
->StriColl (gUnicodeCollation
, SourceCopy
, TargetCopy
);
306 FreePool (SourceCopy
);
307 FreePool (TargetCopy
);
312 Cleans off all the quotes in the string.
314 @param[in] OriginalString pointer to the string to be cleaned.
315 @param[out] CleanString The new string with all quotes removed.
316 Memory allocated in the function and free
319 @retval EFI_SUCCESS The operation was successful.
322 ShellLevel2StripQuotes (
323 IN CONST CHAR16
*OriginalString
,
324 OUT CHAR16
**CleanString
329 if ((OriginalString
== NULL
) || (CleanString
== NULL
)) {
330 return EFI_INVALID_PARAMETER
;
333 *CleanString
= AllocateCopyPool (StrSize (OriginalString
), OriginalString
);
334 if (*CleanString
== NULL
) {
335 return EFI_OUT_OF_RESOURCES
;
338 for (Walker
= *CleanString
; Walker
!= NULL
&& *Walker
!= CHAR_NULL
; Walker
++) {
339 if (*Walker
== L
'\"') {
340 CopyMem (Walker
, Walker
+1, StrSize (Walker
) - sizeof (Walker
[0]));