1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use std::path::{Path, PathBuf};
use sysfs_class::{Block, SysClass};
pub trait BlockDeviceExt {
fn sys_block_path(&self) -> PathBuf {
let path = self.get_device_path();
PathBuf::from(match path.read_link() {
Ok(resolved) => [
"/sys/class/block/",
resolved.file_name().expect("drive does not have a file name").to_str().unwrap(),
].concat(),
_ => [
"/sys/class/block/",
path.file_name().expect("drive does not have a file name").to_str().unwrap(),
].concat(),
})
}
fn is_removable(&self) -> bool {
Block::from_path(&self.sys_block_path())
.ok()
.map_or(false, |block| block.removable().ok() == Some(1))
}
fn is_rotational(&self) -> bool {
Block::from_path(&self.sys_block_path())
.ok()
.map_or(false, |block| block.queue_rotational().ok() == Some(1))
}
fn get_device_path(&self) -> &Path;
fn get_mount_point(&self) -> Option<&Path>;
}