11#define INIT_NAME_BUFFER_SIZE 128
12#define INIT_DATA_BUFFER_SIZE 1024
39 ASSERT (Volatile !=
NULL);
47 Status =
gRT->GetVariable (
54 if (Status == EFI_BUFFER_TOO_SMALL) {
57 return EFI_OUT_OF_RESOURCES;
60 Status =
gRT->GetVariable (
73 if (Status == EFI_NOT_FOUND) {
78 if (EFI_ERROR (Status)) {
101 ASSERT (List !=
NULL);
111 ASSERT (Node !=
NULL);
113 if (Node->Key !=
NULL) {
117 if (Node->Val !=
NULL) {
138 CHAR16 *VariableName;
140 UINTN NameBufferSize;
147 if (ListHead ==
NULL) {
148 return (EFI_INVALID_PARAMETER);
153 ValBufferSize = INIT_DATA_BUFFER_SIZE;
154 NameBufferSize = INIT_NAME_BUFFER_SIZE;
156 if (VariableName ==
NULL) {
157 return (EFI_OUT_OF_RESOURCES);
160 *VariableName = CHAR_NULL;
162 while (!EFI_ERROR (Status)) {
163 NameSize = NameBufferSize;
164 Status =
gRT->GetNextVariableName (&NameSize, VariableName, &Guid);
165 if (Status == EFI_NOT_FOUND) {
168 }
else if (Status == EFI_BUFFER_TOO_SMALL) {
169 NameBufferSize = NameSize > NameBufferSize * 2 ? NameSize : NameBufferSize * 2;
170 SHELL_FREE_NON_NULL (VariableName);
172 if (VariableName ==
NULL) {
173 Status = EFI_OUT_OF_RESOURCES;
177 NameSize = NameBufferSize;
178 Status =
gRT->GetNextVariableName (&NameSize, VariableName, &Guid);
181 if (!EFI_ERROR (Status) &&
CompareGuid (&Guid, &gShellVariableGuid)) {
183 if (VarList ==
NULL) {
184 Status = EFI_OUT_OF_RESOURCES;
186 ValSize = ValBufferSize;
191 if (VarList->Val ==
NULL) {
192 SHELL_FREE_NON_NULL (VarList);
193 Status = EFI_OUT_OF_RESOURCES;
198 if (Status == EFI_BUFFER_TOO_SMALL) {
199 ValBufferSize = ValSize > ValBufferSize * 2 ? ValSize : ValBufferSize * 2;
200 SHELL_FREE_NON_NULL (VarList->Val);
205 if (VarList->Val ==
NULL) {
206 SHELL_FREE_NON_NULL (VarList);
207 Status = EFI_OUT_OF_RESOURCES;
211 ValSize = ValBufferSize;
215 if (!EFI_ERROR (Status)) {
217 if (VarList->Key ==
NULL) {
218 SHELL_FREE_NON_NULL (VarList->Val);
219 SHELL_FREE_NON_NULL (VarList);
220 Status = EFI_OUT_OF_RESOURCES;
225 SHELL_FREE_NON_NULL (VarList->Val);
226 SHELL_FREE_NON_NULL (VarList);
232 SHELL_FREE_NON_NULL (VariableName);
234 if (EFI_ERROR (Status)) {
272 ; !
IsNull (&VarList.Link, &Node->Link)
276 if (Node->Key !=
NULL) {
289 ; !
IsNull (ListHead, &Node->Link)
293 Size =
StrSize (Node->Val) -
sizeof (CHAR16);
326 CONST CHAR16 *CurrentString;
333 if (Environment ==
NULL) {
334 return (EFI_INVALID_PARAMETER);
340 for ( CurrentCount = 0
345 CurrentString = Environment[CurrentCount];
346 if (CurrentString ==
NULL) {
350 ASSERT (
StrStr (CurrentString, L
"=") !=
NULL);
354 return (EFI_OUT_OF_RESOURCES);
358 if (Node->Key ==
NULL) {
359 SHELL_FREE_NON_NULL (Node);
361 return (EFI_OUT_OF_RESOURCES);
369 StrStr (CurrentString, L
"=") - CurrentString + 1,
371 StrStr (CurrentString, L
"=") - CurrentString
378 if (Node->Val ==
NULL) {
379 SHELL_FREE_NON_NULL (Node->Key);
380 SHELL_FREE_NON_NULL (Node);
382 return (EFI_OUT_OF_RESOURCES);
385 Node->Atts = EFI_VARIABLE_BOOTSERVICE_ACCESS;
387 if (VarList ==
NULL) {
389 if (VarList ==
NULL) {
390 SHELL_FREE_NON_NULL (Node->Key);
391 SHELL_FREE_NON_NULL (Node->Val);
392 SHELL_FREE_NON_NULL (Node);
393 return (EFI_OUT_OF_RESOURCES);
430 OUT UINT32 *Atts OPTIONAL
435 if ((Key ==
NULL) || (Value ==
NULL) || (ValueSize ==
NULL)) {
440 ; !
IsNull (&gShellEnvVarList.Link, &Node->Link)
444 if ((Node->Key !=
NULL) && (
StrCmp (Key, Node->Key) == 0)) {
446 *ValueSize =
StrSize (Node->Val);
455 return EFI_NOT_FOUND;
483 if ((Key ==
NULL) || (Value ==
NULL) || (ValueSize == 0)) {
484 return EFI_INVALID_PARAMETER;
488 if (LocalValue ==
NULL) {
489 return EFI_OUT_OF_RESOURCES;
496 ; !
IsNull (&gShellEnvVarList.Link, &Node->Link)
500 if ((Node->Key !=
NULL) && (
StrCmp (Key, Node->Key) == 0)) {
502 SHELL_FREE_NON_NULL (Node->Val);
503 Node->Val = LocalValue;
513 if (LocalKey ==
NULL) {
515 return EFI_OUT_OF_RESOURCES;
522 return EFI_OUT_OF_RESOURCES;
525 Node->Key = LocalKey;
526 Node->Val = LocalValue;
550 return EFI_INVALID_PARAMETER;
554 ; !
IsNull (&gShellEnvVarList.Link, &Node->Link)
558 if ((Node->Key !=
NULL) && (
StrCmp (Key, Node->Key) == 0)) {
559 SHELL_FREE_NON_NULL (Node->Key);
560 SHELL_FREE_NON_NULL (Node->Val);
562 SHELL_FREE_NON_NULL (Node);
567 return EFI_NOT_FOUND;
BOOLEAN EFIAPI IsNull(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
LIST_ENTRY *EFIAPI GetNextNode(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
LIST_ENTRY *EFIAPI GetFirstNode(IN CONST LIST_ENTRY *List)
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
RETURN_STATUS EFIAPI StrnCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source, IN UINTN Length)
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
CHAR16 *EFIAPI StrStr(IN CONST CHAR16 *String, IN CONST CHAR16 *SearchString)
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
EFI_RUNTIME_SERVICES * gRT
#define ASSERT_EFI_ERROR(StatusParameter)
@ SHELL_INVALID_PARAMETER
EFI_STATUS ShellFindEnvVarInList(IN CONST CHAR16 *Key, OUT CHAR16 **Value, OUT UINTN *ValueSize, OUT UINT32 *Atts OPTIONAL)
EFI_STATUS ShellInitEnvVarList(VOID)
EFI_STATUS IsVolatileEnv(IN CONST CHAR16 *EnvVarName, OUT BOOLEAN *Volatile)
EFI_STATUS GetEnvironmentVariableList(IN OUT LIST_ENTRY *ListHead)
EFI_STATUS ShellAddEnvVarToList(IN CONST CHAR16 *Key, IN CONST CHAR16 *Value, IN UINTN ValueSize, IN UINT32 Atts)
EFI_STATUS ShellRemvoeEnvVarFromList(IN CONST CHAR16 *Key)
VOID FreeEnvironmentVariableList(IN LIST_ENTRY *List)
EFI_STATUS SetEnvironmentVariableList(IN LIST_ENTRY *ListHead)
VOID ShellFreeEnvVarList(VOID)
EFI_STATUS SetEnvironmentVariables(IN CONST CHAR16 **Environment)
#define SHELL_SET_ENVIRONMENT_VARIABLE_NV(EnvVarName, BufferSize, Buffer)
#define SHELL_DELETE_ENVIRONMENT_VARIABLE(EnvVarName)
#define SHELL_SET_ENVIRONMENT_VARIABLE_V(EnvVarName, BufferSize, Buffer)
#define SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(EnvVarName, Atts, BufferSize, Buffer)
#define EFI_VARIABLE_NON_VOLATILE