2 function definitions for shell environment functions.
4 the following includes are required:
5 //#include <Guid/ShellVariableGuid.h>
6 //#include <Library/UefiRuntimeServicesTableLib.h>
9 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
10 SPDX-License-Identifier: BSD-2-Clause-Patent
14 #ifndef _SHELL_ENVIRONMENT_VARIABLE_HEADER_
15 #define _SHELL_ENVIRONMENT_VARIABLE_HEADER_
25 // The list is used to cache the environment variables.
27 extern ENV_VAR_LIST gShellEnvVarList
;
30 Reports whether an environment variable is Volatile or Non-Volatile.
32 @param EnvVarName The name of the environment variable in question
33 @param Volatile Return TRUE if the environment variable is volatile
35 @retval EFI_SUCCESS The volatile attribute is returned successfully
36 @retval others Some errors happened.
40 IN CONST CHAR16
*EnvVarName
,
45 Delete a Non-Volatile environment variable.
47 This will use the Runtime Services call SetVariable to remove a non-volatile variable.
49 @param EnvVarName The name of the environment variable in question
51 @retval EFI_SUCCESS The variable was deleted successfully
52 @retval other An error occurred
55 #define SHELL_DELETE_ENVIRONMENT_VARIABLE(EnvVarName) \
56 (gRT->SetVariable((CHAR16*)EnvVarName, \
57 &gShellVariableGuid, \
63 Set a Non-Volatile environment variable.
65 This will use the Runtime Services call SetVariable to set a non-volatile variable.
67 @param EnvVarName The name of the environment variable in question
68 @param BufferSize UINTN size of Buffer
69 @param Buffer Pointer to value to set variable to
71 @retval EFI_SUCCESS The variable was changed successfully
72 @retval other An error occurred
75 #define SHELL_SET_ENVIRONMENT_VARIABLE_NV(EnvVarName, BufferSize, Buffer) \
76 (gRT->SetVariable((CHAR16*)EnvVarName, \
77 &gShellVariableGuid, \
78 EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS, \
83 Get an environment variable.
85 This will use the Runtime Services call GetVariable to get a variable.
87 @param EnvVarName The name of the environment variable in question
88 @param BufferSize Pointer to the UINTN size of Buffer
89 @param Buffer Pointer buffer to get variable value into
91 @retval EFI_SUCCESS The variable's value was retrieved successfully
92 @retval other An error occurred
95 #define SHELL_GET_ENVIRONMENT_VARIABLE(EnvVarName, BufferSize, Buffer) \
96 (gRT->GetVariable((CHAR16*)EnvVarName, \
97 &gShellVariableGuid, \
103 Get an environment variable.
105 This will use the Runtime Services call GetVariable to get a variable.
107 @param EnvVarName The name of the environment variable in question
108 @param Atts Pointer to the UINT32 for attributes (or NULL)
109 @param BufferSize Pointer to the UINTN size of Buffer
110 @param Buffer Pointer buffer to get variable value into
112 @retval EFI_SUCCESS The variable's value was retrieved successfully
113 @retval other An error occurred
116 #define SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(EnvVarName, Atts, BufferSize, Buffer) \
117 (gRT->GetVariable((CHAR16*)EnvVarName, \
118 &gShellVariableGuid, \
124 Set a Volatile environment variable.
126 This will use the Runtime Services call SetVariable to set a volatile variable.
128 @param EnvVarName The name of the environment variable in question
129 @param BufferSize UINTN size of Buffer
130 @param Buffer Pointer to value to set variable to
132 @retval EFI_SUCCESS The variable was changed successfully
133 @retval other An error occurred
136 #define SHELL_SET_ENVIRONMENT_VARIABLE_V(EnvVarName, BufferSize, Buffer) \
137 (gRT->SetVariable((CHAR16*)EnvVarName, \
138 &gShellVariableGuid, \
139 EFI_VARIABLE_BOOTSERVICE_ACCESS, \
144 Creates a list of all Shell-Guid-based environment variables.
146 @param[in, out] List The pointer to pointer to LIST_ENTRY object for
149 @retval EFI_SUCCESS the list was created successfully.
152 GetEnvironmentVariableList (
153 IN OUT LIST_ENTRY
*List
157 Sets a list of all Shell-Guid-based environment variables. this will
158 also eliminate all pre-existing shell environment variables (even if they
159 are not on the list).
161 This function will also deallocate the memory from List.
163 @param[in] List The pointer to LIST_ENTRY from
164 GetShellEnvVarList().
166 @retval EFI_SUCCESS The list was Set successfully.
169 SetEnvironmentVariableList (
174 sets all Shell-Guid-based environment variables. this will
175 also eliminate all pre-existing shell environment variables (even if they
176 are not on the list).
178 @param[in] Environment Points to a NULL-terminated array of environment
179 variables with the format 'x=y', where x is the
180 environment variable name and y is the value.
182 @retval EFI_SUCCESS The command executed successfully.
183 @retval EFI_INVALID_PARAMETER The parameter is invalid.
184 @retval EFI_OUT_OF_RESOURCES Out of resources.
186 @sa SetEnvironmentVariableList
189 SetEnvironmentVariables (
190 IN CONST CHAR16
**Environment
194 free function for ENV_VAR_LIST objects.
196 @param[in] List The pointer to pointer to list.
199 FreeEnvironmentVariableList (
204 Find an environment variable in the gShellEnvVarList.
206 @param Key The name of the environment variable.
207 @param Value The value of the environment variable, the buffer
208 shoule be freed by the caller.
209 @param ValueSize The size in bytes of the environment variable
210 including the tailing CHAR_NULL.
211 @param Atts The attributes of the variable.
213 @retval EFI_SUCCESS The command executed successfully.
214 @retval EFI_NOT_FOUND The environment variable is not found in
219 ShellFindEnvVarInList (
220 IN CONST CHAR16
*Key
,
222 OUT UINTN
*ValueSize
,
223 OUT UINT32
*Atts OPTIONAL
227 Add an environment variable into gShellEnvVarList.
229 @param Key The name of the environment variable.
230 @param Value The value of environment variable.
231 @param ValueSize The size in bytes of the environment variable
232 including the tailing CHAR_NULL
233 @param Atts The attributes of the variable.
235 @retval EFI_SUCCESS The environment variable was added to list successfully.
236 @retval others Some errors happened.
240 ShellAddEnvVarToList (
241 IN CONST CHAR16
*Key
,
242 IN CONST CHAR16
*Value
,
248 Remove a specified environment variable in gShellEnvVarList.
250 @param Key The name of the environment variable.
252 @retval EFI_SUCCESS The command executed successfully.
253 @retval EFI_NOT_FOUND The environment variable is not found in
257 ShellRemvoeEnvVarFromList (
262 Initialize the gShellEnvVarList and cache all Shell-Guid-based environment
267 ShellInitEnvVarList (
272 Destructe the gShellEnvVarList.
276 ShellFreeEnvVarList (
280 #endif //_SHELL_ENVIRONMENT_VARIABLE_HEADER_