Documentation ¶
Index ¶
Constants ¶
const ( EXT2SprblkOff = 1024 // Offset of superblock in partition EXT2SprblkSize = 512 // Actually 1024 but most of the last byters are reserved EXT2SprblkMagicOff = 56 // Offset of magic number in suberblock EXT2SprblkMagicSize = 2 EXT2SprblkMagic = '\uEF53' // fixed value EXT2SprblkUUIDOff = 104 // Offset of UUID in superblock EXT2SprblkUUIDSize = 16 )
see https://www.nongnu.org/ext2-doc/ext2.html#DISK-ORGANISATION
const ( FAT32MagicOff = 82 // Offset of magic number FAT32MagicSize = 8 FAT32Magic = "FAT32 " // fixed value FAT32IDOff = 67 // Offset of filesystem-ID / serielnumber. Treated as short filesystem UUID FAT32IDSize = 4 )
see https://de.wikipedia.org/wiki/File_Allocation_Table#Aufbau
Variables ¶
var (
// LinuxMountsPath is the standard mountpoint list path
LinuxMountsPath = "/proc/mounts"
)
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 ¶
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 ¶
GetMountpointByDevice gets the mountpoint by given device name. Returns on first match
func GetSupportedFilesystems ¶
GetSupportedFilesystems returns the supported file systems for block devices
Types ¶
type BlockDev ¶
BlockDev maps a device name to a BlockStat structure for a given block device
func FilterEFISystemPartitions ¶
FilterEFISystemPartitions returns a list of BlockDev objects whose underlying block device is a valid EFI system partition, or an error if any
func GetBlockStats ¶
GetBlockStats iterates over /sys/class/block entries and returns a list of BlockDev objects, or an error if any
func PartitionsByFsUUID ¶
PartitionsByFsUUID returns a list of BlockDev objects whose underlying block device has a filesystem with the given UUID
func PartitionsByGUID ¶
PartitionsByGUID returns a list of BlockDev objects whose underlying block device has the given GUID
func (BlockDev) Summary ¶
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 ¶
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
type Mountpoint ¶
Mountpoint holds mount point information for a given device
func Mount ¶
func Mount(devname, mountpath string, filesystems []string) (*Mountpoint, error)
Mount tries to mount a block device on the given mountpoint, trying in order the provided file system types. It returns a Mountpoint structure, or an error if the device could not be mounted. If the mount point does not exist, it will be created.