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>
* src/VBox_VisualDisk.cc: placed a small (2px) border around the legend.

View File

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

View File

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

View File

@ -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 ;
}
};

View File

@ -200,30 +200,7 @@ 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 ) )
{
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 )
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 );

View File

@ -20,14 +20,18 @@
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_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 ;

View File

@ -184,32 +184,18 @@ 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
@ -218,7 +204,7 @@ void Dialog_Partition_New::optionmenu_changed( bool type )
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( ) )

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 )
{
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,29 +115,16 @@ 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_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 )

View File

@ -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 );
@ -1069,27 +1069,26 @@ 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 the FAT limits...
if ( new_fs == "fat16" || new_fs == "fat32" )
{
str_temp = "" ;
//check for some limits...
FS fs = Get_FS( new_fs, gparted_core .get_fs( ) ) ;
if ( new_fs == "fat16" && selected_partition.Get_Length_MB() < 32 )
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.") ;
else if ( new_fs == "fat16" && selected_partition.Get_Length_MB() > 1023 )
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.");
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() )
if ( selected_partition .Get_Length_MB( ) < fs .MIN || ( fs .MAX && selected_partition .Get_Length_MB( ) > fs .MAX ) )
{
Gtk::MessageDialog dialog( *this, "<span weight=\"bold\" size=\"larger\">" + str_temp ,true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
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 ( 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 ) ;
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
Partition part_temp;
part_temp .Set( selected_partition .partition, selected_partition .partition_number, selected_partition .type, new_fs, selected_partition .sector_start, selected_partition .sector_end, /*-1,*/ selected_partition .inside_extended, false ) ;

View File

@ -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 ;
}

View File

@ -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 ;
}

View File

@ -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 ;
}