EmuVariable: enable deletion of variables
Make it possible to delete a variable by appending it with size 0. Also ignore keysizes of 0 when reading variables. Signed-off-by: Jeremy Soller <jeremy@system76.com> Signed-off-by: Matt DeVillier <matt.devillier@gmail.com>
This commit is contained in:
committed by
Matt DeVillier
parent
4f60b6a439
commit
1b66efff52
@@ -945,6 +945,7 @@ UpdateVariable (
|
|||||||
VARIABLE_GLOBAL *Global;
|
VARIABLE_GLOBAL *Global;
|
||||||
UINTN NonVolatileVarableStoreSize;
|
UINTN NonVolatileVarableStoreSize;
|
||||||
UINT32 Result;
|
UINT32 Result;
|
||||||
|
BOOLEAN Delete = FALSE;
|
||||||
|
|
||||||
Global = &mVariableModuleGlobal->VariableGlobal[Physical];
|
Global = &mVariableModuleGlobal->VariableGlobal[Physical];
|
||||||
|
|
||||||
@@ -977,10 +978,8 @@ UpdateVariable (
|
|||||||
// specified causes it to be deleted.
|
// specified causes it to be deleted.
|
||||||
//
|
//
|
||||||
if (DataSize == 0 || (Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == 0) {
|
if (DataSize == 0 || (Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == 0) {
|
||||||
Variable->CurrPtr->State &= VAR_DELETED;
|
DataSize = 0;
|
||||||
UpdateVariableInfo (VariableName, VendorGuid, Variable->Volatile, FALSE, FALSE, TRUE, FALSE);
|
Delete = TRUE;
|
||||||
Status = EFI_SUCCESS;
|
|
||||||
goto Done;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -990,8 +989,12 @@ UpdateVariable (
|
|||||||
if (Variable->CurrPtr->DataSize == DataSize &&
|
if (Variable->CurrPtr->DataSize == DataSize &&
|
||||||
CompareMem (Data, GetVariableDataPtr (Variable->CurrPtr), DataSize) == 0
|
CompareMem (Data, GetVariableDataPtr (Variable->CurrPtr), DataSize) == 0
|
||||||
) {
|
) {
|
||||||
Status = EFI_SUCCESS;
|
if (Delete) {
|
||||||
goto Done;
|
goto Update;
|
||||||
|
} else {
|
||||||
|
Status = EFI_SUCCESS;
|
||||||
|
goto Done;
|
||||||
|
}
|
||||||
} else if (Variable->CurrPtr->State == VAR_ADDED) {
|
} else if (Variable->CurrPtr->State == VAR_ADDED) {
|
||||||
//
|
//
|
||||||
// Mark the old variable as in delete transition
|
// Mark the old variable as in delete transition
|
||||||
@@ -1033,6 +1036,10 @@ UpdateVariable (
|
|||||||
VarDataOffset = VarNameOffset + VarNameSize + GET_PAD_SIZE (VarNameSize);
|
VarDataOffset = VarNameOffset + VarNameSize + GET_PAD_SIZE (VarNameSize);
|
||||||
VarSize = VarDataOffset + DataSize + GET_PAD_SIZE (DataSize);
|
VarSize = VarDataOffset + DataSize + GET_PAD_SIZE (DataSize);
|
||||||
|
|
||||||
|
if (Delete) {
|
||||||
|
goto Store;
|
||||||
|
}
|
||||||
|
|
||||||
if ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0) {
|
if ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0) {
|
||||||
NonVolatileVarableStoreSize = ((VARIABLE_STORE_HEADER *)(UINTN)(Global->NonVolatileVariableBase))->Size;
|
NonVolatileVarableStoreSize = ((VARIABLE_STORE_HEADER *)(UINTN)(Global->NonVolatileVariableBase))->Size;
|
||||||
if ((((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != 0)
|
if ((((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != 0)
|
||||||
@@ -1090,7 +1097,16 @@ UpdateVariable (
|
|||||||
DataSize
|
DataSize
|
||||||
);
|
);
|
||||||
|
|
||||||
if (storeInitialized && ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0)) {
|
Store:
|
||||||
|
// If the store is initialized
|
||||||
|
// And we are storing or deleting a non volatile variable
|
||||||
|
// Send the new data to SMMSTORE
|
||||||
|
if (storeInitialized && (
|
||||||
|
(Attributes & EFI_VARIABLE_NON_VOLATILE) != 0 || (
|
||||||
|
Delete &&
|
||||||
|
(Variable->CurrPtr->Attributes & EFI_VARIABLE_NON_VOLATILE) != 0
|
||||||
|
)
|
||||||
|
)) {
|
||||||
|
|
||||||
/* TODO: add hook for logging nv changes here */
|
/* TODO: add hook for logging nv changes here */
|
||||||
|
|
||||||
@@ -1120,6 +1136,7 @@ UpdateVariable (
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Update:
|
||||||
//
|
//
|
||||||
// Mark the old variable as deleted
|
// Mark the old variable as deleted
|
||||||
//
|
//
|
||||||
@@ -1127,7 +1144,11 @@ UpdateVariable (
|
|||||||
Variable->CurrPtr->State &= VAR_DELETED;
|
Variable->CurrPtr->State &= VAR_DELETED;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateVariableInfo (VariableName, VendorGuid, Variable->Volatile, FALSE, TRUE, FALSE, FALSE);
|
if (Delete) {
|
||||||
|
UpdateVariableInfo (VariableName, VendorGuid, Variable->Volatile, FALSE, FALSE, TRUE, FALSE);
|
||||||
|
} else {
|
||||||
|
UpdateVariableInfo (VariableName, VendorGuid, Variable->Volatile, FALSE, TRUE, FALSE, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
Status = EFI_SUCCESS;
|
Status = EFI_SUCCESS;
|
||||||
|
|
||||||
@@ -1943,7 +1964,7 @@ VariableCommonInitialize (
|
|||||||
while (i < read_cmd.bufsize) {
|
while (i < read_cmd.bufsize) {
|
||||||
// assume native endian
|
// assume native endian
|
||||||
UINT32 keysz = ((UINT32 *)(buf + i))[0];
|
UINT32 keysz = ((UINT32 *)(buf + i))[0];
|
||||||
if (keysz == 0xffffffff)
|
if (keysz == 0 || keysz == 0xffffffff)
|
||||||
break; // no more entries
|
break; // no more entries
|
||||||
UINTN valsz = ((UINT32 *)(buf + i))[1];
|
UINTN valsz = ((UINT32 *)(buf + i))[1];
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user