diff --git a/citadel-tool/src/boot/disks.rs b/citadel-tool/src/boot/disks.rs index 73548b6..301361c 100644 --- a/citadel-tool/src/boot/disks.rs +++ b/citadel-tool/src/boot/disks.rs @@ -17,21 +17,33 @@ pub struct DiskPartition { } impl DiskPartition { + const ESP_GUID: &'static str = "c12a7328-f81f-11d2-ba4b-00a0c93ec93b"; + /// Return list of all vfat partitions on the system as a `Vec` - pub fn boot_partitions() -> Result> { + pub fn boot_partitions(check_guid: bool) -> Result> { let pp = fs::read_to_string("/proc/partitions")?; let mut v = Vec::new(); for line in pp.lines().skip(2) { let part = DiskPartition::from_proc_line(&line) .map_err(|e| format_err!("Failed to parse line '{}': {}", line, e))?; - if part.is_vfat()? { + + if part.is_boot_partition(check_guid)? { v.push(part); } } Ok(v) } + fn is_boot_partition(&self, check_guid: bool) -> Result { + let is_boot = if check_guid { + self.is_vfat()? && self.is_esp_guid()? + } else { + self.is_vfat()? + }; + Ok(is_boot) + } + // Parse a single line from /proc/partitions // // Example line: @@ -67,6 +79,11 @@ impl DiskPartition { Ok(ok) } + fn is_esp_guid(&self) -> Result { + let ok = self.partition_guid_type()? == Self::ESP_GUID; + Ok(ok) + } + pub fn path(&self) -> &Path { &self.path } @@ -80,6 +97,19 @@ impl DiskPartition { } fn partition_fstype(&self) -> Result { - cmd_with_output!("/usr/bin/lsblk", "-dno FSTYPE {}", self.path().display()) + self.lsblk_var("FSTYPE") + } + + fn partition_guid_type(&self) -> Result { + self.lsblk_var("PARTTYPE") + } + + pub fn partition_uuid(&self) -> Result { + self.lsblk_var("PARTUUID") + } + + /// Execute lsblk to query for a single output column variable on this partition device + fn lsblk_var(&self, var: &str) -> Result { + cmd_with_output!("/usr/bin/lsblk", "-dno {} {}", var, self.path().display()) } }