@@ -496,6 +496,8 @@ impl Planner {
496
496
debug ! ( "Planning to create new GPT partition table" ) ;
497
497
self . changes . clear ( ) ; // Clear any existing changes
498
498
self . original_regions . clear ( ) ; // Clear original partitions
499
+ self . original_partition_ids . clear ( ) ;
500
+ self . next_partition_id = 1 ;
499
501
self . wipe_disk = true ;
500
502
Ok ( ( ) )
501
503
}
@@ -729,4 +731,26 @@ mod tests {
729
731
730
732
assert_eq ! ( align_down( 4 * mb + ( 600 * kb) , mb) , 5 * mb) ;
731
733
}
734
+
735
+ #[ test]
736
+ fn test_initialize_disk_partition_numbers ( ) {
737
+ let mut disk = create_mock_disk ( ) ;
738
+ // Add some existing partitions
739
+ disk. add_partition ( 0 , 100 * MB ) ;
740
+ disk. add_partition ( 100 * MB , 200 * MB ) ;
741
+ disk. add_partition ( 200 * MB , 300 * MB ) ;
742
+
743
+ let mut planner = Planner :: new ( & BlockDevice :: mock_device ( disk) ) ;
744
+
745
+ // Initialize disk should reset partition numbering
746
+ assert ! ( planner. plan_initialize_disk( ) . is_ok( ) ) ;
747
+
748
+ // Add new partitions - should start from 1
749
+ assert ! ( planner. plan_add_partition( 0 , 100 * MB ) . is_ok( ) ) ;
750
+ assert ! ( planner. plan_add_partition( 100 * MB , 200 * MB ) . is_ok( ) ) ;
751
+
752
+ let layout = planner. current_layout ( ) ;
753
+ assert_eq ! ( layout[ 0 ] . partition_id, Some ( 1 ) ) ;
754
+ assert_eq ! ( layout[ 1 ] . partition_id, Some ( 2 ) ) ;
755
+ }
732
756
}
0 commit comments