efivarfs

package
v0.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2025 License: BSD-3-Clause Imports: 11 Imported by: 2

Documentation

Overview

Package efivarfs allows interaction with efivarfs of the linux kernel.

Package efivarfs allows interaction with efivarfs of the linux kernel.

Index

Constants

View Source
const DefaultVarFS = "/sys/firmware/efi/efivars/"

DefaultVarFS is the path to the efivarfs mount point

View Source
const FS_IMMUTABLE_FL = 0x10

FS_IMMUTABLE_FL is an inode flag to make a file immutable.

Variables

View Source
var (
	// ErrVarsUnavailable is caused by not having a valid backend
	ErrVarsUnavailable = fmt.Errorf("no variable backend is available:%w", os.ErrNotExist)

	// ErrVarNotExist is caused by accessing a non-existing variable
	ErrVarNotExist = os.ErrNotExist

	// ErrVarPermission is caused by not haven the right permissions either
	// because of not being root or xattrs not allowing changes
	ErrVarPermission = os.ErrPermission

	// ErrNoFS is returned when the file system is not available for some
	// reason.
	ErrNoFS = errors.New("varfs not available")
)
View Source
var ErrBadGUID = errors.New("bad GUID")

ErrBadGUID is for any errors parsing GUIDs.

Functions

func RemoveVariable

func RemoveVariable(e EFIVar, desc VariableDescriptor) error

RemoveVariable calls remove() on the current efivarfs backend.

func SimpleListVariables

func SimpleListVariables(e EFIVar) ([]string, error)

SimpleListVariables is like ListVariables but returns a []string instead of a []VariableDescriptor.

func SimpleRemoveVariable

func SimpleRemoveVariable(e EFIVar, v string) error

SimpleRemoveVariable is like RemoveVariable but takes the combined name and guid string of the form name-guid.

func SimpleWriteVariable

func SimpleWriteVariable(e EFIVar, v string, attrs VariableAttributes, data *bytes.Buffer) error

SimpleWriteVariable is like WriteVariable but takes the combined name and guid string of the form name-guid.

func WriteVariable

func WriteVariable(e EFIVar, desc VariableDescriptor, attrs VariableAttributes, data []byte) error

WriteVariable calls set() on the current efivarfs backend.

Types

type EFIVar added in v0.10.0

type EFIVar interface {
	Get(desc VariableDescriptor) (VariableAttributes, []byte, error)
	List() ([]VariableDescriptor, error)
	Remove(desc VariableDescriptor) error
	Set(desc VariableDescriptor, attrs VariableAttributes, data []byte) error
}

EFIVar is the interface for EFI variables. Note that it need not use a file system, but typically does.

type EFIVarFS added in v0.10.0

type EFIVarFS struct {
	// contains filtered or unexported fields
}

EFIVarFS implements EFIVar

func New added in v0.10.0

func New() (*EFIVarFS, error)

New returns an EFIVarFS using the default path.

func NewPath added in v0.10.0

func NewPath(p string) (*EFIVarFS, error)

NewPath returns an EFIVarFS given a path.

func (*EFIVarFS) Get added in v0.10.0

Get reads the contents of an efivar if it exists and has the necessary permission

func (*EFIVarFS) List added in v0.10.0

func (v *EFIVarFS) List() ([]VariableDescriptor, error)

List returns the VariableDescriptor for each efivar in the system TODO: why can't list implement

func (*EFIVarFS) Remove added in v0.10.0

func (v *EFIVarFS) Remove(desc VariableDescriptor) error

Remove makes the specified EFI var mutable and then deletes it

func (*EFIVarFS) Set added in v0.10.0

func (v *EFIVarFS) Set(desc VariableDescriptor, attrs VariableAttributes, data []byte) error

Set modifies a given efivar with the provided contents

type VariableAttributes

type VariableAttributes uint32

VariableAttributes is an uint32 identifying the variables attributes.

const (
	// AttributeNonVolatile indicates a variable is non volatile.
	AttributeNonVolatile VariableAttributes = 0x00000001
	// AttributeBootserviceAccess indicates a variable is accessible during boot service.
	AttributeBootserviceAccess VariableAttributes = 0x00000002
	// AttributeRuntimeAccess indicates a variable is accessible during runtime.
	AttributeRuntimeAccess VariableAttributes = 0x00000004
	// AttributeHardwareErrorRecord indicates a variable holds hardware error records.
	AttributeHardwareErrorRecord VariableAttributes = 0x00000008
	// AttributeAuthenticatedWriteAccess indicates a variable needs authentication before write access.
	AttributeAuthenticatedWriteAccess VariableAttributes = 0x00000010
	// AttributeTimeBasedAuthenticatedWriteAccess indicates a variable needs time based authentication before write access.
	AttributeTimeBasedAuthenticatedWriteAccess VariableAttributes = 0x00000020
	// AttributeAppendWrite indicates data written to this variable is appended.
	AttributeAppendWrite VariableAttributes = 0x00000040
	// AttributeEnhancedAuthenticatedAccess indicate a variable uses the new authentication format.
	AttributeEnhancedAuthenticatedAccess VariableAttributes = 0x00000080
)

func ReadVariable

func ReadVariable(e EFIVar, desc VariableDescriptor) (VariableAttributes, []byte, error)

ReadVariable calls get() on the current efivarfs backend.

func SimpleReadVariable

func SimpleReadVariable(e EFIVar, v string) (VariableAttributes, *bytes.Reader, error)

SimpleReadVariable is like ReadVariable but takes the combined name and guid string of the form name-guid and returns a bytes.Reader instead of a []byte.

type VariableDescriptor

type VariableDescriptor struct {
	Name string
	GUID guid.UUID
}

VariableDescriptor contains the name and GUID identifying a variable

func ListVariables

func ListVariables(e EFIVar) ([]VariableDescriptor, error)

ListVariables calls list() on the current efivarfs backend.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL