From e71d5c5887343c3a0fc647aa6748c886ee233e24 Mon Sep 17 00:00:00 2001 From: Bart Hakvoort Date: Wed, 24 Nov 2004 10:32:56 +0000 Subject: [PATCH] fixed nasty error with resizing 'fixed-start filesystems'. added a check * include/GParted_Core.h, src/GParted_Core.cc: fixed nasty error with resizing 'fixed-start filesystems'. * src/Partition.cc: added a check to prevent unused space from being bigger then total space. * src/ntfs.cc: removed -Q from mkntfs. -Q bypassed some safetychecks to gain performance and (so i heard later) also had a tendency of failing ;) (Adrighem) --- ChangeLog | 8 ++++++++ include/GParted_Core.h | 2 +- src/GParted_Core.cc | 17 +++++++++++++++-- src/Partition.cc | 9 ++++++--- src/ntfs.cc | 2 +- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 14f0adf8..96e49d0b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2004-11-24 Bart Hakvoort + + * include/GParted_Core.h, + src/GParted_Core.cc: fixed nasty error with resizing 'fixed-start filesystems'. + * src/Partition.cc: added a check to prevent unused space from being bigger then total space. + * src/ntfs.cc: removed -Q from mkntfs. -Q bypassed some safetychecks to gain performance and (so i heard later) also had a + tendency of failing ;) (Adrighem) + 2004-11-23 Bart Hakvoort * src/Dialog_Partition_New.cc, diff --git a/include/GParted_Core.h b/include/GParted_Core.h index c6003b48..f3d79c5b 100644 --- a/include/GParted_Core.h +++ b/include/GParted_Core.h @@ -61,7 +61,7 @@ private: void Set_Used_Sectors( Partition & partition ); Glib::ustring Get_Flags( PedPartition *c_partition ) ; int Create_Empty_Partition( const Glib::ustring & device_path, Partition & new_partition, bool copy = false ) ; - bool Resize_Container_Partition( const Glib::ustring & device_path, const Partition & partition_old, const Partition & partition_new ) ; + bool Resize_Container_Partition( const Glib::ustring & device_path, const Partition & partition_old, const Partition & partition_new, bool fixed_start = true ) ; bool Resize_Normal_Using_Libparted( const Glib::ustring & device_path, const Partition & partition_old, const Partition & partition_new ) ; void Show_Error( Glib::ustring message ) ; diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index 5f16cfcf..a898fd67 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -307,6 +307,8 @@ bool GParted_Core::Delete( const Glib::ustring & device_path, const Partition & return_value = ( ped_disk_delete_partition( disk, c_partition ) && Commit( disk ) ) ; close_device_and_disk( device, disk ) ; + + sleep( 1 ) ;//paranoia give the OS some time to update nodes in /dev } return return_value ; @@ -315,7 +317,7 @@ bool GParted_Core::Delete( const Glib::ustring & device_path, const Partition & bool GParted_Core::Resize( const Glib::ustring & device_path, const Partition & partition_old, const Partition & partition_new ) { if ( partition_old .type == GParted::EXTENDED ) - return Resize_Container_Partition( device_path, partition_old, partition_new ) ; + return Resize_Container_Partition( device_path, partition_old, partition_new, false ) ; //these 3 still use libparted's resizer. else if ( partition_old .filesystem == "linux-swap" || @@ -484,7 +486,7 @@ int GParted_Core::Create_Empty_Partition( const Glib::ustring & device_path, Par return new_partition .partition_number ; } -bool GParted_Core::Resize_Container_Partition( const Glib::ustring & device_path, const Partition & partition_old, const Partition & partition_new ) +bool GParted_Core::Resize_Container_Partition( const Glib::ustring & device_path, const Partition & partition_old, const Partition & partition_new, bool fixed_start ) { bool return_value = false ; @@ -501,6 +503,17 @@ bool GParted_Core::Resize_Container_Partition( const Glib::ustring & device_path if ( c_partition ) { constraint = ped_constraint_any( device ); + + if ( fixed_start && constraint ) //create a constraint which keeps de startpoint intact and rounds the end to a cylinderboundary + { + ped_disk_set_partition_geom ( disk, c_partition, constraint, partition_new .sector_start, partition_new .sector_end ) ; + ped_constraint_destroy ( constraint ); + constraint = NULL ; + + ped_geometry_set_start ( & c_partition ->geom, partition_new .sector_start ) ; + constraint = ped_constraint_exact ( & c_partition ->geom ) ; + } + if ( constraint ) { if ( ped_disk_set_partition_geom ( disk, c_partition, constraint, partition_new .sector_start, partition_new .sector_end ) ) diff --git a/src/Partition.cc b/src/Partition.cc index bffb2cf1..69e2e373 100644 --- a/src/Partition.cc +++ b/src/Partition.cc @@ -31,7 +31,7 @@ void Partition::Reset( ) status = GParted::STAT_REAL ; type = GParted::UNALLOCATED ; partition_number = sector_start = sector_end = sectors_used = sectors_unused = -1; - color.set( "black" ) ; + color .set( "black" ) ; inside_extended = busy = false ; logicals .clear( ) ; } @@ -58,8 +58,11 @@ void Partition::Set( const Glib::ustring & partition, void Partition::Set_Unused( Sector sectors_unused ) { - this ->sectors_unused = sectors_unused ; - this ->sectors_used = ( sectors_unused == -1 ) ? -1 : ( sector_end - sector_start) - sectors_unused ; + if ( sectors_unused < ( sector_end - sector_start ) ) + { + this ->sectors_unused = sectors_unused ; + this ->sectors_used = ( sectors_unused == -1 ) ? -1 : ( sector_end - sector_start) - sectors_unused ; + } } void Partition::Set_Unallocated( Sector sector_start, Sector sector_end, bool inside_extended ) diff --git a/src/ntfs.cc b/src/ntfs.cc index e259567f..8428f6ca 100644 --- a/src/ntfs.cc +++ b/src/ntfs.cc @@ -72,7 +72,7 @@ void ntfs::Set_Used_Sectors( Partition & partition ) bool ntfs::Create( const Glib::ustring device_path, const Partition & new_partition ) { - return Execute_Command( "mkntfs -Q " + new_partition .partition ) ; + return Execute_Command( "mkntfs " + new_partition .partition ) ; } bool ntfs::Resize( const Partition & partition_new, bool fill_partition )