Skip to content

Commit

Permalink
partitioning: Add a new Strategy system
Browse files Browse the repository at this point in the history
While the builtin strategies are arguably quite simple it does offer
quite enough reusable scaffolding that one can implement sane automatic
options for installers and provisioning.

The main focus is on disk wipes, and partition reuse. Such that if we
encounter an existing install we can amend to make it correct, or even
by manual planning APIs offer to delete a large rootfs and split into the
correct layout (xbootldr, anyone?)

In time we'll also support resizing operations but we'll need to get these
bits hooked up for GPT and partition types yet.

Signed-off-by: Ikey Doherty <[email protected]>
  • Loading branch information
ikeycode committed Jan 23, 2025
1 parent 5c311d1 commit 8701997
Show file tree
Hide file tree
Showing 3 changed files with 410 additions and 2 deletions.
1 change: 1 addition & 0 deletions crates/partitioning/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ pub mod sparsefile;
pub use gpt;

pub mod planner;
pub mod strategy;
16 changes: 14 additions & 2 deletions crates/partitioning/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub enum PlanError {
RegionOverlap { start: u64, end: u64 },
#[error("Region {start}..{end} exceeds disk bounds")]
RegionOutOfBounds { start: u64, end: u64 },
#[error("No free regions available")]
NoFreeRegions,
}

/// A planned modification to the disk's partition layout
Expand Down Expand Up @@ -66,8 +68,11 @@ pub struct Planner {
/// ```
#[derive(Debug, Clone)]
pub struct Region {
start: u64,
end: u64,
/// The absolute start position of this region in bytes
pub start: u64,

/// The absolute end position of this region in bytes
pub end: u64,
}

/// Default alignment for partition boundaries (1MiB)
Expand Down Expand Up @@ -353,6 +358,13 @@ impl Planner {
pub fn original_disk(&self) -> &Disk {
&self.disk
}
/// Plan to initialize a clean partition layout
pub fn plan_initialize_disk(&mut self) -> Result<(), PlanError> {
debug!("Planning to create new GPT partition table");
self.changes.clear(); // Clear any existing changes
self.original_regions.clear(); // Clear original partitions
Ok(())
}
}
#[cfg(test)]
mod tests {
Expand Down
Loading

0 comments on commit 8701997

Please sign in to comment.