diff --git a/ChangeLog b/ChangeLog index 0434535e..3eb08510 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2004-12-12 Bart Hakvoort + + * include/GParted_Core.h, + src/GParted_Core.cc: modified layoutscan a bit for improved handling of metadata. + * include/Operation.h, + src/Operation.cc: modified Insert_Unallocated() to prevent potential crasher. + 2004-12-12 Bart Hakvoort * The fixes from 12-09 unearthed a number of long forgotten issues and annoyances. Hopefully they're all resolved now. diff --git a/include/GParted_Core.h b/include/GParted_Core.h index d5479653..a0a528c2 100644 --- a/include/GParted_Core.h +++ b/include/GParted_Core.h @@ -59,6 +59,7 @@ public: private: void set_device_partitions( Device & device, bool deep_scan = true ) ; + void Insert_Unallocated( std::vector & partitions, Sector start, Sector end, bool inside_extended ) ; Glib::ustring get_sym_path( const Glib::ustring & real_path ) ; void Set_Used_Sectors( Partition & partition ); Glib::ustring Get_Flags( PedPartition *c_partition ) ; diff --git a/include/Operation.h b/include/Operation.h index 068bd074..c2e07120 100644 --- a/include/Operation.h +++ b/include/Operation.h @@ -55,7 +55,7 @@ public: Glib::ustring copied_partition_path ; //for copy operation.. private: - void Insert_Unallocated( std::vector & partitions, Sector start, Sector end ); + void Insert_Unallocated( std::vector & partitions, Sector start, Sector end, bool inside_extended ); int Get_Index_Original( std::vector & partitions ) ; void Apply_Delete_To_Visual( std::vector & partitions ); diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index f0a3e968..665422f3 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -203,29 +203,11 @@ void GParted_Core::set_device_partitions( Device & device, bool deep_scan ) EXT_INDEX = device .device_partitions .size ( ) ; break ; - case PED_PARTITION_FREESPACE: - case 5: //freespace inside extended (there's no enumvalue for that..) - partition_temp .Set_Unallocated( c_partition ->geom .start, c_partition ->geom .end, c_partition ->type == 4 ? false : true ); - break ; - - case PED_PARTITION_METADATA: - if ( device .device_partitions .size( ) && device .device_partitions .back( ) .type == GParted::UNALLOCATED ) - device .device_partitions .back( ) .sector_end = c_partition ->geom .end ; - - break ; - - case 9: //metadata inside extended (there's no enumvalue for that..) - if ( device .device_partitions[ EXT_INDEX ] .logicals .size( ) && - device .device_partitions[ EXT_INDEX ] .logicals .back( ) .type == GParted::UNALLOCATED - ) - device .device_partitions[ EXT_INDEX ] .logicals .back( ) .sector_end = c_partition ->geom .end ; - - break ; - default: break; } - if ( partition_temp .Get_Length_MB( ) >= 1 ) // check for unallocated < 1MB, and metadatasituations (see PED_PARTITION_METADATA and 9 ) + //if there's an end, there's a partition ;) + if ( partition_temp .sector_end > -1 ) { if ( ! partition_temp .inside_extended ) device .device_partitions .push_back( partition_temp ); @@ -236,6 +218,56 @@ void GParted_Core::set_device_partitions( Device & device, bool deep_scan ) //next partition (if any) c_partition = ped_disk_next_partition ( disk, c_partition ) ; } + + if ( EXT_INDEX > -1 ) + Insert_Unallocated( device .device_partitions[ EXT_INDEX ] .logicals, device .device_partitions[ EXT_INDEX ] .sector_start, device .device_partitions[ EXT_INDEX ] .sector_end, true ) ; + + Insert_Unallocated( device .device_partitions, 0, device .length -1, false ) ; +} + +void GParted_Core::Insert_Unallocated( std::vector & partitions, Sector start, Sector end, bool inside_extended ) +{ + Partition UNALLOCATED ; + UNALLOCATED .Set_Unallocated( 0, 0, inside_extended ) ; + + //if there are no partitions at all.. + if ( partitions .empty( ) ) + { + UNALLOCATED .sector_start = start ; + UNALLOCATED .sector_end = end ; + + partitions .push_back( UNALLOCATED ); + + return ; + } + + //start <---> first partition start + if ( (partitions .front( ) .sector_start - start) >= MEGABYTE ) + { + UNALLOCATED .sector_start = start ; + UNALLOCATED .sector_end = partitions .front( ) .sector_start -1 ; + + partitions .insert( partitions .begin( ), UNALLOCATED ); + } + + //look for gaps in between + for ( unsigned int t =0 ; t < partitions .size( ) -1 ; t++ ) + if ( ( partitions[ t +1 ] .sector_start - partitions[ t ] .sector_end ) >= MEGABYTE ) + { + UNALLOCATED .sector_start = partitions[ t ] .sector_end +1 ; + UNALLOCATED .sector_end = partitions[ t +1 ] .sector_start -1 ; + + partitions .insert( partitions .begin( ) + ++t, UNALLOCATED ); + } + + //last partition end <---> end + if ( (end - partitions .back( ) .sector_end ) >= MEGABYTE ) + { + UNALLOCATED .sector_start = partitions .back( ) .sector_end +1 ; + UNALLOCATED .sector_end = end ; + + partitions .push_back( UNALLOCATED ); + } } int GParted_Core::get_estimated_time( const Operation & operation ) diff --git a/src/Operation.cc b/src/Operation.cc index 611e4ea7..d0a83591 100644 --- a/src/Operation.cc +++ b/src/Operation.cc @@ -108,10 +108,10 @@ void Operation::Apply_Operation_To_Visual( std::vector & partitions ) } } -void Operation::Insert_Unallocated( std::vector & partitions, Sector start, Sector end ) +void Operation::Insert_Unallocated( std::vector & partitions, Sector start, Sector end, bool inside_extended ) { Partition UNALLOCATED ; - UNALLOCATED .Set_Unallocated( 0, 0, partitions .front( ) .inside_extended ) ; + UNALLOCATED .Set_Unallocated( 0, 0, inside_extended ) ; //if there are no partitions at all.. if ( partitions .empty( ) ) @@ -178,11 +178,10 @@ void Operation::Apply_Delete_To_Visual( std::vector & partitions ) { partitions .erase( partitions .begin( ) + Get_Index_Original( partitions ) ); - Insert_Unallocated( partitions, 0, device_length -1 ) ; + Insert_Unallocated( partitions, 0, device_length -1, false ) ; } else { - //unsigned int ext = Get_Index_Extended( partitions ) ; unsigned int ext = 0 ; while ( ext < partitions .size( ) && partitions[ ext ] .type != GParted::EXTENDED ) ext++ ; partitions[ ext ] .logicals .erase( partitions[ ext ] .logicals .begin( ) + Get_Index_Original( partitions[ ext ] .logicals ) ); @@ -195,7 +194,7 @@ void Operation::Apply_Delete_To_Visual( std::vector & partitions ) partitions[ ext ] .logicals[ t ] .Update_Number( partitions[ ext ] .logicals[ t ] .partition_number -1 ); - Insert_Unallocated( partitions[ ext ] .logicals, partitions[ ext ] .sector_start, partitions[ ext ] .sector_end ) ; + Insert_Unallocated( partitions[ ext ] .logicals, partitions[ ext ] .sector_start, partitions[ ext ] .sector_end, true ) ; } } @@ -205,7 +204,7 @@ void Operation::Apply_Create_To_Visual( std::vector & partitions ) { partitions[ Get_Index_Original( partitions ) ] = partition_new ; - Insert_Unallocated( partitions, 0, device_length -1 ) ; + Insert_Unallocated( partitions, 0, device_length -1, false ) ; } else { @@ -213,7 +212,7 @@ void Operation::Apply_Create_To_Visual( std::vector & partitions ) while ( ext < partitions .size( ) && partitions[ ext ] .type != GParted::EXTENDED ) ext++ ; partitions[ ext ] .logicals[ Get_Index_Original( partitions[ ext ] .logicals ) ] = partition_new ; - Insert_Unallocated( partitions[ ext ] .logicals, partitions[ ext ] .sector_start, partitions[ ext ] .sector_end ) ; + Insert_Unallocated( partitions[ ext ] .logicals, partitions[ ext ] .sector_start, partitions[ ext ] .sector_end, true ) ; } } @@ -232,7 +231,7 @@ void Operation::Apply_Resize_Move_Extended_To_Visual( std::vector & p partitions[ ext ] .sector_start = partition_new .sector_start ; partitions[ ext ] .sector_end = partition_new .sector_end ; - Insert_Unallocated( partitions, 0, device_length -1 ) ; + Insert_Unallocated( partitions, 0, device_length -1, false ) ; //stuff INSIDE extended partition ext = 0 ; @@ -244,7 +243,7 @@ void Operation::Apply_Resize_Move_Extended_To_Visual( std::vector & p if ( partitions[ ext ] .logicals .size( ) && partitions[ ext ] .logicals .back( ) .type == GParted::UNALLOCATED ) partitions[ ext ] .logicals .erase( partitions[ ext ] .logicals .end( ) -1 ) ; - Insert_Unallocated( partitions[ ext ] .logicals, partitions[ ext ] .sector_start, partitions[ ext ] .sector_end ) ; + Insert_Unallocated( partitions[ ext ] .logicals, partitions[ ext ] .sector_start, partitions[ ext ] .sector_end, true ) ; } } //GParted