device

package
v0.0.0-...-23e6066 Latest Latest
Warning

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

Go to latest
Published: May 3, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

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

Saving and restoring devices is not necessary if the devices are initialized as package global variables. Package initialization happens in a single goroutine and in a deterministic order, so minor device numbers will be assigned in the same order as packages are loaded.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

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

Device is a simple virtual kernel device.

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.

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.

Jump to

Keyboard shortcuts

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