pub struct BlockDevice {
pub name: String,
pub maj_min: MajMin,
pub rm: bool,
pub size: u64,
pub ro: bool,
pub device_type: DeviceType,
pub mountpoints: Vec<Option<String>>,
pub children: Option<Vec<BlockDevice>>,
}Expand description
Represents a single block device as reported by lsblk.
Children (partitions, RAID/LVM/crypt mappings layered on top) are stored in
the children field. To walk the device tree, use BlockDevice::descendants
or iterate manually via BlockDevice::children_iter.
Fields§
§name: StringThe name of the block device (e.g. "sda", "nvme0n1").
maj_min: MajMinThe major and minor numbers of the block device.
Corresponds to the JSON field "maj:min".
rm: boolWhether the device is removable.
size: u64The size of the block device in bytes.
ro: boolWhether the device is read-only.
device_type: DeviceTypeThe type of the block device.
Corresponds to the JSON field "type" (a reserved keyword in Rust).
mountpoints: Vec<Option<String>>The mountpoints of the device.
Accepts both a single mountpoint (possibly null) and an array of
mountpoints in the input JSON; always stored as a vector.
children: Option<Vec<BlockDevice>>Optional nested children (partitions, RAID/LVM/crypt mappings).
Implementations§
Source§impl BlockDevice
impl BlockDevice
Sourcepub fn has_children(&self) -> bool
pub fn has_children(&self) -> bool
Returns true if this device has any children.
Sourcepub fn children_iter(&self) -> impl Iterator<Item = &BlockDevice>
pub fn children_iter(&self) -> impl Iterator<Item = &BlockDevice>
Returns an iterator over the direct children of this device.
Returns an empty iterator if the device has no children.
Sourcepub fn descendants(&self) -> Descendants<'_> ⓘ
pub fn descendants(&self) -> Descendants<'_> ⓘ
Returns an iterator over self and all descendants in pre-order.
The traversal is iterative, so it will not stack-overflow on pathologically deep device trees.
Sourcepub fn find_child(&self, name: &str) -> Option<&BlockDevice>
pub fn find_child(&self, name: &str) -> Option<&BlockDevice>
Finds a direct child device by name.
Returns None if no direct child with the given name exists. For a
recursive search, use BlockDevice::find_descendant.
Sourcepub fn find_descendant(&self, name: &str) -> Option<&BlockDevice>
pub fn find_descendant(&self, name: &str) -> Option<&BlockDevice>
Recursively finds a descendant device (including self) by name.
Sourcepub fn active_mountpoints(&self) -> Vec<&str>
pub fn active_mountpoints(&self) -> Vec<&str>
Returns all non-null mountpoints for this device as an allocated Vec.
For zero-allocation iteration, prefer BlockDevice::active_mountpoints_iter.
Sourcepub fn active_mountpoints_iter(&self) -> impl Iterator<Item = &str>
pub fn active_mountpoints_iter(&self) -> impl Iterator<Item = &str>
Returns an iterator over the non-null mountpoints for this device.
Sourcepub fn is_mounted(&self) -> bool
pub fn is_mounted(&self) -> bool
Returns true if this device has at least one mountpoint.
Sourcepub fn is_system(&self) -> bool
pub fn is_system(&self) -> bool
Returns true if this device or any of its descendants is mounted at
/ (i.e. holds the root filesystem).
Recursion depth is bounded by the depth of the device tree; for trees
constructed via parse_lsblk, that is in turn bounded by
serde_json’s recursion limit.
Sourcepub fn is_disk(&self) -> bool
pub fn is_disk(&self) -> bool
Returns true if this device is a DeviceType::Disk.
Sourcepub fn is_partition(&self) -> bool
pub fn is_partition(&self) -> bool
Returns true if this device is a DeviceType::Part.
Trait Implementations§
Source§impl Clone for BlockDevice
impl Clone for BlockDevice
Source§fn clone(&self) -> BlockDevice
fn clone(&self) -> BlockDevice
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BlockDevice
impl Debug for BlockDevice
Source§impl<'de> Deserialize<'de> for BlockDevice
impl<'de> Deserialize<'de> for BlockDevice
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for BlockDevice
impl PartialEq for BlockDevice
Source§fn eq(&self, other: &BlockDevice) -> bool
fn eq(&self, other: &BlockDevice) -> bool
self and other values to be equal, and is used by ==.