]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Application/Shell/ShellEnvVar.h
ShellPkg/IsVolatileEnv: Handle memory allocation failure
[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
b62bb885 9 Copyright (c) 2009 - 2016, 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
159EFIAPI\r
160GetEnvironmentVariableList(\r
161 IN OUT LIST_ENTRY *List\r
162 );\r
163\r
164/**\r
165 Sets a list of all Shell-Guid-based environment variables. this will\r
166 also eliminate all pre-existing shell environment variables (even if they\r
167 are not on the list).\r
168\r
169 This function will also deallocate the memory from List.\r
170\r
171 @param[in] List The pointer to LIST_ENTRY from\r
172 GetShellEnvVarList().\r
173\r
174 @retval EFI_SUCCESS The list was Set sucessfully.\r
175**/\r
176EFI_STATUS\r
177EFIAPI\r
178SetEnvironmentVariableList(\r
179 IN LIST_ENTRY *List\r
180 );\r
181\r
182/**\r
183 sets all Shell-Guid-based environment variables. this will\r
184 also eliminate all pre-existing shell environment variables (even if they\r
185 are not on the list).\r
186\r
187 @param[in] Environment Points to a NULL-terminated array of environment\r
188 variables with the format 'x=y', where x is the\r
189 environment variable name and y is the value.\r
190\r
191 @retval EFI_SUCCESS The command executed successfully.\r
192 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
193 @retval EFI_OUT_OF_RESOURCES Out of resources.\r
194\r
195 @sa SetEnvironmentVariableList\r
196**/\r
197EFI_STATUS\r
198EFIAPI\r
199SetEnvironmentVariables(\r
200 IN CONST CHAR16 **Environment\r
201 );\r
202\r
203/**\r
204 free function for ENV_VAR_LIST objects.\r
205\r
206 @param[in] List The pointer to pointer to list.\r
207**/\r
208VOID\r
209EFIAPI\r
210FreeEnvironmentVariableList(\r
211 IN LIST_ENTRY *List\r
212 );\r
213\r
b62bb885
QS
214/**\r
215 Find an environment variable in the gShellEnvVarList.\r
216\r
217 @param Key The name of the environment variable.\r
218 @param Value The value of the environment variable, the buffer\r
219 shoule be freed by the caller.\r
220 @param ValueSize The size in bytes of the environment variable\r
221 including the tailing CHAR_NULL.\r
222 @param Atts The attributes of the variable.\r
223\r
224 @retval EFI_SUCCESS The command executed successfully.\r
225 @retval EFI_NOT_FOUND The environment variable is not found in\r
226 gShellEnvVarList.\r
227\r
228**/\r
229EFI_STATUS\r
230ShellFindEnvVarInList (\r
231 IN CONST CHAR16 *Key,\r
232 OUT CHAR16 **Value,\r
233 OUT UINTN *ValueSize,\r
234 OUT UINT32 *Atts OPTIONAL\r
235 );\r
236\r
237/**\r
238 Add an environment variable into gShellEnvVarList.\r
239\r
240 @param Key The name of the environment variable.\r
241 @param Value The value of environment variable.\r
242 @param ValueSize The size in bytes of the environment variable\r
243 including the tailing CHAR_NELL\r
244 @param Atts The attributes of the variable.\r
245\r
246**/\r
247VOID\r
248ShellAddEnvVarToList (\r
249 IN CONST CHAR16 *Key,\r
250 IN CONST CHAR16 *Value,\r
251 IN UINTN ValueSize,\r
252 IN UINT32 Atts\r
253 );\r
254\r
255/**\r
256 Remove a specified environment variable in gShellEnvVarList.\r
257\r
258 @param Key The name of the environment variable.\r
259\r
260 @retval EFI_SUCCESS The command executed successfully.\r
261 @retval EFI_NOT_FOUND The environment variable is not found in\r
262 gShellEnvVarList.\r
263**/\r
264EFI_STATUS\r
265ShellRemvoeEnvVarFromList (\r
266 IN CONST CHAR16 *Key\r
267 );\r
268\r
269/**\r
270 Initialize the gShellEnvVarList and cache all Shell-Guid-based environment \r
271 variables.\r
272 \r
273**/\r
274EFI_STATUS\r
275ShellInitEnvVarList (\r
276 VOID\r
277 );\r
278\r
279/**\r
280 Destructe the gShellEnvVarList.\r
281\r
282**/\r
283VOID\r
284ShellFreeEnvVarList (\r
285 VOID\r
286 );\r
287\r
a405b86d 288#endif //_SHELL_ENVIRONMENT_VARIABLE_HEADER_\r
289\r