pub struct Device {Show 16 fields
pub name: String,
pub serial: Option<String>,
pub model: Option<String>,
pub partlabel: Option<String>,
pub parttype: Option<String>,
pub partuuid: Option<String>,
pub partn: Option<u32>,
pub children: Option<Vec<Device>>,
pub size: u64,
pub maj_min: Option<String>,
pub start: Option<u64>,
pub label: Option<String>,
pub fstype: Option<String>,
pub uuid: Option<String>,
pub path: Option<String>,
pub pttype: Option<String>,
}Fields§
§name: String§serial: Option<String>§model: Option<String>§partlabel: Option<String>§parttype: Option<String>§partuuid: Option<String>§partn: Option<u32>Partition number (1-indexed). None for whole disk devices.
children: Option<Vec<Device>>§size: u64§maj_min: Option<String>§start: Option<u64>§label: Option<String>§fstype: Option<String>§uuid: Option<String>§path: Option<String>§pttype: Option<String>Partition table type (e.g., “gpt”, “dos”). Only present on whole disk devices.
Implementations§
Source§impl Device
impl Device
pub fn path(&self) -> String
pub fn has_children(&self) -> bool
pub fn is_mpath(&self) -> Result<bool>
Sourcepub fn get_esp_partition_number(&self) -> Result<String>
pub fn get_esp_partition_number(&self) -> Result<String>
Get the numeric partition index of the ESP (e.g. “1”, “2”).
We read /sys/class/block/<name>/partition rather than parsing device
names because naming conventions vary across disk types (sd, nvme, dm, etc.).
On multipath devices the sysfs partition attribute doesn’t exist, so we
fall back to the partn field reported by lsblk.
Sourcepub fn find_partition_of_bios_boot(&self) -> Option<&Device>
pub fn find_partition_of_bios_boot(&self) -> Option<&Device>
Find BIOS boot partition among children.
Sourcepub fn find_colocated_esps(&self) -> Result<Option<Vec<Device>>>
pub fn find_colocated_esps(&self) -> Result<Option<Vec<Device>>>
Find all ESP partitions across all root devices backing this device. Calls find_all_roots() to discover physical disks, then searches each for an ESP. Returns None if no ESPs are found.
Sourcepub fn find_colocated_bios_boot(&self) -> Result<Option<Vec<Device>>>
pub fn find_colocated_bios_boot(&self) -> Result<Option<Vec<Device>>>
Find all BIOS boot partitions across all root devices backing this device. Calls find_all_roots() to discover physical disks, then searches each for a BIOS boot partition. Returns None if no BIOS boot partitions are found.
Sourcepub fn find_partition_of_type(&self, parttype: &str) -> Option<&Device>
pub fn find_partition_of_type(&self, parttype: &str) -> Option<&Device>
Find a child partition by partition type (case-insensitive).
Sourcepub fn find_partition_of_esp(&self) -> Result<&Device>
pub fn find_partition_of_esp(&self) -> Result<&Device>
Find the EFI System Partition (ESP) among children.
For GPT disks, this matches by the ESP partition type GUID. For MBR (dos) disks, this matches by the MBR partition type IDs (0x06 or 0xEF).
Sourcepub fn find_device_by_partno(&self, partno: u32) -> Result<&Device>
pub fn find_device_by_partno(&self, partno: u32) -> Result<&Device>
Find a child partition by partition number (1-indexed).
Sourcepub fn refresh(&mut self) -> Result<()>
pub fn refresh(&mut self) -> Result<()>
Re-query this device’s information from lsblk, updating all fields. This is useful after partitioning when the device’s children have changed.
Sourcepub fn backfill_missing(&mut self) -> Result<()>
pub fn backfill_missing(&mut self) -> Result<()>
Older versions of util-linux may be missing some properties. Backfill them if they’re missing.
Sourcepub fn list_parents(&self) -> Result<Option<Vec<Device>>>
pub fn list_parents(&self) -> Result<Option<Vec<Device>>>
Query parent devices via lsblk --inverse.
Returns Ok(None) if this device is already a root device (no parents).
In the returned Vec<Device>, each device’s children field contains
its own parents (grandparents, etc.), forming the full chain to the
root device(s). A device can have multiple parents (e.g. RAID, LVM).
Sourcepub fn require_single_root(&self) -> Result<Device>
pub fn require_single_root(&self) -> Result<Device>
Walk the parent chain to find all root (whole disk) devices, and fail if more than one root is found.
This is a convenience wrapper around find_all_roots for callers
that expect exactly one backing device (e.g. non-RAID setups).
Sourcepub fn find_all_roots(&self) -> Result<Vec<Device>>
pub fn find_all_roots(&self) -> Result<Vec<Device>>
Walk the parent chain to find all root (whole disk) devices.
Returns all root devices with their children (partitions) populated. This handles devices backed by multiple parents (e.g. RAID arrays) by following all branches of the parent tree. If this device is already a root device, returns a single-element list.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Device
impl<'de> Deserialize<'de> for Device
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>,
Auto Trait Implementations§
impl Freeze for Device
impl RefUnwindSafe for Device
impl Send for Device
impl Sync for Device
impl Unpin for Device
impl UnsafeUnpin for Device
impl UnwindSafe for Device
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more