mirror of https://github.com/acidanthera/audk.git
Fixed issues:
1.Refine the logic about show different attribute. 2.Refine the logic about allocate memory for variable name and data. Signed-off-by: Eric Dong <eric.dong@intel.com> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13558 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
12ea46947d
commit
73c82041dc
|
@ -14,16 +14,47 @@
|
||||||
|
|
||||||
#include "UefiShellDebug1CommandsLib.h"
|
#include "UefiShellDebug1CommandsLib.h"
|
||||||
|
|
||||||
STATIC CHAR16 *AttrType[] = {
|
|
||||||
L"invalid", // 000
|
#define INIT_NAME_BUFFER_SIZE 128
|
||||||
L"invalid", // 001
|
#define INIT_DATA_BUFFER_SIZE 1024
|
||||||
L"BS", // 010
|
#define INIT_ATTS_BUFFER_SIZE 64
|
||||||
L"NV+BS", // 011
|
|
||||||
L"RT+BS", // 100
|
CONST CHAR16 *
|
||||||
L"NV+RT+BS", // 101
|
EFIAPI
|
||||||
L"RT+BS", // 110
|
GetAttrType (
|
||||||
L"NV+RT+BS", // 111
|
IN CONST UINT32 Atts,
|
||||||
};
|
IN OUT CHAR16 *RetString
|
||||||
|
)
|
||||||
|
{
|
||||||
|
StrCpy(RetString, L"");
|
||||||
|
|
||||||
|
if (Atts & EFI_VARIABLE_NON_VOLATILE) {
|
||||||
|
StrCat(RetString, L"+NV");
|
||||||
|
}
|
||||||
|
if (Atts & EFI_VARIABLE_RUNTIME_ACCESS) {
|
||||||
|
StrCat(RetString, L"+RS+BS");
|
||||||
|
} else if (Atts & EFI_VARIABLE_BOOTSERVICE_ACCESS) {
|
||||||
|
StrCat(RetString, L"+BS");
|
||||||
|
}
|
||||||
|
if (Atts & EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
|
||||||
|
StrCat(RetString, L"+HR");
|
||||||
|
}
|
||||||
|
if (Atts & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) {
|
||||||
|
StrCat(RetString, L"+AW");
|
||||||
|
}
|
||||||
|
if (Atts & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) {
|
||||||
|
StrCat(RetString, L"+AT");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RetString[0] == L'+') {
|
||||||
|
return (RetString+1);
|
||||||
|
}
|
||||||
|
if (RetString[0] == CHAR_NULL) {
|
||||||
|
StrCpy(RetString, L"invalid");
|
||||||
|
return (RetString);
|
||||||
|
}
|
||||||
|
return (RetString);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Function to display or delete variables.
|
Function to display or delete variables.
|
||||||
|
@ -47,38 +78,32 @@ ProcessVariables (
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINT64 MaxStorSize;
|
|
||||||
UINT64 RemStorSize;
|
|
||||||
UINT64 MaxVarSize;
|
|
||||||
CHAR16 *FoundVarName;
|
CHAR16 *FoundVarName;
|
||||||
UINTN Size;
|
|
||||||
EFI_GUID FoundVarGuid;
|
EFI_GUID FoundVarGuid;
|
||||||
UINT8 *DataBuffer;
|
UINT8 *DataBuffer;
|
||||||
UINTN DataSize;
|
UINTN DataSize;
|
||||||
UINT32 Atts;
|
UINT32 Atts;
|
||||||
SHELL_STATUS ShellStatus;
|
SHELL_STATUS ShellStatus;
|
||||||
BOOLEAN Found;
|
BOOLEAN Found;
|
||||||
|
UINTN NameBufferSize; // Allocated Name buffer size
|
||||||
Status = gRT->QueryVariableInfo(EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS|EFI_VARIABLE_NON_VOLATILE, &MaxStorSize, &RemStorSize, &MaxVarSize);
|
UINTN NameSize;
|
||||||
if (EFI_ERROR(Status)) {
|
CHAR16 *OldName;
|
||||||
return (SHELL_DEVICE_ERROR);
|
UINTN OldNameBufferSize;
|
||||||
}
|
UINTN DataBufferSize; // Allocated data buffer size
|
||||||
|
CHAR16 RetString[INIT_ATTS_BUFFER_SIZE];
|
||||||
|
|
||||||
Found = FALSE;
|
Found = FALSE;
|
||||||
ShellStatus = SHELL_SUCCESS;
|
ShellStatus = SHELL_SUCCESS;
|
||||||
Size = PcdGet16(PcdShellFileOperationSize);
|
|
||||||
FoundVarName = AllocateZeroPool(Size);
|
|
||||||
|
|
||||||
|
NameBufferSize = INIT_NAME_BUFFER_SIZE;
|
||||||
|
DataBufferSize = INIT_DATA_BUFFER_SIZE;
|
||||||
|
FoundVarName = AllocateZeroPool (NameBufferSize);
|
||||||
if (FoundVarName == NULL) {
|
if (FoundVarName == NULL) {
|
||||||
return (SHELL_OUT_OF_RESOURCES);
|
return (SHELL_OUT_OF_RESOURCES);
|
||||||
}
|
}
|
||||||
FoundVarName[0] = CHAR_NULL;
|
DataBuffer = AllocatePool (DataBufferSize);
|
||||||
|
|
||||||
|
|
||||||
DataSize = (UINTN)MaxVarSize;
|
|
||||||
DataBuffer = AllocateZeroPool(DataSize);
|
|
||||||
if (DataBuffer == NULL) {
|
if (DataBuffer == NULL) {
|
||||||
FreePool(FoundVarName);
|
FreePool (FoundVarName);
|
||||||
return (SHELL_OUT_OF_RESOURCES);
|
return (SHELL_OUT_OF_RESOURCES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,18 +112,35 @@ ProcessVariables (
|
||||||
ShellStatus = SHELL_ABORTED;
|
ShellStatus = SHELL_ABORTED;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Size = (UINTN)PcdGet16(PcdShellFileOperationSize);
|
|
||||||
DataSize = (UINTN)MaxVarSize;
|
|
||||||
|
|
||||||
Status = gRT->GetNextVariableName(&Size, FoundVarName, &FoundVarGuid);
|
NameSize = NameBufferSize;
|
||||||
|
Status = gRT->GetNextVariableName (&NameSize, FoundVarName, &FoundVarGuid);
|
||||||
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
||||||
|
OldName = FoundVarName;
|
||||||
|
OldNameBufferSize = NameBufferSize;
|
||||||
|
//
|
||||||
|
// Expand at least twice to avoid reallocate many times
|
||||||
|
//
|
||||||
|
NameBufferSize = NameSize > NameBufferSize * 2 ? NameSize : NameBufferSize * 2;
|
||||||
|
FoundVarName = AllocateZeroPool (NameBufferSize);
|
||||||
|
if (FoundVarName == NULL) {
|
||||||
|
Status = EFI_OUT_OF_RESOURCES;
|
||||||
|
FreePool (OldName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// Preserve the original content to get correct iteration for GetNextVariableName() call
|
||||||
|
//
|
||||||
|
CopyMem (FoundVarName, OldName, OldNameBufferSize);
|
||||||
|
FreePool (OldName);
|
||||||
|
NameSize = NameBufferSize;
|
||||||
|
Status = gRT->GetNextVariableName (&NameSize, FoundVarName, &FoundVarGuid);
|
||||||
|
}
|
||||||
if (Status == EFI_NOT_FOUND) {
|
if (Status == EFI_NOT_FOUND) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ASSERT_EFI_ERROR(Status);
|
ASSERT_EFI_ERROR(Status);
|
||||||
|
|
||||||
Status = gRT->GetVariable(FoundVarName, &FoundVarGuid, &Atts, &DataSize, DataBuffer);
|
|
||||||
ASSERT_EFI_ERROR(Status);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Check if it matches
|
// Check if it matches
|
||||||
//
|
//
|
||||||
|
@ -113,6 +155,24 @@ ProcessVariables (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DataSize = DataBufferSize;
|
||||||
|
Status = gRT->GetVariable (FoundVarName, &FoundVarGuid, &Atts, &DataSize, DataBuffer);
|
||||||
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
||||||
|
//
|
||||||
|
// Expand at least twice to avoid reallocate many times
|
||||||
|
//
|
||||||
|
FreePool (DataBuffer);
|
||||||
|
DataBufferSize = DataSize > DataBufferSize * 2 ? DataSize : DataBufferSize * 2;
|
||||||
|
DataBuffer = AllocatePool (DataBufferSize);
|
||||||
|
if (DataBuffer == NULL) {
|
||||||
|
Status = EFI_OUT_OF_RESOURCES;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
DataSize = DataBufferSize;
|
||||||
|
Status = gRT->GetVariable (FoundVarName, &FoundVarGuid, &Atts, &DataSize, DataBuffer);
|
||||||
|
}
|
||||||
|
ASSERT_EFI_ERROR(Status);
|
||||||
|
|
||||||
//
|
//
|
||||||
// do the print or delete
|
// do the print or delete
|
||||||
//
|
//
|
||||||
|
@ -124,7 +184,7 @@ ProcessVariables (
|
||||||
NULL,
|
NULL,
|
||||||
STRING_TOKEN(STR_DMPSTORE_HEADER_LINE),
|
STRING_TOKEN(STR_DMPSTORE_HEADER_LINE),
|
||||||
gShellDebug1HiiHandle,
|
gShellDebug1HiiHandle,
|
||||||
AttrType[Atts & 7],
|
GetAttrType(Atts, RetString),
|
||||||
&FoundVarGuid,
|
&FoundVarGuid,
|
||||||
FoundVarName,
|
FoundVarName,
|
||||||
DataSize);
|
DataSize);
|
||||||
|
@ -156,6 +216,11 @@ ProcessVariables (
|
||||||
FreePool(DataBuffer);
|
FreePool(DataBuffer);
|
||||||
}
|
}
|
||||||
if (!Found) {
|
if (!Found) {
|
||||||
|
if (Status == EFI_OUT_OF_RESOURCES) {
|
||||||
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle);
|
||||||
|
return SHELL_OUT_OF_RESOURCES;
|
||||||
|
}
|
||||||
|
|
||||||
if (VariableName != NULL && Guid == NULL) {
|
if (VariableName != NULL && Guid == NULL) {
|
||||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N), gShellDebug1HiiHandle, VariableName);
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N), gShellDebug1HiiHandle, VariableName);
|
||||||
} else if (VariableName != NULL && Guid != NULL) {
|
} else if (VariableName != NULL && Guid != NULL) {
|
||||||
|
|
Loading…
Reference in New Issue