Skip to content

Commit 8701997

Browse files
committed
partitioning: Add a new Strategy system
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]>
1 parent 5c311d1 commit 8701997

File tree

3 files changed

+410
-2
lines changed

3 files changed

+410
-2
lines changed

crates/partitioning/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ pub mod sparsefile;
99
pub use gpt;
1010

1111
pub mod planner;
12+
pub mod strategy;

crates/partitioning/src/planner.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ pub enum PlanError {
2727
RegionOverlap { start: u64, end: u64 },
2828
#[error("Region {start}..{end} exceeds disk bounds")]
2929
RegionOutOfBounds { start: u64, end: u64 },
30+
#[error("No free regions available")]
31+
NoFreeRegions,
3032
}
3133

3234
/// A planned modification to the disk's partition layout
@@ -66,8 +68,11 @@ pub struct Planner {
6668
/// ```
6769
#[derive(Debug, Clone)]
6870
pub struct Region {
69-
start: u64,
70-
end: u64,
71+
/// The absolute start position of this region in bytes
72+
pub start: u64,
73+
74+
/// The absolute end position of this region in bytes
75+
pub end: u64,
7176
}
7277

7378
/// Default alignment for partition boundaries (1MiB)
@@ -353,6 +358,13 @@ impl Planner {
353358
pub fn original_disk(&self) -> &Disk {
354359
&self.disk
355360
}
361+
/// Plan to initialize a clean partition layout
362+
pub fn plan_initialize_disk(&mut self) -> Result<(), PlanError> {
363+
debug!("Planning to create new GPT partition table");
364+
self.changes.clear(); // Clear any existing changes
365+
self.original_regions.clear(); // Clear original partitions
366+
Ok(())
367+
}
356368
}
357369
#[cfg(test)]
358370
mod tests {

0 commit comments

Comments
 (0)