Skip to content

Commit

Permalink
disks: Cleanup names for sysfs API
Browse files Browse the repository at this point in the history
Signed-off-by: Ikey Doherty <[email protected]>
  • Loading branch information
ikeycode committed Jan 20, 2025
1 parent aaed894 commit 85fea5c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions crates/disks/src/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ impl DiskInit for BasicDisk {

Some(Self {
name: name.to_owned(),
sectors: sysfs::sysfs_read(sysroot, &node, "size").unwrap_or(0),
sectors: sysfs::read(sysroot, &node, "size").unwrap_or(0),
device: PathBuf::from(DEVFS_DIR).join(name),
model: sysfs::sysfs_read(sysroot, &node, "device/model"),
vendor: sysfs::sysfs_read(sysroot, &node, "device/vendor"),
model: sysfs::read(sysroot, &node, "device/model"),
vendor: sysfs::read(sysroot, &node, "device/vendor"),
partitions,
})
}
Expand Down
8 changes: 4 additions & 4 deletions crates/disks/src/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::fmt;
use std::path::{Path, PathBuf};

use crate::{sysfs::sysfs_read, DEVFS_DIR, SYSFS_DIR};
use crate::{sysfs, DEVFS_DIR, SYSFS_DIR};

/// Represents a partition on a disk device
/// - Size in sectors
Expand Down Expand Up @@ -50,9 +50,9 @@ impl Partition {
/// * `None` if partition doesn't exist or is invalid
pub fn from_sysfs_path(sysroot: &Path, name: &str) -> Option<Self> {
let node = sysroot.join(SYSFS_DIR).join(name);
let partition_no: u32 = sysfs_read(sysroot, &node, "partition")?;
let start = sysfs_read(sysroot, &node, "start")?;
let size = sysfs_read(sysroot, &node, "size")?;
let partition_no: u32 = sysfs::read(sysroot, &node, "partition")?;
let start = sysfs::read(sysroot, &node, "start")?;
let size = sysfs::read(sysroot, &node, "size")?;
Some(Self {
name: name.to_owned(),
number: partition_no,
Expand Down
2 changes: 1 addition & 1 deletion crates/disks/src/sysfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::{fs, path::Path, str::FromStr};
/// # 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>
pub(crate) fn read<T>(sysroot: &Path, node: &Path, key: &str) -> Option<T>
where
T: FromStr,
{
Expand Down

0 comments on commit 85fea5c

Please sign in to comment.