Documentation ¶
Index ¶
- Constants
- func OsDiskName() (string, error)
- type MockOsDiskDetails
- type Udev
- type UdevDevice
- func (device *UdevDevice) DiskInfoFromLibudev() UdevDiskDetails
- func (ud *UdevDevice) GetAction() string
- func (device *UdevDevice) GetDevLinks() map[string][]string
- func (ud *UdevDevice) GetDevnode() string
- func (ud *UdevDevice) GetDevtype() string
- func (device *UdevDevice) GetFileSystemInfo() string
- func (device *UdevDevice) GetPartitionType() string
- func (ud *UdevDevice) GetPropertyValue(key string) string
- func (ud *UdevDevice) GetSysattrValue(sysattr string) string
- func (device *UdevDevice) GetSyspath() string
- func (device *UdevDevice) GetUid() string
- func (device *UdevDevice) IsDisk() bool
- func (device *UdevDevice) IsParitition() bool
- func (ud *UdevDevice) UdevDeviceUnref()
- type UdevDiskDetails
- type UdevEnumerate
- type UdevListEntry
- type UdevMonitor
Constants ¶
const ( NDMPrefix = "disk-" // NDMPrefix used as disk's uuid prefix UDEV_SUBSYSTEM = "block" // udev to filter this device type UDEV_SYSTEM = "disk" // used to filter devices other than disk which udev tracks (eg. CD ROM) UDEV_PARTITION = "partition" // used to filter out partitions UDEV_PATH = "DEVPATH" // udev attribute to get device path UDEV_WWN = "ID_WWN" // udev attribute to get device WWN number UDEV_SERIAL = "ID_SERIAL_SHORT" // udev attribute to get device serial number UDEV_SERIAL_FULL = "ID_SERIAL" // udev attribute to get - separated vendor, model, serial UDEV_BUS = "ID_BUS" // udev attribute to get bus name UDEV_MODEL = "ID_MODEL" // udev attribute to get device model number UDEV_VENDOR = "ID_VENDOR" // udev attribute to get device vendor details UDEV_TYPE = "ID_TYPE" // udev attribute to get device type UDEV_MAJOR = "MAJOR" // udev attribute to get device major no UDEV_MINOR = "MINOR" // udev attribute to get device minor no UDEV_UUID = "UDEV_UUID" // ndm attribute to get device uuid UDEV_SYSPATH = "UDEV_SYSPATH" // udev attribute to get device syspath UDEV_ACTION = "UDEV_ACTION" // udev attribute to get monitor device action UDEV_ACTION_ADD = "add" // udev attribute constant for add action UDEV_ACTION_REMOVE = "remove" // udev attribute constant for remove action UDEV_DEVTYPE = "DEVTYPE" // udev attribute to get device device type ie - disk or part UDEV_SOURCE = "udev" // udev source constant UDEV_SYSPATH_PREFIX = "/sys/dev/block/" // udev syspath prefix UDEV_DEVNAME = "DEVNAME" // udev attribute contain disk name given by kernel UDEV_DEVLINKS = "DEVLINKS" // udev attribute contain devlinks of a disk BY_ID_LINK = "by-id" // by-path devlink contains this string BY_PATH_LINK = "by-path" // by-path devlink contains this string LINK_ID_INDEX = 4 // this is used to get link index from dev link UDEV_PARTITION_TYPE = "ID_PART_ENTRY_TYPE" // udev attribute to get partition type UDEV_FS_TYPE = "ID_FS_TYPE" // file system type the partition UDEV_FS_NONE = "None" // udev constant for no file system )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type MockOsDiskDetails ¶
type MockOsDiskDetails struct { OsDiskName string DevType string DevNode string Size string SysPath string Model string Serial string Vendor string Wwn string Uid string FileSystem string ByIdDevLinks []string ByPathDevLinks []string }
MockOsDiskDetails struct contain different attribute of os disk.
func MockDiskDetails ¶
func MockDiskDetails() (MockOsDiskDetails, error)
MockDiskDetails returns os disk details which is used in unit test.
type Udev ¶
type Udev struct {
// contains filtered or unexported fields
}
Udev wraps a libudev udev struct
func (*Udev) NewDeviceFromNetlink ¶
func (u *Udev) NewDeviceFromNetlink(source string) (*UdevMonitor, error)
NewDeviceFromNetlink use newUdeviceMonitor() and use returns UdevMonitor pointer in success The function returns nil on failure it can monitor udev or kernel as source.
func (*Udev) NewDeviceFromSysPath ¶
func (u *Udev) NewDeviceFromSysPath(sysPath string) (*UdevDevice, error)
NewDeviceFromSysPath identify the block device currently attached to the system at given sysPath and returns that pointer of C udev_device structure. The caller can query all(available) the disk properties using returned C udev_device structure.
func (*Udev) NewUdevEnumerate ¶
func (u *Udev) NewUdevEnumerate() (*UdevEnumerate, error)
NewUdevEnumerate returns a pointer to a Udevenumerate
type UdevDevice ¶
type UdevDevice struct {
// contains filtered or unexported fields
}
UdevDevice wraps a libudev device object
func (*UdevDevice) DiskInfoFromLibudev ¶
func (device *UdevDevice) DiskInfoFromLibudev() UdevDiskDetails
DiskInfoFromLibudev returns disk attribute extracted using libudev apicalls.
func (*UdevDevice) GetAction ¶
func (ud *UdevDevice) GetAction() string
GetAction returns device action when it is monitored. It can be add,remove,online,offline,change
func (*UdevDevice) GetDevLinks ¶
func (device *UdevDevice) GetDevLinks() map[string][]string
GetDevLinks returns syspath of a disk using syspath we can fell details in diskInfo struct using udev probe
func (*UdevDevice) GetDevnode ¶
func (ud *UdevDevice) GetDevnode() string
GetDevnode returns the device node file name belonging to the udev device. The path is an absolute path, and starts with the device directory.
func (*UdevDevice) GetDevtype ¶
func (ud *UdevDevice) GetDevtype() string
GetDevtype returns the devtype string of the udev device.
func (*UdevDevice) GetFileSystemInfo ¶ added in v0.3.0
func (device *UdevDevice) GetFileSystemInfo() string
GetFileSystemInfo returns filesystem type on disk/partition if it exists.
func (*UdevDevice) GetPartitionType ¶ added in v0.3.0
func (device *UdevDevice) GetPartitionType() string
GetPartitionType returns the partition type of the partition, like DOS, lvm2 etc
func (*UdevDevice) GetPropertyValue ¶
func (ud *UdevDevice) GetPropertyValue(key string) string
GetPropertyValue retrieves the value of a device property
func (*UdevDevice) GetSysattrValue ¶
func (ud *UdevDevice) GetSysattrValue(sysattr string) string
GetSysattrValue retrieves the content of a sys attribute file returns an empty string if there is no sys attribute value. The retrieved value is cached in the device. Repeated calls will return the same value and not open the attribute again.
func (*UdevDevice) GetSyspath ¶
func (device *UdevDevice) GetSyspath() string
GetSyspath returns syspath of a disk using syspath we can fell details in diskInfo struct using udev probe
func (*UdevDevice) GetUid ¶
func (device *UdevDevice) GetUid() string
GetUid returns unique id for the disk block device
func (*UdevDevice) IsDisk ¶
func (device *UdevDevice) IsDisk() bool
IsDisk returns true if device is a disk
func (*UdevDevice) IsParitition ¶ added in v0.3.0
func (device *UdevDevice) IsParitition() bool
IsPartition return true if device is a partition
func (*UdevDevice) UdevDeviceUnref ¶
func (ud *UdevDevice) UdevDeviceUnref()
UdevDeviceUnref frees udev_device structure.
type UdevDiskDetails ¶
type UdevDiskDetails struct { Model string // Model is Model of disk. Serial string // Serial is Serial of a disk. Vendor string // Vendor is Vendor of a disk. Path string // Path is Path of a disk. ByIdDevLinks []string // ByIdDevLinks contains by-id devlinks ByPathDevLinks []string // ByPathDevLinks contains by-path devlinks FileSystem string // FileSystem on the disk }
UdevDiskDetails struct contain different attribute of disk.
type UdevEnumerate ¶
type UdevEnumerate struct {
// contains filtered or unexported fields
}
UdevEnumerate wraps a libudev udev_enumerate object
func (*UdevEnumerate) AddSubsystemFilter ¶
func (ue *UdevEnumerate) AddSubsystemFilter(subSystem string) error
AddSubsystemFilter adds filter in UdeviceMon struct. This filter is efficiently executed inside kernel, and libudev subscribers will usually not be woken up for devices which do not match.
func (*UdevEnumerate) ListEntry ¶
func (ue *UdevEnumerate) ListEntry() *UdevListEntry
ListEntry returns UdevListEntry struct from which we can get device.
func (*UdevEnumerate) ScanDevices ¶
func (ue *UdevEnumerate) ScanDevices() error
ScanDevices scan devices in system and returns list of devices present in system
func (*UdevEnumerate) UnrefUdevEnumerate ¶
func (ue *UdevEnumerate) UnrefUdevEnumerate()
UnrefUdevEnumerate frees udev_enumerate structure.
type UdevListEntry ¶
type UdevListEntry struct {
// contains filtered or unexported fields
}
UdevListEntry wraps a libudev udev_list_entry object
func (*UdevListEntry) GetName ¶
func (le *UdevListEntry) GetName() string
GetName return Udevice syspath.
func (*UdevListEntry) GetNextEntry ¶
func (le *UdevListEntry) GetNextEntry() *UdevListEntry
GetNextEntry returns UdevListEntry struct if next device is present else it returns nil pointer.
type UdevMonitor ¶
type UdevMonitor struct {
// contains filtered or unexported fields
}
UdevMonitor wraps a libudev monitor device object
func (*UdevMonitor) AddSubsystemFilter ¶
func (um *UdevMonitor) AddSubsystemFilter(key string) error
AddSubsystemFilter adds subsystem filter in UdevMonitor struct. This filter is efficiently executed inside kernel, and libudev subscribers will usually not be woken up for devices which do not match.
func (*UdevMonitor) EnableReceiving ¶
func (um *UdevMonitor) EnableReceiving() error
EnableReceiving binds udev_monitor socket to event source.
func (*UdevMonitor) GetFd ¶
func (um *UdevMonitor) GetFd() (int, error)
GetFd retrieves socket file descriptor associated with monitor.
func (*UdevMonitor) ReceiveDevice ¶
func (um *UdevMonitor) ReceiveDevice() (*UdevDevice, error)
ReceiveDevice receives data from udev monitor socket, allocate a new udev device, fill in received data, and return Udevice struct.
func (*UdevMonitor) UdevMonitorUnref ¶
func (um *UdevMonitor) UdevMonitorUnref()
UdevMonitorUnref frees udev monitor structure.