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_read_only(&self) -> bool {
Block::from_path(&self.sys_block_path())
.ok()
.map_or(false, |block| block.ro().ok() == Some(1))
}
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>;
}