Skip to content

Commit 4c2b7c0

Browse files
committed
partitioning: Emit the planned partitions
Signed-off-by: Ikey Doherty <[email protected]>
1 parent ba08d3c commit 4c2b7c0

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

crates/partitioning/src/planner.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ pub struct Region {
8282

8383
/// The absolute end position of this region in bytes
8484
pub end: u64,
85+
86+
/// The partition ID of this region if it represents a partition
87+
pub partition_id: Option<u32>,
8588
}
8689

87-
/// Default alignment for partition boundaries (1MiB)
88-
///
89-
/// Most modern storage devices and partition tables work best with
9090
/// partitions aligned to 1MiB boundaries. This helps ensure optimal
9191
/// performance and compatibility.
9292
pub const PARTITION_ALIGNMENT: u64 = 1024 * 1024;
@@ -98,7 +98,11 @@ pub const PARTITION_ALIGNMENT: u64 = 1024 * 1024;
9898
impl Region {
9999
/// Create a new region with the given bounds
100100
pub fn new(start: u64, end: u64) -> Self {
101-
Self { start, end }
101+
Self {
102+
start,
103+
end,
104+
partition_id: None,
105+
}
102106
}
103107

104108
/// Get the size of this region in bytes
@@ -229,7 +233,9 @@ impl Planner {
229233
let mut max_id = 0u32;
230234

231235
for part in device.partitions() {
232-
original_regions.push(Region::new(part.start, part.end));
236+
let mut region = Region::new(part.start, part.end);
237+
region.partition_id = Some(part.number);
238+
original_regions.push(region);
233239
original_partition_ids.push(part.number);
234240
max_id = max_id.max(part.number);
235241
}
@@ -311,6 +317,7 @@ impl Planner {
311317
layout.push(Region {
312318
start: *start,
313319
end: *end,
320+
partition_id: Some(*partition_id),
314321
});
315322
}
316323
}

crates/partitioning/src/writer.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'a> DiskWriter<'a> {
120120
GptConfig::default().writable(writable).open_from_device(device)?
121121
};
122122

123-
let _layout = self.planner.current_layout();
123+
let layout = self.planner.current_layout();
124124
let changes = self.planner.changes();
125125

126126
for change in changes {
@@ -153,6 +153,13 @@ impl<'a> DiskWriter<'a> {
153153

154154
eprintln!("GPT is now: {gpt_table:?}");
155155

156+
for region in layout.iter() {
157+
eprintln!(
158+
"Region at: {:?}",
159+
region.partition_id.map(|i| self.device.partition_path(i as usize))
160+
);
161+
}
162+
156163
Ok(())
157164
}
158165
}

0 commit comments

Comments
 (0)