OpenCore  1.0.4
OpenCore Bootloader
1.0.4
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
OcVariableLib.c File Reference
#include <Uefi.h>
#include <Guid/OcVariable.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/OcVariableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>

Go to the source code of this file.

Functions

VOID OcVariableInit (IN BOOLEAN ForceOcWriteFlash)
 
EFI_STATUS OcSetSystemVariable (IN CHAR16 *VariableName, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data, IN EFI_GUID *VendorGuid OPTIONAL)
 

Variables

STATIC BOOLEAN mForceOcWriteFlash = FALSE
 
STATIC BOOLEAN mDebugInitialized = FALSE
 

Detailed Description

OpenCore Variable library.

Copyright (c) 2021, Marvin Haeuser. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause

Definition in file OcVariableLib.c.

Function Documentation

◆ OcSetSystemVariable()

EFI_STATUS OcSetSystemVariable ( IN CHAR16 * VariableName,
IN UINT32 Attributes,
IN UINTN DataSize,
IN VOID * Data,
IN EFI_GUID *VendorGuid OPTIONAL )

Sets the value of an OpenCore system variable to the OpenCore vendor GUID. If the write is to be performed non-volatile, this function guarantees to not request a write if the existing data is identical to the data requested to be written.

Parameters
[in]VariableNameA Null-terminated string that is the name of the vendor's variable. Each VariableName is unique for each VendorGuid. VariableName must contain 1 or more characters. If VariableName is an empty string, then EFI_INVALID_PARAMETER is returned.
[in]AttributesAttributes bitmask to set for the variable.
[in]DataSizeThe size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is set, then a SetVariable() call with a DataSize of zero will not cause any change to the variable value (the timestamp associated with the variable may be updated however even if no new data value is provided,see the description of the EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated).
[in]DataThe contents for the variable.
[in]VendorGuidVariable GUID, defaults to gOcVendorVariableGuid if NULL.
Return values
EFI_SUCCESSThe firmware has successfully stored the variable and its data as defined by the Attributes.
EFI_INVALID_PARAMETERAn invalid combination of attribute bits, name, and GUID was supplied, or the DataSize exceeds the maximum allowed.
EFI_INVALID_PARAMETERVariableName is an empty string.
EFI_OUT_OF_RESOURCESNot enough storage is available to hold the variable and its data.
EFI_DEVICE_ERRORThe variable could not be retrieved due to a hardware error.
EFI_WRITE_PROTECTEDThe variable in question is read-only.
EFI_WRITE_PROTECTEDThe variable in question cannot be deleted.
EFI_SECURITY_VIOLATIONThe variable could not be written due to EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo does NOT pass the validation check carried out by the firmware.
EFI_NOT_FOUNDThe variable trying to be updated or deleted was not found.

Definition at line 35 of file OcVariableLib.c.

◆ OcVariableInit()

VOID OcVariableInit ( IN BOOLEAN ForceOcWriteFlash)

Initialize the OpenCore variable library. No other function may be called before this function has returned.

Parameters
[in]ForceOcWriteFlashWhether OC system variables should be forced to be written to flash.

Definition at line 23 of file OcVariableLib.c.

Variable Documentation

◆ mDebugInitialized

STATIC BOOLEAN mDebugInitialized = FALSE

Definition at line 20 of file OcVariableLib.c.

◆ mForceOcWriteFlash

STATIC BOOLEAN mForceOcWriteFlash = FALSE

Definition at line 18 of file OcVariableLib.c.