]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Application/Shell/ShellEnvVar.h
ShellPkg: Clean up source files
[mirror_edk2.git] / ShellPkg / Application / Shell / ShellEnvVar.h
CommitLineData
a405b86d 1/** @file\r
2 function definitions for shell environment functions.\r
3\r
4 the following includes are required:\r
5//#include <Guid/ShellVariableGuid.h>\r
6//#include <Library/UefiRuntimeServicesTableLib.h>\r
7\r
8\r
ba0014b9 9 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
a405b86d 10 This program and the accompanying materials\r
11 are licensed and made available under the terms and conditions of the BSD License\r
12 which accompanies this distribution. The full text of the license may be found at\r
13 http://opensource.org/licenses/bsd-license.php\r
14\r
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
16 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
17\r
18**/\r
19\r
20#ifndef _SHELL_ENVIRONMENT_VARIABLE_HEADER_\r
21#define _SHELL_ENVIRONMENT_VARIABLE_HEADER_\r
22\r
23typedef struct {\r
24 LIST_ENTRY Link;\r
25 CHAR16 *Key;\r
26 CHAR16 *Val;\r
27 UINT32 Atts;\r
28} ENV_VAR_LIST;\r
29\r
b62bb885
QS
30//\r
31// The list is used to cache the environment variables.\r
32//\r
33extern ENV_VAR_LIST gShellEnvVarList;\r
34\r
35\r
a405b86d 36/**\r
31e5b912 37 Reports whether an environment variable is Volatile or Non-Volatile.\r
a405b86d 38\r
39 @param EnvVarName The name of the environment variable in question\r
31e5b912 40 @param Volatile Return TRUE if the environment variable is volatile\r
a405b86d 41\r
31e5b912
RN
42 @retval EFI_SUCCESS The volatile attribute is returned successfully\r
43 @retval others Some errors happened.\r
a405b86d 44**/\r
31e5b912 45EFI_STATUS\r
a405b86d 46IsVolatileEnv (\r
31e5b912
RN
47 IN CONST CHAR16 *EnvVarName,\r
48 OUT BOOLEAN *Volatile\r
a405b86d 49 );\r
50\r
51/**\r
52 Delete a Non-Violatile environment variable.\r
53\r
54 This will use the Runtime Services call SetVariable to remove a non-violatile variable.\r
55\r
56 @param EnvVarName The name of the environment variable in question\r
57\r
58 @retval EFI_SUCCESS The variable was deleted sucessfully\r
59 @retval other An error ocurred\r
60 @sa SetVariable\r
61**/\r
62#define SHELL_DELETE_ENVIRONMENT_VARIABLE(EnvVarName) \\r
63 (gRT->SetVariable((CHAR16*)EnvVarName, \\r
64 &gShellVariableGuid, \\r
65 0, \\r
66 0, \\r
67 NULL))\r
68\r
69/**\r
70 Set a Non-Violatile environment variable.\r
71\r
72 This will use the Runtime Services call SetVariable to set a non-violatile variable.\r
73\r
74 @param EnvVarName The name of the environment variable in question\r
75 @param BufferSize UINTN size of Buffer\r
76 @param Buffer Pointer to value to set variable to\r
77\r
78 @retval EFI_SUCCESS The variable was changed sucessfully\r
79 @retval other An error ocurred\r
80 @sa SetVariable\r
81**/\r
82#define SHELL_SET_ENVIRONMENT_VARIABLE_NV(EnvVarName,BufferSize,Buffer) \\r
83 (gRT->SetVariable((CHAR16*)EnvVarName, \\r
84 &gShellVariableGuid, \\r
85 EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS, \\r
86 BufferSize, \\r
87 (VOID*)Buffer))\r
88\r
89/**\r
90 Get an environment variable.\r
91\r
92 This will use the Runtime Services call GetVariable to get a variable.\r
93\r
94 @param EnvVarName The name of the environment variable in question\r
95 @param BufferSize Pointer to the UINTN size of Buffer\r
96 @param Buffer Pointer buffer to get variable value into\r
97\r
98 @retval EFI_SUCCESS The variable's value was retrieved sucessfully\r
99 @retval other An error ocurred\r
100 @sa SetVariable\r
101**/\r
102#define SHELL_GET_ENVIRONMENT_VARIABLE(EnvVarName,BufferSize,Buffer) \\r
103 (gRT->GetVariable((CHAR16*)EnvVarName, \\r
104 &gShellVariableGuid, \\r
105 0, \\r
106 BufferSize, \\r
107 Buffer))\r
108\r
109/**\r
110 Get an environment variable.\r
111\r
112 This will use the Runtime Services call GetVariable to get a variable.\r
113\r
114 @param EnvVarName The name of the environment variable in question\r
115 @param Atts Pointer to the UINT32 for attributes (or NULL)\r
116 @param BufferSize Pointer to the UINTN size of Buffer\r
117 @param Buffer Pointer buffer to get variable value into\r
118\r
119 @retval EFI_SUCCESS The variable's value was retrieved sucessfully\r
120 @retval other An error ocurred\r
121 @sa SetVariable\r
122**/\r
123#define SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(EnvVarName,Atts,BufferSize,Buffer) \\r
124 (gRT->GetVariable((CHAR16*)EnvVarName, \\r
125 &gShellVariableGuid, \\r
126 Atts, \\r
127 BufferSize, \\r
128 Buffer))\r
129\r
130/**\r
131 Set a Violatile environment variable.\r
132\r
133 This will use the Runtime Services call SetVariable to set a violatile variable.\r
134\r
135 @param EnvVarName The name of the environment variable in question\r
136 @param BufferSize UINTN size of Buffer\r
137 @param Buffer Pointer to value to set variable to\r
138\r
139 @retval EFI_SUCCESS The variable was changed sucessfully\r
140 @retval other An error ocurred\r
141 @sa SetVariable\r
142**/\r
143#define SHELL_SET_ENVIRONMENT_VARIABLE_V(EnvVarName,BufferSize,Buffer) \\r
144 (gRT->SetVariable((CHAR16*)EnvVarName, \\r
145 &gShellVariableGuid, \\r
146 EFI_VARIABLE_BOOTSERVICE_ACCESS, \\r
147 BufferSize, \\r
148 (VOID*)Buffer))\r
149\r
150/**\r
151 Creates a list of all Shell-Guid-based environment variables.\r
152\r
4ff7e37b
ED
153 @param[in, out] List The pointer to pointer to LIST_ENTRY object for\r
154 storing this list.\r
a405b86d 155\r
156 @retval EFI_SUCCESS the list was created sucessfully.\r
157**/\r
158EFI_STATUS\r
a405b86d 159GetEnvironmentVariableList(\r
160 IN OUT LIST_ENTRY *List\r
161 );\r
162\r
163/**\r
164 Sets a list of all Shell-Guid-based environment variables. this will\r
165 also eliminate all pre-existing shell environment variables (even if they\r
166 are not on the list).\r
167\r
168 This function will also deallocate the memory from List.\r
169\r
170 @param[in] List The pointer to LIST_ENTRY from\r
171 GetShellEnvVarList().\r
172\r
173 @retval EFI_SUCCESS The list was Set sucessfully.\r
174**/\r
175EFI_STATUS\r
a405b86d 176SetEnvironmentVariableList(\r
177 IN LIST_ENTRY *List\r
178 );\r
179\r
180/**\r
181 sets all Shell-Guid-based environment variables. this will\r
182 also eliminate all pre-existing shell environment variables (even if they\r
183 are not on the list).\r
184\r
185 @param[in] Environment Points to a NULL-terminated array of environment\r
186 variables with the format 'x=y', where x is the\r
187 environment variable name and y is the value.\r
188\r
189 @retval EFI_SUCCESS The command executed successfully.\r
190 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
191 @retval EFI_OUT_OF_RESOURCES Out of resources.\r
192\r
193 @sa SetEnvironmentVariableList\r
194**/\r
195EFI_STATUS\r
a405b86d 196SetEnvironmentVariables(\r
197 IN CONST CHAR16 **Environment\r
198 );\r
199\r
200/**\r
201 free function for ENV_VAR_LIST objects.\r
202\r
203 @param[in] List The pointer to pointer to list.\r
204**/\r
205VOID\r
a405b86d 206FreeEnvironmentVariableList(\r
207 IN LIST_ENTRY *List\r
208 );\r
209\r
b62bb885
QS
210/**\r
211 Find an environment variable in the gShellEnvVarList.\r
212\r
213 @param Key The name of the environment variable.\r
214 @param Value The value of the environment variable, the buffer\r
215 shoule be freed by the caller.\r
216 @param ValueSize The size in bytes of the environment variable\r
217 including the tailing CHAR_NULL.\r
218 @param Atts The attributes of the variable.\r
219\r
220 @retval EFI_SUCCESS The command executed successfully.\r
221 @retval EFI_NOT_FOUND The environment variable is not found in\r
222 gShellEnvVarList.\r
223\r
224**/\r
225EFI_STATUS\r
226ShellFindEnvVarInList (\r
227 IN CONST CHAR16 *Key,\r
228 OUT CHAR16 **Value,\r
229 OUT UINTN *ValueSize,\r
230 OUT UINT32 *Atts OPTIONAL\r
231 );\r
232\r
233/**\r
234 Add an environment variable into gShellEnvVarList.\r
235\r
236 @param Key The name of the environment variable.\r
237 @param Value The value of environment variable.\r
238 @param ValueSize The size in bytes of the environment variable\r
ffbc60a0 239 including the tailing CHAR_NULL\r
b62bb885
QS
240 @param Atts The attributes of the variable.\r
241\r
ffbc60a0
RN
242 @retval EFI_SUCCESS The environment variable was added to list successfully.\r
243 @retval others Some errors happened.\r
244\r
b62bb885 245**/\r
ffbc60a0 246EFI_STATUS\r
b62bb885
QS
247ShellAddEnvVarToList (\r
248 IN CONST CHAR16 *Key,\r
249 IN CONST CHAR16 *Value,\r
250 IN UINTN ValueSize,\r
251 IN UINT32 Atts\r
252 );\r
253\r
254/**\r
255 Remove a specified environment variable in gShellEnvVarList.\r
256\r
257 @param Key The name of the environment variable.\r
258\r
259 @retval EFI_SUCCESS The command executed successfully.\r
260 @retval EFI_NOT_FOUND The environment variable is not found in\r
261 gShellEnvVarList.\r
262**/\r
263EFI_STATUS\r
264ShellRemvoeEnvVarFromList (\r
265 IN CONST CHAR16 *Key\r
266 );\r
267\r
268/**\r
ba0014b9 269 Initialize the gShellEnvVarList and cache all Shell-Guid-based environment\r
b62bb885 270 variables.\r
ba0014b9 271\r
b62bb885
QS
272**/\r
273EFI_STATUS\r
274ShellInitEnvVarList (\r
275 VOID\r
276 );\r
277\r
278/**\r
279 Destructe the gShellEnvVarList.\r
280\r
281**/\r
282VOID\r
283ShellFreeEnvVarList (\r
284 VOID\r
285 );\r
286\r
a405b86d 287#endif //_SHELL_ENVIRONMENT_VARIABLE_HEADER_\r
288\r