Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BlkIDEncodeLabel ¶
BlkIDEncodeLabel encodes a name for use as a partition or filesystem label symlink by udev. The result matches the output of blkid_encode_string() from libblkid.
func MockMountPointDisksToPartitionMapping ¶
func MockMountPointDisksToPartitionMapping(mockedMountPoints map[Mountpoint]*MockDiskMapping) (restore func())
MockMountPointDisksToPartitionMapping will mock DiskFromMountPoint such that the specified mapping is returned/used. Specifically, keys in the provided map are mountpoints, and the values for those keys are the disks that will be returned from DiskFromMountPoint or used internally in MountPointIsFromDisk.
Types ¶
type Disk ¶
type Disk interface { // FindMatchingPartitionUUID finds the partition uuid for a partition // matching the specified filesystem label on the disk. Note that for // non-ascii labels like "Some label", the label will be encoded using // \x<hex> for potentially non-safe characters like in "Some\x20Label". // If the filesystem label was not found on the disk, and no other errors // were encountered, a FilesystemLabelNotFoundError will be returned. FindMatchingPartitionUUID(string) (string, error) // MountPointIsFromDisk returns whether the specified mountpoint corresponds // to a partition on the disk. Note that this only considers partitions // and mountpoints found when the disk was identified with // DiskFromMountPoint. // TODO:UC20: make this function return what a Disk of where the mount point // is actually from if it is not from the same disk for better // error reporting MountPointIsFromDisk(string, *Options) (bool, error) // Dev returns the string "major:minor" number for the disk device. Dev() string // HasPartitions returns whether the disk has partitions or not. A physical // disk will have partitions, but a mapper device will just be a volume that // does not have partitions for example. HasPartitions() bool }
Disk is a single physical disk device that contains partitions. TODO:UC20: add function to get some properties like an associated /dev node
for a disk for better user error reporting, i.e. /dev/vda3 is much more helpful than 252:3
type FilesystemLabelNotFoundError ¶
type FilesystemLabelNotFoundError struct {
Label string
}
FilesystemLabelNotFoundError is an error where the specified label was not found on the disk.
func (FilesystemLabelNotFoundError) Error ¶
func (e FilesystemLabelNotFoundError) Error() string
type MockDiskMapping ¶
type MockDiskMapping struct { FilesystemLabelToPartUUID map[string]string DiskHasPartitions bool DevNum string }
MockDiskMapping is an implementation of Disk for mocking purposes, it is exported so that other packages can easily mock a specific disk layout without needing to mock the mount setup, sysfs, or udev commands just to test high level logic. DevNum must be a unique string per unique mocked disk, if only one disk is being mocked it can be left empty.
func (*MockDiskMapping) Dev ¶
func (d *MockDiskMapping) Dev() string
Dev returns a unique representation of the mock disk that is suitable for comparing two mock disks to see if they are the same. Part of the Disk interface.
func (*MockDiskMapping) FindMatchingPartitionUUID ¶
func (d *MockDiskMapping) FindMatchingPartitionUUID(label string) (string, error)
FindMatchingPartitionUUID returns a matching PartitionUUID for the specified label if it exists. Part of the Disk interface.
func (*MockDiskMapping) HasPartitions ¶
func (d *MockDiskMapping) HasPartitions() bool
HasPartitions returns if the mock disk has partitions or not. Part of the Disk interface.
func (*MockDiskMapping) MountPointIsFromDisk ¶
func (d *MockDiskMapping) MountPointIsFromDisk(mountpoint string, opts *Options) (bool, error)
MountPointIsFromDisk returns if the disk that the specified mount point comes from is the same disk as the object. Part of the Disk interface.
type Mountpoint ¶
Mountpoint is a combination of a mountpoint location and whether that mountpoint is a decrypted device. It is only used in identifying mount points with MountPointIsFromDisk and DiskFromMountPoint with MockMountPointDisksToPartitionMapping.