Documentation ¶
Overview ¶
Package block finds, mounts, and modifies block devices on Linux systems.
Index ¶
- Variables
- func GetMountpointByDevice(devicePath string) (*string, error)
- type BlockDev
- func (b *BlockDev) BlockSize() (int, error)
- func (b *BlockDev) DevName() string
- func (b BlockDev) DevicePath() string
- func (b *BlockDev) GPTTable() (*gpt.Table, error)
- func (b *BlockDev) KernelBlockSize() (int, error)
- func (b *BlockDev) Mount(path string, flags uintptr) (*mount.MountPoint, error)
- func (b *BlockDev) PCIInfo() (*pci.PCI, error)
- func (b *BlockDev) PhysicalBlockSize() (int, error)
- func (b *BlockDev) ReadPartitionTable() error
- func (b *BlockDev) Size() (uint64, error)
- func (b *BlockDev) String() string
- type BlockDevices
- func (b BlockDevices) FilterBlockPCI(blocklist pci.Devices) BlockDevices
- func (b BlockDevices) FilterBlockPCIString(blocklist string) (BlockDevices, error)
- func (b BlockDevices) FilterFSUUID(fsuuid string) BlockDevices
- func (b BlockDevices) FilterHavingPartitions(parts []int) BlockDevices
- func (b BlockDevices) FilterName(name string) BlockDevices
- func (b BlockDevices) FilterNames(names ...string) BlockDevices
- func (b BlockDevices) FilterPartID(guid string) BlockDevices
- func (b BlockDevices) FilterPartLabel(label string) BlockDevices
- func (b BlockDevices) FilterPartType(guid string) BlockDevices
- func (b BlockDevices) FilterZeroSize() BlockDevices
Constants ¶
This section is empty.
Variables ¶
var ( // LinuxMountsPath is the standard mountpoint list path LinuxMountsPath = "/proc/mounts" // Debug function to override for verbose logging. Debug = func(string, ...interface{}) {} )
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 ¶
GetMountpointByDevice gets the mountpoint by given device name. Returns on first match
Types ¶
type BlockDev ¶
BlockDev maps a device name to a BlockStat structure for a given block device
func Device ¶
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) DevicePath ¶
DevicePath is the path to the actual device.
func (*BlockDev) GPTTable ¶
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 ¶
KernelBlockSize returns the soft block size used inside the kernel (BLKBSZGET).
func (*BlockDev) PCIInfo ¶
PCIInfo searches sysfs for the PCI vendor and device id. We fill in the PCI struct with just those two elements.
func (*BlockDev) PhysicalBlockSize ¶
PhysicalBlockSize returns the physical block size.
func (*BlockDev) ReadPartitionTable ¶
ReadPartitionTable prompts the kernel to re-read the partition table on this block device.
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).