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 - 2016, Intel Corporation. All rights reserved.<BR>
10 This program and the accompanying materials
11 are licensed and made available under the terms and conditions of the BSD License
12 which accompanies this distribution. The full text of the license may be found at
13 http://opensource.org/licenses/bsd-license.php
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
16 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #ifndef _SHELL_ENVIRONMENT_VARIABLE_HEADER_
21 #define _SHELL_ENVIRONMENT_VARIABLE_HEADER_
31 // The list is used to cache the environment variables.
33 extern ENV_VAR_LIST gShellEnvVarList
;
37 Reports whether an environment variable is Volatile or Non-Volatile.
39 @param EnvVarName The name of the environment variable in question
40 @param Volatile Return TRUE if the environment variable is volatile
42 @retval EFI_SUCCESS The volatile attribute is returned successfully
43 @retval others Some errors happened.
47 IN CONST CHAR16
*EnvVarName
,
52 Delete a Non-Violatile environment variable.
54 This will use the Runtime Services call SetVariable to remove a non-violatile variable.
56 @param EnvVarName The name of the environment variable in question
58 @retval EFI_SUCCESS The variable was deleted sucessfully
59 @retval other An error ocurred
62 #define SHELL_DELETE_ENVIRONMENT_VARIABLE(EnvVarName) \
63 (gRT->SetVariable((CHAR16*)EnvVarName, \
64 &gShellVariableGuid, \
70 Set a Non-Violatile environment variable.
72 This will use the Runtime Services call SetVariable to set a non-violatile variable.
74 @param EnvVarName The name of the environment variable in question
75 @param BufferSize UINTN size of Buffer
76 @param Buffer Pointer to value to set variable to
78 @retval EFI_SUCCESS The variable was changed sucessfully
79 @retval other An error ocurred
82 #define SHELL_SET_ENVIRONMENT_VARIABLE_NV(EnvVarName,BufferSize,Buffer) \
83 (gRT->SetVariable((CHAR16*)EnvVarName, \
84 &gShellVariableGuid, \
85 EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS, \
90 Get an environment variable.
92 This will use the Runtime Services call GetVariable to get a variable.
94 @param EnvVarName The name of the environment variable in question
95 @param BufferSize Pointer to the UINTN size of Buffer
96 @param Buffer Pointer buffer to get variable value into
98 @retval EFI_SUCCESS The variable's value was retrieved sucessfully
99 @retval other An error ocurred
102 #define SHELL_GET_ENVIRONMENT_VARIABLE(EnvVarName,BufferSize,Buffer) \
103 (gRT->GetVariable((CHAR16*)EnvVarName, \
104 &gShellVariableGuid, \
110 Get an environment variable.
112 This will use the Runtime Services call GetVariable to get a variable.
114 @param EnvVarName The name of the environment variable in question
115 @param Atts Pointer to the UINT32 for attributes (or NULL)
116 @param BufferSize Pointer to the UINTN size of Buffer
117 @param Buffer Pointer buffer to get variable value into
119 @retval EFI_SUCCESS The variable's value was retrieved sucessfully
120 @retval other An error ocurred
123 #define SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(EnvVarName,Atts,BufferSize,Buffer) \
124 (gRT->GetVariable((CHAR16*)EnvVarName, \
125 &gShellVariableGuid, \
131 Set a Violatile environment variable.
133 This will use the Runtime Services call SetVariable to set a violatile variable.
135 @param EnvVarName The name of the environment variable in question
136 @param BufferSize UINTN size of Buffer
137 @param Buffer Pointer to value to set variable to
139 @retval EFI_SUCCESS The variable was changed sucessfully
140 @retval other An error ocurred
143 #define SHELL_SET_ENVIRONMENT_VARIABLE_V(EnvVarName,BufferSize,Buffer) \
144 (gRT->SetVariable((CHAR16*)EnvVarName, \
145 &gShellVariableGuid, \
146 EFI_VARIABLE_BOOTSERVICE_ACCESS, \
151 Creates a list of all Shell-Guid-based environment variables.
153 @param[in, out] List The pointer to pointer to LIST_ENTRY object for
156 @retval EFI_SUCCESS the list was created sucessfully.
160 GetEnvironmentVariableList(
161 IN OUT LIST_ENTRY
*List
165 Sets a list of all Shell-Guid-based environment variables. this will
166 also eliminate all pre-existing shell environment variables (even if they
167 are not on the list).
169 This function will also deallocate the memory from List.
171 @param[in] List The pointer to LIST_ENTRY from
172 GetShellEnvVarList().
174 @retval EFI_SUCCESS The list was Set sucessfully.
178 SetEnvironmentVariableList(
183 sets all Shell-Guid-based environment variables. this will
184 also eliminate all pre-existing shell environment variables (even if they
185 are not on the list).
187 @param[in] Environment Points to a NULL-terminated array of environment
188 variables with the format 'x=y', where x is the
189 environment variable name and y is the value.
191 @retval EFI_SUCCESS The command executed successfully.
192 @retval EFI_INVALID_PARAMETER The parameter is invalid.
193 @retval EFI_OUT_OF_RESOURCES Out of resources.
195 @sa SetEnvironmentVariableList
199 SetEnvironmentVariables(
200 IN CONST CHAR16
**Environment
204 free function for ENV_VAR_LIST objects.
206 @param[in] List The pointer to pointer to list.
210 FreeEnvironmentVariableList(
215 Find an environment variable in the gShellEnvVarList.
217 @param Key The name of the environment variable.
218 @param Value The value of the environment variable, the buffer
219 shoule be freed by the caller.
220 @param ValueSize The size in bytes of the environment variable
221 including the tailing CHAR_NULL.
222 @param Atts The attributes of the variable.
224 @retval EFI_SUCCESS The command executed successfully.
225 @retval EFI_NOT_FOUND The environment variable is not found in
230 ShellFindEnvVarInList (
231 IN CONST CHAR16
*Key
,
233 OUT UINTN
*ValueSize
,
234 OUT UINT32
*Atts OPTIONAL
238 Add an environment variable into gShellEnvVarList.
240 @param Key The name of the environment variable.
241 @param Value The value of environment variable.
242 @param ValueSize The size in bytes of the environment variable
243 including the tailing CHAR_NULL
244 @param Atts The attributes of the variable.
246 @retval EFI_SUCCESS The environment variable was added to list successfully.
247 @retval others Some errors happened.
251 ShellAddEnvVarToList (
252 IN CONST CHAR16
*Key
,
253 IN CONST CHAR16
*Value
,
259 Remove a specified environment variable in gShellEnvVarList.
261 @param Key The name of the environment variable.
263 @retval EFI_SUCCESS The command executed successfully.
264 @retval EFI_NOT_FOUND The environment variable is not found in
268 ShellRemvoeEnvVarFromList (
273 Initialize the gShellEnvVarList and cache all Shell-Guid-based environment
278 ShellInitEnvVarList (
283 Destructe the gShellEnvVarList.
287 ShellFreeEnvVarList (
291 #endif //_SHELL_ENVIRONMENT_VARIABLE_HEADER_