storage

package
v6.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2019 License: BSD-3-Clause Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
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

View Source
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

View Source
var (
	// LinuxMountsPath is the standard mountpoint list path
	LinuxMountsPath = "/proc/mounts"
)
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 GetGPTTable

func GetGPTTable(device BlockDev) (*gpt.Table, error)

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

func GetMountpointByDevice(devicePath string) (*string, error)

GetMountpointByDevice gets the mountpoint by given device name. Returns on first match

func GetSupportedFilesystems

func GetSupportedFilesystems() (fstypes []string, err error)

GetSupportedFilesystems returns the supported file systems for block devices

Types

type BlockDev

type BlockDev struct {
	Name   string
	Stat   BlockStat
	FsUUID string
}

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

func FilterEFISystemPartitions

func FilterEFISystemPartitions(devices []BlockDev) ([]BlockDev, error)

FilterEFISystemPartitions returns a list of BlockDev objects whose underlying block device is a valid EFI system partition, or an error if any

func GetBlockStats

func GetBlockStats() ([]BlockDev, error)

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

func PartitionsByFsUUID

func PartitionsByFsUUID(devices []BlockDev, fsuuid string) []BlockDev

PartitionsByFsUUID returns a list of BlockDev objects whose underlying block device has a filesystem with the given UUID

func PartitionsByGUID

func PartitionsByGUID(devices []BlockDev, guid string) ([]BlockDev, error)

PartitionsByGUID returns a list of BlockDev objects whose underlying block device has the given GUID

func (BlockDev) Summary

func (b BlockDev) Summary() string

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

func BlockStatFromBytes(buf []byte) (*BlockStat, error)

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

type Mountpoint struct {
	DeviceName string
	Path       string
	FsType     string
}

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.

Jump to

Keyboard shortcuts

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