sys

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DriveTypeHDD represents a rotating hard disk drive
	DriveTypeHDD = "HDD"

	// DriveTypeSSD represents a solid state drive
	DriveTypeSSD = "SSD"

	// DriveTypeUnknown is used when the drive type of the disk could not be determined.
	DriveTypeUnknown = "Unknown"
)
View Source
const (
	// BlockSubSystem is the key used to represent block subsystem in sysfs
	BlockSubSystem = "block"
	// NVMeSubSystem is the key used to represent nvme subsystem in sysfs
	NVMeSubSystem = "nvme"
)
View Source
const (
	// SparseBlockDeviceType is the sparse blockdevice type
	SparseBlockDeviceType = "sparse"
	// BlockDeviceType is the type for blockdevice.
	BlockDeviceType = "blockdevice"

	// BlockDevicePrefix is the prefix used in UUIDs
	BlockDevicePrefix = BlockDeviceType + "-"

	// The following blockdevice types correspond to the types as seen by the host system
	// BlockDeviceTypeDisk represents a disk type
	BlockDeviceTypeDisk = "disk"

	// BlockDeviceTypePartition represents a partition
	BlockDeviceTypePartition = "partition"

	// BlockDeviceTypeLoop represents a loop device
	BlockDeviceTypeLoop = "loop"

	// BlockDeviceTypeDMDevice is a dm device
	BlockDeviceTypeDMDevice = "dm"

	// BlockDeviceTypeLVM is an lvm device type
	BlockDeviceTypeLVM = "lvm"

	// BlockDeviceTypeCrypt is a LUKS volume
	BlockDeviceTypeCrypt = "crypt"

	// BlockDeviceTypeMultiPath is a multipath device
	BlockDeviceTypeMultiPath = "mpath"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device represents a blockdevice using its sysfs path.

func NewDevice

func NewDevice(sysPath string, path string, devName string) *Device

NewDevice

func NewSysFsDeviceFromDevPath

func NewSysFsDeviceFromDevPath(devPath string) (*Device, error)

NewSysFsDeviceFromDevPath is used to get sysfs device struct from the device devpath The sysfs device struct contains the device name along with the syspath

func (Device) GetCapacityInBytes

func (s Device) GetCapacityInBytes() (int64, error)

GetCapacityInBytes gets the capacity of the device in bytes

func (Device) GetDeviceType

func (s Device) GetDeviceType(devType string) (string, error)

GetDeviceType gets the device type, as shown in lsblk devtype should be prefilled by udev probe (DEVTYPE) as disk/part for this to work

Ported from https://github.com/karelzak/util-linux/blob/master/misc-utils/lsblk.c

func (Device) GetDriveType

func (s Device) GetDriveType() (string, error)

GetDriveType gets the drive type of the device based on the rotational value. Can be HDD or SSD

func (Device) GetHardwareSectorSize

func (s Device) GetHardwareSectorSize() (int64, error)

GetHardwareSectorSize gets the hardware sector size of the device

func (Device) GetLogicalBlockSize

func (s Device) GetLogicalBlockSize() (int64, error)

GetLogicalBlockSize gets the logical block size, the caller should handle if 0 LB size is returned

func (Device) GetPartitions

func (s Device) GetPartitions() ([]string, bool)

getPartitions gets the partitions of this device if it has any

func (Device) GetPhysicalBlockSize

func (s Device) GetPhysicalBlockSize() (int64, error)

GetPhysicalBlockSize gets the physical block size of the device

Jump to

Keyboard shortcuts

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