lsblk

package module
v0.0.0-...-28312ac Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MIT Imports: 4 Imported by: 0

README

lsblk

This is a Go wrapper for lsblk (from util-linux), a tool which list block devices.

It doesn't generalize or cover enough of lsblk to be a comprehensive wrapper as it mostly supports the need coming from sneakernet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteCountIEC

func ByteCountIEC(b int64) string

ByteCountIEC .

func ByteCountSI

func ByteCountSI(b int64) string

ByteCountSI .

func GetLsblkOutput

func GetLsblkOutput() []byte

GetLsblkOutput []byte output from `lbslk -pabOJ`

Types

type Blockdevice

type Blockdevice struct {
	Name         string      // device name
	Kname        string      // internal kernel device name
	Pkname       string      // internal parent kernel device name
	Path         string      // path to the device node
	MajMin       string      `json:"maj:min"` // major:minor device number
	Fsavail      Num         // filesystem size available
	Fssize       Num         // filesystem size in bytes
	Fstype       string      // filesystem type
	Fsused       string      // filesystem size used
	Fsusep       string      `json:"fsuse%"` // filesystem use percentage
	Fsver        string      // filesystem version
	Mountpoint   string      // path where the device is mounted
	Label        string      // filesystem LABEL
	UUID         string      // filesystem UUID
	Ptuuid       string      // partition table identifier (usually UUID)
	Pttype       string      // partition table type
	Parttype     string      // partition type code or UUID
	Parttypename string      // partition type name
	Partlabel    string      // partition LABEL
	Partuuid     string      // partition UUID
	Partflags    string      // partition flags
	Ra           json.Number // read-ahead of the devic
	Ro           bool        // read-only device
	Rm           bool        // removable device
	Hotplug      bool        // removable or hotplug device (usb, pcmcia, ...)
	Rota         bool        // rotational device
	Rand         bool        // adds randomness
	Model        string      // device identifier
	Serial       string      // disk serial number
	Size         Num         // size of the device in bytes
	State        string      // state of the device e.g. suspended, running, live
	Owner        string      // user name
	Group        string      // group name
	Mode         string      // device node permissions e.g. brw-rw----
	Alignment    json.Number // alignment offset
	Minio        json.Number `json:"min-io"`  // minimum I/O size
	Optio        json.Number `json:"opt-io"`  // optimal I/O size
	Physec       json.Number `json:"phy-sec"` // physical sector size
	Logsec       json.Number `json:"log-sec"` // logical sector size
	Sched        string      // I/O scheduler name e.g. mq-deadline
	Rqsize       json.Number `json:"rq-size"` // request queue size
	Type         string      // device type e.g. loop, disk, part, crypt, lvm
	Discaln      json.Number `json:"disc-aln"`  // discard alignment offset
	Discgran     json.Number `json:"disc-gran"` // discard granularity
	Discmax      json.Number `json:"disc-max"`  // discard max bytes
	Disczero     bool        `json:"disc-zero"` // discard zeroes data
	Wsame        json.Number // write same max bytes
	Wwn          string      // unique storage identifier
	Hctl         string      // Host:Channel:Target:Lun for SCSI
	Tran         string      // device transport type e.g. usb, nvme
	Subsystems   string      // de-duplicated chain of subsystems e.g. block, block:scsi:usb:pci, block:nvme:pci
	Rev          string      // device revision
	Vendor       string      // device vendor
	Zoned        string      // zone model
	Dax          bool        // dax-capable device
	Children     []Blockdevice
}

Blockdevice JSON strruct with details for every device

func USBMountedPartitions

func USBMountedPartitions() []Blockdevice

USBMountedPartitions returns all USB disk mounted partitions

func USBNotMountedPartitionOfLargestSize

func USBNotMountedPartitionOfLargestSize() Blockdevice

USBNotMountedPartitionOfLargestSize .

func USBNotMountedPartitions

func USBNotMountedPartitions() []Blockdevice

USBNotMountedPartitions returns all USB disk NOT mounted partitions

func (Blockdevice) HasPartitions

func (b Blockdevice) HasPartitions() bool

HasPartitions checks if blockdevice has partitions

func (Blockdevice) IsMounted

func (b Blockdevice) IsMounted() bool

IsMounted checks if blockdevice has mountpoint

func (Blockdevice) IsRunning

func (b Blockdevice) IsRunning() bool

IsRunning checks if blockdevice is running

func (Blockdevice) IsUsbTran

func (b Blockdevice) IsUsbTran() bool

IsUsbTran checks if blockdevices has USB as its transport

func (*Blockdevice) UnmarshalJSON

func (b *Blockdevice) UnmarshalJSON(data []byte) error

UnmarshalJSON custom marshaling of the JSON fields

type Lsblk

type Lsblk struct {
	Blockdevices []Blockdevice
}

Lsblk main JSON struct to capture the output of `lsblk`

func GetLsblk

func GetLsblk() Lsblk

GetLsblk returns lsblk output as Lsblk.Blockdevices struct

type Num

type Num struct {
	Int64         int64
	String        string
	HumanReadable string
}

Num custom field with string, int64 & HumanReadable K,M,Gb conversion of bytes

Jump to

Keyboard shortcuts

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