device

package
v0.0.0-...-9ec6d29 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: Apache-2.0, MIT Imports: 5 Imported by: 0

Documentation

Overview

Package device defines reserved virtual kernel devices and structures for managing them.

Index

Constants

This section is empty.

Variables

View Source
var SimpleDevices = newRegistry()

SimpleDevices is the system-wide simple device registry. This is saved/restored by kernel.Kernel, but defined here to allow access without depending on the kernel package. See kernel.Kernel.deviceRegistry.

Functions

This section is empty.

Types

type Device

type Device struct {
	ID
	// contains filtered or unexported fields
}

Device is a simple virtual kernel device.

+stateify savable

func NewAnonDevice

func NewAnonDevice() *Device

NewAnonDevice creates a new anonymous device. Packages that require an anonymous device should initialize the device in a global variable in a file called device.go:

var myDevice = device.NewAnonDevice()

func (*Device) NextIno

func (d *Device) NextIno() uint64

NextIno generates a new inode number

type ID

type ID struct {
	Major uint64
	Minor uint64
}

ID identifies a device.

+stateify savable

func (*ID) DeviceID

func (i *ID) DeviceID() uint64

DeviceID formats a major and minor device number into a standard device number.

type MultiDevice

type MultiDevice struct {
	ID
	// contains filtered or unexported fields
}

MultiDevice allows for remapping resources that come from a variety of raw devices into a single device. The device ID should be one of the static Device IDs above and cannot be reused.

func NewAnonMultiDevice

func NewAnonMultiDevice() *MultiDevice

NewAnonMultiDevice creates a new multi-keyed anonymous device. Packages that require a multi-key anonymous device should initialize the device in a global variable in a file called device.go:

var myDevice = device.NewAnonMultiDevice()

func (*MultiDevice) Load

func (m *MultiDevice) Load(key MultiDeviceKey, value uint64) bool

Load loads a raw device and inode into MultiDevice inode mappings with value as the virtual inode.

By design, inodes start from 1 and continue until max uint64. This means that the zero value, which is often the uninitialized value, can be rejected as invalid.

func (*MultiDevice) Map

func (m *MultiDevice) Map(key MultiDeviceKey) uint64

Map maps a raw device and inode into the inode space of MultiDevice, returning a virtualized inode. Raw devices and inodes can be reused; in this case, the same virtual inode will be returned.

func (*MultiDevice) String

func (m *MultiDevice) String() string

String stringifies MultiDevice.

type MultiDeviceKey

type MultiDeviceKey struct {
	Device          uint64
	SecondaryDevice string
	Inode           uint64
}

MultiDeviceKey provides a hashable key for a MultiDevice. The key consists of a raw device and inode for a resource, which must consistently identify the unique resource. It may optionally include a secondary device if appropriate.

Note that using the path is not enough, because filesystems may rename a file to a different backing resource, at which point the path points to a different entity. Using only the inode is also not enough because the inode is assumed to be unique only within the device on which the resource exists.

func (MultiDeviceKey) String

func (m MultiDeviceKey) String() string

String stringifies the key.

type Registry

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

Registry tracks all simple devices and related state on the system for save/restore.

The set of devices across save/restore must remain consistent. That is, no devices may be created or removed on restore relative to the saved system. Practically, this means do not create new devices specifically as part of restore.

+stateify savable

func (*Registry) LoadFrom

func (r *Registry) LoadFrom(other *Registry)

LoadFrom initializes the internal state of all devices in r from other. The set of devices in both registries must match. Devices may not be created or destroyed across save/restore.

Jump to

Keyboard shortcuts

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