2 Main file for Alias shell level 3 function.
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved. <BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "UefiShellLevel3CommandsLib.h"
18 #include <Library/ShellLib.h>
21 Print out each alias registered with the Shell.
23 @retval STATUS_SUCCESS the printout was sucessful
24 @return any return code from GetNextVariableName except EFI_NOT_FOUND
31 CONST CHAR16
*ConstAllAliasList
;
33 CONST CHAR16
*Command
;
39 ConstAllAliasList
= gEfiShellProtocol
->GetAlias(NULL
, NULL
);
40 if (ConstAllAliasList
== NULL
) {
41 return (SHELL_SUCCESS
);
43 Alias
= AllocateZeroPool(StrSize(ConstAllAliasList
));
45 return (SHELL_OUT_OF_RESOURCES
);
47 Walker
= (CHAR16
*)ConstAllAliasList
;
50 CopyMem(Alias
, Walker
, StrSize(Walker
));
51 Walker
= StrStr(Alias
, L
";");
53 Walker
[0] = CHAR_NULL
;
56 Command
= gEfiShellProtocol
->GetAlias(Alias
, &Volatile
);
57 if (ShellCommandIsOnAliasList(Alias
)) {
60 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_ALIAS_OUTPUT
), gShellLevel3HiiHandle
, !Volatile
?L
' ':L
'*', Alias
, Command
);
61 } while (Walker
!= NULL
&& Walker
[0] != CHAR_NULL
);
65 return (SHELL_SUCCESS
);
68 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
75 Function for 'alias' command.
77 @param[in] ImageHandle Handle to the Image (NULL if Internal).
78 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
82 ShellCommandRunAlias (
83 IN EFI_HANDLE ImageHandle
,
84 IN EFI_SYSTEM_TABLE
*SystemTable
90 SHELL_STATUS ShellStatus
;
94 CONST CHAR16
*ConstAliasVal
;
98 ShellStatus
= SHELL_SUCCESS
;
102 // initialize the shell lib (we must be in non-auto-init...)
104 Status
= ShellInitialize();
105 ASSERT_EFI_ERROR(Status
);
107 Status
= CommandInit();
108 ASSERT_EFI_ERROR(Status
);
111 // parse the command line
113 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
114 if (EFI_ERROR(Status
)) {
115 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
116 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel3HiiHandle
, L
"alias", ProblemParam
);
117 FreePool(ProblemParam
);
118 ShellStatus
= SHELL_INVALID_PARAMETER
;
123 Param1
= ShellCommandLineGetRawValue(Package
, 1);
124 Param2
= ShellCommandLineGetRawValue(Package
, 2);
126 if (Param2
!= NULL
) {
127 CleanParam2
= AllocateCopyPool (StrSize(Param2
), Param2
);
128 if (CleanParam2
== NULL
) {
129 return SHELL_OUT_OF_RESOURCES
;
132 if (CleanParam2
[0] == L
'\"' && CleanParam2
[StrLen(CleanParam2
)-1] == L
'\"') {
133 CleanParam2
[StrLen(CleanParam2
)-1] = L
'\0';
134 CopyMem (CleanParam2
, CleanParam2
+ 1, StrSize(CleanParam2
) - sizeof(CleanParam2
[0]));
141 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
144 if (ShellCommandLineGetCount(Package
) == 1) {
148 Status
= PrintAllShellAlias();
149 } else if (ShellCommandLineGetFlag(Package
, L
"-d")) {
153 Status
= gEfiShellProtocol
->SetAlias(Param1
, NULL
, TRUE
, FALSE
);
154 if (EFI_ERROR(Status
)) {
155 if (Status
== EFI_ACCESS_DENIED
) {
156 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel3HiiHandle
, L
"alias");
157 ShellStatus
= SHELL_ACCESS_DENIED
;
158 } else if (Status
== EFI_NOT_FOUND
) {
159 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_NOT_FOUND
), gShellLevel3HiiHandle
, L
"alias", Param1
);
160 ShellStatus
= SHELL_NOT_FOUND
;
162 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel3HiiHandle
, L
"alias", Status
);
163 ShellStatus
= SHELL_DEVICE_ERROR
;
166 } else if (ShellCommandLineGetCount(Package
) == 3) {
168 // must be adding an alias
170 Status
= gEfiShellProtocol
->SetAlias(CleanParam2
, Param1
, FALSE
, ShellCommandLineGetFlag(Package
, L
"-v"));
171 if (EFI_ERROR(Status
)) {
172 if (Status
== EFI_ACCESS_DENIED
) {
173 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel3HiiHandle
, L
"alias");
174 ShellStatus
= SHELL_ACCESS_DENIED
;
176 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel3HiiHandle
, L
"alias", Status
);
177 ShellStatus
= SHELL_DEVICE_ERROR
;
180 } else if (ShellCommandLineGetCount(Package
) == 2) {
182 // print out a single alias
184 ConstAliasVal
= gEfiShellProtocol
->GetAlias(Param1
, &Volatile
);
185 if (ConstAliasVal
== NULL
) {
186 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellLevel3HiiHandle
, L
"alias", Param1
);
187 ShellStatus
= SHELL_INVALID_PARAMETER
;
189 if (ShellCommandIsOnAliasList(Param1
)) {
192 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_ALIAS_OUTPUT
), gShellLevel3HiiHandle
, !Volatile
?L
' ':L
'*', Param1
, ConstAliasVal
);
195 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel3HiiHandle
, L
"alias");
196 ShellStatus
= SHELL_INVALID_PARAMETER
;
199 // free the command line package
201 ShellCommandLineFreeVarList (Package
);
204 SHELL_FREE_NON_NULL (CleanParam2
);
205 return (ShellStatus
);