TianoCore EDK2 master
Loading...
Searching...
No Matches
DmpStore.c
Go to the documentation of this file.
1
11
12typedef enum {
13 DmpStoreDisplay,
14 DmpStoreDelete,
15 DmpStoreSave,
16 DmpStoreLoad
17} DMP_STORE_TYPE;
18
19typedef struct {
20 UINT32 Signature;
21 CHAR16 *Name;
22 EFI_GUID Guid;
23 UINT32 Attributes;
24 UINT32 DataSize;
25 UINT8 *Data;
26 LIST_ENTRY Link;
28
29#define DMP_STORE_VARIABLE_SIGNATURE SIGNATURE_32 ('_', 'd', 's', 's')
30
38CHAR16 *
40 IN CONST UINT32 Atts
41 )
42{
43 UINTN BufLen;
44 CHAR16 *RetString;
45
46 BufLen = 0;
47 RetString = NULL;
48
49 if ((Atts & EFI_VARIABLE_NON_VOLATILE) != 0) {
50 StrnCatGrow (&RetString, &BufLen, L"+NV", 0);
51 }
52
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);
57 }
58
59 if ((Atts & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != 0) {
60 StrnCatGrow (&RetString, &BufLen, L"+HR", 0);
61 }
62
64 StrnCatGrow (&RetString, &BufLen, L"+AW", 0);
65 }
66
68 StrnCatGrow (&RetString, &BufLen, L"+AT", 0);
69 }
70
71 if (RetString == NULL) {
72 RetString = StrnCatGrow (&RetString, &BufLen, L"Invalid", 0);
73 }
74
75 if ((RetString != NULL) && (RetString[0] == L'+')) {
76 CopyMem (RetString, RetString + 1, StrSize (RetString + 1));
77 }
78
79 return RetString;
80}
81
92CHAR16 *
94 IN VOID *Buffer,
95 IN UINTN BufferSize,
96 IN OUT CHAR16 *HexString,
97 IN UINTN HexStringSize
98 )
99{
100 UINTN Index;
101 UINTN StringIndex;
102
103 ASSERT (Buffer != NULL);
104 ASSERT ((BufferSize * 2 + 1) * sizeof (CHAR16) <= HexStringSize);
105
106 for (Index = 0, StringIndex = 0; Index < BufferSize; Index += 1) {
107 StringIndex +=
109 &HexString[StringIndex],
110 HexStringSize - StringIndex * sizeof (CHAR16),
111 L"%02x",
112 ((UINT8 *)Buffer)[Index]
113 );
114 }
115
116 return HexString;
117}
118
134 IN SHELL_FILE_HANDLE FileHandle,
135 IN CONST CHAR16 *Name,
136 IN CONST EFI_GUID *Guid,
137 OUT BOOLEAN *Found
138 )
139{
140 EFI_STATUS Status;
141 SHELL_STATUS ShellStatus;
142 UINT32 NameSize;
143 UINT32 DataSize;
144 UINTN BufferSize;
145 UINTN RemainingSize;
146 UINT64 Position;
147 UINT64 FileSize;
148 LIST_ENTRY List;
149 DMP_STORE_VARIABLE *Variable;
150 LIST_ENTRY *Link;
151 CHAR16 *Attributes;
152 UINT8 *Buffer;
153 UINT32 Crc32;
154
155 Status = ShellGetFileSize (FileHandle, &FileSize);
156 if (EFI_ERROR (Status)) {
157 return SHELL_DEVICE_ERROR;
158 }
159
160 ShellStatus = SHELL_SUCCESS;
161
162 InitializeListHead (&List);
163
164 Position = 0;
165 while (Position < FileSize) {
166 //
167 // NameSize
168 //
169 BufferSize = sizeof (NameSize);
170 Status = ShellReadFile (FileHandle, &BufferSize, &NameSize);
171 if (EFI_ERROR (Status) || (BufferSize != sizeof (NameSize))) {
172 ShellStatus = SHELL_VOLUME_CORRUPTED;
173 break;
174 }
175
176 //
177 // DataSize
178 //
179 BufferSize = sizeof (DataSize);
180 Status = ShellReadFile (FileHandle, &BufferSize, &DataSize);
181 if (EFI_ERROR (Status) || (BufferSize != sizeof (DataSize))) {
182 ShellStatus = SHELL_VOLUME_CORRUPTED;
183 break;
184 }
185
186 //
187 // Name, Guid, Attributes, Data, Crc32
188 //
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;
194 break;
195 }
196
197 BufferSize = RemainingSize;
198 Status = ShellReadFile (FileHandle, &BufferSize, (UINT32 *)Buffer + 2);
199 if (EFI_ERROR (Status) || (BufferSize != RemainingSize)) {
200 ShellStatus = SHELL_VOLUME_CORRUPTED;
201 FreePool (Buffer);
202 break;
203 }
204
205 //
206 // Check Crc32
207 //
208 *(UINT32 *)Buffer = NameSize;
209 *((UINT32 *)Buffer + 1) = DataSize;
210 BufferSize = RemainingSize + sizeof (NameSize) + sizeof (DataSize) - sizeof (Crc32);
211 gBS->CalculateCrc32 (
212 Buffer,
213 BufferSize,
214 &Crc32
215 );
216 if (Crc32 != *(UINT32 *)(Buffer + BufferSize)) {
217 FreePool (Buffer);
218 ShellStatus = SHELL_VOLUME_CORRUPTED;
219 break;
220 }
221
222 Position += BufferSize + sizeof (Crc32);
223
224 Variable = AllocateZeroPool (sizeof (*Variable) + NameSize + DataSize);
225 if (Variable == NULL) {
226 FreePool (Buffer);
227 ShellStatus = SHELL_OUT_OF_RESOURCES;
228 break;
229 }
230
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);
239
240 InsertTailList (&List, &Variable->Link);
241 FreePool (Buffer);
242 }
243
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;
248 }
249 }
250
251 for ( Link = GetFirstNode (&List)
252 ; !IsNull (&List, Link) && (ShellStatus == SHELL_SUCCESS)
253 ; Link = GetNextNode (&List, Link)
254 )
255 {
256 Variable = CR (Link, DMP_STORE_VARIABLE, Link, DMP_STORE_VARIABLE_SIGNATURE);
257
258 if (((Name == NULL) || gUnicodeCollation->MetaiMatch (gUnicodeCollation, Variable->Name, (CHAR16 *)Name)) &&
259 ((Guid == NULL) || CompareGuid (&Variable->Guid, Guid))
260 )
261 {
262 Attributes = GetAttrType (Variable->Attributes);
264 -1,
265 -1,
266 NULL,
267 STRING_TOKEN (STR_DMPSTORE_HEADER_LINE),
268 gShellDebug1HiiHandle,
269 Attributes,
270 &Variable->Guid,
271 Variable->Name,
272 Variable->DataSize
273 );
274 SHELL_FREE_NON_NULL (Attributes);
275
276 *Found = TRUE;
277 Status = gRT->SetVariable (
278 Variable->Name,
279 &Variable->Guid,
280 Variable->Attributes,
281 Variable->DataSize,
282 Variable->Data
283 );
284 if (EFI_ERROR (Status)) {
285 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_LOAD_GEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", Variable->Name, Status);
286 }
287 }
288 }
289
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);
293 FreePool (Variable);
294 }
295
296 return ShellStatus;
297}
298
315 IN SHELL_FILE_HANDLE FileHandle,
316 IN CONST CHAR16 *Name,
317 IN CONST EFI_GUID *Guid,
318 IN UINT32 Attributes,
319 IN UINT32 DataSize,
320 IN CONST UINT8 *Data
321 )
322{
323 UINT32 NameSize;
324 UINT8 *Buffer;
325 UINT8 *Ptr;
326 UINTN BufferSize;
327 EFI_STATUS Status;
328
329 NameSize = (UINT32)StrSize (Name);
330 BufferSize = sizeof (NameSize) + sizeof (DataSize)
331 + sizeof (*Guid)
332 + sizeof (Attributes)
333 + NameSize + DataSize
334 + sizeof (UINT32);
335
336 Buffer = AllocatePool (BufferSize);
337 if (Buffer == NULL) {
338 return EFI_OUT_OF_RESOURCES;
339 }
340
341 Ptr = Buffer;
342 //
343 // NameSize and DataSize
344 //
345 *(UINT32 *)Ptr = NameSize;
346 Ptr += sizeof (NameSize);
347 *(UINT32 *)Ptr = DataSize;
348 Ptr += sizeof (DataSize);
349
350 //
351 // Name
352 //
353 CopyMem (Ptr, Name, NameSize);
354 Ptr += NameSize;
355
356 //
357 // Guid
358 //
359 CopyMem (Ptr, Guid, sizeof (*Guid));
360 Ptr += sizeof (*Guid);
361
362 //
363 // Attributes
364 //
365 *(UINT32 *)Ptr = Attributes;
366 Ptr += sizeof (Attributes);
367
368 //
369 // Data
370 //
371 CopyMem (Ptr, Data, DataSize);
372 Ptr += DataSize;
373
374 //
375 // Crc32
376 //
377 gBS->CalculateCrc32 (Buffer, (UINTN)Ptr - (UINTN)Buffer, (UINT32 *)Ptr);
378
379 Status = ShellWriteFile (FileHandle, &BufferSize, Buffer);
380 FreePool (Buffer);
381
382 if (!EFI_ERROR (Status) &&
383 (BufferSize != sizeof (NameSize) + sizeof (DataSize) + sizeof (*Guid) + sizeof (Attributes) + NameSize + DataSize + sizeof (UINT32))
384 )
385 {
386 Status = EFI_DEVICE_ERROR;
387 }
388
389 return Status;
390}
391
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
426 )
427{
428 EFI_STATUS Status;
429 CHAR16 *FoundVarName;
430 UINT8 *DataBuffer;
431 UINTN DataSize;
432 UINT32 Atts;
433 SHELL_STATUS ShellStatus;
434 UINTN NameSize;
435 CHAR16 *AttrString;
436 CHAR16 *HexString;
437 EFI_STATUS SetStatus;
438 CONST CHAR16 *GuidName;
439
441 return (SHELL_ABORTED);
442 }
443
444 NameSize = 0;
445 FoundVarName = NULL;
446
447 if (PrevName != NULL) {
448 StrnCatGrow (&FoundVarName, &NameSize, PrevName, 0);
449 } else {
450 FoundVarName = AllocateZeroPool (sizeof (CHAR16));
451 if (FoundVarName == NULL) {
452 return (SHELL_OUT_OF_RESOURCES);
453 }
454
455 NameSize = sizeof (CHAR16);
456 }
457
458 Status = gRT->GetNextVariableName (&NameSize, FoundVarName, &FoundVarGuid);
459 if (Status == EFI_BUFFER_TOO_SMALL) {
460 SHELL_FREE_NON_NULL (FoundVarName);
461 FoundVarName = AllocateZeroPool (NameSize);
462 if (FoundVarName != NULL) {
463 if (PrevName != NULL) {
464 StrnCpyS (FoundVarName, NameSize/sizeof (CHAR16), PrevName, NameSize/sizeof (CHAR16) - 1);
465 }
466
467 Status = gRT->GetNextVariableName (&NameSize, FoundVarName, &FoundVarGuid);
468 } else {
469 Status = EFI_OUT_OF_RESOURCES;
470 }
471 }
472
473 //
474 // No more is fine.
475 //
476 if (Status == EFI_NOT_FOUND) {
477 SHELL_FREE_NON_NULL (FoundVarName);
478 return (SHELL_SUCCESS);
479 } else if (EFI_ERROR (Status)) {
480 SHELL_FREE_NON_NULL (FoundVarName);
481 return (SHELL_DEVICE_ERROR);
482 }
483
484 //
485 // Recurse to the next iteration. We know "our" variable's name.
486 //
487 ShellStatus = CascadeProcessVariables (Name, Guid, Type, FileHandle, FoundVarName, FoundVarGuid, FoundOne, StandardFormatOutput);
488
489 if (ShellGetExecutionBreakFlag () || (ShellStatus == SHELL_ABORTED)) {
490 SHELL_FREE_NON_NULL (FoundVarName);
491 return (SHELL_ABORTED);
492 }
493
494 //
495 // No matter what happened we process our own variable
496 // Only continue if Guid and VariableName are each either NULL or a match
497 //
498 if ( ( (Name == NULL)
499 || gUnicodeCollation->MetaiMatch (gUnicodeCollation, FoundVarName, (CHAR16 *)Name))
500 && ( (Guid == NULL)
501 || CompareGuid (&FoundVarGuid, Guid))
502 )
503 {
504 DataSize = 0;
505 DataBuffer = NULL;
506 //
507 // do the print or delete
508 //
509 *FoundOne = TRUE;
510 Status = gRT->GetVariable (FoundVarName, &FoundVarGuid, &Atts, &DataSize, DataBuffer);
511 if (Status == EFI_BUFFER_TOO_SMALL) {
512 SHELL_FREE_NON_NULL (DataBuffer);
513 DataBuffer = AllocatePool (DataSize);
514 if (DataBuffer == NULL) {
515 Status = EFI_OUT_OF_RESOURCES;
516 } else {
517 Status = gRT->GetVariable (FoundVarName, &FoundVarGuid, &Atts, &DataSize, DataBuffer);
518 }
519 }
520
521 //
522 // Last error check then print this variable out.
523 //
524 if (Type == DmpStoreDisplay) {
525 if (!EFI_ERROR (Status) && (DataBuffer != NULL) && (FoundVarName != NULL)) {
526 AttrString = GetAttrType (Atts);
527 if (StandardFormatOutput) {
528 HexString = AllocatePool ((DataSize * 2 + 1) * sizeof (CHAR16));
529 if (HexString != NULL) {
531 -1,
532 -1,
533 NULL,
534 STRING_TOKEN (STR_DMPSTORE_VAR_SFO),
535 gShellDebug1HiiHandle,
536 FoundVarName,
537 &FoundVarGuid,
538 Atts,
539 DataSize,
541 DataBuffer,
542 DataSize,
543 HexString,
544 (DataSize * 2 + 1) * sizeof (CHAR16)
545 )
546 );
547 FreePool (HexString);
548 } else {
549 Status = EFI_OUT_OF_RESOURCES;
550 }
551 } else {
552 Status = gEfiShellProtocol->GetGuidName (&FoundVarGuid, &GuidName);
553 if (EFI_ERROR (Status)) {
555 -1,
556 -1,
557 NULL,
558 STRING_TOKEN (STR_DMPSTORE_HEADER_LINE),
559 gShellDebug1HiiHandle,
560 AttrString,
561 &FoundVarGuid,
562 FoundVarName,
563 DataSize
564 );
565 } else {
567 -1,
568 -1,
569 NULL,
570 STRING_TOKEN (STR_DMPSTORE_HEADER_LINE2),
571 gShellDebug1HiiHandle,
572 AttrString,
573 GuidName,
574 FoundVarName,
575 DataSize
576 );
577 }
578
579 DumpHex (2, 0, DataSize, DataBuffer);
580 }
581
582 SHELL_FREE_NON_NULL (AttrString);
583 }
584 } else if (Type == DmpStoreSave) {
585 if (!EFI_ERROR (Status) && (DataBuffer != NULL) && (FoundVarName != NULL)) {
586 AttrString = GetAttrType (Atts);
588 -1,
589 -1,
590 NULL,
591 STRING_TOKEN (STR_DMPSTORE_HEADER_LINE),
592 gShellDebug1HiiHandle,
593 AttrString,
594 &FoundVarGuid,
595 FoundVarName,
596 DataSize
597 );
599 FileHandle,
600 FoundVarName,
601 &FoundVarGuid,
602 Atts,
603 (UINT32)DataSize,
604 DataBuffer
605 );
606 SHELL_FREE_NON_NULL (AttrString);
607 }
608 } else if (Type == DmpStoreDelete) {
609 //
610 // We only need name to delete it...
611 //
612 SetStatus = gRT->SetVariable (FoundVarName, &FoundVarGuid, Atts, 0, NULL);
613 if (StandardFormatOutput) {
614 if (SetStatus == EFI_SUCCESS) {
616 -1,
617 -1,
618 NULL,
619 STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_NG_SFO),
620 gShellDebug1HiiHandle,
621 FoundVarName,
622 &FoundVarGuid
623 );
624 }
625 } else {
627 -1,
628 -1,
629 NULL,
630 STRING_TOKEN (STR_DMPSTORE_DELETE_LINE),
631 gShellDebug1HiiHandle,
632 &FoundVarGuid,
633 FoundVarName,
634 SetStatus
635 );
636 }
637 }
638
639 SHELL_FREE_NON_NULL (DataBuffer);
640 }
641
642 SHELL_FREE_NON_NULL (FoundVarName);
643
644 if (Status == EFI_DEVICE_ERROR) {
645 ShellStatus = SHELL_DEVICE_ERROR;
646 } else if (Status == EFI_SECURITY_VIOLATION) {
647 ShellStatus = SHELL_SECURITY_VIOLATION;
648 } else if (EFI_ERROR (Status)) {
649 ShellStatus = SHELL_NOT_READY;
650 }
651
652 return (ShellStatus);
653}
654
672 IN CONST CHAR16 *Name OPTIONAL,
673 IN CONST EFI_GUID *Guid OPTIONAL,
674 IN DMP_STORE_TYPE Type,
675 IN SHELL_FILE_HANDLE FileHandle OPTIONAL,
676 IN BOOLEAN StandardFormatOutput
677 )
678{
679 SHELL_STATUS ShellStatus;
680 BOOLEAN Found;
681 EFI_GUID FoundVarGuid;
682
683 Found = FALSE;
684 ShellStatus = SHELL_SUCCESS;
685 ZeroMem (&FoundVarGuid, sizeof (EFI_GUID));
686
687 if (StandardFormatOutput) {
688 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_SFO_HEADER), gShellDebug1HiiHandle, L"dmpstore");
689 }
690
691 if (Type == DmpStoreLoad) {
692 ShellStatus = LoadVariablesFromFile (FileHandle, Name, Guid, &Found);
693 } else {
694 ShellStatus = CascadeProcessVariables (Name, Guid, Type, FileHandle, NULL, FoundVarGuid, &Found, StandardFormatOutput);
695 }
696
697 if (!Found) {
698 if (ShellStatus == SHELL_OUT_OF_RESOURCES) {
699 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"dmpstore");
700 return (ShellStatus);
701 } else if ((Name != NULL) && (Guid == NULL)) {
702 if (StandardFormatOutput) {
703 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N_SFO), gShellDebug1HiiHandle, Name);
704 } else {
705 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N), gShellDebug1HiiHandle, L"dmpstore", Name);
706 }
707 } else if ((Name != NULL) && (Guid != NULL)) {
708 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_GN), gShellDebug1HiiHandle, L"dmpstore", Guid, Name);
709 } else if ((Name == NULL) && (Guid == NULL)) {
710 if (StandardFormatOutput) {
711 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_SFO), gShellDebug1HiiHandle);
712 } else {
713 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND), gShellDebug1HiiHandle, L"dmpstore");
714 }
715 } else if ((Name == NULL) && (Guid != NULL)) {
716 if (StandardFormatOutput) {
717 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_G_SFO), gShellDebug1HiiHandle, Guid);
718 } else {
719 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_G), gShellDebug1HiiHandle, L"dmpstore", Guid);
720 }
721 }
722
723 return (SHELL_NOT_FOUND);
724 }
725
726 return (ShellStatus);
727}
728
729STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
730 { L"-d", TypeFlag },
731 { L"-l", TypeValue },
732 { L"-s", TypeValue },
733 { L"-all", TypeFlag },
734 { L"-guid", TypeValue },
735 { L"-sfo", TypeFlag },
736 { NULL, TypeMax }
737};
738
746EFIAPI
748 IN EFI_HANDLE ImageHandle,
749 IN EFI_SYSTEM_TABLE *SystemTable
750 )
751{
752 EFI_STATUS Status;
753 RETURN_STATUS RStatus;
754 LIST_ENTRY *Package;
755 CHAR16 *ProblemParam;
756 SHELL_STATUS ShellStatus;
757 CONST CHAR16 *GuidStr;
758 CONST CHAR16 *File;
759 EFI_GUID *Guid;
760 EFI_GUID GuidData;
761 CONST CHAR16 *Name;
762 DMP_STORE_TYPE Type;
763 SHELL_FILE_HANDLE FileHandle;
765 BOOLEAN StandardFormatOutput;
766
767 ShellStatus = SHELL_SUCCESS;
768 Package = NULL;
769 FileHandle = NULL;
770 File = NULL;
771 Type = DmpStoreDisplay;
772 StandardFormatOutput = FALSE;
773
774 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
775 if (EFI_ERROR (Status)) {
776 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
777 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"dmpstore", ProblemParam);
778 FreePool (ProblemParam);
779 ShellStatus = SHELL_INVALID_PARAMETER;
780 } else {
781 ASSERT (FALSE);
782 }
783 } else {
784 if (ShellCommandLineGetCount (Package) > 2) {
785 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"dmpstore");
786 ShellStatus = SHELL_INVALID_PARAMETER;
787 } else if (ShellCommandLineGetFlag (Package, L"-all") && ShellCommandLineGetFlag (Package, L"-guid")) {
788 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-all", L"-guid");
789 ShellStatus = SHELL_INVALID_PARAMETER;
790 } else if (ShellCommandLineGetFlag (Package, L"-s") && ShellCommandLineGetFlag (Package, L"-l")) {
791 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-l", L"-s");
792 ShellStatus = SHELL_INVALID_PARAMETER;
793 } else if ((ShellCommandLineGetFlag (Package, L"-s") || ShellCommandLineGetFlag (Package, L"-l")) && ShellCommandLineGetFlag (Package, L"-d")) {
794 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-l or -s", L"-d");
795 ShellStatus = SHELL_INVALID_PARAMETER;
796 } else if ((ShellCommandLineGetFlag (Package, L"-s") || ShellCommandLineGetFlag (Package, L"-l")) && ShellCommandLineGetFlag (Package, L"-sfo")) {
797 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"dmpstore", L"-l or -s", L"-sfo");
798 ShellStatus = SHELL_INVALID_PARAMETER;
799 } else {
800 //
801 // Determine the GUID to search for based on -all and -guid parameters
802 //
803 if (!ShellCommandLineGetFlag (Package, L"-all")) {
804 GuidStr = ShellCommandLineGetValue (Package, L"-guid");
805 if (GuidStr != NULL) {
806 RStatus = StrToGuid (GuidStr, &GuidData);
807 if (RETURN_ERROR (RStatus) || (GuidStr[GUID_STRING_LENGTH] != L'\0')) {
808 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmpstore", GuidStr);
809 ShellStatus = SHELL_INVALID_PARAMETER;
810 }
811
812 Guid = &GuidData;
813 } else {
814 Guid = &gEfiGlobalVariableGuid;
815 }
816 } else {
817 Guid = NULL;
818 }
819
820 //
821 // Get the Name of the variable to find
822 //
823 Name = ShellCommandLineGetRawValue (Package, 1);
824
825 if (ShellStatus == SHELL_SUCCESS) {
826 if (ShellCommandLineGetFlag (Package, L"-s")) {
827 Type = DmpStoreSave;
828 File = ShellCommandLineGetValue (Package, L"-s");
829 if (File == NULL) {
830 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"dmpstore", L"-s");
831 ShellStatus = SHELL_INVALID_PARAMETER;
832 } else {
833 Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ, 0);
834 if (!EFI_ERROR (Status)) {
835 //
836 // Delete existing file, but do not delete existing directory
837 //
838 FileInfo = ShellGetFileInfo (FileHandle);
839 if (FileInfo == NULL) {
840 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File);
841 Status = EFI_DEVICE_ERROR;
842 } else {
843 if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) {
844 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_IS_DIRECTORY), gShellDebug1HiiHandle, L"dmpstore", File);
845 Status = EFI_INVALID_PARAMETER;
846 } else {
847 Status = ShellDeleteFile (&FileHandle);
848 if (EFI_ERROR (Status)) {
849 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_DELETE_FAIL), gShellDebug1HiiHandle, L"dmpstore", File);
850 }
851 }
852
854 }
855 } else if (Status == EFI_NOT_FOUND) {
856 //
857 // Good when file doesn't exist
858 //
859 Status = EFI_SUCCESS;
860 } else {
861 //
862 // Otherwise it's bad.
863 //
864 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File);
865 }
866
867 if (!EFI_ERROR (Status)) {
868 Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_CREATE | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ, 0);
869 if (EFI_ERROR (Status)) {
870 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File);
871 }
872 }
873
874 if (EFI_ERROR (Status)) {
875 ShellStatus = SHELL_INVALID_PARAMETER;
876 }
877 }
878 } else if (ShellCommandLineGetFlag (Package, L"-l")) {
879 Type = DmpStoreLoad;
880 File = ShellCommandLineGetValue (Package, L"-l");
881 if (File == NULL) {
882 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"dmpstore", L"-l");
883 ShellStatus = SHELL_INVALID_PARAMETER;
884 } else {
885 Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_READ, 0);
886 if (EFI_ERROR (Status)) {
887 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File);
888 ShellStatus = SHELL_INVALID_PARAMETER;
889 } else {
890 FileInfo = ShellGetFileInfo (FileHandle);
891 if (FileInfo == NULL) {
892 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"dmpstore", File);
893 ShellStatus = SHELL_DEVICE_ERROR;
894 } else {
895 if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) {
896 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_IS_DIRECTORY), gShellDebug1HiiHandle, L"dmpstore", File);
897 ShellStatus = SHELL_INVALID_PARAMETER;
898 }
899
901 }
902 }
903 }
904 } else if (ShellCommandLineGetFlag (Package, L"-d")) {
905 Type = DmpStoreDelete;
906 }
907
908 if (ShellCommandLineGetFlag (Package, L"-sfo")) {
909 StandardFormatOutput = TRUE;
910 }
911 }
912
913 if (ShellStatus == SHELL_SUCCESS) {
914 if (Type == DmpStoreSave) {
915 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_SAVE), gShellDebug1HiiHandle, File);
916 } else if (Type == DmpStoreLoad) {
917 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_LOAD), gShellDebug1HiiHandle, File);
918 }
919
920 ShellStatus = ProcessVariables (Name, Guid, Type, FileHandle, StandardFormatOutput);
921 if ((Type == DmpStoreLoad) || (Type == DmpStoreSave)) {
922 ShellCloseFile (&FileHandle);
923 }
924 }
925 }
926 }
927
928 if (Package != NULL) {
930 }
931
932 return ShellStatus;
933}
UINT64 UINTN
BOOLEAN EFIAPI IsNull(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
Definition: LinkedList.c:443
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
LIST_ENTRY *EFIAPI GetNextNode(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
Definition: LinkedList.c:333
LIST_ENTRY *EFIAPI GetFirstNode(IN CONST LIST_ENTRY *List)
Definition: LinkedList.c:298
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
Definition: LinkedList.c:590
RETURN_STATUS EFIAPI StrToGuid(IN CONST CHAR16 *String, OUT GUID *Guid)
Definition: SafeString.c:1500
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
Definition: LinkedList.c:182
RETURN_STATUS EFIAPI StrnCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source, IN UINTN Length)
Definition: SafeString.c:310
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
Definition: LinkedList.c:259
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
CHAR16 * GetAttrType(IN CONST UINT32 Atts)
Definition: DmpStore.c:39
SHELL_STATUS CascadeProcessVariables(IN CONST CHAR16 *Name OPTIONAL, IN CONST EFI_GUID *Guid OPTIONAL, IN DMP_STORE_TYPE Type, IN EFI_FILE_PROTOCOL *FileHandle OPTIONAL, IN CONST CHAR16 *CONST PrevName, IN EFI_GUID FoundVarGuid, IN BOOLEAN *FoundOne, IN BOOLEAN StandardFormatOutput)
Definition: DmpStore.c:417
SHELL_STATUS LoadVariablesFromFile(IN SHELL_FILE_HANDLE FileHandle, IN CONST CHAR16 *Name, IN CONST EFI_GUID *Guid, OUT BOOLEAN *Found)
Definition: DmpStore.c:133
EFI_STATUS AppendSingleVariableToFile(IN SHELL_FILE_HANDLE FileHandle, IN CONST CHAR16 *Name, IN CONST EFI_GUID *Guid, IN UINT32 Attributes, IN UINT32 DataSize, IN CONST UINT8 *Data)
Definition: DmpStore.c:314
SHELL_STATUS ProcessVariables(IN CONST CHAR16 *Name OPTIONAL, IN CONST EFI_GUID *Guid OPTIONAL, IN DMP_STORE_TYPE Type, IN SHELL_FILE_HANDLE FileHandle OPTIONAL, IN BOOLEAN StandardFormatOutput)
Definition: DmpStore.c:671
CHAR16 * BinaryToHexString(IN VOID *Buffer, IN UINTN BufferSize, IN OUT CHAR16 *HexString, IN UINTN HexStringSize)
Definition: DmpStore.c:93
SHELL_STATUS EFIAPI ShellCommandRunDmpStore(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: DmpStore.c:747
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
UINTN EFIAPI UnicodeSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString,...)
Definition: PrintLib.c:408
EFI_RUNTIME_SERVICES * gRT
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define RETURN_ERROR(StatusCode)
Definition: Base.h:1061
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define CR(Record, TYPE, Field, TestSignature)
Definition: DebugLib.h:659
SHELL_STATUS
Definition: Shell.h:21
@ SHELL_OUT_OF_RESOURCES
Definition: Shell.h:73
@ SHELL_ABORTED
Definition: Shell.h:128
@ SHELL_SUCCESS
Definition: Shell.h:25
@ SHELL_NOT_READY
Definition: Shell.h:57
@ SHELL_NOT_FOUND
Definition: Shell.h:101
@ SHELL_DEVICE_ERROR
Definition: Shell.h:63
@ SHELL_SECURITY_VIOLATION
Definition: Shell.h:141
@ SHELL_INVALID_PARAMETER
Definition: Shell.h:35
@ SHELL_VOLUME_CORRUPTED
Definition: Shell.h:79
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_FILE_INFO * FileInfo(IN EFI_FILE_HANDLE FHand)
VOID EFIAPI DumpHex(IN UINTN Indent, IN UINTN Offset, IN UINTN DataSize, IN VOID *UserData)
EFI_STATUS EFIAPI ShellGetFileSize(IN SHELL_FILE_HANDLE FileHandle, OUT UINT64 *Size)
CONST CHAR16 *EFIAPI ShellCommandLineGetValue(IN CONST LIST_ENTRY *CheckPackage, IN CHAR16 *KeyString)
EFI_FILE_INFO *EFIAPI ShellGetFileInfo(IN SHELL_FILE_HANDLE FileHandle)
Definition: UefiShellLib.c:573
EFI_STATUS EFIAPI ShellDeleteFile(IN SHELL_FILE_HANDLE *FileHandle)
Definition: UefiShellLib.c:992
BOOLEAN EFIAPI ShellGetExecutionBreakFlag(VOID)
#define ShellCommandLineParse(CheckList, CheckPackage, ProblemParam, AutoPageBreak)
Make it easy to upgrade from older versions of the shell library.
Definition: ShellLib.h:755
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
BOOLEAN EFIAPI ShellCommandLineGetFlag(IN CONST LIST_ENTRY *CONST CheckPackage, IN CONST CHAR16 *CONST KeyString)
@ TypeValue
A flag that has some data following it with a space (IE "-a 1").
Definition: ShellLib.h:700
@ TypeFlag
A flag that is present or not present only (IE "-a").
Definition: ShellLib.h:699
EFI_STATUS EFIAPI ShellOpenFileByName(IN CONST CHAR16 *FileName, OUT SHELL_FILE_HANDLE *FileHandle, IN UINT64 OpenMode, IN UINT64 Attributes)
Definition: UefiShellLib.c:720
CHAR16 *EFIAPI StrnCatGrow(IN OUT CHAR16 **Destination, IN OUT UINTN *CurrentSize, IN CONST CHAR16 *Source, IN UINTN Count)
VOID EFIAPI ShellCommandLineFreeVarList(IN LIST_ENTRY *CheckPackage)
CONST CHAR16 *EFIAPI ShellCommandLineGetRawValue(IN CONST LIST_ENTRY *CONST CheckPackage, IN UINTN Position)
UINTN EFIAPI ShellCommandLineGetCount(IN CONST LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellWriteFile(IN SHELL_FILE_HANDLE FileHandle, IN OUT UINTN *BufferSize, IN VOID *Buffer)
Definition: UefiShellLib.c:947
EFI_STATUS EFIAPI ShellCloseFile(IN SHELL_FILE_HANDLE *FileHandle)
Definition: UefiShellLib.c:969
EFI_STATUS EFIAPI ShellReadFile(IN SHELL_FILE_HANDLE FileHandle, IN OUT UINTN *ReadSize, OUT VOID *Buffer)
Definition: UefiShellLib.c:912
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
GUID EFI_GUID
Definition: UefiBaseType.h:25
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
#define STRING_TOKEN(t)
#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
#define EFI_VARIABLE_HARDWARE_ERROR_RECORD
#define EFI_VARIABLE_NON_VOLATILE
#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
UINT64 Attribute
Definition: FileInfo.h:47
Definition: Base.h:213