2 Main file for DmpStore shell Debug1 function.
4 (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "UefiShellDebug1CommandsLib.h"
29 #define DMP_STORE_VARIABLE_SIGNATURE SIGNATURE_32 ('_', 'd', 's', 's')
32 Base on the input attribute value to return the attribute string.
34 @param[in] Atts The input attribute value
36 @retval The attribute string info.
49 if ((Atts
& EFI_VARIABLE_NON_VOLATILE
) != 0) {
50 StrnCatGrow (&RetString
, &BufLen
, L
"+NV", 0);
53 if ((Atts
& EFI_VARIABLE_RUNTIME_ACCESS
) != 0) {
54 StrnCatGrow (&RetString
, &BufLen
, L
"+RT+BS", 0);
55 } else if ((Atts
& EFI_VARIABLE_BOOTSERVICE_ACCESS
) != 0) {
56 StrnCatGrow (&RetString
, &BufLen
, L
"+BS", 0);
59 if ((Atts
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) != 0) {
60 StrnCatGrow (&RetString
, &BufLen
, L
"+HR", 0);
63 if ((Atts
& EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
) != 0) {
64 StrnCatGrow (&RetString
, &BufLen
, L
"+AW", 0);
67 if ((Atts
& EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
) != 0) {
68 StrnCatGrow (&RetString
, &BufLen
, L
"+AT", 0);
71 if (RetString
== NULL
) {
72 RetString
= StrnCatGrow (&RetString
, &BufLen
, L
"Invalid", 0);
75 if ((RetString
!= NULL
) && (RetString
[0] == L
'+')) {
76 CopyMem (RetString
, RetString
+ 1, StrSize (RetString
+ 1));
83 Convert binary to hex format string.
85 @param[in] Buffer The binary data.
86 @param[in] BufferSize The size in bytes of the binary data.
87 @param[in, out] HexString Hex format string.
88 @param[in] HexStringSize The size in bytes of the string.
90 @return The hex format string.
96 IN OUT CHAR16
*HexString
,
97 IN UINTN HexStringSize
103 ASSERT (Buffer
!= NULL
);
104 ASSERT ((BufferSize
* 2 + 1) * sizeof (CHAR16
) <= HexStringSize
);
106 for (Index
= 0, StringIndex
= 0; Index
< BufferSize
; Index
+= 1) {
109 &HexString
[StringIndex
],
110 HexStringSize
- StringIndex
* sizeof (CHAR16
),
112 ((UINT8
*)Buffer
)[Index
]
120 Load the variable data from file and set to variable data base.
122 @param[in] FileHandle The file to be read.
123 @param[in] Name The name of the variables to be loaded.
124 @param[in] Guid The guid of the variables to be loaded.
125 @param[out] Found TRUE when at least one variable was loaded and set.
127 @retval SHELL_DEVICE_ERROR Cannot access the file.
128 @retval SHELL_VOLUME_CORRUPTED The file is in bad format.
129 @retval SHELL_OUT_OF_RESOURCES There is not enough memory to perform the operation.
130 @retval SHELL_SUCCESS Successfully load and set the variables.
133 LoadVariablesFromFile (
134 IN SHELL_FILE_HANDLE FileHandle
,
135 IN CONST CHAR16
*Name
,
136 IN CONST EFI_GUID
*Guid
,
141 SHELL_STATUS ShellStatus
;
149 DMP_STORE_VARIABLE
*Variable
;
155 Status
= ShellGetFileSize (FileHandle
, &FileSize
);
156 if (EFI_ERROR (Status
)) {
157 return SHELL_DEVICE_ERROR
;
160 ShellStatus
= SHELL_SUCCESS
;
162 InitializeListHead (&List
);
165 while (Position
< FileSize
) {
169 BufferSize
= sizeof (NameSize
);
170 Status
= ShellReadFile (FileHandle
, &BufferSize
, &NameSize
);
171 if (EFI_ERROR (Status
) || (BufferSize
!= sizeof (NameSize
))) {
172 ShellStatus
= SHELL_VOLUME_CORRUPTED
;
179 BufferSize
= sizeof (DataSize
);
180 Status
= ShellReadFile (FileHandle
, &BufferSize
, &DataSize
);
181 if (EFI_ERROR (Status
) || (BufferSize
!= sizeof (DataSize
))) {
182 ShellStatus
= SHELL_VOLUME_CORRUPTED
;
187 // Name, Guid, Attributes, Data, Crc32
189 RemainingSize
= NameSize
+ sizeof (EFI_GUID
) + sizeof (UINT32
) + DataSize
+ sizeof (Crc32
);
190 BufferSize
= sizeof (NameSize
) + sizeof (DataSize
) + RemainingSize
;
191 Buffer
= AllocatePool (BufferSize
);
192 if (Buffer
== NULL
) {
193 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
197 BufferSize
= RemainingSize
;
198 Status
= ShellReadFile (FileHandle
, &BufferSize
, (UINT32
*)Buffer
+ 2);
199 if (EFI_ERROR (Status
) || (BufferSize
!= RemainingSize
)) {
200 ShellStatus
= SHELL_VOLUME_CORRUPTED
;
208 *(UINT32
*)Buffer
= NameSize
;
209 *((UINT32
*)Buffer
+ 1) = DataSize
;
210 BufferSize
= RemainingSize
+ sizeof (NameSize
) + sizeof (DataSize
) - sizeof (Crc32
);
211 gBS
->CalculateCrc32 (
216 if (Crc32
!= *(UINT32
*)(Buffer
+ BufferSize
)) {
218 ShellStatus
= SHELL_VOLUME_CORRUPTED
;
222 Position
+= BufferSize
+ sizeof (Crc32
);
224 Variable
= AllocateZeroPool (sizeof (*Variable
) + NameSize
+ DataSize
);
225 if (Variable
== NULL
) {
227 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
231 Variable
->Signature
= DMP_STORE_VARIABLE_SIGNATURE
;
232 Variable
->Name
= (CHAR16
*)(Variable
+ 1);
233 Variable
->DataSize
= DataSize
;
234 Variable
->Data
= (UINT8
*)Variable
->Name
+ NameSize
;
235 CopyMem (Variable
->Name
, Buffer
+ sizeof (NameSize
) + sizeof (DataSize
), NameSize
);
236 CopyMem (&Variable
->Guid
, Buffer
+ sizeof (NameSize
) + sizeof (DataSize
) + NameSize
, sizeof (EFI_GUID
));
237 CopyMem (&Variable
->Attributes
, Buffer
+ sizeof (NameSize
) + sizeof (DataSize
) + NameSize
+ sizeof (EFI_GUID
), sizeof (UINT32
));
238 CopyMem (Variable
->Data
, Buffer
+ sizeof (NameSize
) + sizeof (DataSize
) + NameSize
+ sizeof (EFI_GUID
) + sizeof (UINT32
), DataSize
);
240 InsertTailList (&List
, &Variable
->Link
);
244 if ((Position
!= FileSize
) || (ShellStatus
!= SHELL_SUCCESS
)) {
245 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_LOAD_BAD_FILE
), gShellDebug1HiiHandle
, L
"dmpstore");
246 if (Position
!= FileSize
) {
247 ShellStatus
= SHELL_VOLUME_CORRUPTED
;
251 for ( Link
= GetFirstNode (&List
)
252 ; !IsNull (&List
, Link
) && (ShellStatus
== SHELL_SUCCESS
)
253 ; Link
= GetNextNode (&List
, Link
)
256 Variable
= CR (Link
, DMP_STORE_VARIABLE
, Link
, DMP_STORE_VARIABLE_SIGNATURE
);
258 if (((Name
== NULL
) || gUnicodeCollation
->MetaiMatch (gUnicodeCollation
, Variable
->Name
, (CHAR16
*)Name
)) &&
259 ((Guid
== NULL
) || CompareGuid (&Variable
->Guid
, Guid
))
262 Attributes
= GetAttrType (Variable
->Attributes
);
267 STRING_TOKEN (STR_DMPSTORE_HEADER_LINE
),
268 gShellDebug1HiiHandle
,
274 SHELL_FREE_NON_NULL (Attributes
);
277 Status
= gRT
->SetVariable (
280 Variable
->Attributes
,
284 if (EFI_ERROR (Status
)) {
285 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_LOAD_GEN_FAIL
), gShellDebug1HiiHandle
, L
"dmpstore", Variable
->Name
, Status
);
290 for (Link
= GetFirstNode (&List
); !IsNull (&List
, Link
); ) {
291 Variable
= CR (Link
, DMP_STORE_VARIABLE
, Link
, DMP_STORE_VARIABLE_SIGNATURE
);
292 Link
= RemoveEntryList (&Variable
->Link
);
300 Append one variable to file.
302 @param[in] FileHandle The file to be appended.
303 @param[in] Name The variable name.
304 @param[in] Guid The variable GUID.
305 @param[in] Attributes The variable attributes.
306 @param[in] DataSize The variable data size.
307 @param[in] Data The variable data.
309 @retval EFI_OUT_OF_RESOURCES There is not enough memory to perform the operation.
310 @retval EFI_SUCCESS The variable is appended to file successfully.
311 @retval others Failed to append the variable to file.
314 AppendSingleVariableToFile (
315 IN SHELL_FILE_HANDLE FileHandle
,
316 IN CONST CHAR16
*Name
,
317 IN CONST EFI_GUID
*Guid
,
318 IN UINT32 Attributes
,
329 NameSize
= (UINT32
)StrSize (Name
);
330 BufferSize
= sizeof (NameSize
) + sizeof (DataSize
)
332 + sizeof (Attributes
)
333 + NameSize
+ DataSize
336 Buffer
= AllocatePool (BufferSize
);
337 if (Buffer
== NULL
) {
338 return EFI_OUT_OF_RESOURCES
;
343 // NameSize and DataSize
345 *(UINT32
*)Ptr
= NameSize
;
346 Ptr
+= sizeof (NameSize
);
347 *(UINT32
*)Ptr
= DataSize
;
348 Ptr
+= sizeof (DataSize
);
353 CopyMem (Ptr
, Name
, NameSize
);
359 CopyMem (Ptr
, Guid
, sizeof (*Guid
));
360 Ptr
+= sizeof (*Guid
);
365 *(UINT32
*)Ptr
= Attributes
;
366 Ptr
+= sizeof (Attributes
);
371 CopyMem (Ptr
, Data
, DataSize
);
377 gBS
->CalculateCrc32 (Buffer
, (UINTN
)Ptr
- (UINTN
)Buffer
, (UINT32
*)Ptr
);
379 Status
= ShellWriteFile (FileHandle
, &BufferSize
, Buffer
);
382 if (!EFI_ERROR (Status
) &&
383 (BufferSize
!= sizeof (NameSize
) + sizeof (DataSize
) + sizeof (*Guid
) + sizeof (Attributes
) + NameSize
+ DataSize
+ sizeof (UINT32
))
386 Status
= EFI_DEVICE_ERROR
;
393 Recursive function to display or delete variables.
395 This function will call itself to create a stack-based list of allt he variables to process,
396 then fromt he last to the first, they will do either printing or deleting.
398 This is necessary since once a delete happens GetNextVariableName() will work.
400 @param[in] Name The variable name of the EFI variable (or NULL).
401 @param[in] Guid The GUID of the variable set (or NULL).
402 @param[in] Type The operation type.
403 @param[in] FileHandle The file to operate on (or NULL).
404 @param[in] PrevName The previous variable name from GetNextVariableName. L"" to start.
405 @param[in] FoundVarGuid The previous GUID from GetNextVariableName. ignored at start.
406 @param[in] FoundOne If a VariableName or Guid was specified and one was printed or
407 deleted, then set this to TRUE, otherwise ignored.
408 @param[in] StandardFormatOutput TRUE indicates Standard-Format Output.
410 @retval SHELL_SUCCESS The operation was successful.
411 @retval SHELL_OUT_OF_RESOURCES A memorty allocation failed.
412 @retval SHELL_ABORTED The abort message was received.
413 @retval SHELL_DEVICE_ERROR UEFI Variable Services returned an error.
414 @retval SHELL_NOT_FOUND the Name/Guid pair could not be found.
417 CascadeProcessVariables (
418 IN CONST CHAR16
*Name OPTIONAL
,
419 IN CONST EFI_GUID
*Guid OPTIONAL
,
420 IN DMP_STORE_TYPE Type
,
421 IN EFI_FILE_PROTOCOL
*FileHandle OPTIONAL
,
422 IN CONST CHAR16
*CONST PrevName
,
423 IN EFI_GUID FoundVarGuid
,
424 IN BOOLEAN
*FoundOne
,
425 IN BOOLEAN StandardFormatOutput
429 CHAR16
*FoundVarName
;
433 SHELL_STATUS ShellStatus
;
437 EFI_STATUS SetStatus
;
438 CONST CHAR16
*GuidName
;
440 if (ShellGetExecutionBreakFlag ()) {
441 return (SHELL_ABORTED
);
447 if (PrevName
!= NULL
) {
448 StrnCatGrow (&FoundVarName
, &NameSize
, PrevName
, 0);
450 FoundVarName
= AllocateZeroPool (sizeof (CHAR16
));
451 NameSize
= sizeof (CHAR16
);
454 Status
= gRT
->GetNextVariableName (&NameSize
, FoundVarName
, &FoundVarGuid
);
455 if (Status
== EFI_BUFFER_TOO_SMALL
) {
456 SHELL_FREE_NON_NULL (FoundVarName
);
457 FoundVarName
= AllocateZeroPool (NameSize
);
458 if (FoundVarName
!= NULL
) {
459 if (PrevName
!= NULL
) {
460 StrnCpyS (FoundVarName
, NameSize
/sizeof (CHAR16
), PrevName
, NameSize
/sizeof (CHAR16
) - 1);
463 Status
= gRT
->GetNextVariableName (&NameSize
, FoundVarName
, &FoundVarGuid
);
465 Status
= EFI_OUT_OF_RESOURCES
;
472 if (Status
== EFI_NOT_FOUND
) {
473 SHELL_FREE_NON_NULL (FoundVarName
);
474 return (SHELL_SUCCESS
);
475 } else if (EFI_ERROR (Status
)) {
476 SHELL_FREE_NON_NULL (FoundVarName
);
477 return (SHELL_DEVICE_ERROR
);
481 // Recurse to the next iteration. We know "our" variable's name.
483 ShellStatus
= CascadeProcessVariables (Name
, Guid
, Type
, FileHandle
, FoundVarName
, FoundVarGuid
, FoundOne
, StandardFormatOutput
);
485 if (ShellGetExecutionBreakFlag () || (ShellStatus
== SHELL_ABORTED
)) {
486 SHELL_FREE_NON_NULL (FoundVarName
);
487 return (SHELL_ABORTED
);
491 // No matter what happened we process our own variable
492 // Only continue if Guid and VariableName are each either NULL or a match
494 if ( ( (Name
== NULL
)
495 || gUnicodeCollation
->MetaiMatch (gUnicodeCollation
, FoundVarName
, (CHAR16
*)Name
))
497 || CompareGuid (&FoundVarGuid
, Guid
))
503 // do the print or delete
506 Status
= gRT
->GetVariable (FoundVarName
, &FoundVarGuid
, &Atts
, &DataSize
, DataBuffer
);
507 if (Status
== EFI_BUFFER_TOO_SMALL
) {
508 SHELL_FREE_NON_NULL (DataBuffer
);
509 DataBuffer
= AllocatePool (DataSize
);
510 if (DataBuffer
== NULL
) {
511 Status
= EFI_OUT_OF_RESOURCES
;
513 Status
= gRT
->GetVariable (FoundVarName
, &FoundVarGuid
, &Atts
, &DataSize
, DataBuffer
);
518 // Last error check then print this variable out.
520 if (Type
== DmpStoreDisplay
) {
521 if (!EFI_ERROR (Status
) && (DataBuffer
!= NULL
) && (FoundVarName
!= NULL
)) {
522 AttrString
= GetAttrType (Atts
);
523 if (StandardFormatOutput
) {
524 HexString
= AllocatePool ((DataSize
* 2 + 1) * sizeof (CHAR16
));
525 if (HexString
!= NULL
) {
530 STRING_TOKEN (STR_DMPSTORE_VAR_SFO
),
531 gShellDebug1HiiHandle
,
540 (DataSize
* 2 + 1) * sizeof (CHAR16
)
543 FreePool (HexString
);
545 Status
= EFI_OUT_OF_RESOURCES
;
548 Status
= gEfiShellProtocol
->GetGuidName (&FoundVarGuid
, &GuidName
);
549 if (EFI_ERROR (Status
)) {
554 STRING_TOKEN (STR_DMPSTORE_HEADER_LINE
),
555 gShellDebug1HiiHandle
,
566 STRING_TOKEN (STR_DMPSTORE_HEADER_LINE2
),
567 gShellDebug1HiiHandle
,
575 DumpHex (2, 0, DataSize
, DataBuffer
);
578 SHELL_FREE_NON_NULL (AttrString
);
580 } else if (Type
== DmpStoreSave
) {
581 if (!EFI_ERROR (Status
) && (DataBuffer
!= NULL
) && (FoundVarName
!= NULL
)) {
582 AttrString
= GetAttrType (Atts
);
587 STRING_TOKEN (STR_DMPSTORE_HEADER_LINE
),
588 gShellDebug1HiiHandle
,
594 Status
= AppendSingleVariableToFile (
602 SHELL_FREE_NON_NULL (AttrString
);
604 } else if (Type
== DmpStoreDelete
) {
606 // We only need name to delete it...
608 SetStatus
= gRT
->SetVariable (FoundVarName
, &FoundVarGuid
, Atts
, 0, NULL
);
609 if (StandardFormatOutput
) {
610 if (SetStatus
== EFI_SUCCESS
) {
615 STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_NG_SFO
),
616 gShellDebug1HiiHandle
,
626 STRING_TOKEN (STR_DMPSTORE_DELETE_LINE
),
627 gShellDebug1HiiHandle
,
635 SHELL_FREE_NON_NULL (DataBuffer
);
638 SHELL_FREE_NON_NULL (FoundVarName
);
640 if (Status
== EFI_DEVICE_ERROR
) {
641 ShellStatus
= SHELL_DEVICE_ERROR
;
642 } else if (Status
== EFI_SECURITY_VIOLATION
) {
643 ShellStatus
= SHELL_SECURITY_VIOLATION
;
644 } else if (EFI_ERROR (Status
)) {
645 ShellStatus
= SHELL_NOT_READY
;
648 return (ShellStatus
);
652 Function to display or delete variables. This will set up and call into the recursive function.
654 @param[in] Name The variable name of the EFI variable (or NULL).
655 @param[in] Guid The GUID of the variable set (or NULL).
656 @param[in] Type The operation type.
657 @param[in] FileHandle The file to save or load variables.
658 @param[in] StandardFormatOutput TRUE indicates Standard-Format Output.
660 @retval SHELL_SUCCESS The operation was successful.
661 @retval SHELL_OUT_OF_RESOURCES A memorty allocation failed.
662 @retval SHELL_ABORTED The abort message was received.
663 @retval SHELL_DEVICE_ERROR UEFI Variable Services returned an error.
664 @retval SHELL_NOT_FOUND the Name/Guid pair could not be found.
668 IN CONST CHAR16
*Name OPTIONAL
,
669 IN CONST EFI_GUID
*Guid OPTIONAL
,
670 IN DMP_STORE_TYPE Type
,
671 IN SHELL_FILE_HANDLE FileHandle OPTIONAL
,
672 IN BOOLEAN StandardFormatOutput
675 SHELL_STATUS ShellStatus
;
677 EFI_GUID FoundVarGuid
;
680 ShellStatus
= SHELL_SUCCESS
;
681 ZeroMem (&FoundVarGuid
, sizeof (EFI_GUID
));
683 if (StandardFormatOutput
) {
684 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_SFO_HEADER
), gShellDebug1HiiHandle
, L
"dmpstore");
687 if (Type
== DmpStoreLoad
) {
688 ShellStatus
= LoadVariablesFromFile (FileHandle
, Name
, Guid
, &Found
);
690 ShellStatus
= CascadeProcessVariables (Name
, Guid
, Type
, FileHandle
, NULL
, FoundVarGuid
, &Found
, StandardFormatOutput
);
694 if (ShellStatus
== SHELL_OUT_OF_RESOURCES
) {
695 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_OUT_MEM
), gShellDebug1HiiHandle
, L
"dmpstore");
696 return (ShellStatus
);
697 } else if ((Name
!= NULL
) && (Guid
== NULL
)) {
698 if (StandardFormatOutput
) {
699 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N_SFO
), gShellDebug1HiiHandle
, Name
);
701 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N
), gShellDebug1HiiHandle
, L
"dmpstore", Name
);
703 } else if ((Name
!= NULL
) && (Guid
!= NULL
)) {
704 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_GN
), gShellDebug1HiiHandle
, L
"dmpstore", Guid
, Name
);
705 } else if ((Name
== NULL
) && (Guid
== NULL
)) {
706 if (StandardFormatOutput
) {
707 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_SFO
), gShellDebug1HiiHandle
);
709 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND
), gShellDebug1HiiHandle
, L
"dmpstore");
711 } else if ((Name
== NULL
) && (Guid
!= NULL
)) {
712 if (StandardFormatOutput
) {
713 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_G_SFO
), gShellDebug1HiiHandle
, Guid
);
715 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_G
), gShellDebug1HiiHandle
, L
"dmpstore", Guid
);
719 return (SHELL_NOT_FOUND
);
722 return (ShellStatus
);
725 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
727 { L
"-l", TypeValue
},
728 { L
"-s", TypeValue
},
729 { L
"-all", TypeFlag
},
730 { L
"-guid", TypeValue
},
731 { L
"-sfo", TypeFlag
},
736 Function for 'dmpstore' command.
738 @param[in] ImageHandle Handle to the Image (NULL if Internal).
739 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
743 ShellCommandRunDmpStore (
744 IN EFI_HANDLE ImageHandle
,
745 IN EFI_SYSTEM_TABLE
*SystemTable
749 RETURN_STATUS RStatus
;
751 CHAR16
*ProblemParam
;
752 SHELL_STATUS ShellStatus
;
753 CONST CHAR16
*GuidStr
;
759 SHELL_FILE_HANDLE FileHandle
;
760 EFI_FILE_INFO
*FileInfo
;
761 BOOLEAN StandardFormatOutput
;
763 ShellStatus
= SHELL_SUCCESS
;
767 Type
= DmpStoreDisplay
;
768 StandardFormatOutput
= FALSE
;
770 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
771 if (EFI_ERROR (Status
)) {
772 if ((Status
== EFI_VOLUME_CORRUPTED
) && (ProblemParam
!= NULL
)) {
773 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, L
"dmpstore", ProblemParam
);
774 FreePool (ProblemParam
);
775 ShellStatus
= SHELL_INVALID_PARAMETER
;
780 if (ShellCommandLineGetCount (Package
) > 2) {
781 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
, L
"dmpstore");
782 ShellStatus
= SHELL_INVALID_PARAMETER
;
783 } else if (ShellCommandLineGetFlag (Package
, L
"-all") && ShellCommandLineGetFlag (Package
, L
"-guid")) {
784 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CONFLICT
), gShellDebug1HiiHandle
, L
"dmpstore", L
"-all", L
"-guid");
785 ShellStatus
= SHELL_INVALID_PARAMETER
;
786 } else if (ShellCommandLineGetFlag (Package
, L
"-s") && ShellCommandLineGetFlag (Package
, L
"-l")) {
787 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CONFLICT
), gShellDebug1HiiHandle
, L
"dmpstore", L
"-l", L
"-s");
788 ShellStatus
= SHELL_INVALID_PARAMETER
;
789 } else if ((ShellCommandLineGetFlag (Package
, L
"-s") || ShellCommandLineGetFlag (Package
, L
"-l")) && ShellCommandLineGetFlag (Package
, L
"-d")) {
790 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CONFLICT
), gShellDebug1HiiHandle
, L
"dmpstore", L
"-l or -s", L
"-d");
791 ShellStatus
= SHELL_INVALID_PARAMETER
;
792 } else if ((ShellCommandLineGetFlag (Package
, L
"-s") || ShellCommandLineGetFlag (Package
, L
"-l")) && ShellCommandLineGetFlag (Package
, L
"-sfo")) {
793 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CONFLICT
), gShellDebug1HiiHandle
, L
"dmpstore", L
"-l or -s", L
"-sfo");
794 ShellStatus
= SHELL_INVALID_PARAMETER
;
797 // Determine the GUID to search for based on -all and -guid parameters
799 if (!ShellCommandLineGetFlag (Package
, L
"-all")) {
800 GuidStr
= ShellCommandLineGetValue (Package
, L
"-guid");
801 if (GuidStr
!= NULL
) {
802 RStatus
= StrToGuid (GuidStr
, &GuidData
);
803 if (RETURN_ERROR (RStatus
) || (GuidStr
[GUID_STRING_LENGTH
] != L
'\0')) {
804 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_INV
), gShellDebug1HiiHandle
, L
"dmpstore", GuidStr
);
805 ShellStatus
= SHELL_INVALID_PARAMETER
;
810 Guid
= &gEfiGlobalVariableGuid
;
817 // Get the Name of the variable to find
819 Name
= ShellCommandLineGetRawValue (Package
, 1);
821 if (ShellStatus
== SHELL_SUCCESS
) {
822 if (ShellCommandLineGetFlag (Package
, L
"-s")) {
824 File
= ShellCommandLineGetValue (Package
, L
"-s");
826 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellDebug1HiiHandle
, L
"dmpstore", L
"-s");
827 ShellStatus
= SHELL_INVALID_PARAMETER
;
829 Status
= ShellOpenFileByName (File
, &FileHandle
, EFI_FILE_MODE_WRITE
| EFI_FILE_MODE_READ
, 0);
830 if (!EFI_ERROR (Status
)) {
832 // Delete existing file, but do not delete existing directory
834 FileInfo
= ShellGetFileInfo (FileHandle
);
835 if (FileInfo
== NULL
) {
836 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL
), gShellDebug1HiiHandle
, L
"dmpstore", File
);
837 Status
= EFI_DEVICE_ERROR
;
839 if ((FileInfo
->Attribute
& EFI_FILE_DIRECTORY
) == EFI_FILE_DIRECTORY
) {
840 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_IS_DIRECTORY
), gShellDebug1HiiHandle
, L
"dmpstore", File
);
841 Status
= EFI_INVALID_PARAMETER
;
843 Status
= ShellDeleteFile (&FileHandle
);
844 if (EFI_ERROR (Status
)) {
845 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_DELETE_FAIL
), gShellDebug1HiiHandle
, L
"dmpstore", File
);
851 } else if (Status
== EFI_NOT_FOUND
) {
853 // Good when file doesn't exist
855 Status
= EFI_SUCCESS
;
858 // Otherwise it's bad.
860 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL
), gShellDebug1HiiHandle
, L
"dmpstore", File
);
863 if (!EFI_ERROR (Status
)) {
864 Status
= ShellOpenFileByName (File
, &FileHandle
, EFI_FILE_MODE_CREATE
| EFI_FILE_MODE_WRITE
| EFI_FILE_MODE_READ
, 0);
865 if (EFI_ERROR (Status
)) {
866 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL
), gShellDebug1HiiHandle
, L
"dmpstore", File
);
870 if (EFI_ERROR (Status
)) {
871 ShellStatus
= SHELL_INVALID_PARAMETER
;
874 } else if (ShellCommandLineGetFlag (Package
, L
"-l")) {
876 File
= ShellCommandLineGetValue (Package
, L
"-l");
878 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellDebug1HiiHandle
, L
"dmpstore", L
"-l");
879 ShellStatus
= SHELL_INVALID_PARAMETER
;
881 Status
= ShellOpenFileByName (File
, &FileHandle
, EFI_FILE_MODE_READ
, 0);
882 if (EFI_ERROR (Status
)) {
883 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL
), gShellDebug1HiiHandle
, L
"dmpstore", File
);
884 ShellStatus
= SHELL_INVALID_PARAMETER
;
886 FileInfo
= ShellGetFileInfo (FileHandle
);
887 if (FileInfo
== NULL
) {
888 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL
), gShellDebug1HiiHandle
, L
"dmpstore", File
);
889 ShellStatus
= SHELL_DEVICE_ERROR
;
891 if ((FileInfo
->Attribute
& EFI_FILE_DIRECTORY
) == EFI_FILE_DIRECTORY
) {
892 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_IS_DIRECTORY
), gShellDebug1HiiHandle
, L
"dmpstore", File
);
893 ShellStatus
= SHELL_INVALID_PARAMETER
;
900 } else if (ShellCommandLineGetFlag (Package
, L
"-d")) {
901 Type
= DmpStoreDelete
;
904 if (ShellCommandLineGetFlag (Package
, L
"-sfo")) {
905 StandardFormatOutput
= TRUE
;
909 if (ShellStatus
== SHELL_SUCCESS
) {
910 if (Type
== DmpStoreSave
) {
911 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_SAVE
), gShellDebug1HiiHandle
, File
);
912 } else if (Type
== DmpStoreLoad
) {
913 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_LOAD
), gShellDebug1HiiHandle
, File
);
916 ShellStatus
= ProcessVariables (Name
, Guid
, Type
, FileHandle
, StandardFormatOutput
);
917 if ((Type
== DmpStoreLoad
) || (Type
== DmpStoreSave
)) {
918 ShellCloseFile (&FileHandle
);
924 if (Package
!= NULL
) {
925 ShellCommandLineFreeVarList (Package
);