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