Storage device wrappers¶
Quick example¶
Basic usage of storage wrappers uses the disk device type wrapped in
Disk
wrapper, and accessing disk and partition
information using properties on that object. All partitions are accessible
through the object’s partitions
attribute, so it
is not necessary to separately wrap partition objects (though there is nothing
wrong with that).
Example:
>>> devs = list(udev.devices_by_subsystem('block'))
>>> device = storage.Disk(devs[0])
>>> device.bus
u'ata'
>>> device.size
256060514304
>>> device.sectors
500118192
>>> device.part_table_type
u'gpt'
>>> p1 = device.partitions[0]
>>> p1.offset
4097
>>> p1.size
314573312
>>> p1.format
u'vfat'
Module contents¶
-
class
hwd.storage.
Disk
(dev)¶ Wrapper for
pyudev.Device
objects of ‘disk’ type.-
is_read_only
¶ Whether disk is read-only. This evaluates to
True
if disk is read-only.
-
is_removable
¶ Whether disk is removable. This property evaluates to
True
if disk is removable. Note that this does not mean disk is USB-attached, and does not necessarily match the common notion of removable devices.If you wish to know whether a device is USB-attached, check whether the value of the
bus
property is'usb'
.
-
part_table_type
¶ Partition table type. Evaluates to either
'dos'
or'gpt'
.
-
partitions
¶ Iterable containing disk’s partition objects. Objects in the iterable are
Partition
instances.
-
sectors
¶ Disk size in sectors. If for some reason, this information is not available, this property evaluates to
-1
.
-
size
¶ Disk capacity in bytes. This value is obtained by multiplying sector size by 512.
-
uuid
¶ Partition table UUID. Note that UUIDs for different partition table types have different fomats.
-
-
class
hwd.storage.
Fstat
(total, used, free, pct_used, pct_free)¶ -
free
¶ Alias for field number 2
-
pct_free
¶ Alias for field number 4
-
pct_used
¶ Alias for field number 3
-
total
¶ Alias for field number 0
-
used
¶ Alias for field number 1
-
-
class
hwd.storage.
Mountable
¶ Mixing providing interfaces for mountable storage devices.
-
mount_points
¶ Iterator of partition’s mount points obtained by reading /proc/mounts. Returns empty list if /proc/mounts is not readable or if there are no mount points.
-
size
¶ Subclasses using this mixin must implement their own size property which returns the total capacity in bytes.
-
-
class
hwd.storage.
MtabEntry
(dev, mdir, fstype, opts, cfreq, cpass)¶ -
cfreq
¶ Alias for field number 4
-
cpass
¶ Alias for field number 5
-
dev
¶ Alias for field number 0
-
fstype
¶ Alias for field number 2
-
mdir
¶ Alias for field number 1
-
opts
¶ Alias for field number 3
-
-
class
hwd.storage.
Partition
(dev, disk=None)¶ Wrapper for
pyudev.Device
objects of ‘partition’ type.As with all wrappers, this class takes
dev
as its first argument. The optionaldisk
argument can be passed, and is stored as thedisk
property. This is mostly used byDisk
class to maintain a refrence to itself.-
format
¶ Fiesystem type. This evaluates to any number of supported file system types such as
'ext4'
or'vfat'
.Note
Extended partitions will have this property evaluate to
None
.
-
is_extended
¶ Whether partition is extended.
-
label
¶ Volume label. This property evaluates to
None
if no volume label is not set on a partition.
-
number
¶ Partition number. This specifies a position of the partition in the partition table. If the value is not known for some reason, this property evaluates to
-1
.
-
offset
¶ Partition offset in sectors. If this information is not available for some reason, it evaluates to
-1
.
-
part_type
¶ Partition type ID. This is expressed in hex string. Note that this is not the same as filesystem type which is available through the
part_type
property.
-
scheme
¶ Partition entry scheme. This evaluates to either
'dos'
or'gpt'
.
-
sectors
¶ Partition size in sectors. If this information is not available for some reason, it evaluates to
-1
.
-
size
¶ Partition size in bytes. This value is obtained by multiplying the sector size by 512.
-
usage
¶ Filesystem usage (purpose). In most cases this should evaluate to
'filesystem'
. In some cases (e.g., swap partition), it may evaluate to'other'
or some other value.
-
uuid
¶ Filesystem UUID. Note that this is not the same as the partition UUID (which is not available through this wrapper, other than directly accessing the underlying
pyudev.Device
object).
-
-
class
hwd.storage.
PartitionBase
(dev, disk=None)¶ Base class for all partition devices. This class encapsulates the base functionality for all mountable partitions. It takes
disk
as an optional argument, and allows access to parent device from the partition devices.
-
class
hwd.storage.
UbiContainer
(dev)¶ Wrapper for
pyudev.Device
objects of the ‘ubi’ subsytem.The ‘ubi’ subsystem has two types of devices. The parent devices serve as containers for the actual volumes. This class is meant to be used by containers, rather than volumes.
This class mainly exists to facilitate the
PartitionBase
API, specifically the API that allows access to parent device.
-
class
hwd.storage.
UbiVolume
(dev, disk=None)¶ Wrapper for
pyudev.Device
objects of the ‘ubi’ subsytem.The ‘ubi’ subsystem has two types of devices. The parent devices serve as containers for the actual volumes. This class is meant to be used by volumes, rather than their parent devices.
-
aliases
¶ Aliases for UBI volume. This propery evaluates to device node itself plus the
'ubi${INDEX}:${LABEL}'
string. The latter is used to identify the device in /proc/mounts table, and is not really an alias.
-
parent_class
¶ alias of
UbiContainer
-
sectors
¶ Simulated number of sectors derived from volume size. This property is provided for compatibility with
Partition
API.Warning
The concept does not really apply to UBI volumes, so it’s best to not rely on the value of this property.
-
size
¶ Volume capacity in bytes. This property evaluates to -1 if size information is not available for any reason.
-
-
hwd.storage.
mounts
()¶ Iterator yielding mount points that appear in /proc/mounts. If /proc/mounts is not readable or does not exist, this function raises an exception.