@@ -45,13 +45,12 @@ pub enum Change {
4545}
4646
4747/// A disk partitioning planner.
48+ #[ derive( Debug , Clone ) ]
4849pub struct Planner {
4950 /// First usable LBA position on disk in bytes
5051 usable_start : u64 ,
5152 /// Last usable LBA position on disk in bytes
5253 usable_end : u64 ,
53- /// The original block device state that we're planning changes for
54- device : BlockDevice ,
5554 /// Stack of changes that can be undone
5655 changes : VecDeque < Change > ,
5756 /// Original partition layout for reference
@@ -124,8 +123,8 @@ impl Region {
124123///
125124/// ```
126125/// use partitioning::planner::format_size;
127- /// assert_eq!(format_size(1500), "1.5KB ");
128- /// assert_eq!(format_size(1500000), "1.4MB ");
126+ /// assert_eq!(format_size(1500), "1.5KiB ");
127+ /// assert_eq!(format_size(1500000), "1.4MiB ");
129128/// ```
130129pub fn format_size ( size : u64 ) -> String {
131130 const KB : f64 = 1024.0 ;
@@ -135,13 +134,13 @@ pub fn format_size(size: u64) -> String {
135134
136135 let size = size as f64 ;
137136 if size >= TB {
138- format ! ( "{:.1}TB " , size / TB )
137+ format ! ( "{:.1}TiB " , size / TB )
139138 } else if size >= GB {
140- format ! ( "{:.1}GB " , size / GB )
139+ format ! ( "{:.1}GiB " , size / GB )
141140 } else if size >= MB {
142- format ! ( "{:.1}MB " , size / MB )
141+ format ! ( "{:.1}MiB " , size / MB )
143142 } else if size >= KB {
144- format ! ( "{:.1}KB " , size / KB )
143+ format ! ( "{:.1}KiB " , size / KB )
145144 } else {
146145 format ! ( "{}B" , size)
147146 }
@@ -207,7 +206,7 @@ impl Change {
207206
208207impl Planner {
209208 /// Creates a new partitioning planner for the given disk.
210- pub fn new ( device : BlockDevice ) -> Self {
209+ pub fn new ( device : & BlockDevice ) -> Self {
211210 debug ! ( "Creating new partition planner for device of size {}" , device. size( ) ) ;
212211
213212 // Extract original regions from device
@@ -220,7 +219,6 @@ impl Planner {
220219 Self {
221220 usable_start : 0 ,
222221 usable_end : device. size ( ) ,
223- device,
224222 changes : VecDeque :: new ( ) ,
225223 original_regions,
226224 }
@@ -350,8 +348,8 @@ impl Planner {
350348 for region in & current {
351349 if new_region. overlaps_with ( region) {
352350 warn ! (
353- "Partition would overlap with existing partition at {}..{}" ,
354- region. start, region. end
351+ "Partition would overlap with existing partition at {}..{} - attempted region {}..{} " ,
352+ region. start, region. end, new_region . start , new_region . end
355353 ) ;
356354 return Err ( PlanError :: RegionOverlap {
357355 start : aligned_start,
@@ -412,11 +410,6 @@ impl Planner {
412410 & self . changes
413411 }
414412
415- /// Get the original block device state
416- pub fn original_device ( & self ) -> & BlockDevice {
417- & self . device
418- }
419-
420413 /// Get the size of the usable disk region in bytes
421414 pub fn usable_size ( & self ) -> u64 {
422415 self . usable_end - self . usable_start
@@ -469,7 +462,7 @@ mod tests {
469462 #[ test]
470463 fn test_fresh_installation ( ) {
471464 let disk = create_mock_disk ( ) ;
472- let mut planner = Planner :: new ( BlockDevice :: mock_device ( disk) ) ;
465+ let mut planner = Planner :: new ( & BlockDevice :: mock_device ( disk) ) ;
473466
474467 // Create typical Linux partition layout with absolute positions
475468 // - 0 -> 512MB: EFI System Partition
@@ -491,7 +484,7 @@ mod tests {
491484 #[ test]
492485 fn test_dual_boot_with_windows ( ) {
493486 let disk = create_windows_disk ( ) ;
494- let mut planner = Planner :: new ( BlockDevice :: mock_device ( disk) ) ;
487+ let mut planner = Planner :: new ( & BlockDevice :: mock_device ( disk) ) ;
495488
496489 // Available space starts after Windows partitions (~ 200.6GB)
497490 let start = 200 * GB + 616 * MB ;
@@ -518,7 +511,7 @@ mod tests {
518511 disk. add_partition ( 512 * MB , 4 * GB + 512 * MB ) ; // Swap: 512MB -> 4.5GB
519512 disk. add_partition ( 4 * GB + 512 * MB , 500 * GB ) ; // Root: 4.5GB -> 500GB
520513
521- let mut planner = Planner :: new ( BlockDevice :: mock_device ( disk) ) ;
514+ let mut planner = Planner :: new ( & BlockDevice :: mock_device ( disk) ) ;
522515
523516 // Delete old Linux partitions
524517 assert ! ( planner. plan_delete_partition( 1 ) . is_ok( ) ) ; // Delete swap
@@ -541,7 +534,7 @@ mod tests {
541534 #[ test]
542535 fn test_region_validation ( ) {
543536 let disk = create_mock_disk ( ) ;
544- let mut planner = Planner :: new ( BlockDevice :: mock_device ( disk) ) ;
537+ let mut planner = Planner :: new ( & BlockDevice :: mock_device ( disk) ) ;
545538
546539 // Test out of bounds
547540 assert ! ( matches!(
@@ -560,7 +553,7 @@ mod tests {
560553 #[ test]
561554 fn test_undo_operations ( ) {
562555 let disk = create_mock_disk ( ) ;
563- let mut planner = Planner :: new ( BlockDevice :: mock_device ( disk) ) ;
556+ let mut planner = Planner :: new ( & BlockDevice :: mock_device ( disk) ) ;
564557
565558 // Add some partitions
566559 assert ! ( planner. plan_add_partition( 0 , 100 * GB ) . is_ok( ) ) ;
@@ -582,7 +575,7 @@ mod tests {
582575 #[ test]
583576 fn test_partition_boundaries ( ) {
584577 let disk = create_mock_disk ( ) ;
585- let mut planner = Planner :: new ( BlockDevice :: mock_device ( disk) ) ;
578+ let mut planner = Planner :: new ( & BlockDevice :: mock_device ( disk) ) ;
586579
587580 // Add first partition from 0 to 100GB
588581 assert ! ( planner. plan_add_partition( 0 , 100 * GB ) . is_ok( ) ) ;
@@ -609,7 +602,7 @@ mod tests {
609602 #[ test]
610603 fn test_alignment ( ) {
611604 let disk = create_mock_disk ( ) ;
612- let mut planner = Planner :: new ( BlockDevice :: mock_device ( disk) ) ;
605+ let mut planner = Planner :: new ( & BlockDevice :: mock_device ( disk) ) ;
613606
614607 // Already aligned values should not be re-aligned
615608 let aligned_start = PARTITION_ALIGNMENT ;
0 commit comments