5.2.6 QueryVariableInfo()

Use this UEFI Runtime Service to retrieve information about the container used to store UEFI variables including their size, available space, and the maximum size of a single UEFI variable.

In general, UEFI Drivers do not use UEFI variables, and those UEFI Drivers that do use UEFI variables are provided with the UEFI system firmware where this type of information is usually already known. As a result, this service is rarely used by UEFI Drivers. It is more typically used by OS installers and OS kernels to determine the platform storage capabilities for UEFI variables.

The following code fragment shows how the QueryVariableInfo() service is used to collect information storage containers for UEFI variables that persist across reboots and power cycles and are available in both the pre-boot environment and by the OS.

Example 68-Collect information about the UEFI variable store
#include <Uefi.h>
#include <Library/UefiRuntimeServicesTableLib.h>

EFI_STATUS Status;
UINT64 MaximumVariableStorageSize;
UINT64 RemainingVariableStorageSize;
UINT64 MaximumVariableSize;

Status = gRT->QueryVariableInfo (
                EFI_VARIABLE_BOOTSERVICE_ACCESS |
                EFI_VARIABLE_RUNTIME_ACCESS |
                EFI_VARIABLE_NON_VOLATILE,
                &MaximumVariableStorageSize,
                &RemainingVariableStorageSize,
                &MaximumVariableSize
                );
if (EFI_ERROR (Status)) {
  return Status;
}