blockdev

package module
v0.0.0-...-2421105 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

README

blockdev

GoDoc

List linux block devices in Go.

Usage

package main

import (
    "fmt"
    "context"
    "github.com/threez/blockdev"
)

func main() {
    devices, err := blockdev.List(context.Background())
    if err != nil {
        panic(err)
    }

    fmt.Println("Devices", devices)
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var Lsblk = "lsblk"

Lsblk List information about block devices

Functions

This section is empty.

Types

type BlockDevice

type BlockDevice struct {
	// Name device name
	Name string `json:"name"`

	// Kname internal kernel device name
	Kname string `json:"kname"`

	// MajMin major:minor device number
	MajMin string `json:"maj:min"`

	// Fstype filesystem type
	Fstype *string `json:"fstype"`

	// Mountpoint where the device is mounted
	Mountpoint *string `json:"mountpoint"`

	// Label filesystem LABEL
	Label *string `json:"label"`

	// UUID filesystem UUID
	UUID *string `json:"uuid"`

	// Parttype partition type UUID
	Parttype *string `json:"parttype"`

	// Partlabel partition LABEL
	Partlabel *string `json:"partlabel"`

	// Partuuid partition UUID
	Partuuid *string `json:"partuuid"`

	// Partflags partition flags
	Partflags *string `json:"partflags"`

	// Ra read-ahead of the device
	Ra int `json:"ra,string"`

	// Ro read-only device
	Ro int `json:"ro,string"`

	// Rm removable device
	Rm int `json:"rm,string"`

	// Hotplug removable or hotplug device (usb, pcmcia, ...)
	Hotplug int `json:"hotplug,string"`

	// Model device identifier
	Model string `json:"model"`

	// Serial disk serial number
	Serial string `json:"serial"`

	// Size size of the device
	Size int64 `json:"size,string"`

	// State state of the device
	State *string `json:"state"`

	// Owner user name
	Owner string `json:"owner"`

	// Group group name
	Group string `json:"group"`

	// Mode device node permissions
	Mode string `json:"mode"`

	// Alignment alignment offset
	Alignment int `json:"alignment,string"`

	// MinIo minimum I/O size
	MinIo int `json:"min-io,string"`

	// OptIo optimal I/O size
	OptIo int `json:"opt-io,string"`

	// PhySec physical sector size
	PhySec int `json:"phy-sec,string"`

	// LogSec logical sector size
	LogSec int `json:"log-sec,string"`

	// Rota rotational device
	Rota int `json:"rota,string"`

	// Sched I/O scheduler name
	Sched string `json:"sched"`

	// RqSize request queue size
	RqSize int `json:"rq-size,string"`

	// Type device type
	Type string `json:"type"`

	// DiscAln discard alignment offset
	DiscAln int `json:"disc-aln,string"`

	// DiscGran discard granularity
	DiscGran int `json:"disc-gran,string"`

	// DiscMax discard max bytes
	DiscMax int `json:"disc-max,string"`

	// DiscZero discard zeroes data
	DiscZero int `json:"disc-zero,string"`

	// Wsame write same max bytes
	Wsame int `json:"wsame,string"`

	// Wwn unique storage identifier
	Wwn *string `json:"wwn"`

	// Rand adds randomness
	Rand int `json:"rand,string"`

	// Pkname internal parent kernel device name
	Pkname *string `json:"pkname"`

	// Hctl Host:Channel:Target:Lun for SCSI
	Hctl *string `json:"hctl"`

	// Tran device transport type
	Tran *string `json:"tran"`

	// Subsystems de-duplicated chain of subsystems
	Subsystems string `json:"subsystems"`

	// Rev device revision
	Rev *string `json:"rev"`

	// Vendor device vendor
	Vendor *string `json:"vendor"`

	Children []*BlockDevice `json:"children"`
}

BlockDevice contains hierarchical information about linux block devices

func List

func List(ctx context.Context) ([]*BlockDevice, error)

List of the linux system

Example
package main

import (
	"context"
	"fmt"

	"github.com/threez/blockdev"
)

func main() {
	// configure to use the test executable (for persitant output)
	blockdev.Lsblk = "./test/lsblk-fake"
	devices, err := blockdev.List(context.Background())
	if err != nil {
		panic(err)
	}

	fmt.Println("Devices", devices)
}
Output:
Devices [loop0 (7:0) loop1 (7:1) loop2 (7:2) loop3 (7:3) loop4 (7:4) loop5 (7:5) loop6 (7:6) loop7 (7:7) sda (8:0) sr0 (11:0) sr1 (11:1) sr2 (11:2) nbd0 (43:0) nbd1 (43:1) nbd2 (43:2) nbd3 (43:3) nbd4 (43:4) nbd5 (43:5) nbd6 (43:6) nbd7 (43:7) nbd8 (43:8) nbd9 (43:9) nbd10 (43:10) nbd11 (43:11) nbd12 (43:12) nbd13 (43:13) nbd14 (43:14) nbd15 (43:15)]

func (BlockDevice) String

func (d BlockDevice) String() string

Jump to

Keyboard shortcuts

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