device

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// MaxIndex is the maximum index usable for Name / returned by ParseName.
	MaxIndex = numLetters*numLetters + numLetters - 1

	// OnmetalPrefix is the device prefix used by onmetal devices.
	OnmetalPrefix = "od"
)

Variables

This section is empty.

Functions

func Name

func Name(prefix string, idx int) string

Name creates a device name with the given prefix and index. If idx is greater than MaxIndex or if the prefix is not a valid prefix (two lowercase letters) it panics.

func ParseName

func ParseName(name string) (string, int, error)

ParseName parses the name into its prefix and index. An error is returned if the name is not a valid device name.

Types

type Namer

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

Namer allows managing multiple device names. It remembers reserved ones and allows claiming / releasing new ones.

func NewNamer

func NewNamer() *Namer

NewNamer creates a new Namer that allows managing multiple device names.

func (*Namer) Free

func (n *Namer) Free(name string) error

Free releases the given name. If it has not been claimed before, an error is returned.

func (*Namer) Generate

func (n *Namer) Generate(prefix string) (string, error)

Generate generates and claims a new free device name. An error is returned if no free device names are available.

func (*Namer) Observe

func (n *Namer) Observe(name string) error

Observe marks the given name as already claimed. If it already has been claimed, an error is returned.

Jump to

Keyboard shortcuts

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