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

Method backfill_missing

crates/blockdev/src/blockdev.rs:344–372  ·  view source on GitHub ↗

Backfill properties that may be missing from lsblk output. Older versions of util-linux may lack `start` and `partn`; these are backfilled from sysfs. When the udev database is unavailable (e.g. inside a container sandbox), `parttype` and `pttype` are backfilled via `blkid -p` which reads directly from the disk.

(&mut self)

Source from the content-addressed store, hash-verified

342 /// inside a container sandbox), `parttype` and `pttype` are backfilled
343 /// via `blkid -p` which reads directly from the disk.
344 pub fn backfill_missing(&mut self) -> Result<()> {
345 // The "start" parameter was only added in a version of util-linux that's only
346 // in Fedora 40 as of this writing.
347 if self.start.is_none() {
348 self.start = self.read_sysfs_property("start")?;
349 }
350 // The "partn" column was added in util-linux 2.39, which is newer than
351 // what CentOS 9 / RHEL 9 ship (2.37). Note: sysfs uses "partition" not "partn".
352 if self.partn.is_none() {
353 self.partn = self.read_sysfs_property("partition")?;
354 }
355 // When udev is unavailable, lsblk can't populate parttype/pttype from
356 // the udev database. Fall back to blkid -p which probes the disk
357 // directly. See https://github.com/osbuild/osbuild/pull/2428
358 if !have_udev() && (self.parttype.is_none() || self.pttype.is_none()) {
359 let props = blkid_probe(&self.path())?;
360 if self.parttype.is_none() {
361 self.parttype = props.get("PART_ENTRY_TYPE").cloned();
362 }
363 if self.pttype.is_none() {
364 self.pttype = props.get("PTTYPE").cloned();
365 }
366 }
367 // Recurse to child devices
368 for child in self.children.iter_mut().flatten() {
369 child.backfill_missing()?;
370 }
371 Ok(())
372 }
373
374 /// Query parent devices via `lsblk --inverse`.
375 ///

Callers 2

list_parentsMethod · 0.80
list_devFunction · 0.80

Calls 4

have_udevFunction · 0.85
blkid_probeFunction · 0.85
read_sysfs_propertyMethod · 0.80
pathMethod · 0.45

Tested by

no test coverage detected