pub struct Disk {
pub dev_path: PathBuf,
pub model: Option<String>,
pub size: Memory,
pub partitions: Vec<Partition>,
pub technology: DiskTechnology,
pub removable: bool,
pub partition_table_type: Option<PartitionTableType>,
}Expand description
Contains basic information about disk
Fields§
§dev_path: PathBufDevice path to disk
e.g. “/dev/nvme0n1” or “/dev/sda”
model: Option<String>Disk model
size: MemoryDisk size
partitions: Vec<Partition>Partition on disk
technology: DiskTechnologySSD or HDD
removable: boolDisk is removable
partition_table_type: Option<PartitionTableType>Partition table type
Implementations§
Source§impl Disk
impl Disk
Sourcepub fn fetch_table_type(&mut self) -> Result<()>
pub fn fetch_table_type(&mut self) -> Result<()>
Fetch partition table type
this function updates Disk’s field Disk::partition_table_type
root access is required, otherwise you will get an error “Permission denied”
Examples found in repository?
examples/disk.rs (line 15)
5fn main() {
6 if let Ok(all_drives) = disk::fetch_all() {
7 for mut disk in all_drives {
8 println!("Device: {:?}", disk.dev_path);
9 if let Some(model) = disk.model.clone() {
10 println!("- Model: {model}");
11 }
12 println!("- Size: {:.1}GiB", disk.size.gb);
13 println!("- Technology: {:?}", disk.technology);
14 println!("- Is removable: {}", disk.removable);
15 if disk.fetch_table_type().is_ok() {
16 println!("- Partition table: {:?}", disk.partition_table_type);
17 }
18 match disk.fetch_partitions() {
19 Ok(_) => {
20 if !disk.partitions.is_empty() {
21 disk.sort_partitions();
22 println!("- Partitions:");
23 for partition in disk.partitions.clone().into_iter() {
24 println!(" Device: {}", partition.dev_path.to_string_lossy());
25 println!(" - Partition number: {}", partition.number);
26 println!(" - Size: {:.1}GiB", partition.size.gb);
27 println!(" - Is read-only: {}", partition.readonly);
28 }
29 }
30 }
31 Err(err) => eprintln!("encountered error during partitions fetching: {err:#?}"),
32 }
33 }
34 } else {
35 println!("Platform not supported.");
36 }
37}Sourcepub fn fetch_partitions(&mut self) -> Result<()>
pub fn fetch_partitions(&mut self) -> Result<()>
Fetch all partitions on disk
Examples found in repository?
examples/disk.rs (line 18)
5fn main() {
6 if let Ok(all_drives) = disk::fetch_all() {
7 for mut disk in all_drives {
8 println!("Device: {:?}", disk.dev_path);
9 if let Some(model) = disk.model.clone() {
10 println!("- Model: {model}");
11 }
12 println!("- Size: {:.1}GiB", disk.size.gb);
13 println!("- Technology: {:?}", disk.technology);
14 println!("- Is removable: {}", disk.removable);
15 if disk.fetch_table_type().is_ok() {
16 println!("- Partition table: {:?}", disk.partition_table_type);
17 }
18 match disk.fetch_partitions() {
19 Ok(_) => {
20 if !disk.partitions.is_empty() {
21 disk.sort_partitions();
22 println!("- Partitions:");
23 for partition in disk.partitions.clone().into_iter() {
24 println!(" Device: {}", partition.dev_path.to_string_lossy());
25 println!(" - Partition number: {}", partition.number);
26 println!(" - Size: {:.1}GiB", partition.size.gb);
27 println!(" - Is read-only: {}", partition.readonly);
28 }
29 }
30 }
31 Err(err) => eprintln!("encountered error during partitions fetching: {err:#?}"),
32 }
33 }
34 } else {
35 println!("Platform not supported.");
36 }
37}Sourcepub fn fetch_filesystems(&mut self) -> Result<Option<Filesystem>>
pub fn fetch_filesystems(&mut self) -> Result<Option<Filesystem>>
Function under construction !
Fetch filesystems on partitions
Make sure that disk contains partitions (run Disk::fetch_partitions ) and table type (run Disk::fetch_table_type)
Currently only MBR disks supported
Sourcepub fn sort_partitions(&mut self)
pub fn sort_partitions(&mut self)
Sort Disk::partitions by number
Examples found in repository?
examples/disk.rs (line 21)
5fn main() {
6 if let Ok(all_drives) = disk::fetch_all() {
7 for mut disk in all_drives {
8 println!("Device: {:?}", disk.dev_path);
9 if let Some(model) = disk.model.clone() {
10 println!("- Model: {model}");
11 }
12 println!("- Size: {:.1}GiB", disk.size.gb);
13 println!("- Technology: {:?}", disk.technology);
14 println!("- Is removable: {}", disk.removable);
15 if disk.fetch_table_type().is_ok() {
16 println!("- Partition table: {:?}", disk.partition_table_type);
17 }
18 match disk.fetch_partitions() {
19 Ok(_) => {
20 if !disk.partitions.is_empty() {
21 disk.sort_partitions();
22 println!("- Partitions:");
23 for partition in disk.partitions.clone().into_iter() {
24 println!(" Device: {}", partition.dev_path.to_string_lossy());
25 println!(" - Partition number: {}", partition.number);
26 println!(" - Size: {:.1}GiB", partition.size.gb);
27 println!(" - Is read-only: {}", partition.readonly);
28 }
29 }
30 }
31 Err(err) => eprintln!("encountered error during partitions fetching: {err:#?}"),
32 }
33 }
34 } else {
35 println!("Platform not supported.");
36 }
37}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Disk
impl RefUnwindSafe for Disk
impl Send for Disk
impl Sync for Disk
impl Unpin for Disk
impl UnwindSafe for Disk
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more