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
;
31 Reports whether an environment variable is Volatile or Non-Volatile.
33 @param EnvVarName The name of the environment variable in question
34 @param Volatile Return TRUE if the environment variable is volatile
36 @retval EFI_SUCCESS The volatile attribute is returned successfully
37 @retval others Some errors happened.
41 IN CONST CHAR16
*EnvVarName
,
46 Delete a Non-Violatile environment variable.
48 This will use the Runtime Services call SetVariable to remove a non-violatile variable.
50 @param EnvVarName The name of the environment variable in question
52 @retval EFI_SUCCESS The variable was deleted sucessfully
53 @retval other An error ocurred
56 #define SHELL_DELETE_ENVIRONMENT_VARIABLE(EnvVarName) \
57 (gRT->SetVariable((CHAR16*)EnvVarName, \
58 &gShellVariableGuid, \
64 Set a Non-Violatile environment variable.
66 This will use the Runtime Services call SetVariable to set a non-violatile variable.
68 @param EnvVarName The name of the environment variable in question
69 @param BufferSize UINTN size of Buffer
70 @param Buffer Pointer to value to set variable to
72 @retval EFI_SUCCESS The variable was changed sucessfully
73 @retval other An error ocurred
76 #define SHELL_SET_ENVIRONMENT_VARIABLE_NV(EnvVarName,BufferSize,Buffer) \
77 (gRT->SetVariable((CHAR16*)EnvVarName, \
78 &gShellVariableGuid, \
79 EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS, \
84 Get an environment variable.
86 This will use the Runtime Services call GetVariable to get a variable.
88 @param EnvVarName The name of the environment variable in question
89 @param BufferSize Pointer to the UINTN size of Buffer
90 @param Buffer Pointer buffer to get variable value into
92 @retval EFI_SUCCESS The variable's value was retrieved sucessfully
93 @retval other An error ocurred
96 #define SHELL_GET_ENVIRONMENT_VARIABLE(EnvVarName,BufferSize,Buffer) \
97 (gRT->GetVariable((CHAR16*)EnvVarName, \
98 &gShellVariableGuid, \
104 Get an environment variable.
106 This will use the Runtime Services call GetVariable to get a variable.
108 @param EnvVarName The name of the environment variable in question
109 @param Atts Pointer to the UINT32 for attributes (or NULL)
110 @param BufferSize Pointer to the UINTN size of Buffer
111 @param Buffer Pointer buffer to get variable value into
113 @retval EFI_SUCCESS The variable's value was retrieved sucessfully
114 @retval other An error ocurred
117 #define SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(EnvVarName,Atts,BufferSize,Buffer) \
118 (gRT->GetVariable((CHAR16*)EnvVarName, \
119 &gShellVariableGuid, \
125 Set a Violatile environment variable.
127 This will use the Runtime Services call SetVariable to set a violatile variable.
129 @param EnvVarName The name of the environment variable in question
130 @param BufferSize UINTN size of Buffer
131 @param Buffer Pointer to value to set variable to
133 @retval EFI_SUCCESS The variable was changed sucessfully
134 @retval other An error ocurred
137 #define SHELL_SET_ENVIRONMENT_VARIABLE_V(EnvVarName,BufferSize,Buffer) \
138 (gRT->SetVariable((CHAR16*)EnvVarName, \
139 &gShellVariableGuid, \
140 EFI_VARIABLE_BOOTSERVICE_ACCESS, \
145 Creates a list of all Shell-Guid-based environment variables.
147 @param[in, out] List The pointer to pointer to LIST_ENTRY object for
150 @retval EFI_SUCCESS the list was created sucessfully.
153 GetEnvironmentVariableList(
154 IN OUT LIST_ENTRY
*List
158 Sets a list of all Shell-Guid-based environment variables. this will
159 also eliminate all pre-existing shell environment variables (even if they
160 are not on the list).
162 This function will also deallocate the memory from List.
164 @param[in] List The pointer to LIST_ENTRY from
165 GetShellEnvVarList().
167 @retval EFI_SUCCESS The list was Set sucessfully.
170 SetEnvironmentVariableList(
175 sets all Shell-Guid-based environment variables. this will
176 also eliminate all pre-existing shell environment variables (even if they
177 are not on the list).
179 @param[in] Environment Points to a NULL-terminated array of environment
180 variables with the format 'x=y', where x is the
181 environment variable name and y is the value.
183 @retval EFI_SUCCESS The command executed successfully.
184 @retval EFI_INVALID_PARAMETER The parameter is invalid.
185 @retval EFI_OUT_OF_RESOURCES Out of resources.
187 @sa SetEnvironmentVariableList
190 SetEnvironmentVariables(
191 IN CONST CHAR16
**Environment
195 free function for ENV_VAR_LIST objects.
197 @param[in] List The pointer to pointer to list.
200 FreeEnvironmentVariableList(
205 Find an environment variable in the gShellEnvVarList.
207 @param Key The name of the environment variable.
208 @param Value The value of the environment variable, the buffer
209 shoule be freed by the caller.
210 @param ValueSize The size in bytes of the environment variable
211 including the tailing CHAR_NULL.
212 @param Atts The attributes of the variable.
214 @retval EFI_SUCCESS The command executed successfully.
215 @retval EFI_NOT_FOUND The environment variable is not found in
220 ShellFindEnvVarInList (
221 IN CONST CHAR16
*Key
,
223 OUT UINTN
*ValueSize
,
224 OUT UINT32
*Atts OPTIONAL
228 Add an environment variable into gShellEnvVarList.
230 @param Key The name of the environment variable.
231 @param Value The value of environment variable.
232 @param ValueSize The size in bytes of the environment variable
233 including the tailing CHAR_NULL
234 @param Atts The attributes of the variable.
236 @retval EFI_SUCCESS The environment variable was added to list successfully.
237 @retval others Some errors happened.
241 ShellAddEnvVarToList (
242 IN CONST CHAR16
*Key
,
243 IN CONST CHAR16
*Value
,
249 Remove a specified environment variable in gShellEnvVarList.
251 @param Key The name of the environment variable.
253 @retval EFI_SUCCESS The command executed successfully.
254 @retval EFI_NOT_FOUND The environment variable is not found in
258 ShellRemvoeEnvVarFromList (
263 Initialize the gShellEnvVarList and cache all Shell-Guid-based environment
268 ShellInitEnvVarList (
273 Destructe the gShellEnvVarList.
277 ShellFreeEnvVarList (
281 #endif //_SHELL_ENVIRONMENT_VARIABLE_HEADER_