From 951797caa7a6f324e460527ead00336bcb6035ac Mon Sep 17 00:00:00 2001 From: Bart Hakvoort Date: Thu, 9 Dec 2004 22:56:33 +0000 Subject: [PATCH] added MIN and MAX to filesystemstruct to set min. and max sizes of a * added MIN and MAX to filesystemstruct to set min. and max sizes of a filesystem. So instead of checking per filesystem i now simply check the fs.MIN or fs.MAX. this results in less and cleaner code. Also this will come in handy when adding support for new filesystems. (This also fixed several minor bugs with filesystemsizes and gained some improvement in resizer performance) --- ChangeLog | 7 +++++ include/Dialog_Base_Partition.h | 1 + include/Dialog_Partition_Copy.h | 2 +- include/Utils.h | 9 +++++- src/Dialog_Base_Partition.cc | 29 ++----------------- src/Dialog_Partition_Copy.cc | 18 +++++------- src/Dialog_Partition_New.cc | 45 +++++++---------------------- src/Dialog_Partition_Resize_Move.cc | 27 +++++------------ src/Win_GParted.cc | 41 +++++++++++++------------- src/fat16.cc | 4 +++ src/fat32.cc | 2 ++ src/reiserfs.cc | 2 ++ 12 files changed, 74 insertions(+), 113 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4f38caa5..62d06b0d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2004-12-09 Bart Hakvoort + + * added MIN and MAX to filesystemstruct to set min. and max sizes of a filesystem. So instead of checking per filesystem + i now simply check the fs.MIN or fs.MAX. this results in less and cleaner code. Also this will come in handy when adding + support for new filesystems. (This also fixed several minor bugs with filesystemsizes and gained some improvement in resizer + performance) + 2004-12-07 Bart Hakvoort * src/VBox_VisualDisk.cc: placed a small (2px) border around the legend. diff --git a/include/Dialog_Base_Partition.h b/include/Dialog_Base_Partition.h index 5661fa5f..98976d5a 100644 --- a/include/Dialog_Base_Partition.h +++ b/include/Dialog_Base_Partition.h @@ -81,6 +81,7 @@ protected: bool fixed_start, GRIP ; double before_value ; int x_start, x_end ; + FS fs ; private: void Check_Change() ; diff --git a/include/Dialog_Partition_Copy.h b/include/Dialog_Partition_Copy.h index e5da00bc..8a9d8a94 100644 --- a/include/Dialog_Partition_Copy.h +++ b/include/Dialog_Partition_Copy.h @@ -26,7 +26,7 @@ namespace GParted class Dialog_Partition_Copy : public Dialog_Base_Partition { public: - Dialog_Partition_Copy( ) ; + Dialog_Partition_Copy( std::vector FILESYSTEMS ) ; void Set_Data( const Partition & selected_partition, const Partition & copied_partition ); Partition Get_New_Partition( ) ; diff --git a/include/Utils.h b/include/Utils.h index 01c47f91..1c7ce72f 100644 --- a/include/Utils.h +++ b/include/Utils.h @@ -49,8 +49,15 @@ struct FS bool move ; //startpoint and endpoint bool check ; //some checktool available? bool copy ; + int MIN ; + int MAX ; - FS( ) {read = create = resize = move = check = copy = false ;} + FS( ) + { + read = create = resize = move = check = copy = false ; + MIN = 1 ; + MAX = 0 ; + } }; diff --git a/src/Dialog_Base_Partition.cc b/src/Dialog_Base_Partition.cc index bc7ebde4..1bf7c01d 100644 --- a/src/Dialog_Base_Partition.cc +++ b/src/Dialog_Base_Partition.cc @@ -200,35 +200,12 @@ void Dialog_Base_Partition::on_signal_resize( int x_start, int x_end, Frame_Resi { GRIP = true ; - //check for upper/lower limit fat16 - if ( selected_partition.filesystem == "fat16" && ( ( x_end - x_start ) * MB_PER_PIXEL > 1023 || ( x_end - x_start ) * MB_PER_PIXEL < 32 ) ) - { + if ( ( x_end - x_start ) * MB_PER_PIXEL < fs .MIN || ( fs .MAX && ( x_end - x_start ) * MB_PER_PIXEL > fs .MAX ) ) + { frame_resizer_base ->set_x_start( this ->x_start ); frame_resizer_base ->set_x_end( this ->x_end ); - frame_resizer_base ->Draw_Partition() ; - GRIP = false ; - return ; - } - - //check for lower limit fat32 - if ( selected_partition.filesystem == "fat32" && ( x_end - x_start ) * MB_PER_PIXEL < 256 ) - { - frame_resizer_base ->set_x_start( this ->x_start ); - frame_resizer_base ->set_x_end( this ->x_end ); - - frame_resizer_base ->Draw_Partition() ; - GRIP = false ; - return ; - } - - //check for lower limit reiserfs - if ( selected_partition.filesystem == "reiserfs" && ( x_end - x_start ) * MB_PER_PIXEL < 40 ) - { - frame_resizer_base ->set_x_start( this ->x_start ); - frame_resizer_base ->set_x_end( this ->x_end ); - - frame_resizer_base ->Draw_Partition() ; + frame_resizer_base ->Draw_Partition( ) ; GRIP = false ; return ; } diff --git a/src/Dialog_Partition_Copy.cc b/src/Dialog_Partition_Copy.cc index 0605c4d8..4bc1158f 100644 --- a/src/Dialog_Partition_Copy.cc +++ b/src/Dialog_Partition_Copy.cc @@ -20,14 +20,18 @@ namespace GParted { -Dialog_Partition_Copy::Dialog_Partition_Copy() +Dialog_Partition_Copy::Dialog_Partition_Copy( std::vector FILESYSTEMS ) { + this ->FILESYSTEMS = FILESYSTEMS ; + Set_Resizer( false ) ; Set_Confirm_Button( PASTE ) ; } void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, const Partition & copied_partition ) { + fs = Get_FS( copied_partition .filesystem, FILESYSTEMS ) ; + GRIP = true ; //prevents on spinbutton_changed from getting activated prematurely this ->set_title( String::ucompose( _("Paste %1"), copied_partition .partition ) ) ; @@ -54,14 +58,8 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons spinbutton_before .set_range( 0, TOTAL_MB - copied_partition .Get_Length_MB( ) -1 ) ;//mind the -1 !! spinbutton_before .set_value( 0 ) ; - //set values of spinbutton_size (check for fat16 maxsize of 1023 MB) - long UPPER; - if ( copied_partition .filesystem == "fat16" && Sector_To_MB( total_length ) > 1023 ) - UPPER = 1023 ; - else - UPPER = TOTAL_MB ; - - spinbutton_size .set_range( copied_partition .Get_Length_MB( ) +1, UPPER ) ; + //set values of spinbutton_size + spinbutton_size .set_range( copied_partition .Get_Length_MB( ) +1, fs .MAX ? fs .MAX : TOTAL_MB ) ; spinbutton_size .set_value( copied_partition .Get_Length_MB( ) ) ; //set values of spinbutton_after @@ -69,7 +67,7 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons spinbutton_after .set_value( TOTAL_MB - copied_partition .Get_Length_MB( ) ) ; //set contents of label_minmax - Set_MinMax_Text( copied_partition .Get_Length_MB( ) +1, UPPER ) ; + Set_MinMax_Text( copied_partition .Get_Length_MB( ) +1, fs .MAX ? fs .MAX : TOTAL_MB ) ; //set global selected_partition (see Dialog_Base_Partition::Get_New_Partition ) this ->selected_partition = copied_partition ; diff --git a/src/Dialog_Partition_New.cc b/src/Dialog_Partition_New.cc index 479c1a9a..03f6533f 100644 --- a/src/Dialog_Partition_New.cc +++ b/src/Dialog_Partition_New.cc @@ -184,41 +184,27 @@ void Dialog_Partition_New::optionmenu_changed( bool type ) //optionmenu_filesystem if ( ! type ) { + fs = FILESYSTEMS[ optionmenu_filesystem .get_history( ) ] ; + //needed vor upper limit check (see also Dialog_Base_Partition::on_signal_resize ) - selected_partition .filesystem = FILESYSTEMS[ optionmenu_filesystem .get_history( ) ] .filesystem ; + selected_partition .filesystem = fs .filesystem ; //set new spinbutton ranges - long MIN, MAX; - switch ( optionmenu_filesystem .get_history() ) - { - case 2: MIN = 32 ; - TOTAL_MB > 1023 ? MAX = 1023 : MAX = TOTAL_MB ; - break; - case 3: MIN = 256 ; - MAX = TOTAL_MB ; - break; - case 5: MIN = 40 ; - MAX = TOTAL_MB ; - break; - default: MIN = 1 ; - MAX = TOTAL_MB ; - } - - spinbutton_before .set_range( 0, TOTAL_MB - MIN ) ; - spinbutton_size .set_range( MIN, MAX ) ; - spinbutton_after .set_range( 0, TOTAL_MB - MIN ) ; + spinbutton_before .set_range( 0, TOTAL_MB - fs .MIN ) ; + spinbutton_size .set_range( fs .MIN, fs .MAX ? fs .MAX : TOTAL_MB ) ; + spinbutton_after .set_range( 0, TOTAL_MB - fs .MIN ) ; //set contents of label_minmax - Set_MinMax_Text( MIN, MAX ) ; + Set_MinMax_Text( fs .MIN, fs .MAX ? fs .MAX : TOTAL_MB ) ; } //set fitting resizer colors //backgroundcolor.. - optionmenu_type.get_history() == 2 ? color_temp .set( "darkgrey" ) : color_temp .set( "white" ) ; + optionmenu_type .get_history( ) == 2 ? color_temp .set( "darkgrey" ) : color_temp .set( "white" ) ; frame_resizer_base ->override_default_rgb_unused_color( color_temp ); //partitioncolor.. - color_temp .set( Get_Color( FILESYSTEMS[ optionmenu_filesystem.get_history() ] .filesystem ) ) ; + color_temp .set( Get_Color( fs .filesystem ) ) ; frame_resizer_base ->set_rgb_partition_color( color_temp ) ; frame_resizer_base ->Draw_Partition( ) ; @@ -230,23 +216,12 @@ void Dialog_Partition_New::Build_Filesystems_Menu( bool only_unformatted ) for ( unsigned int t = 0 ; t < FILESYSTEMS .size( ) -1 ; t++ ) { menu_filesystem .items( ) .push_back( Gtk::Menu_Helpers::MenuElem( FILESYSTEMS[ t ] .filesystem ) ) ; - menu_filesystem .items( )[ t ] .set_sensitive( FILESYSTEMS[ t ] .create && ! only_unformatted ) ; + menu_filesystem .items( )[ t ] .set_sensitive( ! only_unformatted && FILESYSTEMS[ t ] .create && this ->selected_partition .Get_Length_MB() >= FILESYSTEMS[ t ] .MIN ) ; } //unformatted is always available menu_filesystem .items( ) .back( ) .set_sensitive( true ) ; - //check if selected unallocated is big enough for fs'es with min. size - //fat16 - if ( this ->selected_partition .Get_Length_MB() < 32 ) - menu_filesystem .items()[ 2 ] .set_sensitive( false ) ; - //fat32 - if ( this ->selected_partition .Get_Length_MB() < 256 ) - menu_filesystem .items()[ 3 ] .set_sensitive( false ) ; - //reiserfs - if ( this ->selected_partition .Get_Length_MB() < 40 ) - menu_filesystem .items()[ 5 ] .set_sensitive( false ) ; - //find and set first enabled filesystem for ( unsigned int t = 0 ; t < menu_filesystem .items( ) .size( ) ; t++ ) if ( menu_filesystem .items( )[ t ] .sensitive( ) ) diff --git a/src/Dialog_Partition_Resize_Move.cc b/src/Dialog_Partition_Resize_Move.cc index 86846e1f..7626d7fe 100644 --- a/src/Dialog_Partition_Resize_Move.cc +++ b/src/Dialog_Partition_Resize_Move.cc @@ -68,8 +68,10 @@ void Dialog_Partition_Resize_Move::Set_Data( const Partition & selected_partitio void Dialog_Partition_Resize_Move::Resize_Move_Normal( const std::vector & partitions ) { + fs = Get_FS( selected_partition .filesystem, FILESYSTEMS ) ; + //see if we need a fixed_start - if ( Get_FS( selected_partition .filesystem, FILESYSTEMS ) .move ) + if ( fs .move ) { this ->set_title( String::ucompose( _("Resize/Move %1"), selected_partition .partition ) ) ; frame_resizer_base ->set_fixed_start( false ) ; @@ -113,30 +115,17 @@ 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 - long LOWER, UPPER; - if ( selected_partition .filesystem == "fat16" && selected_partition .Get_Used_MB( ) < 32 ) - LOWER = 32 ; - else if ( selected_partition .filesystem == "fat32" && selected_partition .Get_Used_MB( ) < 256 ) - LOWER = 256 ; - else if ( selected_partition .filesystem == "reiserfs" && selected_partition .Get_Used_MB( ) < 40 ) - LOWER = 40 ; - else - LOWER = selected_partition .Get_Used_MB( ) ; - + long LOWER = ( selected_partition .Get_Used_MB( ) < fs .MIN ) ? fs .MIN : selected_partition .Get_Used_MB( ) ; + LOWER += BUF ; - //in certain (rare) case LOWER is a bit too high... + //in certain (rare) cases LOWER is a bit too high... if ( LOWER > selected_partition .Get_Length_MB( ) ) LOWER = selected_partition .Get_Length_MB( ) ; - if ( selected_partition.filesystem == "fat16" && Sector_To_MB( total_length ) > 1023 ) - UPPER = 1023 ; - else - UPPER = Sector_To_MB( total_length ) ; - - + long UPPER = fs .MAX ? fs .MAX : Sector_To_MB( total_length ) ; + //set values of spinbutton_before if ( ! fixed_start ) { diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc index 36e76eb1..994152eb 100644 --- a/src/Win_GParted.cc +++ b/src/Win_GParted.cc @@ -923,7 +923,7 @@ void Win_GParted::activate_paste() { if ( ! max_amount_prim_reached( ) ) { - Dialog_Partition_Copy dialog ; + Dialog_Partition_Copy dialog( gparted_core .get_fs( ) ) ; dialog .Set_Data( selected_partition, copied_partition ) ; dialog .set_transient_for( *this ); @@ -1059,35 +1059,34 @@ void Win_GParted::activate_convert( const Glib::ustring & new_fs ) str_temp += String::ucompose( _("Are you sure you want to convert this filesystem to %1?"), new_fs ) + "\n\n" ; str_temp += String::ucompose( _("This operation will destroy all data on %1"), selected_partition .partition ) ; - Gtk::MessageDialog dialog( *this, str_temp, true, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_CANCEL, true); + Gtk::MessageDialog dialog( *this, str_temp, true, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_CANCEL, true ); dialog. add_button( Gtk::Stock::CONVERT, Gtk::RESPONSE_OK ) ; - dialog. show_all_children() ; + dialog. show_all_children( ) ; - if ( dialog.run() == Gtk::RESPONSE_CANCEL ) + if ( dialog .run( ) == Gtk::RESPONSE_CANCEL ) return ; - dialog.hide() ;//i want to be sure the dialog is gone _before_ operationslist shows up (only matters if first operation) + dialog .hide( ) ;//i want to be sure the dialog is gone _before_ operationslist shows up (only matters if first operation) - //check for the FAT limits... - if ( new_fs == "fat16" || new_fs == "fat32" ) + //check for some limits... + 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 ) ) { - str_temp = "" ; + str_temp = "" ; + str_temp += String::ucompose( _("Can not convert this filesystem to %1."), new_fs ) ; + str_temp += "\n\n" ; - if ( new_fs == "fat16" && selected_partition.Get_Length_MB() < 32 ) - str_temp = (Glib::ustring) _("Can not convert this filesystem to fat16.") + "\n\n" + (Glib::ustring) _( "A fat16 filesystem requires a partition of at least 32 MB.") ; - else if ( new_fs == "fat16" && selected_partition.Get_Length_MB() > 1023 ) - str_temp = (Glib::ustring) _("Can not convert this filesystem to fat16.") + "\n\n" + (Glib::ustring) _( "A partition with a fat16 filesystem has a maximum size of 1023 MB."); - else if ( new_fs == "fat32" && selected_partition.Get_Length_MB() < 256 ) - str_temp = (Glib::ustring) _("Can not convert this filesystem to fat32.") + "\n\n" + (Glib::ustring) _( "A fat32 filesystem requires a partition of at least 256 MB."); + if ( selected_partition .Get_Length_MB( ) < fs .MIN ) + str_temp += String::ucompose( _( "A %1 filesystem requires a partition of at least %2 MB."), new_fs, fs .MIN ) ; + else + str_temp += String::ucompose( _( "A partition with a %1 filesystem has a maximum size of %2 MB."), new_fs, fs .MAX ) ; - if ( ! str_temp .empty() ) - { - Gtk::MessageDialog dialog( *this, "" + str_temp ,true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); - dialog.run() ; - return ; - } - + + Gtk::MessageDialog dialog( *this, str_temp, true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true ); + dialog .run( ) ; + return ; } //ok we made it :P lets create an fitting partition object diff --git a/src/fat16.cc b/src/fat16.cc index 610fcec8..40649574 100644 --- a/src/fat16.cc +++ b/src/fat16.cc @@ -39,6 +39,10 @@ FS fat16::get_filesystem_support( ) if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) ) fs .copy = true ; + + fs .MIN = 32 ; + fs .MAX = 1023 ; + return fs ; } diff --git a/src/fat32.cc b/src/fat32.cc index da31a864..56bfbdb4 100644 --- a/src/fat32.cc +++ b/src/fat32.cc @@ -42,6 +42,8 @@ FS fat32::get_filesystem_support( ) if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) ) fs .copy = true ; + fs .MIN = 256 ; + return fs ; } diff --git a/src/reiserfs.cc b/src/reiserfs.cc index 6c49716c..8295ba39 100644 --- a/src/reiserfs.cc +++ b/src/reiserfs.cc @@ -44,6 +44,8 @@ FS reiserfs::get_filesystem_support( ) if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) && fs .resize ) fs .copy = true ; + fs .MIN = 40 ; + return fs ; }