1 | /** @file
|
---|
2 | Main file for attrib shell level 2 function.
|
---|
3 |
|
---|
4 | (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
|
---|
5 | Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
|
---|
6 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 |
|
---|
8 | **/
|
---|
9 |
|
---|
10 | #include "UefiShellLevel2CommandsLib.h"
|
---|
11 |
|
---|
12 | /**
|
---|
13 | Print out each environment variable registered with the Shell 2.0 GUID.
|
---|
14 |
|
---|
15 | If you spawn a pre 2.0 shell from the Shell 2.0 the environment variable may not carry through.
|
---|
16 |
|
---|
17 | @retval STATUS_SUCCESS the printout was successful
|
---|
18 | @return any return code from GetNextVariableName except EFI_NOT_FOUND
|
---|
19 | **/
|
---|
20 | SHELL_STATUS
|
---|
21 | PrintAllShellEnvVars (
|
---|
22 | VOID
|
---|
23 | )
|
---|
24 | {
|
---|
25 | CONST CHAR16 *Value;
|
---|
26 | CONST CHAR16 *ConstEnvNameList;
|
---|
27 |
|
---|
28 | ConstEnvNameList = gEfiShellProtocol->GetEnv (NULL);
|
---|
29 | if (ConstEnvNameList == NULL) {
|
---|
30 | return (SHELL_SUCCESS);
|
---|
31 | }
|
---|
32 |
|
---|
33 | while (*ConstEnvNameList != CHAR_NULL) {
|
---|
34 | Value = gEfiShellProtocol->GetEnv (ConstEnvNameList);
|
---|
35 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SET_DISP), gShellLevel2HiiHandle, ConstEnvNameList, Value);
|
---|
36 | ConstEnvNameList += StrLen (ConstEnvNameList)+1;
|
---|
37 | }
|
---|
38 |
|
---|
39 | return (SHELL_SUCCESS);
|
---|
40 | }
|
---|
41 |
|
---|
42 | STATIC CONST SHELL_PARAM_ITEM SetParamList[] = {
|
---|
43 | { L"-d", TypeValue },
|
---|
44 | { L"-v", TypeFlag },
|
---|
45 | { NULL, TypeMax }
|
---|
46 | };
|
---|
47 |
|
---|
48 | /**
|
---|
49 | Function for 'set' command.
|
---|
50 |
|
---|
51 | @param[in] ImageHandle Handle to the Image (NULL if Internal).
|
---|
52 | @param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
---|
53 | **/
|
---|
54 | SHELL_STATUS
|
---|
55 | EFIAPI
|
---|
56 | ShellCommandRunSet (
|
---|
57 | IN EFI_HANDLE ImageHandle,
|
---|
58 | IN EFI_SYSTEM_TABLE *SystemTable
|
---|
59 | )
|
---|
60 | {
|
---|
61 | EFI_STATUS Status;
|
---|
62 | LIST_ENTRY *Package;
|
---|
63 | CONST CHAR16 *KeyName;
|
---|
64 | CONST CHAR16 *Value;
|
---|
65 | CHAR16 *ProblemParam;
|
---|
66 | SHELL_STATUS ShellStatus;
|
---|
67 |
|
---|
68 | ProblemParam = NULL;
|
---|
69 | ShellStatus = SHELL_SUCCESS;
|
---|
70 |
|
---|
71 | //
|
---|
72 | // initialize the shell lib (we must be in non-auto-init...)
|
---|
73 | //
|
---|
74 | Status = ShellInitialize ();
|
---|
75 | ASSERT_EFI_ERROR (Status);
|
---|
76 |
|
---|
77 | //
|
---|
78 | // Make sure globals are good...
|
---|
79 | //
|
---|
80 | Status = CommandInit ();
|
---|
81 | ASSERT_EFI_ERROR (Status);
|
---|
82 |
|
---|
83 | //
|
---|
84 | // parse the command line
|
---|
85 | //
|
---|
86 | Status = ShellCommandLineParse (SetParamList, &Package, &ProblemParam, TRUE);
|
---|
87 | if (EFI_ERROR (Status)) {
|
---|
88 | if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
|
---|
89 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"set", ProblemParam);
|
---|
90 | FreePool (ProblemParam);
|
---|
91 | return (SHELL_INVALID_PARAMETER);
|
---|
92 | } else {
|
---|
93 | ASSERT (FALSE);
|
---|
94 | }
|
---|
95 | } else {
|
---|
96 | //
|
---|
97 | // check for "-?"
|
---|
98 | //
|
---|
99 | if (ShellCommandLineGetFlag (Package, L"-?")) {
|
---|
100 | ASSERT (FALSE);
|
---|
101 | } else if (ShellCommandLineGetRawValue (Package, 3) != NULL) {
|
---|
102 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"set");
|
---|
103 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
104 | } else if ((ShellCommandLineGetRawValue (Package, 1) != NULL) && ShellCommandLineGetFlag (Package, L"-d")) {
|
---|
105 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"set");
|
---|
106 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
107 | } else if (ShellCommandLineGetFlag (Package, L"-d")) {
|
---|
108 | //
|
---|
109 | // delete a environment variable
|
---|
110 | //
|
---|
111 | KeyName = ShellCommandLineGetValue (Package, L"-d");
|
---|
112 | if (KeyName == NULL) {
|
---|
113 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellLevel2HiiHandle, L"set", L"-d");
|
---|
114 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
115 | } else {
|
---|
116 | Status = ShellSetEnvironmentVariable (KeyName, L"", ShellCommandLineGetFlag (Package, L"-v"));
|
---|
117 | if (EFI_ERROR (Status)) {
|
---|
118 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SET_ND), gShellLevel2HiiHandle, L"set", KeyName);
|
---|
119 | ShellStatus = SHELL_DEVICE_ERROR;
|
---|
120 | }
|
---|
121 | }
|
---|
122 | } else if (ShellCommandLineGetRawValue (Package, 1) == NULL) {
|
---|
123 | //
|
---|
124 | // print out all current environment variables
|
---|
125 | //
|
---|
126 | return (PrintAllShellEnvVars ());
|
---|
127 | } else {
|
---|
128 | //
|
---|
129 | // we are either printing one or assigning one
|
---|
130 | //
|
---|
131 | KeyName = ShellCommandLineGetRawValue (Package, 1);
|
---|
132 | Value = ShellCommandLineGetRawValue (Package, 2);
|
---|
133 | if ((KeyName != NULL) && (Value != NULL)) {
|
---|
134 | //
|
---|
135 | // assigning one
|
---|
136 | //
|
---|
137 | Status = ShellSetEnvironmentVariable (KeyName, Value, ShellCommandLineGetFlag (Package, L"-v"));
|
---|
138 | if (EFI_ERROR (Status)) {
|
---|
139 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SET_ERROR_SET), gShellLevel2HiiHandle, L"set", KeyName);
|
---|
140 | ShellStatus = (SHELL_STATUS)(Status & (~MAX_BIT));
|
---|
141 | }
|
---|
142 | } else {
|
---|
143 | if (KeyName != NULL) {
|
---|
144 | //
|
---|
145 | // print out value for this one only.
|
---|
146 | //
|
---|
147 | Value = ShellGetEnvironmentVariable (KeyName);
|
---|
148 | if (Value == NULL) {
|
---|
149 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SET_NF), gShellLevel2HiiHandle, L"set", KeyName);
|
---|
150 | ShellStatus = SHELL_SUCCESS;
|
---|
151 | } else {
|
---|
152 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SET_DISP), gShellLevel2HiiHandle, KeyName, Value);
|
---|
153 | ShellStatus = SHELL_SUCCESS;
|
---|
154 | }
|
---|
155 | } else {
|
---|
156 | ASSERT (FALSE);
|
---|
157 | }
|
---|
158 | }
|
---|
159 | }
|
---|
160 | }
|
---|
161 |
|
---|
162 | //
|
---|
163 | // free the command line package
|
---|
164 | //
|
---|
165 | ShellCommandLineFreeVarList (Package);
|
---|
166 |
|
---|
167 | return (ShellStatus);
|
---|
168 | }
|
---|