in some places i still used MiB's instead of sectors to store sizes. this

* in some places i still used MiB's instead of sectors to store sizes.
  this has been fixed everywhere. Only the spinbuttons still use
  MiB's. I have a few ideas on how to solve this, but i'll take it up
  with #usability first.
This commit is contained in:
Bart Hakvoort 2006-02-25 10:09:30 +00:00
parent a1ad7dea33
commit 391ca32a2b
23 changed files with 219 additions and 182 deletions

View File

@ -1,3 +1,10 @@
2006-02-25 Bart Hakvoort <hakvoort@cvs.gnome.org>
* in some places i still used MiB's instead of sectors to store sizes.
this has been fixed everywhere. Only the spinbuttons still use
MiB's. I have a few ideas on how to solve this, but i'll take it up
with #usability first.
2006-02-22 Bart Hakvoort <hakvoort@cvs.gnome.org> 2006-02-22 Bart Hakvoort <hakvoort@cvs.gnome.org>
* configure.in: bumped to gparted-0.2.2 * configure.in: bumped to gparted-0.2.2

View File

@ -37,7 +37,7 @@ public:
long heads ; long heads ;
long sectors ; long sectors ;
long cylinders ; long cylinders ;
long cylsize ;//FIXME we should store this one as a Sector Sector cylsize ;
Glib::ustring model; Glib::ustring model;
Glib::ustring path; Glib::ustring path;
Glib::ustring realpath; Glib::ustring realpath;

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( const FS & fs, long cylinder_size ) ; Dialog_Partition_Copy( const FS & fs, Sector cylinder_size ) ;
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

@ -30,7 +30,12 @@ class Dialog_Partition_New : public Dialog_Base_Partition
{ {
public: public:
Dialog_Partition_New() ; Dialog_Partition_New() ;
void Set_Data( const Partition & partition, bool any_extended, unsigned short new_count, const std::vector<FS> & FILESYSTEMS, bool only_unformatted, int cylinder_size ); void Set_Data( const Partition & partition,
bool any_extended,
unsigned short new_count,
const std::vector<FS> & FILESYSTEMS,
bool only_unformatted,
Sector cylinder_size );
Partition Get_New_Partition() ;//overridden function Partition Get_New_Partition() ;//overridden function
private: private:

View File

@ -26,7 +26,7 @@ namespace GParted
class Dialog_Partition_Resize_Move : public Dialog_Base_Partition class Dialog_Partition_Resize_Move : public Dialog_Base_Partition
{ {
public: public:
Dialog_Partition_Resize_Move( const FS & fs, long cylinder_size ) ; Dialog_Partition_Resize_Move( const FS & fs, Sector cylinder_size ) ;
void Set_Data( const Partition & selected_partition, const std::vector <Partition> & partitions ) ; void Set_Data( const Partition & selected_partition, const std::vector <Partition> & partitions ) ;
private: private:

View File

@ -69,10 +69,6 @@ public:
//update partition number (used when a logical partition is deleted) //update partition number (used when a logical partition is deleted)
void Update_Number( int new_number ); void Update_Number( int new_number );
//FIXME the 3 *MB function are obsolete and should be replaced by Utils::sector_to_unit()
long Get_Length_MB() const ;
long Get_Used_MB() const ;
long Get_Unused_MB() const ;
Sector get_length() const ; Sector get_length() const ;
bool operator==( const Partition & partition ) const ; bool operator==( const Partition & partition ) const ;

View File

@ -97,9 +97,8 @@ struct FS
Support check ; //some checktool available? Support check ; //some checktool available?
Support copy ; Support copy ;
//FIXME: these 2 should hold 'Sectors' instead if MiB's Sector MIN ;
int MIN ; Sector MAX ;
int MAX ;
FS() FS()
{ {

View File

@ -28,8 +28,8 @@ Device::Device()
void Device::Reset() void Device::Reset()
{ {
partitions .clear() ; partitions .clear() ;
length = 0 ; length = cylsize = 0 ;
heads = sectors = cylinders = cylsize = 0 ; heads = sectors = cylinders = 0 ;
model = path = realpath = disktype = "" ; model = path = realpath = disktype = "" ;
max_prims = highest_busy = 0 ; max_prims = highest_busy = 0 ;
readonly = false ; readonly = false ;

View File

@ -20,7 +20,7 @@
namespace GParted namespace GParted
{ {
Dialog_Partition_Copy::Dialog_Partition_Copy( const FS & fs, long cylinder_size ) Dialog_Partition_Copy::Dialog_Partition_Copy( const FS & fs, Sector cylinder_size )
{ {
this ->fs = fs ; this ->fs = fs ;
@ -40,42 +40,49 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons
//set some widely used values... //set some widely used values...
START = selected_partition .sector_start ; START = selected_partition .sector_start ;
total_length = selected_partition .sector_end - selected_partition .sector_start ; total_length = selected_partition .sector_end - selected_partition .sector_start ;
TOTAL_MB = selected_partition .Get_Length_MB( ) ; TOTAL_MB = Utils::Round( Utils::sector_to_unit( selected_partition .get_length(), GParted::UNIT_MIB ) ) ;
MB_PER_PIXEL = TOTAL_MB / 500.00 ; MB_PER_PIXEL = TOTAL_MB / 500.00 ;
long COPIED_LENGTH_MB = copied_partition .Get_Length_MB( ) ; long COPIED_LENGTH_MB = Utils::Round( Utils::sector_to_unit( copied_partition .get_length(), GParted::UNIT_MIB ) ) ;
//now calculate proportional length of partition //now calculate proportional length of partition
frame_resizer_base ->set_x_start( 0 ) ; frame_resizer_base ->set_x_start( 0 ) ;
int x_end = Utils::Round( COPIED_LENGTH_MB / ( TOTAL_MB/500.00 ) ) ; //> 500 px only possible with xfs... int x_end = Utils::Round( COPIED_LENGTH_MB / ( TOTAL_MB/500.00 ) ) ; //> 500 px only possible with xfs...
frame_resizer_base ->set_x_end( x_end > 500 ? 500 : x_end ) ; frame_resizer_base ->set_x_end( x_end > 500 ? 500 : x_end ) ;
frame_resizer_base ->set_used( Utils::Round( copied_partition .Get_Used_MB( ) / ( TOTAL_MB/500.00) ) ) ; frame_resizer_base ->set_used(
Utils::Round( Utils::sector_to_unit(
copied_partition .sectors_used, GParted::UNIT_MIB ) / (TOTAL_MB/500.00) ) ) ;
fs .MAX = ( ! fs .MAX || fs .MAX > TOTAL_MB ) ? TOTAL_MB : fs .MAX -= BUF ; fs .MAX = ( ! fs .MAX || fs .MAX > (TOTAL_MB * MEBIBYTE) ) ? (TOTAL_MB * MEBIBYTE) : fs .MAX -= BUF ;
if ( fs .filesystem == GParted::FS_XFS ) //bit hackisch, but most effective, since it's a unique situation if ( fs .filesystem == GParted::FS_XFS ) //bit hackisch, but most effective, since it's a unique situation
fs .MIN = copied_partition .Get_Used_MB( ) + (BUF * 2) ; fs .MIN = copied_partition .sectors_used + (BUF * 2) ;
else else
fs .MIN = COPIED_LENGTH_MB +1 ; fs .MIN = (COPIED_LENGTH_MB +1) * MEBIBYTE ;
GRIP = true ; GRIP = true ;
//set values of spinbutton_before //set values of spinbutton_before
spinbutton_before .set_range( 0, TOTAL_MB - fs .MIN ) ; spinbutton_before .set_range( 0, TOTAL_MB - Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ) ) ;
spinbutton_before .set_value( 0 ) ; spinbutton_before .set_value( 0 ) ;
//set values of spinbutton_size //set values of spinbutton_size
spinbutton_size .set_range( fs .MIN, fs .MAX ) ; spinbutton_size .set_range(
Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ),
Utils::Round( Utils::sector_to_unit( fs .MAX, GParted::UNIT_MIB ) ) ) ;
spinbutton_size .set_value( COPIED_LENGTH_MB ) ; spinbutton_size .set_value( COPIED_LENGTH_MB ) ;
//set values of spinbutton_after //set values of spinbutton_after
spinbutton_after .set_range( 0, TOTAL_MB - fs .MIN ) ; spinbutton_after .set_range( 0, TOTAL_MB - Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ) ) ;
spinbutton_after .set_value( TOTAL_MB - COPIED_LENGTH_MB ) ; spinbutton_after .set_value( TOTAL_MB - COPIED_LENGTH_MB ) ;
GRIP = false ; GRIP = false ;
frame_resizer_base ->set_size_limits( Utils::Round(fs .MIN / MB_PER_PIXEL), Utils::Round(fs .MAX / MB_PER_PIXEL) +1 ) ; frame_resizer_base ->set_size_limits( Utils::Round( fs .MIN / (MB_PER_PIXEL * MEBIBYTE) ),
Utils::Round( fs .MAX / (MB_PER_PIXEL * MEBIBYTE) ) +1 ) ;
//set contents of label_minmax //set contents of label_minmax
Set_MinMax_Text( fs .MIN, fs .MAX ) ; Set_MinMax_Text(
Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ),
Utils::Round( Utils::sector_to_unit( fs .MAX, GParted::UNIT_MIB ) ) ) ;
//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

@ -144,7 +144,7 @@ void Dialog_Partition_Info::Display_Info( )
{ {
//calculate relative diskusage //calculate relative diskusage
int percent_used = int percent_used =
Utils::Round( static_cast<double>(partition .Get_Used_MB() ) / partition .Get_Length_MB() *100 ) ; Utils::Round( partition .sectors_used / static_cast<double>( partition .get_length() ) * 100 ) ;
//used //used
table ->attach( * Utils::mk_label( "<b>" + (Glib::ustring) _( "Used:" ) + "</b>" ), 0, 1, top, bottom, Gtk::FILL ) ; table ->attach( * Utils::mk_label( "<b>" + (Glib::ustring) _( "Used:" ) + "</b>" ), 0, 1, top, bottom, Gtk::FILL ) ;

View File

@ -39,7 +39,12 @@ Dialog_Partition_New::Dialog_Partition_New( )
this ->get_vbox() ->pack_start( checkbutton_round_to_cylinders, Gtk::PACK_SHRINK ) ; this ->get_vbox() ->pack_start( checkbutton_round_to_cylinders, Gtk::PACK_SHRINK ) ;
} }
void Dialog_Partition_New::Set_Data( const Partition & partition, bool any_extended, unsigned short new_count, const std::vector<FS> & FILESYSTEMS, bool only_unformatted, int cylinder_size ) void Dialog_Partition_New::Set_Data( const Partition & partition,
bool any_extended,
unsigned short new_count,
const std::vector<FS> & FILESYSTEMS,
bool only_unformatted,
Sector cylinder_size )
{ {
this ->new_count = new_count; this ->new_count = new_count;
this ->selected_partition = partition; this ->selected_partition = partition;
@ -58,7 +63,9 @@ void Dialog_Partition_New::Set_Data( const Partition & partition, bool any_exten
hbox_main .pack_start( table_create, Gtk::PACK_SHRINK ); hbox_main .pack_start( table_create, Gtk::PACK_SHRINK );
/*TO TRANSLATORS: used as label for a list of choices. Create as: <optionmenu with choices> */ /*TO TRANSLATORS: used as label for a list of choices. Create as: <optionmenu with choices> */
table_create.attach( * Utils::mk_label( (Glib::ustring) _("Create as:") + "\t" ), 0, 1, 0, 1, Gtk::FILL); table_create .attach( * Utils::mk_label( static_cast<Glib::ustring>( _("Create as:") ) + "\t" ),
0, 1, 0, 1,
Gtk::FILL );
//fill partitiontype menu //fill partitiontype menu
menu_type .items() .push_back( Gtk::Menu_Helpers::MenuElem( _("Primary Partition") ) ) ; menu_type .items() .push_back( Gtk::Menu_Helpers::MenuElem( _("Primary Partition") ) ) ;
@ -80,23 +87,31 @@ void Dialog_Partition_New::Set_Data( const Partition & partition, bool any_exten
} }
optionmenu_type .set_menu( menu_type ); optionmenu_type .set_menu( menu_type );
optionmenu_type .set_size_request( 160, -1 ); //160 is the ideal width for this table column, (when one widget is set, the rest wil take this width as well)
optionmenu_type .signal_changed( ) .connect( sigc::bind<bool>( sigc::mem_fun( *this, &Dialog_Partition_New::optionmenu_changed ), true ) ); //160 is the ideal width for this table column.
//(when one widget is set, the rest wil take this width as well)
optionmenu_type .set_size_request( 160, -1 );
optionmenu_type .signal_changed() .connect(
sigc::bind<bool>( sigc::mem_fun( *this, &Dialog_Partition_New::optionmenu_changed ), true ) );
table_create .attach( optionmenu_type, 1, 2, 0, 1, Gtk::FILL ); table_create .attach( optionmenu_type, 1, 2, 0, 1, Gtk::FILL );
//filesystems to choose from //filesystems to choose from
table_create.attach( * Utils::mk_label( (Glib::ustring) _("Filesystem:") + "\t" ), 0, 1, 1, 2, Gtk::FILL ); table_create .attach( * Utils::mk_label( static_cast<Glib::ustring>( _("Filesystem:") ) + "\t" ),
0, 1, 1, 2,
Gtk::FILL );
Build_Filesystems_Menu( only_unformatted ) ; Build_Filesystems_Menu( only_unformatted ) ;
optionmenu_filesystem .set_menu( menu_filesystem ); optionmenu_filesystem .set_menu( menu_filesystem );
optionmenu_filesystem .signal_changed( ) .connect( sigc::bind<bool>( sigc::mem_fun( *this, &Dialog_Partition_New::optionmenu_changed ), false ) ); optionmenu_filesystem .signal_changed() .connect(
sigc::bind<bool>( sigc::mem_fun( *this, &Dialog_Partition_New::optionmenu_changed ), false ) );
table_create .attach( optionmenu_filesystem, 1, 2, 1, 2, Gtk::FILL ); table_create .attach( optionmenu_filesystem, 1, 2, 1, 2, Gtk::FILL );
//set some widely used values... //set some widely used values...
START = partition.sector_start ; START = partition.sector_start ;
total_length = partition.sector_end - partition.sector_start ; total_length = partition.sector_end - partition.sector_start ;
TOTAL_MB = this ->selected_partition .Get_Length_MB( ) ; TOTAL_MB = Utils::Round( Utils::sector_to_unit( this ->selected_partition .get_length(), GParted::UNIT_MIB ) ) ;
MB_PER_PIXEL = TOTAL_MB / 500.00 ; MB_PER_PIXEL = TOTAL_MB / 500.00 ;
//set first enabled filesystem //set first enabled filesystem
@ -105,11 +120,11 @@ void Dialog_Partition_New::Set_Data( const Partition & partition, bool any_exten
//set spinbuttons initial values //set spinbuttons initial values
spinbutton_after .set_value( 0 ) ; spinbutton_after .set_value( 0 ) ;
spinbutton_size .set_value( fs .MAX ) ; spinbutton_size .set_value( Utils::Round( Utils::sector_to_unit( fs .MAX, GParted::UNIT_MIB ) ) ) ;
spinbutton_before .set_value( 0 ) ; spinbutton_before .set_value( 0 ) ;
//euhrm, this wil only happen when there's a very small free space (usually the effect of a bad partitionmanager) //euhrm, this wil only happen when there's a very small free space (usually the effect of a bad partitionmanager)
if ( TOTAL_MB < cylinder_size ) if ( TOTAL_MB * MEBIBYTE < this ->cylinder_size )
frame_resizer_base ->set_sensitive( false ) ; frame_resizer_base ->set_sensitive( false ) ;
this ->show_all_children() ; this ->show_all_children() ;
@ -130,8 +145,8 @@ Partition Dialog_Partition_New::Get_New_Partition()
default : part_type = GParted::TYPE_UNALLOCATED ; default : part_type = GParted::TYPE_UNALLOCATED ;
} }
new_start = START + (Sector) (spinbutton_before .get_value( ) * MEBIBYTE) ; new_start = START + (spinbutton_before .get_value_as_int() * MEBIBYTE) ;
new_end = new_start + (Sector) (spinbutton_size .get_value( ) * MEBIBYTE) ; new_end = new_start + (spinbutton_size .get_value_as_int() * MEBIBYTE) ;
/* due to loss of precision during calcs from Sector -> MiB and back, it is possible the new /* due to loss of precision during calcs from Sector -> MiB and back, it is possible the new
* partition thinks it's bigger then it can be. Here we try to solve this.*/ * partition thinks it's bigger then it can be. Here we try to solve this.*/
@ -158,7 +173,10 @@ Partition Dialog_Partition_New::Get_New_Partition()
if ( part_temp .type == GParted::TYPE_EXTENDED ) if ( part_temp .type == GParted::TYPE_EXTENDED )
{ {
Partition UNALLOCATED ; Partition UNALLOCATED ;
UNALLOCATED .Set_Unallocated( part_temp .device_path, part_temp .sector_start, part_temp .sector_end, true ) ; UNALLOCATED .Set_Unallocated( part_temp .device_path,
part_temp .sector_start,
part_temp .sector_end,
true ) ;
part_temp .logicals .push_back( UNALLOCATED ) ; part_temp .logicals .push_back( UNALLOCATED ) ;
} }
@ -172,13 +190,16 @@ void Dialog_Partition_New::optionmenu_changed( bool type )
//optionmenu_type //optionmenu_type
if ( type ) if ( type )
{ {
if ( optionmenu_type .get_history( ) == GParted::TYPE_EXTENDED && menu_filesystem .items( ) .size( ) < FILESYSTEMS .size( ) ) if ( optionmenu_type .get_history() == GParted::TYPE_EXTENDED &&
menu_filesystem .items() .size() < FILESYSTEMS .size() )
{ {
menu_filesystem .items( ) .push_back( Gtk::Menu_Helpers::MenuElem( Utils::Get_Filesystem_String( GParted::FS_EXTENDED ) ) ) ; menu_filesystem .items() .push_back(
Gtk::Menu_Helpers::MenuElem( Utils::Get_Filesystem_String( GParted::FS_EXTENDED ) ) ) ;
optionmenu_filesystem .set_history( menu_filesystem .items() .size() -1 ) ; optionmenu_filesystem .set_history( menu_filesystem .items() .size() -1 ) ;
optionmenu_filesystem .set_sensitive( false ) ; optionmenu_filesystem .set_sensitive( false ) ;
} }
else if ( optionmenu_type .get_history( ) != GParted::TYPE_EXTENDED && menu_filesystem .items( ) .size( ) == FILESYSTEMS .size( ) ) else if ( optionmenu_type .get_history() != GParted::TYPE_EXTENDED &&
menu_filesystem .items() .size() == FILESYSTEMS .size() )
{ {
menu_filesystem .items() .remove( menu_filesystem .items() .back() ) ; menu_filesystem .items() .remove( menu_filesystem .items() .back() ) ;
optionmenu_filesystem .set_sensitive( true ) ; optionmenu_filesystem .set_sensitive( true ) ;
@ -196,23 +217,31 @@ void Dialog_Partition_New::optionmenu_changed( bool type )
if ( fs .MIN < cylinder_size ) if ( fs .MIN < cylinder_size )
fs .MIN = cylinder_size ; fs .MIN = cylinder_size ;
} }
else if ( fs .MIN < 1 ) else if ( fs .MIN < MEBIBYTE )
fs .MIN = 1 ; fs .MIN = MEBIBYTE ;
if ( selected_partition .Get_Length_MB( ) < fs .MIN ) if ( selected_partition .get_length() < fs .MIN )
fs .MIN = selected_partition .Get_Length_MB( ) ; fs .MIN = selected_partition .get_length() ;
fs .MAX = ( fs .MAX && ( fs .MAX - cylinder_size ) < TOTAL_MB ) ? fs .MAX - cylinder_size : TOTAL_MB ; fs .MAX = ( fs .MAX && ( fs .MAX - cylinder_size ) < (TOTAL_MB * MEBIBYTE) ) ?
fs .MAX - cylinder_size : TOTAL_MB * MEBIBYTE ;
frame_resizer_base ->set_size_limits( static_cast<int>(fs .MIN / MB_PER_PIXEL), static_cast<int>(fs .MAX / MB_PER_PIXEL) +1 ) ; frame_resizer_base ->set_size_limits( Utils::Round( fs .MIN / (MB_PER_PIXEL * MEBIBYTE) ),
Utils::Round( fs .MAX / (MB_PER_PIXEL * MEBIBYTE) ) +1 ) ;
//set new spinbutton ranges //set new spinbutton ranges
spinbutton_before .set_range( 0, TOTAL_MB - fs .MIN ) ; spinbutton_before .set_range(
spinbutton_size .set_range( fs .MIN, fs .MAX ) ; 0, TOTAL_MB - Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ) ) ;
spinbutton_after .set_range( 0, TOTAL_MB - fs .MIN ) ; spinbutton_size .set_range(
Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ),
Utils::Round( Utils::sector_to_unit( fs .MAX, GParted::UNIT_MIB ) ) ) ;
spinbutton_after .set_range(
0, TOTAL_MB - Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ) ) ;
//set contents of label_minmax //set contents of label_minmax
Set_MinMax_Text( fs .MIN, fs .MAX ) ; Set_MinMax_Text(
Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ),
Utils::Round( Utils::sector_to_unit( fs .MAX, GParted::UNIT_MIB ) ) ) ;
} }
//set fitting resizer colors //set fitting resizer colors
@ -232,8 +261,11 @@ void Dialog_Partition_New::Build_Filesystems_Menu( bool only_unformatted )
//fill the filesystem menu with the filesystems (except for extended) //fill the filesystem menu with the filesystems (except for extended)
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( Utils::Get_Filesystem_String( FILESYSTEMS[ t ] .filesystem ) ) ) ; menu_filesystem .items() .push_back(
menu_filesystem .items( )[ t ] .set_sensitive( ! only_unformatted && FILESYSTEMS[ t ] .create && this ->selected_partition .Get_Length_MB() >= FILESYSTEMS[ t ] .MIN ) ; Gtk::Menu_Helpers::MenuElem( Utils::Get_Filesystem_String( FILESYSTEMS[ t ] .filesystem ) ) ) ;
menu_filesystem .items()[ t ] .set_sensitive(
! only_unformatted && FILESYSTEMS[ t ] .create &&
this ->selected_partition .get_length() >= FILESYSTEMS[ t ] .MIN ) ;
} }
//unformatted is always available //unformatted is always available

View File

@ -20,7 +20,7 @@
namespace GParted namespace GParted
{ {
Dialog_Partition_Resize_Move::Dialog_Partition_Resize_Move( const FS & fs, long cylinder_size ) Dialog_Partition_Resize_Move::Dialog_Partition_Resize_Move( const FS & fs, Sector cylinder_size )
{ {
this ->fs = fs ; this ->fs = fs ;
@ -111,40 +111,46 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const std::vector <Partit
if ( fs .shrink ) if ( fs .shrink )
{ {
//since some filesystems have lower limits we need to check for this //since some filesystems have lower limits we need to check for this
if ( selected_partition .Get_Used_MB( ) > fs .MIN ) if ( selected_partition .sectors_used > fs .MIN )
fs .MIN = selected_partition .Get_Used_MB( ) ; fs .MIN = selected_partition .sectors_used ;
//if fs. MIN is 0 here (means used == 0 as well) it's safe to have BUF / 2 //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 ; fs .MIN += fs .MIN ? BUF : BUF/2 ;
//in certain (rare) cases fs .MIN is a bit too high... //in certain (rare) cases fs .MIN is a bit too high...
if ( fs .MIN > selected_partition .Get_Length_MB( ) ) if ( fs .MIN > selected_partition .get_length() )
fs .MIN = selected_partition .Get_Length_MB( ) ; fs .MIN = selected_partition .get_length() ;
} }
else //only grow.. else //only grow..
fs .MIN = selected_partition .Get_Length_MB( ) ; fs .MIN = selected_partition .get_length() ;
fs .MAX = ( ! fs .MAX || fs .MAX > TOTAL_MB ) ? TOTAL_MB : fs .MAX -= BUF/2 ; fs .MAX = ( ! fs .MAX || fs .MAX > (TOTAL_MB * MEBIBYTE) ) ? ( TOTAL_MB * MEBIBYTE ) : fs .MAX -= BUF/2 ;
//set values of spinbutton_before //set values of spinbutton_before
if ( ! fixed_start ) if ( ! fixed_start )
{ {
spinbutton_before .set_range( 0, TOTAL_MB - fs .MIN ) ; spinbutton_before .set_range( 0, TOTAL_MB - Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ) ) ;
spinbutton_before .set_value( Utils::Round( Utils::sector_to_unit( previous, GParted::UNIT_MIB ) ) ) ; spinbutton_before .set_value( Utils::Round( Utils::sector_to_unit( previous, GParted::UNIT_MIB ) ) ) ;
} }
//set values of spinbutton_size //set values of spinbutton_size
spinbutton_size .set_range( fs .MIN, fs .MAX ) ; spinbutton_size .set_range(
spinbutton_size .set_value( selected_partition .Get_Length_MB( ) ) ; Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ),
Utils::Round( Utils::sector_to_unit( fs .MAX, GParted::UNIT_MIB ) ) ) ;
spinbutton_size .set_value(
Utils::Round( Utils::sector_to_unit( selected_partition .get_length(), GParted::UNIT_MIB ) ) ) ;
//set values of spinbutton_after //set values of spinbutton_after
spinbutton_after .set_range( 0, TOTAL_MB - fs .MIN ) ; spinbutton_after .set_range( 0, TOTAL_MB - Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ) ) ;
spinbutton_after .set_value( Utils::Round( Utils::sector_to_unit( next, GParted::UNIT_MIB ) ) ) ; spinbutton_after .set_value( Utils::Round( Utils::sector_to_unit( next, GParted::UNIT_MIB ) ) ) ;
frame_resizer_base ->set_size_limits( Utils::Round( fs .MIN / MB_PER_PIXEL ), Utils::Round( fs .MAX / MB_PER_PIXEL ) +1 ) ; frame_resizer_base ->set_size_limits( Utils::Round( fs .MIN / (MB_PER_PIXEL * MEBIBYTE) ),
Utils::Round( fs .MAX / (MB_PER_PIXEL * MEBIBYTE) ) +1 ) ;
//set contents of label_minmax //set contents of label_minmax
Set_MinMax_Text( fs .MIN, fs .MAX ) ; Set_MinMax_Text(
Utils::Round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ),
Utils::Round( Utils::sector_to_unit( fs .MAX, GParted::UNIT_MIB ) ) ) ;
} }
void Dialog_Partition_Resize_Move::Resize_Move_Extended( const std::vector <Partition> & partitions ) void Dialog_Partition_Resize_Move::Resize_Move_Extended( const std::vector <Partition> & partitions )
@ -196,7 +202,7 @@ void Dialog_Partition_Resize_Move::Resize_Move_Extended( const std::vector <Part
//set values of spinbutton_before (we assume there is no fixed start.) //set values of spinbutton_before (we assume there is no fixed start.)
if ( first == 0 ) //no logicals if ( first == 0 ) //no logicals
spinbutton_before .set_range( 0, TOTAL_MB - BUF/2 ) ; spinbutton_before .set_range( 0, TOTAL_MB - Utils::Round( Utils::sector_to_unit( BUF/2, GParted::UNIT_MIB ) ) ) ;
else else
spinbutton_before .set_range( 0, Utils::Round( Utils::sector_to_unit( first - START, GParted::UNIT_MIB ) ) ) ; spinbutton_before .set_range( 0, Utils::Round( Utils::sector_to_unit( first - START, GParted::UNIT_MIB ) ) ) ;
@ -204,22 +210,23 @@ void Dialog_Partition_Resize_Move::Resize_Move_Extended( const std::vector <Part
//set values of spinbutton_size //set values of spinbutton_size
if ( first == 0 ) //no logicals if ( first == 0 ) //no logicals
spinbutton_size .set_range( BUF/2, TOTAL_MB ) ; spinbutton_size .set_range( Utils::Round( Utils::sector_to_unit( BUF/2, GParted::UNIT_MIB ) ), TOTAL_MB ) ;
else else
spinbutton_size .set_range( Utils::Round( Utils::sector_to_unit( used, GParted::UNIT_MIB ) ), TOTAL_MB ) ; spinbutton_size .set_range( Utils::Round( Utils::sector_to_unit( used, GParted::UNIT_MIB ) ), TOTAL_MB ) ;
spinbutton_size .set_value( selected_partition .Get_Length_MB( ) ) ; spinbutton_size .set_value(
Utils::Round( Utils::sector_to_unit( selected_partition .get_length(), GParted::UNIT_MIB ) ) ) ;
//set values of spinbutton_after //set values of spinbutton_after
if ( first == 0 ) //no logicals if ( first == 0 ) //no logicals
spinbutton_after .set_range( 0, TOTAL_MB - BUF/2 ) ; spinbutton_after .set_range( 0, TOTAL_MB - Utils::Round( Utils::sector_to_unit( BUF/2, GParted::UNIT_MIB ) ) ) ;
else else
spinbutton_after .set_range( 0, Utils::Round( Utils::sector_to_unit( total_length + START - first - used, GParted::UNIT_MIB ) ) ) ; spinbutton_after .set_range( 0, Utils::Round( Utils::sector_to_unit( total_length + START - first - used, GParted::UNIT_MIB ) ) ) ;
spinbutton_after .set_value( Utils::Round( Utils::sector_to_unit( next, GParted::UNIT_MIB ) ) ) ; spinbutton_after .set_value( Utils::Round( Utils::sector_to_unit( next, GParted::UNIT_MIB ) ) ) ;
//set contents of label_minmax //set contents of label_minmax
Set_MinMax_Text( first == 0 ? BUF/2 : Utils::Round( Utils::sector_to_unit( used, GParted::UNIT_MIB ) ), Set_MinMax_Text( Utils::Round( Utils::sector_to_unit( first == 0 ? BUF/2 : used, GParted::UNIT_MIB ) ),
Utils::Round( Utils::sector_to_unit( total_length, GParted::UNIT_MIB ) ) ) ; Utils::Round( Utils::sector_to_unit( total_length, GParted::UNIT_MIB ) ) ) ;
} }

View File

@ -127,13 +127,11 @@ void GParted_Core::get_devices( std::vector<Device> & devices )
temp_device .sectors = lp_device ->bios_geom .sectors ; temp_device .sectors = lp_device ->bios_geom .sectors ;
temp_device .cylinders = lp_device ->bios_geom .cylinders ; temp_device .cylinders = lp_device ->bios_geom .cylinders ;
temp_device .length = temp_device .heads * temp_device .sectors * temp_device .cylinders ; temp_device .length = temp_device .heads * temp_device .sectors * temp_device .cylinders ;
temp_device .cylsize = Utils::Round( Utils::sector_to_unit( temp_device .cylsize = temp_device .heads * temp_device .sectors ;
temp_device .heads * temp_device .sectors,
GParted::UNIT_MIB ) ) ;
//make sure cylsize is at least 1 MiB //make sure cylsize is at least 1 MiB
if ( temp_device .cylsize < 1 ) if ( temp_device .cylsize < MEBIBYTE )
temp_device .cylsize = 1 ; temp_device .cylsize = MEBIBYTE ;
//normal harddisk //normal harddisk
if ( lp_disk ) if ( lp_disk )
@ -545,7 +543,7 @@ bool GParted_Core::create( const Device & device,
else if ( create_empty_partition( else if ( create_empty_partition(
new_partition, new_partition,
operation_details, operation_details,
( new_partition .Get_Length_MB() - device .cylsize ) < get_fs( new_partition .filesystem ) .MIN ) > 0 ) ( new_partition .get_length() - device .cylsize ) < get_fs( new_partition .filesystem ) .MIN * MEBIBYTE ) > 0 )
{ {
set_proper_filesystem( new_partition .filesystem ) ; set_proper_filesystem( new_partition .filesystem ) ;
@ -628,7 +626,7 @@ bool GParted_Core::resize( const Device & device,
if ( partition_new .get_length() < partition_old .get_length() ) if ( partition_new .get_length() < partition_old .get_length() )
{ {
p_filesystem ->cylinder_size = MEBIBYTE * device .cylsize ; p_filesystem ->cylinder_size = device .cylsize ;
succes = p_filesystem ->Resize( partition_new, operation_details ) ; succes = p_filesystem ->Resize( partition_new, operation_details ) ;
} }

View File

@ -52,11 +52,11 @@ Glib::ustring Operation::Get_String( )
else else
temp = partition_original .partition ; temp = partition_original .partition ;
/*TO TRANSLATORS: looks like Delete /dev/hda2 (ntfs, 2345 MiB) from /dev/hda */ /*TO TRANSLATORS: looks like Delete /dev/hda2 (ntfs, 345 MiB) from /dev/hda */
return String::ucompose( _("Delete %1 (%2, %3 MiB) from %4"), return String::ucompose( _("Delete %1 (%2, %3) from %4"),
temp, temp,
Utils::Get_Filesystem_String( partition_original .filesystem ), Utils::Get_Filesystem_String( partition_original .filesystem ),
partition_original .Get_Length_MB( ), Utils::format_size( partition_original .get_length() ),
device .path ) ; device .path ) ;
case CREATE : case CREATE :
@ -75,49 +75,45 @@ Glib::ustring Operation::Get_String( )
default : default :
break; break;
} }
/*TO TRANSLATORS: looks like Create Logical Partition #1 (ntfs, 2345 MiB) on /dev/hda */ /*TO TRANSLATORS: looks like Create Logical Partition #1 (ntfs, 345 MiB) on /dev/hda */
return String::ucompose( _("Create %1 #%2 (%3, %4 MiB) on %5"), return String::ucompose( _("Create %1 #%2 (%3, %4) on %5"),
temp, temp,
partition_new.partition_number, partition_new.partition_number,
Utils::Get_Filesystem_String( partition_new.filesystem ), Utils::Get_Filesystem_String( partition_new.filesystem ),
partition_new .Get_Length_MB( ), Utils::format_size( partition_new .get_length() ),
device .path ) ; device .path ) ;
case RESIZE_MOVE: case RESIZE_MOVE:
//if startsector has changed >= 1 MiB we consider it a move //if startsector has changed we consider it a move
diff = std::abs( partition_new .sector_start - partition_original .sector_start ) ; diff = std::abs( partition_new .sector_start - partition_original .sector_start ) ;
if ( diff >= MEBIBYTE ) if ( diff )
{ {
if ( partition_new .sector_start > partition_original .sector_start ) if ( partition_new .sector_start > partition_original .sector_start )
temp = String::ucompose( _("Move %1 forward by %2 MiB"), temp = String::ucompose( _("Move %1 forward by %2"),
partition_new .partition, partition_new .partition,
Utils::Round( Utils::sector_to_unit( diff, GParted::UNIT_MIB ) ) ) ; Utils::format_size( diff ) ) ;
else else
temp = String::ucompose( _("Move %1 backward by %2 MiB"), temp = String::ucompose( _("Move %1 backward by %2"),
partition_new .partition, partition_new .partition,
Utils::Round( Utils::sector_to_unit( diff, GParted::UNIT_MIB ) ) ) ; Utils::format_size( diff ) ) ;
} }
//check if size has changed ( we only consider changes >= 1 MiB ) //check if size has changed
diff = std::abs( (partition_original .sector_end - partition_original .sector_start) - (partition_new .sector_end - partition_new .sector_start) ) ; diff = std::abs( partition_original .get_length() - partition_new .get_length() ) ;
if ( diff )
if ( diff >= MEBIBYTE )
{ {
if ( temp .empty() ) if ( temp .empty() )
temp = String::ucompose( _("Resize %1 from %2 MiB to %3 MiB"), temp = String::ucompose( _("Resize %1 from %2 to %3"),
partition_new.partition, partition_new.partition,
partition_original .Get_Length_MB(), Utils::format_size( partition_original .get_length() ),
partition_new .Get_Length_MB() ) ; Utils::format_size( partition_new .get_length() ) ) ;
else else
temp += " " + String::ucompose( _("and Resize %1 from %2 MiB to %3 MiB"), temp += " " + String::ucompose( _("and Resize %1 from %2 to %3"),
partition_new.partition, partition_new.partition,
partition_original .Get_Length_MB(), Utils::format_size( partition_original .get_length() ),
partition_new .Get_Length_MB() ) ; Utils::format_size( partition_new .get_length() ) ) ;
} }
if ( temp .empty( ) )
temp = _("Sorry, changes are too small to make sense");
return temp; return temp;
case FORMAT : case FORMAT :
@ -127,11 +123,11 @@ Glib::ustring Operation::Get_String( )
Utils::Get_Filesystem_String( partition_new .filesystem ) ) ; Utils::Get_Filesystem_String( partition_new .filesystem ) ) ;
case COPY : case COPY :
/*TO TRANSLATORS: looks like Copy /dev/hda4 to /dev/hdd (start at 2500 MiB) */ /*TO TRANSLATORS: looks like Copy /dev/hda4 to /dev/hdd (start at 250 MiB) */
return String::ucompose( _("Copy %1 to %2 (start at %3 MiB)"), return String::ucompose( _("Copy %1 to %2 (start at %3)"),
partition_new .partition, partition_new .partition,
device .path, device .path,
Utils::Round( Utils::sector_to_unit( partition_new .sector_start, GParted::UNIT_MIB ) ) ) ; Utils::format_size( partition_new .sector_start ) ) ;
default : default :
return ""; return "";

View File

@ -97,21 +97,6 @@ void Partition::Update_Number( int new_number )
this ->partition_number = new_number; this ->partition_number = new_number;
} }
long Partition::Get_Length_MB() const
{
return Utils::Round( Utils::sector_to_unit( get_length(), GParted::UNIT_MIB ) ) ;
}
long Partition::Get_Used_MB() const
{
return Utils::Round( Utils::sector_to_unit( sectors_used, GParted::UNIT_MIB ) ) ;
}
long Partition::Get_Unused_MB() const
{
return Get_Length_MB() - Get_Used_MB( ) ;
}
Sector Partition::get_length() const Sector Partition::get_length() const
{ {
return sector_end - sector_start + 1 ; return sector_end - sector_start + 1 ;

View File

@ -164,22 +164,19 @@ Glib::ustring Utils::format_size( Sector size )
double Utils::sector_to_unit( Sector sectors, SIZE_UNIT size_unit ) double Utils::sector_to_unit( Sector sectors, SIZE_UNIT size_unit )
{ {
/* NOTE: this could have been done more efficient by using static numbers.
* However, the performancegain would be unnoticable and this way its easier to read/debug
*/
switch ( size_unit ) switch ( size_unit )
{ {
case UNIT_BYTE : case UNIT_BYTE :
return sectors * 512 ; return sectors * 512 ;
case UNIT_KIB : case UNIT_KIB :
return sector_to_unit( sectors, UNIT_BYTE ) / 1024 ; return sectors / static_cast<double>( KIBIBYTE ) ;
case UNIT_MIB : case UNIT_MIB :
return sector_to_unit( sectors, UNIT_KIB ) / 1024 ; return sectors / static_cast<double>( MEBIBYTE ) ;
case UNIT_GIB : case UNIT_GIB :
return sector_to_unit( sectors, UNIT_MIB ) / 1024 ; return sectors / static_cast<double>( GIBIBYTE ) ;
case UNIT_TIB : case UNIT_TIB :
return sector_to_unit( sectors, UNIT_GIB ) / 1024 ; return sectors / static_cast<double>( TEBIBYTE ) ;
default: default:
return sectors ; return sectors ;

View File

@ -705,9 +705,13 @@ void Win_GParted::set_valid_operations()
//find out if there is a copied partition and if it fits inside this unallocated space //find out if there is a copied partition and if it fits inside this unallocated space
if ( ! copied_partition .partition .empty() && ! devices[ current_device ] .readonly ) if ( ! copied_partition .partition .empty() && ! devices[ current_device ] .readonly )
{ {
if ( (copied_partition .Get_Length_MB() + devices[ current_device ] .cylsize) < selected_partition .Get_Length_MB() || Sector required_size ;
(copied_partition .filesystem == GParted::FS_XFS && (copied_partition .Get_Used_MB() + devices[ current_device ] .cylsize) < selected_partition .Get_Length_MB() ) if ( copied_partition .filesystem == GParted::FS_XFS )
) required_size = copied_partition .sectors_used ;
else
required_size = copied_partition .get_length() ;
if ( ( required_size + devices[ current_device ] .cylsize ) <= selected_partition .get_length() )
allow_paste( true ) ; allow_paste( true ) ;
} }
@ -1091,7 +1095,8 @@ void Win_GParted::activate_resize()
if ( operations[ t ] .device .path == devices[ current_device ] .path ) if ( operations[ t ] .device .path == devices[ current_device ] .path )
operations[ t ] .Apply_Operation_To_Visual( partitions ) ; operations[ t ] .Apply_Operation_To_Visual( partitions ) ;
Dialog_Partition_Resize_Move dialog( gparted_core .get_fs( selected_partition .filesystem ), devices[ current_device ] .cylsize ) ; Dialog_Partition_Resize_Move dialog( gparted_core .get_fs( selected_partition .filesystem ),
devices[ current_device ] .cylsize ) ;
if ( selected_partition .type == GParted::TYPE_LOGICAL ) if ( selected_partition .type == GParted::TYPE_LOGICAL )
{ {
@ -1281,8 +1286,8 @@ void Win_GParted::activate_format( GParted::FILESYSTEM new_fs )
//check for some limits... //check for some limits...
fs = gparted_core .get_fs( new_fs ) ; fs = gparted_core .get_fs( new_fs ) ;
if ( selected_partition .Get_Length_MB() < fs .MIN || if ( selected_partition .get_length() < fs .MIN ||
fs .MAX && selected_partition .Get_Length_MB() > fs .MAX ) fs .MAX && selected_partition .get_length() > fs .MAX )
{ {
Gtk::MessageDialog dialog( *this, Gtk::MessageDialog dialog( *this,
String::ucompose( _("Cannot format this filesystem to %1."), String::ucompose( _("Cannot format this filesystem to %1."),
@ -1292,14 +1297,16 @@ void Win_GParted::activate_format( GParted::FILESYSTEM new_fs )
Gtk::BUTTONS_OK, Gtk::BUTTONS_OK,
true ); true );
if ( selected_partition .Get_Length_MB() < fs .MIN ) if ( selected_partition .get_length() < fs .MIN )
dialog .set_secondary_text( String::ucompose( _( "A %1 filesystem requires a partition of at least %2 MiB."), dialog .set_secondary_text( String::ucompose(
_( "A %1 filesystem requires a partition of at least %2."),
Utils::Get_Filesystem_String( new_fs ), Utils::Get_Filesystem_String( new_fs ),
fs .MIN ) ); Utils::format_size( fs .MIN ) ) );
else else
dialog .set_secondary_text( String::ucompose( _( "A partition with a %1 filesystem has a maximum size of %2 MiB."), dialog .set_secondary_text( String::ucompose(
_( "A partition with a %1 filesystem has a maximum size of %2."),
Utils::Get_Filesystem_String( new_fs ), Utils::Get_Filesystem_String( new_fs ),
fs .MAX ) ); Utils::format_size( fs .MAX ) ) );
dialog .run() ; dialog .run() ;
return ; return ;

View File

@ -44,8 +44,8 @@ FS fat16::get_filesystem_support( )
if ( ! Glib::find_program_in_path( "dd" ) .empty() ) if ( ! Glib::find_program_in_path( "dd" ) .empty() )
fs .copy = GParted::FS::EXTERNAL ; fs .copy = GParted::FS::EXTERNAL ;
fs .MIN = 16 ; fs .MIN = 16 * MEBIBYTE ;
fs .MAX = 4096 ; fs .MAX = 4096 * MEBIBYTE ;
return fs ; return fs ;
} }
@ -69,6 +69,7 @@ void fat16::Set_Used_Sectors( Partition & partition )
if ( N > -1 && S > -1 ) if ( N > -1 && S > -1 )
partition .Set_Unused( Utils::Round( N * ( S / 512.0 ) ) ) ; partition .Set_Unused( Utils::Round( N * ( S / 512.0 ) ) ) ;
} }
//FIXME: all fs classes should send 'error' to stdout here.
} }
bool fat16::Create( const Partition & new_partition, std::vector<OperationDetails> & operation_details ) bool fat16::Create( const Partition & new_partition, std::vector<OperationDetails> & operation_details )

View File

@ -44,7 +44,7 @@ FS fat32::get_filesystem_support( )
if ( ! Glib::find_program_in_path( "dd" ) .empty() ) if ( ! Glib::find_program_in_path( "dd" ) .empty() )
fs .copy = GParted::FS::EXTERNAL ; fs .copy = GParted::FS::EXTERNAL ;
fs .MIN = 32 ; //smaller fs'es will cause windows scandisk to fail.. fs .MIN = 32 * MEBIBYTE ; //smaller fs'es will cause windows scandisk to fail..
return fs ; return fs ;
} }

View File

@ -35,7 +35,7 @@ FS hfs::get_filesystem_support()
if ( ! Glib::find_program_in_path( "dd" ) .empty() ) if ( ! Glib::find_program_in_path( "dd" ) .empty() )
fs .copy = GParted::FS::EXTERNAL ; fs .copy = GParted::FS::EXTERNAL ;
fs .MAX = 2048 ; fs .MAX = 2048 * MEBIBYTE ;
return fs ; return fs ;
} }

View File

@ -61,7 +61,7 @@ FS jfs::get_filesystem_support()
if ( ! Glib::find_program_in_path( "dd" ) .empty() && fs .grow ) if ( ! Glib::find_program_in_path( "dd" ) .empty() && fs .grow )
fs .copy = GParted::FS::EXTERNAL ; fs .copy = GParted::FS::EXTERNAL ;
fs .MIN = 16 ; fs .MIN = 16 * MEBIBYTE ;
return fs ; return fs ;
} }

View File

@ -48,7 +48,7 @@ FS reiserfs::get_filesystem_support()
if ( ! Glib::find_program_in_path( "dd" ) .empty() && fs .grow ) if ( ! Glib::find_program_in_path( "dd" ) .empty() && fs .grow )
fs .copy = GParted::FS::EXTERNAL ; fs .copy = GParted::FS::EXTERNAL ;
fs .MIN = 32 ; fs .MIN = 32 * MEBIBYTE ;
return fs ; return fs ;
} }

View File

@ -62,7 +62,7 @@ FS xfs::get_filesystem_support( )
fs .check && fs .create ) fs .check && fs .create )
fs .copy = GParted::FS::EXTERNAL ; fs .copy = GParted::FS::EXTERNAL ;
fs .MIN = 32 ;//official minsize = 16MB, but the smallest xfs_repair can handle is 32MB... fs .MIN = 32 * MEBIBYTE ;//official minsize = 16MB, but the smallest xfs_repair can handle is 32MB...
return fs ; return fs ;
} }