storage

package
v0.0.0-...-ba47a78 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2020 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// LinuxMountsPath is the standard mountpoint list path
	LinuxMountsPath = "/proc/mounts"
)
View Source
var SystemPartitionGUID = gpt.Guid([...]byte{
	0x28, 0x73, 0x2a, 0xc1,
	0x1f, 0xf8,
	0xd2, 0x11,
	0xba, 0x4b,
	0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b,
})

SystemPartitionGUID is the GUID of EFI system partitions EFI System partitions have GUID C12A7328-F81F-11D2-BA4B-00A0C93EC93B

Functions

func GetGPTTable

func GetGPTTable(device BlockDev) (*gpt.Table, error)

GetGPTTable tries to read a GPT table from the block device described by the passed BlockDev object, and returns a gpt.Table object, or an error if any

func GetMountpointByDevice

func GetMountpointByDevice(devicePath string) (*string, error)

GetMountpointByDevice gets the mountpoint by given device name. Returns on first match

Types

type BlockDev

type BlockDev struct {
	Name   string
	FSType string
	Stat   BlockStat
	FsUUID string
}

BlockDev maps a device name to a BlockStat structure for a given block device

func FilterEFISystemPartitions

func FilterEFISystemPartitions(devices []BlockDev) ([]BlockDev, error)

FilterEFISystemPartitions returns a list of BlockDev objects whose underlying block device is a valid EFI system partition, or an error if any

func GetBlockStats

func GetBlockStats() ([]BlockDev, error)

GetBlockStats iterates over /sys/class/block entries and returns a list of BlockDev objects, or an error if any

func PartitionsByFsUUID

func PartitionsByFsUUID(devices []BlockDev, fsuuid string) []BlockDev

PartitionsByFsUUID returns a list of BlockDev objects whose underlying block device has a filesystem with the given UUID

func PartitionsByGUID

func PartitionsByGUID(devices []BlockDev, guid string) ([]BlockDev, error)

PartitionsByGUID returns a list of BlockDev objects whose underlying block device has the given GUID

func PartitionsByName

func PartitionsByName(devices []BlockDev, name string) []BlockDev

PartitionsByName returns a list of BlockDev objects whose underlying block device has a Name with the given Name

func (BlockDev) Mount

func (b BlockDev) Mount(path string, flags uintptr) (*mount.MountPoint, error)

Mount implements mount.Mounter.

func (BlockDev) String

func (b BlockDev) String() string

String implements fmt.Stringer.

func (BlockDev) Summary

func (b BlockDev) Summary() string

Summary prints a multiline summary of the BlockDev object https://www.kernel.org/doc/Documentation/block/stat.txt

type BlockStat

type BlockStat struct {
	ReadIOs      uint64
	ReadMerges   uint64
	ReadSectors  uint64
	ReadTicks    uint64
	WriteIOs     uint64
	WriteMerges  uint64
	WriteSectors uint64
	WriteTicks   uint64
	InFlight     uint64
	IOTicks      uint64
	TimeInQueue  uint64
	// Kernel 4.18 added four fields for discard tracking, see
	// https://github.com/torvalds/linux/commit/bdca3c87fb7ad1cc61d231d37eb0d8f90d001e0c
	DiscardIOs     uint64
	DiscardMerges  uint64
	DiscardSectors uint64
	DiscardTicks   uint64
}

BlockStat provides block device information as contained in /sys/class/block/<device_name>/stat

func BlockStatFromBytes

func BlockStatFromBytes(buf []byte) (*BlockStat, error)

BlockStatFromBytes parses a block stat file and returns a BlockStat object. The format of the block stat file is the one defined by Linux for /sys/class/block/<device_name>/stat

Jump to

Keyboard shortcuts

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