diff --git a/ChangeLog b/ChangeLog index c207244e..c7acab03 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-07-17 Bart Hakvoort + + * src/Win_GParted.cc, + include/GParted_Core.h, + src/GParted_Core.cc: implemented snap to cylinder algorithm. + Although the algorithm is very simple, it seems to work perfectly. + However, some additional testing is required. + 2006-07-11 Bart Hakvoort * lots of fixes and improvements (mostly move-related) diff --git a/include/GParted_Core.h b/include/GParted_Core.h index c907534f..8b533e2a 100644 --- a/include/GParted_Core.h +++ b/include/GParted_Core.h @@ -38,7 +38,7 @@ public: void set_user_devices( const std::vector & user_devices ) ; void set_devices( std::vector & devices ) ; - bool snap_to_cylinder( Partition & partition ) ; + bool snap_to_cylinder( const Device & device, Partition & partition ) ; bool apply_operation_to_disk( Operation * operation ); bool set_disklabel( const Glib::ustring & device_path, const Glib::ustring & disklabel ) ; diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index f8d51b76..49edb39f 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -153,7 +153,7 @@ void GParted_Core::set_devices( std::vector & devices ) while ( lp_device ) { device_paths .push_back( lp_device ->path ) ; - + lp_device = ped_device_get_next( lp_device ) ; } close_device_and_disk() ; @@ -229,9 +229,40 @@ void GParted_Core::set_devices( std::vector & devices ) fstab_info .clear() ; } -bool GParted_Core::snap_to_cylinder( Partition & partition ) +bool GParted_Core::snap_to_cylinder( const Device & device, Partition & partition ) { - //FIXME: insert here basicly the functionality of snap_to_boundaries from parted.c + if ( ! partition .strict ) + { + Sector diff = partition .sector_start % device .cylsize ; + if ( diff ) + { + if ( diff < ( device .cylsize / 2 ) ) + partition .sector_start -= diff ; + else + partition .sector_start += (device .cylsize - diff ) ; + } + + diff = (partition .sector_end +1) % device .cylsize ; + if ( diff ) + { + if ( diff < ( device .cylsize / 2 ) ) + partition .sector_end -= diff ; + else + partition .sector_end += (device .cylsize - diff ) ; + } + + if ( partition .sector_start < 0 ) + partition .sector_start = 0 ; + if ( partition .sector_end > device .length ) + partition .sector_end = device .length -1 ; + + //FIXME: it would be perfect if we could check for overlapping with adjacent partitions as well, + //however, finding the adjacent partitions is not as easy as it seems and at this moment all the dialogs + //already perform these checks. A perfect 'fixme-later' ;) + + //FIXME: what kind of errorchecking could we do here? maybe checking if partitionlenght > used? + } + return true ; } diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc index ff949513..8ff59828 100644 --- a/src/Win_GParted.cc +++ b/src/Win_GParted.cc @@ -617,7 +617,7 @@ void Win_GParted::Add_Operation( OperationType operationtype, } //FIXME: do this in two separate steps and be more verbose in case of error.. - if ( operation && gparted_core .snap_to_cylinder( operation ->partition_new ) ) + if ( operation && gparted_core .snap_to_cylinder( operation ->device, operation ->partition_new ) ) { operation ->create_description() ;