block

package
v0.0.0-...-b79a0d8 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package block contains functions dealing with linux block devices and the underlying hardware.

Index

Constants

This section is empty.

Variables

View Source
var Verbose bool

Functions

func AllBlockDevs

func AllBlockDevs() []string

Return a path for each non-virtual block device. Unlike Devices(), include partitions.

func BFiltNotRecovery

func BFiltNotRecovery(bi BlkInfo) bool

func DFiltOnlyParts

func DFiltOnlyParts(dir, relpath string) bool

func DFiltOnlyUsb

func DFiltOnlyUsb(_, relpath string) bool

func DFiltOnlyUsbParts

func DFiltOnlyUsbParts(dir, relpath string) bool

func FilterBlockDevs

func FilterBlockDevs(filter DevIncludeFn) []string

like AllBlockDevs, but uses a filter function to limit the results

func IsDev

func IsDev(dev string) bool

IsDev returns true if given dev represents a physical device

func IsPart

func IsPart(dev string) bool

IsPart returns true if given dev is a partition

func PartNum

func PartNum(dev string) string

PartNum returns the part number of a partition, or empty string

func PartParent

func PartParent(dev string) string

PartParent returns the parent block device for the given partition. Does not check if dev is actually a partition.

func ReadModel

func ReadModel(dev string) (m string, err error)

given a dev like '/dev/sda', find device model string for sata, 'model' file includes vendor as well

func ReadSize

func ReadSize(dev string) (devSize uint64, err error)

use ioctl to find dev size

func ReadVendor

func ReadVendor(dev string) (v string, err error)

for sata, always returns ATA for scsi, ??? for usb, returns actual vendor

func SizeToleranceMatch

func SizeToleranceMatch(have, want, tol uint64) bool

SizeToleranceMatch returns true if actual value is within tolerance of desired value. Tolerance is expressed as an integer 1-100, representing a percent.

Types

type BlkIncludeFn

type BlkIncludeFn func(bi BlkInfo) bool

a function that returns false if given bi should be filtered out

type BlkInfo

type BlkInfo struct {
	FsType    FsType
	UUID      string
	Partition bool
	PartUUID  string
	Label     string
	Usage     string
	Device    string
}

func GetFilesystems

func GetFilesystems(blkfilter BlkIncludeFn, devfilter DevIncludeFn) []BlkInfo

return a BlkInfo for each blockdevice containing a filesystem we recognize

func GetInfo

func GetInfo(device string) (bi BlkInfo, err error)

type BlockDev

type BlockDev struct {
	Name   string
	Size   uint64
	Model  string
	Vendor string
}

func Devices

func Devices() (devs []BlockDev)

return name, size of storage devices

func (BlockDev) String

func (b BlockDev) String() string

type DevIncludeFn

type DevIncludeFn func(dir, relpath string) bool

A function that returns true if the entry is to be kept. relpath is relative to dir, which is likely /sys/class/block.

type FsType

type FsType int
const (
	FsUnknown FsType = iota
	FsExt4
	FsNtfs
	FsFat
	FsExfat
)

func DetermineFSType

func DetermineFSType(device string) FsType

func FsFromStr

func FsFromStr(s string) FsType

func (FsType) Recognized

func (f FsType) Recognized() bool

func (FsType) String

func (f FsType) String() (t string)

Directories

Path Synopsis
Package md does various things with mdadm.
Package md does various things with mdadm.
Package partitioning allows creation of MBR and GPT partition tables and partitions, DESTROYING ANY EXISTING DATA.
Package partitioning allows creation of MBR and GPT partition tables and partitions, DESTROYING ANY EXISTING DATA.

Jump to

Keyboard shortcuts

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