lfs_core/
disk.rs

1/// what we have most looking like a physical device
2#[derive(Debug, Clone)]
3pub struct Disk {
4    /// a name, like "sda", "sdc", "nvme0n1", etc.
5    #[cfg(not(windows))]
6    pub name: String,
7
8    /// true for HDD, false for SSD, None for unknown.
9    /// This information isn't reliable for USB devices
10    pub rotational: Option<bool>,
11
12    /// whether the system thinks the media is removable.
13    /// Seems reliable when not mapped
14    pub removable: Option<bool>,
15
16    /// whether the disk is read-only
17    pub read_only: Option<bool>,
18
19    /// whether it's a RAM disk
20    pub ram: bool,
21
22    /// disk image (Mac only right now)
23    pub image: bool,
24
25    /// whether it's on LVM
26    pub lvm: bool,
27
28    /// whether it's a crypted disk
29    pub crypted: bool,
30
31    /// whether it's a remote disk
32    #[cfg(windows)]
33    pub remote: bool,
34}
35
36impl Disk {
37    /// a synthetic code trying to express the essence of the type of media,
38    /// an empty str being returned when information couldn't be gathered.
39    /// This code is for humans and may change in future minor versions.
40    pub fn disk_type(&self) -> &'static str {
41        if self.ram {
42            "RAM"
43        } else if self.image {
44            "imag"
45        } else if self.crypted {
46            "crypt"
47        } else if self.lvm {
48            "LVM"
49        } else {
50            match (self.removable, self.rotational) {
51                (Some(true), _) => "remov",
52                (Some(false), Some(true)) => "HDD",
53                (Some(false), Some(false)) => "SSD",
54                _ => "",
55            }
56        }
57    }
58}