TianoCore EDK2 master
Loading...
Searching...
No Matches
UefiShellLevel2CommandsLib.c
Go to the documentation of this file.
1
30
31CONST CHAR16 mFileName[] = L"ShellCommands";
32EFI_HII_HANDLE gShellLevel2HiiHandle = NULL;
33
39CONST CHAR16 *
40EFIAPI
42 VOID
43 )
44{
45 return (mFileName);
46}
47
60EFIAPI
62 IN EFI_HANDLE ImageHandle,
63 IN EFI_SYSTEM_TABLE *SystemTable
64 )
65{
66 //
67 // if shell level is less than 2 do nothing
68 //
69 if (PcdGet8 (PcdShellSupportLevel) < 2) {
70 return (EFI_SUCCESS);
71 }
72
73 gShellLevel2HiiHandle = HiiAddPackages (&gShellLevel2HiiGuid, gImageHandle, UefiShellLevel2CommandsLibStrings, NULL);
74 if (gShellLevel2HiiHandle == NULL) {
75 return (EFI_DEVICE_ERROR);
76 }
77
78 //
79 // install our shell command handlers that are always installed
80 //
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));
94
95 //
96 // support for permanent (built in) aliases
97 //
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");
107 //
108 // These are installed in level 2 or 3...
109 //
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));
114 } else {
116 //
117 // we want to be able to test these so install them under a different name in debug mode...
118 //
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));
123 }
124
125 return (EFI_SUCCESS);
126}
127
137EFIAPI
139 IN EFI_HANDLE ImageHandle,
140 IN EFI_SYSTEM_TABLE *SystemTable
141 )
142{
143 if (gShellLevel2HiiHandle != NULL) {
144 HiiRemovePackages (gShellLevel2HiiHandle);
145 }
146
147 return (EFI_SUCCESS);
148}
149
166CHAR16 *
168 IN CONST CHAR16 *Path
169 )
170{
171 CHAR16 *PathToReturn;
172 UINTN Size;
173 CONST CHAR16 *CurDir;
174
175 PathToReturn = NULL;
176 Size = 0;
177
178 ASSERT ((PathToReturn == NULL && Size == 0) || (PathToReturn != NULL));
179 //
180 // convert a local path to an absolute path
181 //
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'\\') {
187 Path++;
188 }
189 }
190
191 StrnCatGrow (&PathToReturn, &Size, Path, 0);
192
193 PathCleanUpDirectories (PathToReturn);
194
195 if (PathToReturn == NULL) {
196 return NULL;
197 }
198
199 while (PathToReturn[StrLen (PathToReturn)-1] == L'*') {
200 PathToReturn[StrLen (PathToReturn)-1] = CHAR_NULL;
201 }
202
203 return (PathToReturn);
204}
205
215 IN CONST CHAR16 *Path
216 )
217{
218 EFI_STATUS Status;
219 CHAR16 *PathCopy;
220 CHAR16 *TempSpot;
221 SHELL_FILE_HANDLE FileHandle;
222
223 ASSERT (Path != NULL);
224
225 Status = EFI_SUCCESS;
226 PathCopy = NULL;
227 PathCopy = StrnCatGrow (&PathCopy, NULL, Path, 0);
228 FileHandle = NULL;
229
230 if (PathCopy == NULL) {
231 return (EFI_OUT_OF_RESOURCES);
232 }
233
234 for (TempSpot = &PathCopy[StrLen (PathCopy)-1]; *TempSpot != CHAR_NULL && *TempSpot != L'\\'; TempSpot = &PathCopy[StrLen (PathCopy)-1]) {
235 *TempSpot = CHAR_NULL;
236 }
237
238 if (*TempSpot == L'\\') {
239 *TempSpot = CHAR_NULL;
240 }
241
242 if ((PathCopy != NULL) && (*PathCopy != CHAR_NULL)) {
243 Status = VerifyIntermediateDirectories (PathCopy);
244
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);
250 }
251 }
252 }
253 }
254
255 SHELL_FREE_NON_NULL (PathCopy);
256
257 return (Status);
258}
259
271INTN
273 IN CONST CHAR16 *Source,
274 IN CONST CHAR16 *Target,
275 IN CONST UINTN Count
276 )
277{
278 CHAR16 *SourceCopy;
279 CHAR16 *TargetCopy;
280 UINTN SourceLength;
281 UINTN TargetLength;
282 INTN Result;
283
284 if (Count == 0) {
285 return 0;
286 }
287
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) {
294 return -1;
295 }
296
297 TargetCopy = AllocateCopyPool ((TargetLength + 1) * sizeof (CHAR16), Target);
298 if (TargetCopy == NULL) {
299 FreePool (SourceCopy);
300 return -1;
301 }
302
303 SourceCopy[SourceLength] = L'\0';
304 TargetCopy[TargetLength] = L'\0';
305 Result = gUnicodeCollation->StriColl (gUnicodeCollation, SourceCopy, TargetCopy);
306 FreePool (SourceCopy);
307 FreePool (TargetCopy);
308 return Result;
309}
310
323 IN CONST CHAR16 *OriginalString,
324 OUT CHAR16 **CleanString
325 )
326{
327 CHAR16 *Walker;
328
329 if ((OriginalString == NULL) || (CleanString == NULL)) {
330 return EFI_INVALID_PARAMETER;
331 }
332
333 *CleanString = AllocateCopyPool (StrSize (OriginalString), OriginalString);
334 if (*CleanString == NULL) {
335 return EFI_OUT_OF_RESOURCES;
336 }
337
338 for (Walker = *CleanString; Walker != NULL && *Walker != CHAR_NULL;) {
339 if (*Walker == L'\"') {
340 CopyMem (Walker, Walker+1, StrSize (Walker) - sizeof (Walker[0]));
341 } else {
342 Walker++;
343 }
344 }
345
346 return EFI_SUCCESS;
347}
UINT64 UINTN
INT64 INTN
SHELL_STATUS EFIAPI ShellCommandRunAttrib(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Attrib.c:34
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
CHAR16 *EFIAPI PathCleanUpDirectories(IN CHAR16 *Path)
Definition: FilePaths.c:68
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
CHAR16 *EFIAPI StrStr(IN CONST CHAR16 *String, IN CONST CHAR16 *SearchString)
Definition: String.c:224
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
SHELL_STATUS EFIAPI ShellCommandRunCd(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Cd.c:173
SHELL_STATUS EFIAPI ShellCommandRunCp(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Cp.c:658
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
EFI_HII_HANDLE EFIAPI HiiAddPackages(IN CONST EFI_GUID *PackageListGuid, IN EFI_HANDLE DeviceHandle OPTIONAL,...)
Definition: HiiLib.c:141
VOID EFIAPI HiiRemovePackages(IN EFI_HII_HANDLE HiiHandle)
Definition: HiiLib.c:253
SHELL_STATUS EFIAPI ShellCommandRunLs(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Ls.c:722
SHELL_STATUS EFIAPI ShellCommandRunMap(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Map.c:1113
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define MIN(a, b)
Definition: Base.h:1007
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG_CODE_BEGIN()
Definition: DebugLib.h:564
#define DEBUG_CODE_END()
Definition: DebugLib.h:578
SHELL_STATUS EFIAPI ShellCommandRunMkDir(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: MkDir.c:20
SHELL_STATUS EFIAPI ShellCommandRunMv(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Mv.c:751
SHELL_STATUS EFIAPI ShellCommandRunParse(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Parse.c:245
#define PcdGet8(TokenName)
Definition: PcdLib.h:336
SHELL_STATUS EFIAPI ShellCommandRunRm(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Rm.c:279
SHELL_STATUS EFIAPI ShellCommandRunSet(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Set.c:56
RETURN_STATUS EFIAPI ShellCommandRegisterCommandName(IN CONST CHAR16 *CommandString, IN SHELL_RUN_COMMAND CommandHandler, IN SHELL_GET_MAN_FILENAME GetManFileName, IN UINT32 ShellMinSupportLevel, IN CONST CHAR16 *ProfileName, IN CONST BOOLEAN CanAffectLE, IN CONST EFI_HII_HANDLE HiiHandle, IN CONST EFI_STRING_ID ManFormatHelp)
RETURN_STATUS EFIAPI ShellCommandRegisterAlias(IN CONST CHAR16 *Command, IN CONST CHAR16 *Alias)
EFI_STATUS EFIAPI ShellOpenFileByName(IN CONST CHAR16 *FileName, OUT SHELL_FILE_HANDLE *FileHandle, IN UINT64 OpenMode, IN UINT64 Attributes)
Definition: UefiShellLib.c:720
CHAR16 *EFIAPI StrnCatGrow(IN OUT CHAR16 **Destination, IN OUT UINTN *CurrentSize, IN CONST CHAR16 *Source, IN UINTN Count)
EFI_STATUS EFIAPI ShellCloseFile(IN SHELL_FILE_HANDLE *FileHandle)
Definition: UefiShellLib.c:969
SHELL_STATUS EFIAPI ShellCommandRunReset(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Reset.c:28
SHELL_STATUS EFIAPI ShellCommandRunLoad(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Load.c:193
SHELL_STATUS EFIAPI ShellCommandRunTime(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: TimeDate.c:409
SHELL_STATUS EFIAPI ShellCommandRunTimeZone(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: TimeDate.c:821
SHELL_STATUS EFIAPI ShellCommandRunDate(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: TimeDate.c:177
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_HANDLE gImageHandle
#define STRING_TOKEN(t)
VOID * EFI_HII_HANDLE
CHAR16 * GetFullyQualifiedPath(IN CONST CHAR16 *Path)
CONST CHAR16 *EFIAPI ShellCommandGetManFileNameLevel2(VOID)
INTN StrniCmp(IN CONST CHAR16 *Source, IN CONST CHAR16 *Target, IN CONST UINTN Count)
EFI_STATUS VerifyIntermediateDirectories(IN CONST CHAR16 *Path)
EFI_STATUS ShellLevel2StripQuotes(IN CONST CHAR16 *OriginalString, OUT CHAR16 **CleanString)
EFI_STATUS EFIAPI ShellLevel2CommandsLibDestructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI ShellLevel2CommandsLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
SHELL_STATUS EFIAPI ShellCommandRunVol(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Vol.c:215