@@ -496,6 +496,8 @@ impl Planner {
496496 debug ! ( "Planning to create new GPT partition table" ) ;
497497 self . changes . clear ( ) ; // Clear any existing changes
498498 self . original_regions . clear ( ) ; // Clear original partitions
499+ self . original_partition_ids . clear ( ) ;
500+ self . next_partition_id = 1 ;
499501 self . wipe_disk = true ;
500502 Ok ( ( ) )
501503 }
@@ -729,4 +731,26 @@ mod tests {
729731
730732 assert_eq ! ( align_down( 4 * mb + ( 600 * kb) , mb) , 5 * mb) ;
731733 }
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+ }
732756}
0 commit comments