MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / SetNvramVariable

Function SetNvramVariable

rEFIt_UEFI/Platform/Nvram.cpp:177–220  ·  view source on GitHub ↗

Sets NVRAM variable. Does nothing if variable with the same data and attributes already exists. */

Source from the content-addressed store, hash-verified

175
176/** Sets NVRAM variable. Does nothing if variable with the same data and attributes already exists. */
177EFI_STATUS
178SetNvramVariable (
179 IN CONST CHAR16 *VariableName,
180 IN EFI_GUID *VendorGuid,
181 IN UINT32 Attributes,
182 IN UINTN DataSize,
183 IN CONST VOID *Data
184 )
185{
186 //EFI_STATUS Status;
187 VOID *OldData;
188 UINTN OldDataSize = 0;
189 UINT32 OldAttributes = 0;
190
191 //DBG("SetNvramVariable (%ls, guid, 0x%X, %d):", VariableName, Attributes, DataSize);
192 OldData = (__typeof__(OldData))GetNvramVariable(VariableName, VendorGuid, &OldAttributes, &OldDataSize);
193 if (OldData != NULL) {
194 // var already exists - check if it equal to new value
195 //DBG(" exists(0x%X, %d)", OldAttributes, OldDataSize);
196 if ((OldAttributes == Attributes) &&
197 (OldDataSize == DataSize) &&
198 (CompareMem (OldData, Data, DataSize) == 0)) {
199 // it's the same - do nothing
200 //DBG(", equal -> not writing again.\n");
201 FreePool(OldData);
202 return EFI_SUCCESS;
203 }
204 //DBG(", not equal\n");
205
206 FreePool(OldData);
207
208 // not the same - delete previous one if attributes are different
209 if (OldAttributes != Attributes) {
210 DeleteNvramVariable (VariableName, VendorGuid);
211 //DBG(", diff. attr: deleting old (%s)", efiStrError(Status));
212 }
213 }
214 //DBG("\n"); // for debug without Status
215 //DBG(" -> writing new (%s)\n", efiStrError(Status));
216 //return Status;
217
218 return gRT->SetVariable(VariableName, VendorGuid, Attributes, DataSize, (VOID*)Data); // CONST missing in EFI_SET_VARIABLE->SetVariable
219
220}
221EFI_STATUS
222SetNvramXString8 (
223 IN CONST CHAR16 *VariableName,

Callers 6

ApplyInputsFunction · 0.85
SetVariablesForOSXFunction · 0.85
SetNvramXString8Function · 0.85
PutNvramPlistToRtVarsFunction · 0.85
SetStartupDiskVolumeFunction · 0.85
SetBootCurrentFunction · 0.85

Calls 4

GetNvramVariableFunction · 0.85
DeleteNvramVariableFunction · 0.85
CompareMemFunction · 0.50
FreePoolFunction · 0.50

Tested by

no test coverage detected