block

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2021 License: BSD-3-Clause Imports: 16 Imported by: 64

Documentation

Overview

Package block finds, mounts, and modifies block devices on Linux systems.

Index

Constants

This section is empty.

Variables

View Source
var (
	// LinuxMountsPath is the standard mountpoint list path
	LinuxMountsPath = "/proc/mounts"

	// Debug function to override for verbose logging.
	Debug = func(string, ...interface{}) {}
)
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 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
	FsUUID string
}

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

func Device

func Device(maybeDevpath string) (*BlockDev, error)

Device makes sure the block device exists and returns a handle to it.

maybeDevpath can be path like /dev/sda1, /sys/class/block/sda1 or just sda1. We will just use the last component.

func (*BlockDev) BlockSize

func (b *BlockDev) BlockSize() (int, error)

BlockSize returns the logical block size (BLKSSZGET).

func (*BlockDev) DevName

func (b *BlockDev) DevName() string

Name implements mount.Mounter.

func (BlockDev) DevicePath

func (b BlockDev) DevicePath() string

DevicePath is the path to the actual device.

func (*BlockDev) GPTTable

func (b *BlockDev) GPTTable() (*gpt.Table, error)

GPTTable 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 (*BlockDev) KernelBlockSize

func (b *BlockDev) KernelBlockSize() (int, error)

KernelBlockSize returns the soft block size used inside the kernel (BLKBSZGET).

func (*BlockDev) Mount

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

Mount implements mount.Mounter.

func (*BlockDev) PCIInfo

func (b *BlockDev) PCIInfo() (*pci.PCI, error)

PCIInfo searches sysfs for the PCI vendor and device id. We fill in the PCI struct with just those two elements.

func (*BlockDev) PhysicalBlockSize

func (b *BlockDev) PhysicalBlockSize() (int, error)

PhysicalBlockSize returns the physical block size.

func (*BlockDev) ReadPartitionTable

func (b *BlockDev) ReadPartitionTable() error

ReadPartitionTable prompts the kernel to re-read the partition table on this block device.

func (*BlockDev) Size

func (b *BlockDev) Size() (uint64, error)

Size returns the size in bytes.

func (*BlockDev) String

func (b *BlockDev) String() string

String implements fmt.Stringer.

type BlockDevices

type BlockDevices []*BlockDev

BlockDevices is a list of block devices.

func GetBlockDevices

func GetBlockDevices() (BlockDevices, error)

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

func (BlockDevices) FilterBlockPCI

func (b BlockDevices) FilterBlockPCI(blocklist pci.Devices) BlockDevices

FilterBlockPCI returns a list of BlockDev objects whose backing pci devices do not match the blocklist of PCI devices passed in. FilterBlockPCI discards entries which have a matching PCI vendor and device ID as an entry in the blocklist.

func (BlockDevices) FilterBlockPCIString

func (b BlockDevices) FilterBlockPCIString(blocklist string) (BlockDevices, error)

FilterBlockPCIString parses a string in the format vendor:device,vendor:device and returns a list of BlockDev objects whose backing pci devices do not match the vendor:device pairs passed in. All values are treated as hex. E.g. 0x8086:0xABCD,8086:0x1234

func (BlockDevices) FilterFSUUID

func (b BlockDevices) FilterFSUUID(fsuuid string) BlockDevices

FilterFSUUID returns a list of BlockDev objects whose underlying block device has a filesystem with the given FSUUID.

func (BlockDevices) FilterHavingPartitions

func (b BlockDevices) FilterHavingPartitions(parts []int) BlockDevices

FilterHavingPartitions returns BlockDevices with have the specified partitions. (e.g. f(1, 2) {sda, sda1, sda2, sdb} -> {sda})

func (BlockDevices) FilterName

func (b BlockDevices) FilterName(name string) BlockDevices

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

func (BlockDevices) FilterNames

func (b BlockDevices) FilterNames(names ...string) BlockDevices

FilterNames filters block devices by the given list of device names (e.g. /dev/sda1 sda2 /sys/class/block/sda3).

func (BlockDevices) FilterPartID

func (b BlockDevices) FilterPartID(guid string) BlockDevices

FilterPartID returns partitions with the given partition ID GUID.

func (BlockDevices) FilterPartLabel

func (b BlockDevices) FilterPartLabel(label string) BlockDevices

FilterPartLabel returns a list of BlockDev objects whose underlying block device has the given partition label. The name comparison is case-insensitive.

func (BlockDevices) FilterPartType

func (b BlockDevices) FilterPartType(guid string) BlockDevices

FilterPartType returns partitions with the given partition type GUID.

func (BlockDevices) FilterZeroSize

func (b BlockDevices) FilterZeroSize() BlockDevices

FilterZeroSize attempts to find block devices that have at least one block of content.

This serves to eliminate block devices that have no backing storage, but appear in /sys/class/block anyway (like some loop, nbd, or ram devices).

Jump to

Keyboard shortcuts

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