Skip to content

Commit d34bf3b

Browse files
committed
efi: update validate() according to the split change
1 parent 45dcab6 commit d34bf3b

File tree

1 file changed

+29
-34
lines changed

1 file changed

+29
-34
lines changed

src/efi.rs

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ use walkdir::WalkDir;
2020
use widestring::U16CString;
2121

2222
use crate::bootupd::RootContext;
23-
use crate::{blockdev, filetree};
2423
use crate::model::*;
2524
use crate::ostreeutil;
2625
use crate::util::{self, CommandRunExt};
26+
use crate::{blockdev, filetree};
2727
use crate::{component::*, packagesystem};
2828

2929
/// Well-known paths to the ESP that may have been mounted external to us.
@@ -61,28 +61,7 @@ pub(crate) struct Efi {
6161
}
6262

6363
impl Efi {
64-
fn esp_path(&self) -> Result<PathBuf> {
65-
self.ensure_mounted_esp(Path::new("/"))
66-
.map(|v| v.join("EFI"))
67-
}
68-
69-
fn open_esp_optional(&self) -> Result<Option<openat::Dir>> {
70-
if !is_efi_booted()? && self.get_esp_device().is_none() {
71-
log::debug!("Skip EFI");
72-
return Ok(None);
73-
}
74-
let sysroot = openat::Dir::open("/")?;
75-
let esp = sysroot.sub_dir_optional(&self.esp_path()?)?;
76-
Ok(esp)
77-
}
78-
79-
fn open_esp(&self) -> Result<openat::Dir> {
80-
self.ensure_mounted_esp(Path::new("/"))?;
81-
let sysroot = openat::Dir::open("/")?;
82-
let esp = sysroot.sub_dir(&self.esp_path()?)?;
83-
Ok(esp)
84-
}
85-
64+
// Get esp device via EFI partlabel
8665
fn get_esp_device(&self) -> Option<PathBuf> {
8766
let esp_devices = [COREOS_ESP_PART_LABEL, ANACONDA_ESP_PART_LABEL]
8867
.into_iter()
@@ -100,13 +79,11 @@ impl Efi {
10079
// Get mounted point for esp
10180
pub(crate) fn get_mounted_esp(&self, root: &Path) -> Result<Option<PathBuf>> {
10281
// First check all potential mount points without holding the borrow
103-
let found_mount = ESP_MOUNTS.iter()
104-
.map(|&mnt| root.join(mnt))
105-
.find(|mnt| {
106-
mnt.exists() &&
107-
rustix::fs::statfs(mnt).map_or(false, |st| st.f_type == libc::MSDOS_SUPER_MAGIC) &&
108-
util::ensure_writable_mount(mnt).is_ok()
109-
});
82+
let found_mount = ESP_MOUNTS.iter().map(|&mnt| root.join(mnt)).find(|mnt| {
83+
mnt.exists()
84+
&& rustix::fs::statfs(mnt).map_or(false, |st| st.f_type == libc::MSDOS_SUPER_MAGIC)
85+
&& util::ensure_writable_mount(mnt).is_ok()
86+
});
11087

11188
// Only borrow mutably if we found a mount point
11289
if let Some(mnt) = found_mount {
@@ -381,7 +358,7 @@ impl Component for Efi {
381358
.sub_dir(&component_updatedirname(self))
382359
.context("opening update dir")?;
383360
let updatef = filetree::FileTree::new_from_dir(&updated).context("reading update dir")?;
384-
let diff = currentf.diff(&updatef)?;
361+
let diff = currentf.diff(&updatef)?;
385362

386363
let Some(esp_devices) = blockdev::find_colocated_esps(&sysroot.devices)? else {
387364
anyhow::bail!("Failed to find all esp devices");
@@ -452,15 +429,33 @@ impl Component for Efi {
452429
}
453430

454431
fn validate(&self, current: &InstalledContent) -> Result<ValidationResult> {
455-
if !is_efi_booted()? && self.get_esp_device().is_none() {
432+
let devices = crate::blockdev::get_devices("/").context("get parent devices")?;
433+
let esp_devices = blockdev::find_colocated_esps(&devices)?;
434+
if !is_efi_booted()? && esp_devices.is_none() {
456435
return Ok(ValidationResult::Skip);
457436
}
458437
let currentf = current
459438
.filetree
460439
.as_ref()
461440
.ok_or_else(|| anyhow::anyhow!("No filetree for installed EFI found!"))?;
462-
self.ensure_mounted_esp(Path::new("/"))?;
463-
let efidir = self.open_esp()?;
441+
442+
// Confirm that esp_devices is Some(value)
443+
let esp_devices = esp_devices.unwrap();
444+
let mut devices = esp_devices.iter();
445+
let Some(esp) = devices.next() else {
446+
anyhow::bail!("Failed to find esp device");
447+
};
448+
449+
if let Some(next_esp) = devices.next() {
450+
anyhow::bail!(
451+
"Found multiple esp devices {esp} and {next_esp}; not currently supported"
452+
);
453+
}
454+
let destpath = &self.ensure_mounted_esp(Path::new("/"), Path::new(&esp))?;
455+
456+
let efidir = &openat::Dir::open(&destpath.join("EFI"))
457+
.with_context(|| format!("opening EFI dir {}", destpath.display()))?;
458+
464459
let diff = currentf.relative_diff_to(&efidir)?;
465460
let mut errs = Vec::new();
466461
for f in diff.changes.iter() {

0 commit comments

Comments
 (0)