-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathlib.rs
More file actions
64 lines (54 loc) · 2.04 KB
/
lib.rs
File metadata and controls
64 lines (54 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! Boot integration for composefs filesystem images.
//!
//! This crate provides functionality to transform composefs filesystem images for boot
//! scenarios by extracting boot resources, applying SELinux labels, and preparing
//! bootloader entries. It supports both Boot Loader Specification (Type 1) entries
//! and Unified Kernel Images (Type 2) for UEFI boot.
#![deny(missing_debug_implementations)]
pub mod bootloader;
pub mod cmdline;
pub mod os_release;
pub mod selabel;
pub mod uki;
pub mod write_boot;
use anyhow::Result;
use composefs::{fsverity::FsVerityHashValue, repository::Repository, tree::FileSystem};
use crate::bootloader::{get_boot_resources, BootEntry};
/// These directories are required to exist in images.
/// They may have content in the container, but we don't
/// want to expose them in the final merged root.
///
/// # /boot
///
/// This is how sealed UKIs are handled; the UKI in /boot has the composefs
/// digest, so we can't include it in the rendered image.
///
/// # /sysroot
///
/// See https://github.com/containers/composefs-rs/issues/164
/// Basically there is only content here in ostree-container cases,
/// and us traversing there for SELinux labeling will cause problems.
/// The ostree-container code special cases it in a different way, but
/// here we can just ignore it.
const REQUIRED_TOPLEVEL_TO_EMPTY_DIRS: &[&str] = &["boot", "sysroot"];
pub trait BootOps<ObjectID: FsVerityHashValue> {
fn transform_for_boot(
&mut self,
repo: &Repository<ObjectID>,
) -> Result<Vec<BootEntry<ObjectID>>>;
}
impl<ObjectID: FsVerityHashValue> BootOps<ObjectID> for FileSystem<ObjectID> {
fn transform_for_boot(
&mut self,
repo: &Repository<ObjectID>,
) -> Result<Vec<BootEntry<ObjectID>>> {
let boot_entries = get_boot_resources(self)?;
for d in REQUIRED_TOPLEVEL_TO_EMPTY_DIRS {
let d = self.root.get_directory_mut(d.as_ref())?;
d.stat.st_mtim_sec = 0;
d.clear();
}
selabel::selabel(self, repo)?;
Ok(boot_entries)
}
}