Skip to content

Commit 89b38dd

Browse files
committed
disks: Fix paths
Signed-off-by: Ikey Doherty <[email protected]>
1 parent c12ee57 commit 89b38dd

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

crates/disks/src/disk.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use std::{
99
path::{Path, PathBuf},
1010
};
1111

12-
use crate::{mmc, mock, nvme, partition::Partition, scsi, sysfs, virt, DEVFS_DIR};
12+
use crate::SYSFS_DIR;
13+
use crate::{mmc, mock, nvme, partition::Partition, scsi, sysfs, virt};
1314

1415
/// Represents the type of disk device.
1516
#[derive(Debug)]
@@ -144,7 +145,7 @@ pub trait DiskInit: Sized {
144145

145146
impl DiskInit for BasicDisk {
146147
fn from_sysfs_path(sysroot: &Path, name: &str) -> Option<Self> {
147-
let node = sysroot.join(name);
148+
let node = sysroot.join(SYSFS_DIR).join(name);
148149

149150
log::debug!("Initializing disk at sysfs path: {:?}", node);
150151

@@ -162,7 +163,7 @@ impl DiskInit for BasicDisk {
162163
let sectors = sysfs::read(&node, "size").unwrap_or(0);
163164
log::debug!("Read {} sectors for disk {}", sectors, name);
164165

165-
let device = PathBuf::from(DEVFS_DIR).join(name);
166+
let device = PathBuf::from("/dev").join(name);
166167
log::debug!("Device path: {:?}", device);
167168

168169
let model = sysfs::read(&node, "device/model");

crates/disks/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl BlockDevice {
139139
// For all the discovered block devices, try to create a Disk instance
140140
// At this point we completely ignore partitions. They come later.
141141
for entry in entries {
142-
if let Ok(device) = BlockDevice::from_sysfs_path(&sysfs_dir, &entry) {
142+
if let Ok(device) = BlockDevice::from_sysfs_path(sysroot, &entry) {
143143
devices.push(device);
144144
}
145145
}

crates/disks/src/loopback.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl Device {
4242
/// * `None` if the name doesn't match or the device can't be initialized
4343
pub fn from_sysfs_path(sysroot: &Path, name: &str) -> Option<Self> {
4444
let matching = name.starts_with("loop") && name[4..].chars().all(char::is_numeric);
45-
let node = sysroot.join(name);
45+
let node = sysroot.join(SYSFS_DIR).join(name);
4646
let file = sysfs::read::<PathBuf>(&node, "loop/backing_file");
4747
let disk = file.as_ref().and_then(|_| BasicDisk::from_sysfs_path(sysroot, name));
4848
if matching {
@@ -60,7 +60,7 @@ impl Device {
6060
/// Creates a new Device instance from a device path.
6161
pub fn from_device_path(device: &Path) -> Option<Self> {
6262
let name = device.file_name()?.to_string_lossy().to_string();
63-
Self::from_sysfs_path(&PathBuf::from("/").join(SYSFS_DIR), &name)
63+
Self::from_sysfs_path(&PathBuf::from("/"), &name)
6464
}
6565

6666
/// Returns the device name.

crates/disks/src/partition.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use std::fmt;
66
use std::path::{Path, PathBuf};
77

8-
use crate::{sysfs, DEVFS_DIR};
8+
use crate::{sysfs, DEVFS_DIR, SYSFS_DIR};
99

1010
/// Represents a partition on a disk device
1111
/// - Size in sectors
@@ -49,7 +49,7 @@ impl Partition {
4949
/// * `Some(Partition)` if partition exists and is valid
5050
/// * `None` if partition doesn't exist or is invalid
5151
pub fn from_sysfs_path(sysroot: &Path, name: &str) -> Option<Self> {
52-
let node = sysroot.join(name);
52+
let node = sysroot.join(SYSFS_DIR).join(name);
5353
let partition_no: u32 = sysfs::read(&node, "partition")?;
5454
let start = sysfs::read(&node, "start")?;
5555
let size = sysfs::read(&node, "size")?;

0 commit comments

Comments
 (0)