From 4815b171539c93e8423b4f91306e17788050cb74 Mon Sep 17 00:00:00 2001 From: Bart Hakvoort Date: Mon, 13 Dec 2004 13:58:51 +0000 Subject: [PATCH] Replaced boolean 'resize' with 'shrink' and 'grow'. It seems some * Replaced boolean 'resize' with 'shrink' and 'grow'. It seems some filesystems only support growing (e.g. xfs) so i need two flags to control the behaviour of the filesystemclasses. --- ChangeLog | 5 +++++ include/Utils.h | 5 +++-- include/Win_GParted.h | 3 ++- src/Dialog_Partition_Resize_Move.cc | 30 +++++++++++++++-------------- src/Win_GParted.cc | 14 ++++++-------- src/ext2.cc | 2 +- src/ext3.cc | 2 +- src/fat16.cc | 3 ++- src/fat32.cc | 3 ++- src/linux_swap.cc | 3 ++- src/ntfs.cc | 6 +++--- src/reiserfs.cc | 4 ++-- 12 files changed, 45 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index 598de308..e64ede5d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-12-13 Bart Hakvoort + + * Replaced boolean 'resize' with 'shrink' and 'grow'. It seems some filesystems only support growing (e.g. xfs) so i need + two flags to control the behaviour of the filesystemclasses. + 2004-12-13 Bart Hakvoort * include/GParted_Core.h, diff --git a/include/Utils.h b/include/Utils.h index fd83d727..246d209a 100644 --- a/include/Utils.h +++ b/include/Utils.h @@ -45,7 +45,8 @@ struct FS Glib::ustring filesystem ; bool read ; //can we get the amount of used sectors? bool create ; - bool resize ; //only endpoint + bool grow ; + bool shrink ; bool move ; //startpoint and endpoint bool check ; //some checktool available? bool copy ; @@ -54,7 +55,7 @@ struct FS FS( ) { - read = create = resize = move = check = copy = false ; + read = create = grow = shrink = move = check = copy = false ; MIN = 0 ; MAX = 0 ; } diff --git a/include/Win_GParted.h b/include/Win_GParted.h index 84a135d2..0601aa14 100644 --- a/include/Win_GParted.h +++ b/include/Win_GParted.h @@ -174,7 +174,8 @@ private: bool any_logic,any_extended;//used in some checks (e.g. see optionmenu_devices_changed() unsigned short primary_count ;//primary_count checks for max. of 4 pimary partitions unsigned short new_count;//new_count keeps track of the new created partitions - Glib::ustring str_temp ; //mostly used for constructing dialogmessages + Glib::ustring str_temp ; //mostly used for constructing dialogmessages + FS fs ; GParted_Core gparted_core ; GParted::Device *temp_device ; diff --git a/src/Dialog_Partition_Resize_Move.cc b/src/Dialog_Partition_Resize_Move.cc index cbd68a38..e86113d9 100644 --- a/src/Dialog_Partition_Resize_Move.cc +++ b/src/Dialog_Partition_Resize_Move.cc @@ -111,21 +111,23 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const std::vector set_x_end( ( Round( (double) (selected_partition.sector_end - selected_partition.sector_start) / ( (double)total_length/500) )) + frame_resizer_base ->get_x_start() ) ; frame_resizer_base ->set_used( Round( (double) selected_partition.sectors_used / ( (double)total_length/500) ) ) ; - //since some filesystems have upper and lower limits we need to check for this - if ( selected_partition .Get_Used_MB( ) > fs .MIN ) - fs .MIN = selected_partition .Get_Used_MB( ) ; - - //if fs. MIN is 0 here (means used == 0 as well) it's safe to have BUF / 2 - fs .MIN += fs .MIN ? BUF : BUF/2 ; - - //in certain (rare) cases fs .MIN is a bit too high... - if ( fs .MIN > selected_partition .Get_Length_MB( ) ) + if ( fs .shrink ) + { + //since some filesystems have lower limits we need to check for this + if ( selected_partition .Get_Used_MB( ) > fs .MIN ) + fs .MIN = selected_partition .Get_Used_MB( ) ; + + //if fs. MIN is 0 here (means used == 0 as well) it's safe to have BUF / 2 + fs .MIN += fs .MIN ? BUF : BUF/2 ; + + //in certain (rare) cases fs .MIN is a bit too high... + if ( fs .MIN > selected_partition .Get_Length_MB( ) ) + fs .MIN = selected_partition .Get_Length_MB( ) ; + } + else //only grow.. fs .MIN = selected_partition .Get_Length_MB( ) ; - - if ( ! fs .MAX ) - fs .MAX = TOTAL_MB ; - - if ( fs .MAX > TOTAL_MB ) + + if ( ! fs .MAX || fs .MAX > TOTAL_MB ) fs .MAX = TOTAL_MB ; //set values of spinbutton_before diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc index 7852fc36..9ff2102b 100644 --- a/src/Win_GParted.cc +++ b/src/Win_GParted.cc @@ -617,14 +617,13 @@ void Win_GParted::Set_Valid_Operations() allow_convert( true ) ; //find out if resizing/moving and copying is possible - if ( Get_FS( selected_partition .filesystem, gparted_core .get_fs( ) ) .resize && ! devices[ current_device ] .readonly ) + fs = Get_FS( selected_partition .filesystem, gparted_core .get_fs( ) ) ; + if ( (fs .grow || fs .shrink) && ! devices[ current_device ] .readonly ) { allow_resize( true ) ; //only allow copying of real partitions - if ( selected_partition .status != GParted::STAT_NEW && - selected_partition .status != GParted::STAT_COPY && - Get_FS( selected_partition .filesystem, gparted_core .get_fs( ) ) .copy ) + if ( selected_partition .status != GParted::STAT_NEW && selected_partition .status != GParted::STAT_COPY && fs .copy ) allow_copy( true ) ; } @@ -801,8 +800,7 @@ void Win_GParted::mouse_click( GdkEventButton *event, const Partition & partitio { selected_partition = partition; - Set_Valid_Operations () ; - + Set_Valid_Operations( ) ; treeview_detail .Set_Selected( partition ); vbox_visual_disk ->Set_Selected( partition ); @@ -858,7 +856,7 @@ void Win_GParted::activate_resize() hbox_resize_move .pack_start( * mk_label( _("Resize/Move") ), Gtk::PACK_SHRINK ) ; button_resize_move .add( hbox_resize_move ) ; - dialog .add_action_widget ( button_resize_move, Gtk::RESPONSE_OK ) ; + dialog .add_action_widget( button_resize_move, Gtk::RESPONSE_OK ) ; dialog .show_all_children( ) ; if ( dialog.run( ) == Gtk::RESPONSE_CANCEL ) @@ -1076,7 +1074,7 @@ void Win_GParted::activate_convert( const Glib::ustring & new_fs ) dialog .hide( ) ;//i want to be sure the dialog is gone _before_ operationslist shows up (only matters if first operation) //check for some limits... - FS fs = Get_FS( new_fs, gparted_core .get_fs( ) ) ; + fs = Get_FS( new_fs, gparted_core .get_fs( ) ) ; if ( selected_partition .Get_Length_MB( ) < fs .MIN || ( fs .MAX && selected_partition .Get_Length_MB( ) > fs .MAX ) ) { diff --git a/src/ext2.cc b/src/ext2.cc index c87d4d6a..dbf9a145 100644 --- a/src/ext2.cc +++ b/src/ext2.cc @@ -37,7 +37,7 @@ FS ext2::get_filesystem_support( ) //resizing is a delicate process which requires 3 commands.. if ( ! system( "which resize2fs 1>/dev/null 2>/dev/null" ) && fs .read && fs .check ) - fs .resize = true ; + fs .grow = fs .shrink = true ; if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) ) fs .copy = true ; diff --git a/src/ext3.cc b/src/ext3.cc index 29303568..b9547390 100644 --- a/src/ext3.cc +++ b/src/ext3.cc @@ -37,7 +37,7 @@ FS ext3::get_filesystem_support( ) //resizing is a delicate process which requires 3 commands.. if ( ! system( "which resize2fs 1>/dev/null 2>/dev/null" ) && fs .read && fs .check ) - fs .resize = true ; + fs .grow = fs .shrink = true ; if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) ) fs .copy = true ; diff --git a/src/fat16.cc b/src/fat16.cc index 433ddce8..c3e66818 100644 --- a/src/fat16.cc +++ b/src/fat16.cc @@ -36,7 +36,8 @@ FS fat16::get_filesystem_support( ) fs .check = true ; //resizing of start and endpoint are provided by libparted - fs .resize = true ; + fs .grow = true ; + fs .shrink = true ; fs .move = true ; if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) ) diff --git a/src/fat32.cc b/src/fat32.cc index 56bfbdb4..4bfdd65b 100644 --- a/src/fat32.cc +++ b/src/fat32.cc @@ -36,7 +36,8 @@ FS fat32::get_filesystem_support( ) fs .check = true ; //resizing of start and endpoint are provided by libparted - fs .resize = true ; + fs .grow = true ; + fs .shrink = true ; fs .move = true ; if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) ) diff --git a/src/linux_swap.cc b/src/linux_swap.cc index de82b6db..d45cef3b 100644 --- a/src/linux_swap.cc +++ b/src/linux_swap.cc @@ -28,7 +28,8 @@ FS linux_swap::get_filesystem_support( ) fs .filesystem = "linux-swap" ; fs .read = false ; //used/unused isn't relevant for swapspace fs .create = true ; - fs .resize = true ; + fs .grow = true ; + fs .shrink = true ; fs .move = true ; if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) ) diff --git a/src/ntfs.cc b/src/ntfs.cc index 87e6e8e0..405ac437 100644 --- a/src/ntfs.cc +++ b/src/ntfs.cc @@ -37,10 +37,10 @@ FS ntfs::get_filesystem_support( ) //resizing is a delicate process which requires 3 commands.. if ( ! system( "which ntfsresize 1>/dev/null 2>/dev/null" ) && fs .read && fs .check ) - fs .resize = true ; + fs .grow = fs .shrink = true ; - //we need resize to set correct used/unused after cloning - if ( ! system( "which ntfsclone 1>/dev/null 2>/dev/null" ) && fs .resize ) + //we need ntfsresize to set correct used/unused after cloning + if ( ! system( "which ntfsclone 1>/dev/null 2>/dev/null" ) && fs .grow ) fs .copy = true ; return fs ; diff --git a/src/reiserfs.cc b/src/reiserfs.cc index 5f863f63..fbcfe9ba 100644 --- a/src/reiserfs.cc +++ b/src/reiserfs.cc @@ -38,10 +38,10 @@ FS reiserfs::get_filesystem_support( ) //resizing is a delicate process which requires 3 commands.. if ( ! system( "which resize_reiserfs 1>/dev/null 2>/dev/null" ) && fs .read && fs .check ) - fs .resize = true ; + fs .grow = fs .shrink = true ; //we need to call resize_reiserfs after a copy to get proper used/unused - if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) && fs .resize ) + if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) && fs .grow ) fs .copy = true ; fs .MIN = 32 ;