Skip to main content

BlockDevice

Struct BlockDevice 

Source
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: String

The name of the block device (e.g. "sda", "nvme0n1").

§maj_min: MajMin

The major and minor numbers of the block device.

Corresponds to the JSON field "maj:min".

§rm: bool

Whether the device is removable.

§size: u64

The size of the block device in bytes.

§ro: bool

Whether the device is read-only.

§device_type: DeviceType

The 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

Source

pub fn has_children(&self) -> bool

Returns true if this device has any children.

Source

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.

Source

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.

Source

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.

Source

pub fn find_descendant(&self, name: &str) -> Option<&BlockDevice>

Recursively finds a descendant device (including self) by name.

Source

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.

Source

pub fn active_mountpoints_iter(&self) -> impl Iterator<Item = &str>

Returns an iterator over the non-null mountpoints for this device.

Source

pub fn is_mounted(&self) -> bool

Returns true if this device has at least one mountpoint.

Source

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.

Source

pub fn is_disk(&self) -> bool

Returns true if this device is a DeviceType::Disk.

Source

pub fn is_partition(&self) -> bool

Returns true if this device is a DeviceType::Part.

Trait Implementations§

Source§

impl Clone for BlockDevice

Source§

fn clone(&self) -> BlockDevice

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BlockDevice

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for BlockDevice

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for BlockDevice

Source§

fn eq(&self, other: &BlockDevice) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for BlockDevice

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for BlockDevice

Source§

impl StructuralPartialEq for BlockDevice

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,