MCPcopy Create free account
hub / github.com/bootc-dev/bootc / list_parents

Method list_parents

crates/blockdev/src/blockdev.rs:380–403  ·  view source on GitHub ↗

Query parent devices via `lsblk --inverse`. Returns `Ok(None)` if this device is already a root device (no parents). In the returned `Vec `, 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).

(&self)

Source from the content-addressed store, hash-verified

378 /// *its own* parents (grandparents, etc.), forming the full chain to the
379 /// root device(s). A device can have multiple parents (e.g. RAID, LVM).
380 pub fn list_parents(&self) -> Result<Option<Vec<Device>>> {
381 let path = self.path();
382 let output: DevicesOutput = Command::new("lsblk")
383 .args(["-J", "-b", "-O", "--inverse"])
384 .arg(&path)
385 .log_debug()
386 .run_and_parse_json()?;
387
388 let device = output
389 .blockdevices
390 .into_iter()
391 .next()
392 .ok_or_else(|| anyhow!("no device output from lsblk --inverse for {path}"))?;
393
394 match device.children {
395 Some(mut children) if !children.is_empty() => {
396 for child in &mut children {
397 child.backfill_missing()?;
398 }
399 Ok(Some(children))
400 }
401 _ => Ok(None),
402 }
403 }
404
405 /// Walk the parent chain to find all root (whole disk) devices,
406 /// and fail if more than one root is found.

Callers 1

find_all_rootsMethod · 0.80

Calls 9

run_and_parse_jsonMethod · 0.80
log_debugMethod · 0.80
argMethod · 0.80
argsMethod · 0.80
backfill_missingMethod · 0.80
pathMethod · 0.45
nextMethod · 0.45
into_iterMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected