Read a sysfs property for this device and parse it as the target type.
(&self, property: &str)
| 314 | |
| 315 | /// Read a sysfs property for this device and parse it as the target type. |
| 316 | fn read_sysfs_property<T>(&self, property: &str) -> Result<Option<T>> |
| 317 | where |
| 318 | T: std::str::FromStr, |
| 319 | T::Err: std::error::Error + Send + Sync + 'static, |
| 320 | { |
| 321 | let Some(majmin) = self.maj_min.as_deref() else { |
| 322 | return Ok(None); |
| 323 | }; |
| 324 | let sysfs_path = format!("/sys/dev/block/{majmin}/{property}"); |
| 325 | if !Utf8Path::new(&sysfs_path).try_exists()? { |
| 326 | return Ok(None); |
| 327 | } |
| 328 | let value = std::fs::read_to_string(&sysfs_path) |
| 329 | .with_context(|| format!("Reading {sysfs_path}"))?; |
| 330 | let parsed = value |
| 331 | .trim() |
| 332 | .parse() |
| 333 | .with_context(|| format!("Parsing sysfs {property} property"))?; |
| 334 | tracing::debug!("backfilled {property} to {value}"); |
| 335 | Ok(Some(parsed)) |
| 336 | } |
| 337 | |
| 338 | /// Backfill properties that may be missing from lsblk output. |
| 339 | /// |