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)
This commit is contained in:
Bart Hakvoort 2004-12-09 22:56:33 +00:00
parent 296b6d4b56
commit 951797caa7
12 changed files with 74 additions and 113 deletions

View File

@ -1,3 +1,10 @@
2004-12-09 Bart Hakvoort <gparted@users.sf.net>
* 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 <gparted@users.sf.net> 2004-12-07 Bart Hakvoort <gparted@users.sf.net>
* src/VBox_VisualDisk.cc: placed a small (2px) border around the legend. * src/VBox_VisualDisk.cc: placed a small (2px) border around the legend.

View File

@ -81,6 +81,7 @@ protected:
bool fixed_start, GRIP ; bool fixed_start, GRIP ;
double before_value ; double before_value ;
int x_start, x_end ; int x_start, x_end ;
FS fs ;
private: private:
void Check_Change() ; void Check_Change() ;

View File

@ -26,7 +26,7 @@ namespace GParted
class Dialog_Partition_Copy : public Dialog_Base_Partition class Dialog_Partition_Copy : public Dialog_Base_Partition
{ {
public: public:
Dialog_Partition_Copy( ) ; Dialog_Partition_Copy( std::vector<FS> FILESYSTEMS ) ;
void Set_Data( const Partition & selected_partition, const Partition & copied_partition ); void Set_Data( const Partition & selected_partition, const Partition & copied_partition );
Partition Get_New_Partition( ) ; Partition Get_New_Partition( ) ;

View File

@ -49,8 +49,15 @@ struct FS
bool move ; //startpoint and endpoint bool move ; //startpoint and endpoint
bool check ; //some checktool available? bool check ; //some checktool available?
bool copy ; 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 ;
}
}; };

View File

@ -200,35 +200,12 @@ void Dialog_Base_Partition::on_signal_resize( int x_start, int x_end, Frame_Resi
{ {
GRIP = true ; GRIP = true ;
//check for upper/lower limit fat16 if ( ( x_end - x_start ) * MB_PER_PIXEL < fs .MIN || ( fs .MAX && ( x_end - x_start ) * MB_PER_PIXEL > fs .MAX ) )
if ( selected_partition.filesystem == "fat16" && ( ( x_end - x_start ) * MB_PER_PIXEL > 1023 || ( x_end - x_start ) * MB_PER_PIXEL < 32 ) ) {
{
frame_resizer_base ->set_x_start( this ->x_start ); frame_resizer_base ->set_x_start( this ->x_start );
frame_resizer_base ->set_x_end( this ->x_end ); frame_resizer_base ->set_x_end( this ->x_end );
frame_resizer_base ->Draw_Partition() ; 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() ;
GRIP = false ; GRIP = false ;
return ; return ;
} }

View File

@ -20,14 +20,18 @@
namespace GParted namespace GParted
{ {
Dialog_Partition_Copy::Dialog_Partition_Copy() Dialog_Partition_Copy::Dialog_Partition_Copy( std::vector<FS> FILESYSTEMS )
{ {
this ->FILESYSTEMS = FILESYSTEMS ;
Set_Resizer( false ) ; Set_Resizer( false ) ;
Set_Confirm_Button( PASTE ) ; Set_Confirm_Button( PASTE ) ;
} }
void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, const Partition & copied_partition ) 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 GRIP = true ; //prevents on spinbutton_changed from getting activated prematurely
this ->set_title( String::ucompose( _("Paste %1"), copied_partition .partition ) ) ; 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_range( 0, TOTAL_MB - copied_partition .Get_Length_MB( ) -1 ) ;//mind the -1 !!
spinbutton_before .set_value( 0 ) ; spinbutton_before .set_value( 0 ) ;
//set values of spinbutton_size (check for fat16 maxsize of 1023 MB) //set values of spinbutton_size
long UPPER; spinbutton_size .set_range( copied_partition .Get_Length_MB( ) +1, fs .MAX ? fs .MAX : TOTAL_MB ) ;
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 ) ;
spinbutton_size .set_value( copied_partition .Get_Length_MB( ) ) ; spinbutton_size .set_value( copied_partition .Get_Length_MB( ) ) ;
//set values of spinbutton_after //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( ) ) ; spinbutton_after .set_value( TOTAL_MB - copied_partition .Get_Length_MB( ) ) ;
//set contents of label_minmax //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 ) //set global selected_partition (see Dialog_Base_Partition::Get_New_Partition )
this ->selected_partition = copied_partition ; this ->selected_partition = copied_partition ;

View File

@ -184,41 +184,27 @@ void Dialog_Partition_New::optionmenu_changed( bool type )
//optionmenu_filesystem //optionmenu_filesystem
if ( ! type ) if ( ! type )
{ {
fs = FILESYSTEMS[ optionmenu_filesystem .get_history( ) ] ;
//needed vor upper limit check (see also Dialog_Base_Partition::on_signal_resize ) //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 //set new spinbutton ranges
long MIN, MAX; spinbutton_before .set_range( 0, TOTAL_MB - fs .MIN ) ;
switch ( optionmenu_filesystem .get_history() ) spinbutton_size .set_range( fs .MIN, fs .MAX ? fs .MAX : TOTAL_MB ) ;
{ spinbutton_after .set_range( 0, TOTAL_MB - fs .MIN ) ;
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 ) ;
//set contents of label_minmax //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 //set fitting resizer colors
//backgroundcolor.. //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 ); frame_resizer_base ->override_default_rgb_unused_color( color_temp );
//partitioncolor.. //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 ->set_rgb_partition_color( color_temp ) ;
frame_resizer_base ->Draw_Partition( ) ; 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++ ) 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( ) .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 //unformatted is always available
menu_filesystem .items( ) .back( ) .set_sensitive( true ) ; 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 //find and set first enabled filesystem
for ( unsigned int t = 0 ; t < menu_filesystem .items( ) .size( ) ; t++ ) for ( unsigned int t = 0 ; t < menu_filesystem .items( ) .size( ) ; t++ )
if ( menu_filesystem .items( )[ t ] .sensitive( ) ) if ( menu_filesystem .items( )[ t ] .sensitive( ) )

View File

@ -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 <Partition> & partitions ) void Dialog_Partition_Resize_Move::Resize_Move_Normal( const std::vector <Partition> & partitions )
{ {
fs = Get_FS( selected_partition .filesystem, FILESYSTEMS ) ;
//see if we need a fixed_start //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 ) ) ; this ->set_title( String::ucompose( _("Resize/Move %1"), selected_partition .partition ) ) ;
frame_resizer_base ->set_fixed_start( false ) ; frame_resizer_base ->set_fixed_start( false ) ;
@ -113,30 +115,17 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const std::vector <Partit
frame_resizer_base ->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_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) ) ) ; 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 //since some filesystems have upper and lower limits we need to check for this
long LOWER, UPPER; long LOWER = ( selected_partition .Get_Used_MB( ) < fs .MIN ) ? fs .MIN : selected_partition .Get_Used_MB( ) ;
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( ) ;
LOWER += BUF ; 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( ) ) if ( LOWER > selected_partition .Get_Length_MB( ) )
LOWER = selected_partition .Get_Length_MB( ) ; LOWER = selected_partition .Get_Length_MB( ) ;
if ( selected_partition.filesystem == "fat16" && Sector_To_MB( total_length ) > 1023 ) long UPPER = fs .MAX ? fs .MAX : Sector_To_MB( total_length ) ;
UPPER = 1023 ;
else
UPPER = Sector_To_MB( total_length ) ;
//set values of spinbutton_before //set values of spinbutton_before
if ( ! fixed_start ) if ( ! fixed_start )
{ {

View File

@ -923,7 +923,7 @@ void Win_GParted::activate_paste()
{ {
if ( ! max_amount_prim_reached( ) ) 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_Data( selected_partition, copied_partition ) ;
dialog .set_transient_for( *this ); 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 ) + "</span>\n\n" ; str_temp += String::ucompose( _("Are you sure you want to convert this filesystem to %1?"), new_fs ) + "</span>\n\n" ;
str_temp += String::ucompose( _("This operation will destroy all data on %1"), selected_partition .partition ) ; 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. 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 ; 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... //check for some limits...
if ( new_fs == "fat16" || new_fs == "fat32" ) 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 = "<span weight=\"bold\" size=\"larger\">" ;
str_temp += String::ucompose( _("Can not convert this filesystem to %1."), new_fs ) ;
str_temp += "</span>\n\n" ;
if ( new_fs == "fat16" && selected_partition.Get_Length_MB() < 32 ) if ( selected_partition .Get_Length_MB( ) < fs .MIN )
str_temp = (Glib::ustring) _("Can not convert this filesystem to fat16.") + "</span>\n\n" + (Glib::ustring) _( "A fat16 filesystem requires a partition of at least 32 MB.") ; str_temp += String::ucompose( _( "A %1 filesystem requires a partition of at least %2 MB."), new_fs, fs .MIN ) ;
else if ( new_fs == "fat16" && selected_partition.Get_Length_MB() > 1023 ) else
str_temp = (Glib::ustring) _("Can not convert this filesystem to fat16.") + "</span>\n\n" + (Glib::ustring) _( "A partition with a fat16 filesystem has a maximum size of 1023 MB."); str_temp += String::ucompose( _( "A partition with a %1 filesystem has a maximum size of %2 MB."), new_fs, fs .MAX ) ;
else if ( new_fs == "fat32" && selected_partition.Get_Length_MB() < 256 )
str_temp = (Glib::ustring) _("Can not convert this filesystem to fat32.") + "</span>\n\n" + (Glib::ustring) _( "A fat32 filesystem requires a partition of at least 256 MB.");
if ( ! str_temp .empty() )
{ Gtk::MessageDialog dialog( *this, str_temp, true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true );
Gtk::MessageDialog dialog( *this, "<span weight=\"bold\" size=\"larger\">" + str_temp ,true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); dialog .run( ) ;
dialog.run() ; return ;
return ;
}
} }
//ok we made it :P lets create an fitting partition object //ok we made it :P lets create an fitting partition object

View File

@ -39,6 +39,10 @@ FS fat16::get_filesystem_support( )
if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) ) if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) )
fs .copy = true ; fs .copy = true ;
fs .MIN = 32 ;
fs .MAX = 1023 ;
return fs ; return fs ;
} }

View File

@ -42,6 +42,8 @@ FS fat32::get_filesystem_support( )
if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) ) if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) )
fs .copy = true ; fs .copy = true ;
fs .MIN = 256 ;
return fs ; return fs ;
} }

View File

@ -44,6 +44,8 @@ FS reiserfs::get_filesystem_support( )
if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) && fs .resize ) if ( ! system( "which dd 1>/dev/null 2>/dev/null" ) && fs .resize )
fs .copy = true ; fs .copy = true ;
fs .MIN = 40 ;
return fs ; return fs ;
} }