-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
disks: Total revamp, disks is now primarily a sysfs walker
We differentiate between different types of disks to control exactly which ones we're interested in, and group the commonality into the new BasicDisk type. Using static dispatch etc. Signed-off-by: Ikey Doherty <[email protected]>
- Loading branch information
Showing
4 changed files
with
257 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// SPDX-FileCopyrightText: Copyright © 2025 Serpent OS Developers | ||
// | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
//! Helper functions for interacting with Linux sysfs interfaces | ||
use std::{fs, path::Path, str::FromStr}; | ||
|
||
/// Reads a value from a sysfs node and attempts to parse it to type T | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `sysroot` - Base path of the sysfs mount point | ||
/// * `node` - Path to specific sysfs node relative to sysroot | ||
/// * `key` - Name of the sysfs attribute to read | ||
/// | ||
/// # Returns | ||
/// | ||
/// * `Some(T)` if the value was successfully read and parsed | ||
/// * `None` if the file could not be read or parsed | ||
/// | ||
/// # Type Parameters | ||
/// | ||
/// * `T` - Target type that implements FromStr for parsing the raw value | ||
pub(crate) fn sysfs_read<T>(sysroot: &Path, node: &Path, key: &str) -> Option<T> | ||
where | ||
T: FromStr, | ||
{ | ||
let path = sysroot.join(node).join(key); | ||
fs::read_to_string(&path).ok()?.trim().parse().ok() | ||
} |