disk

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: MPL-2.0 Imports: 7 Imported by: 3

Documentation

Overview

Package disk provides utility method for disk listing and searching using /sys/block data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Match

func Match(disk *Disk, matchers ...Matcher) bool

Match checks if the disk matches the spec. Spec can contain part of the field and strings can contain wildcards. "and" condition is used when this spec is processed.

Types

type Disk

type Disk struct {
	// Size disk size in bytes.
	Size uint64
	// Model from /sys/block/*/device/model.
	Model string
	// DeviceName device name (e.g. /dev/sda).
	DeviceName string
	// Name /sys/block/<dev>/device/name.
	Name string
	// Serial /sys/block/<dev>/device/serial.
	Serial string
	// Modalias /sys/block/<dev>/device/modalias.
	Modalias string
	// WWID /sys/block/<dev>/wwid.
	WWID string
	// UUID /sys/block/<dev>/uuid.
	UUID string
	// Type is the disk type: HDD, SSD, SD card, NVMe drive.
	Type Type
	// BusPath PCI bus path.
	BusPath string
	// SubSystem is the dest path of symlink /sys/block/<dev>/subsystem.
	SubSystem string
	// ReadOnly indicates that the kernel has marked this disk as read-only.
	ReadOnly bool
}

Disk reresents disk information obtained by reading /sys/block.

func Find

func Find(matchers ...Matcher) (*Disk, error)

Find disk matching provided spec. string parameters may include wildcards.

func Get

func Get(dev string) *Disk

Get gathers disk information from sys block.

func List

func List() ([]*Disk, error)

List returns list of disks by reading /sys/block.

type Matcher

type Matcher func(disk *Disk) bool

Matcher is a function that can handle some custom disk matching logic.

func WithBusPath

func WithBusPath(path string) Matcher

WithBusPath select disk by it's full path.

func WithModalias

func WithModalias(modalias string) Matcher

WithModalias select disk with modalias.

func WithModel

func WithModel(model string) Matcher

WithModel select disk with model.

func WithName

func WithName(name string) Matcher

WithName select disk with name.

func WithSerial

func WithSerial(serial string) Matcher

WithSerial select disk with serial.

func WithType

func WithType(t Type) Matcher

WithType select disk with type.

func WithUUID

func WithUUID(uuid string) Matcher

WithUUID select disk with UUID.

func WithWWID

func WithWWID(wwid string) Matcher

WithWWID select disk with WWID.

type Type

type Type int

Type is the disk type: HDD, SSD, SD card, NVMe drive.

const (
	// TypeUnknown is set when couldn't detect the disk type.
	TypeUnknown Type = iota
	// TypeSSD SATA SSD disk.
	TypeSSD
	// TypeHDD HDD disk.
	TypeHDD
	// TypeNVMe NVMe disk.
	TypeNVMe
	// TypeSD SD card.
	TypeSD
)

func ParseType

func ParseType(id string) (Type, error)

ParseType converts string id to the disk type id.

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

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