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

Function blkid_probe

crates/blockdev/src/blockdev.rs:47–71  ·  view source on GitHub ↗

Probe a device with `blkid -p` and return all discovered properties as key-value pairs. This uses the `export` output format (`KEY=value`, one per line) to retrieve all tags in a single invocation, rather than spawning blkid once per property. Returns `Ok(empty map)` if blkid exits with code 2 (no tags found, e.g. the device is a whole disk). Other non-zero exits are propagated as errors.

(dev: &str)

Source from the content-addressed store, hash-verified

45/// e.g. the device is a whole disk). Other non-zero exits are propagated
46/// as errors.
47fn blkid_probe(dev: &str) -> Result<HashMap<String, String>> {
48 let mut cmd = Command::new("blkid");
49 cmd.args(["-p", "-o", "export"]).arg(dev);
50 cmd.log_debug();
51 let output = cmd.output().context("Failed to run blkid")?;
52 if !output.status.success() {
53 // blkid exits with 2 when no tags are found (e.g. whole disk)
54 if output.status.code() == Some(2) {
55 return Ok(HashMap::new());
56 }
57 let stderr = String::from_utf8_lossy(&output.stderr);
58 anyhow::bail!(
59 "blkid -p failed on {dev} (exit status {}): {stderr}",
60 output.status
61 );
62 }
63 let text = String::from_utf8(output.stdout).context("blkid output is not UTF-8")?;
64 let mut props = HashMap::new();
65 for line in text.lines() {
66 if let Some((key, value)) = line.split_once('=') {
67 props.insert(key.to_string(), value.to_string());
68 }
69 }
70 Ok(props)
71}
72
73/// MBR partition type IDs that indicate an EFI System Partition.
74/// 0x06 is FAT16 (used as ESP on some MBR systems), 0xEF is the

Callers 1

backfill_missingMethod · 0.85

Calls 3

argMethod · 0.80
argsMethod · 0.80
log_debugMethod · 0.80

Tested by

no test coverage detected