Enhance sector_to_unit() for sector sizes > 512 bytes

This commit is contained in:
Curtis Gedak 2010-03-23 12:14:53 -06:00
parent f9f603256e
commit 1aa81bba94
10 changed files with 59 additions and 58 deletions

View file

@ -146,7 +146,7 @@ public:
static Glib::ustring get_filesystem_software( FILESYSTEM filesystem ) ;
static Glib::ustring format_size( Sector size ) ;
static Glib::ustring format_time( std::time_t seconds ) ;
static double sector_to_unit( Sector sectors, SIZE_UNIT size_unit ) ;
static double sector_to_unit( Sector sectors, Byte_Value sector_size, SIZE_UNIT size_unit ) ;
static int execute_command( const Glib::ustring & command ) ;
static int execute_command( const Glib::ustring & command,
Glib::ustring & output,

View file

@ -1,5 +1,5 @@
/* Copyright (C) 2004 Bart
* Copyright (C) 2008, 2009 Curtis Gedak
* Copyright (C) 2008, 2009, 2010 Curtis Gedak
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -41,10 +41,10 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons
//set some widely used values...
START = selected_partition .sector_start ;
total_length = selected_partition .get_length() ;
TOTAL_MB = Utils::round( Utils::sector_to_unit( selected_partition .get_length(), GParted::UNIT_MIB ) ) ;
TOTAL_MB = Utils::round( Utils::sector_to_unit( selected_partition .get_length(), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ;
MB_PER_PIXEL = TOTAL_MB / 500.00 ;
long COPIED_LENGTH_MB = Utils::round( Utils::sector_to_unit( copied_partition .get_length(), GParted::UNIT_MIB ) ) ;
long COPIED_LENGTH_MB = Utils::round( Utils::sector_to_unit( copied_partition .get_length(), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ;
// /* Copy Primary not at start of disk to within Extended partition */
// Adjust when a primary partition is copied and pasted
// into an unallocated space in an extended partition
@ -96,7 +96,7 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons
frame_resizer_base ->set_x_end( x_end > 500 ? 500 : x_end ) ;
frame_resizer_base ->set_used(
Utils::round( Utils::sector_to_unit(
copied_partition .sectors_used, GParted::UNIT_MIB ) / (TOTAL_MB/500.00) ) ) ;
copied_partition .sectors_used, DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) / (TOTAL_MB/500.00) ) ) ;
if ( fs .grow )
fs .MAX = ( ! fs .MAX || fs .MAX > (TOTAL_MB * MEBI_FACTOR) ) ? (TOTAL_MB * MEBI_FACTOR) : fs .MAX - (BUF * DEFAULT_SECTOR_SIZE) ;
@ -111,17 +111,17 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons
GRIP = true ;
//set values of spinbutton_before
spinbutton_before .set_range( 0, TOTAL_MB - Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), GParted::UNIT_MIB ) ) ) ;
spinbutton_before .set_range( 0, TOTAL_MB - Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ) ;
spinbutton_before .set_value( 0 ) ;
//set values of spinbutton_size
spinbutton_size .set_range(
Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), GParted::UNIT_MIB ) ),
Utils::round( Utils::sector_to_unit( (fs .MAX / DEFAULT_SECTOR_SIZE), GParted::UNIT_MIB ) ) ) ;
Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ),
Utils::round( Utils::sector_to_unit( (fs .MAX / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ) ;
spinbutton_size .set_value( COPIED_LENGTH_MB ) ;
//set values of spinbutton_after
spinbutton_after .set_range( 0, TOTAL_MB - Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), GParted::UNIT_MIB ) ) ) ;
spinbutton_after .set_range( 0, TOTAL_MB - Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ) ;
spinbutton_after .set_value( TOTAL_MB - COPIED_LENGTH_MB ) ;
GRIP = false ;
@ -130,8 +130,8 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons
//set contents of label_minmax
Set_MinMax_Text(
Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), GParted::UNIT_MIB ) ),
Utils::round( Utils::sector_to_unit( (fs .MAX / DEFAULT_SECTOR_SIZE), GParted::UNIT_MIB ) ) ) ;
Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ),
Utils::round( Utils::sector_to_unit( (fs .MAX / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ) ;
//set global selected_partition (see Dialog_Base_Partition::Get_New_Partition )
this ->selected_partition = copied_partition ;

View file

@ -142,7 +142,7 @@ void Dialog_Partition_New::Set_Data( const Partition & partition,
//set some widely used values...
START = partition.sector_start ;
total_length = partition.sector_end - partition.sector_start ;
TOTAL_MB = Utils::round( Utils::sector_to_unit( this ->selected_partition .get_length(), GParted::UNIT_MIB ) ) ;
TOTAL_MB = Utils::round( Utils::sector_to_unit( this ->selected_partition .get_length(), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ;
MB_PER_PIXEL = TOTAL_MB / 500.00 ;
//set first enabled file system
@ -151,7 +151,7 @@ void Dialog_Partition_New::Set_Data( const Partition & partition,
//set spinbuttons initial values
spinbutton_after .set_value( 0 ) ;
spinbutton_size .set_value( Utils::round( Utils::sector_to_unit( (fs .MAX / DEFAULT_SECTOR_SIZE), GParted::UNIT_MIB ) ) ) ;
spinbutton_size .set_value( Utils::round( Utils::sector_to_unit( (fs .MAX / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ) ;
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)
@ -267,17 +267,17 @@ void Dialog_Partition_New::optionmenu_changed( bool type )
//set new spinbutton ranges
spinbutton_before .set_range(
0, TOTAL_MB - Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), GParted::UNIT_MIB ) ) ) ;
0, TOTAL_MB - Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ) ;
spinbutton_size .set_range(
Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), GParted::UNIT_MIB ) ),
Utils::round( Utils::sector_to_unit( (fs .MAX / DEFAULT_SECTOR_SIZE), GParted::UNIT_MIB ) ) ) ;
Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ),
Utils::round( Utils::sector_to_unit( (fs .MAX / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ) ;
spinbutton_after .set_range(
0, TOTAL_MB - Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), GParted::UNIT_MIB ) ) ) ;
0, TOTAL_MB - Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ) ;
//set contents of label_minmax
Set_MinMax_Text(
Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), GParted::UNIT_MIB ) ),
Utils::round( Utils::sector_to_unit( (fs .MAX / DEFAULT_SECTOR_SIZE), GParted::UNIT_MIB ) ) ) ;
Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ),
Utils::round( Utils::sector_to_unit( (fs .MAX / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ) ;
}
//set fitting resizer colors

View file

@ -1,4 +1,5 @@
/* Copyright (C) 2004 Bart
* Copyright (C) 2010 Curtis Gedak
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -103,7 +104,7 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const std::vector<Partiti
next = partitions[t +1] .get_length() ;
total_length = previous + selected_partition .get_length() + next;
TOTAL_MB = Utils::round( Utils::sector_to_unit( total_length, GParted::UNIT_MIB ) ) ;
TOTAL_MB = Utils::round( Utils::sector_to_unit( total_length, DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ;
MB_PER_PIXEL = TOTAL_MB / 500.00 ;
@ -147,33 +148,33 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const std::vector<Partiti
{
spinbutton_before .set_range(
0,
TOTAL_MB - Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), GParted::UNIT_MIB ) ) ) ;
TOTAL_MB - Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ) ;
spinbutton_before .set_value(
Utils::round( Utils::sector_to_unit( previous, GParted::UNIT_MIB ) ) ) ;
Utils::round( Utils::sector_to_unit( previous, DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ) ;
}
//set values of spinbutton_size
spinbutton_size .set_range(
Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), GParted::UNIT_MIB ) ),
Utils::round( Utils::sector_to_unit( (fs .MAX / DEFAULT_SECTOR_SIZE), GParted::UNIT_MIB ) ) ) ;
Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ),
Utils::round( Utils::sector_to_unit( (fs .MAX / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ) ;
spinbutton_size .set_value(
Utils::round( Utils::sector_to_unit( selected_partition .get_length(), GParted::UNIT_MIB ) ) ) ;
Utils::round( Utils::sector_to_unit( selected_partition .get_length(), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ) ;
//set values of spinbutton_after
Sector after_min = ( ! fs .grow && ! fs .move ) ? next : 0 ;
spinbutton_after .set_range(
Utils::round( Utils::sector_to_unit( after_min, GParted::UNIT_MIB ) ),
TOTAL_MB - Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), GParted::UNIT_MIB ) ) ) ;
Utils::round( Utils::sector_to_unit( after_min, DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ),
TOTAL_MB - Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ) ;
spinbutton_after .set_value(
Utils::round( Utils::sector_to_unit( next, GParted::UNIT_MIB ) ) ) ;
Utils::round( Utils::sector_to_unit( next, DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ) ;
frame_resizer_base ->set_size_limits( Utils::round( fs .MIN / (MB_PER_PIXEL * MEBI_FACTOR) ),
Utils::round( fs .MAX / (MB_PER_PIXEL * MEBI_FACTOR) ) ) ;
//set contents of label_minmax
Set_MinMax_Text(
Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), GParted::UNIT_MIB ) ),
Utils::round( Utils::sector_to_unit( (fs .MAX / DEFAULT_SECTOR_SIZE), GParted::UNIT_MIB ) ) ) ;
Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ),
Utils::round( Utils::sector_to_unit( (fs .MAX / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ) ;
}
void Dialog_Partition_Resize_Move::Resize_Move_Extended( const std::vector<Partition> & partitions )
@ -200,7 +201,7 @@ void Dialog_Partition_Resize_Move::Resize_Move_Extended( const std::vector<Parti
//now we have enough data to calculate some important values..
total_length = previous + selected_partition .get_length() + next;
TOTAL_MB = Utils::round( Utils::sector_to_unit( total_length, UNIT_MIB ) ) ;
TOTAL_MB = Utils::round( Utils::sector_to_unit( total_length, DEFAULT_SECTOR_SIZE, UNIT_MIB ) ) ;
MB_PER_PIXEL = TOTAL_MB / 500.00 ;
//calculate proportional length of partition ( in pixels )
@ -226,34 +227,34 @@ void Dialog_Partition_Resize_Move::Resize_Move_Extended( const std::vector<Parti
//set values of spinbutton_before (we assume there is no fixed start.)
if ( first == 0 ) //no logicals
spinbutton_before .set_range( 0, TOTAL_MB - Utils::round( Utils::sector_to_unit( BUF/2, GParted::UNIT_MIB ) ) ) ;
spinbutton_before .set_range( 0, TOTAL_MB - Utils::round( Utils::sector_to_unit( BUF/2, DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ) ;
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, DEFAULT_SECTOR_SIZE, 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, DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ) ;
//set values of spinbutton_size
if ( first == 0 ) //no logicals
spinbutton_size .set_range( Utils::round( Utils::sector_to_unit( BUF/2, GParted::UNIT_MIB ) ), TOTAL_MB ) ;
spinbutton_size .set_range( Utils::round( Utils::sector_to_unit( BUF/2, DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ), TOTAL_MB ) ;
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, DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ), TOTAL_MB ) ;
spinbutton_size .set_value(
Utils::round( Utils::sector_to_unit( selected_partition .get_length(), GParted::UNIT_MIB ) ) ) ;
Utils::round( Utils::sector_to_unit( selected_partition .get_length(), DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ) ;
//set values of spinbutton_after
if ( first == 0 ) //no logicals
spinbutton_after .set_range(
0, TOTAL_MB - Utils::round( Utils::sector_to_unit( BUF/2, GParted::UNIT_MIB ) ) ) ;
0, TOTAL_MB - Utils::round( Utils::sector_to_unit( BUF/2, DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ) ;
else
spinbutton_after .set_range(
0, Utils::round( Utils::sector_to_unit( total_length + START - first - used, GParted::UNIT_MIB ) ) ) ;
0, Utils::round( Utils::sector_to_unit( total_length + START - first - used, DEFAULT_SECTOR_SIZE, 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, DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ) ;
//set contents of label_minmax
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 ) ) ) ;
Set_MinMax_Text( Utils::round( Utils::sector_to_unit( first == 0 ? BUF/2 : used, DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ),
Utils::round( Utils::sector_to_unit( total_length, DEFAULT_SECTOR_SIZE, GParted::UNIT_MIB ) ) ) ;
}
} //GParted

View file

@ -174,27 +174,27 @@ Glib::ustring Utils::format_size( Sector size )
if ( size < KIBIBYTE )
{
ss << sector_to_unit( size, UNIT_BYTE ) ;
ss << sector_to_unit( size, DEFAULT_SECTOR_SIZE, UNIT_BYTE ) ;
return String::ucompose( _("%1 B"), ss .str() ) ;
}
else if ( size < MEBIBYTE )
{
ss << sector_to_unit( size, UNIT_KIB ) ;
ss << sector_to_unit( size, DEFAULT_SECTOR_SIZE, UNIT_KIB ) ;
return String::ucompose( _("%1 KiB"), ss .str() ) ;
}
else if ( size < GIBIBYTE )
{
ss << sector_to_unit( size, UNIT_MIB ) ;
ss << sector_to_unit( size, DEFAULT_SECTOR_SIZE, UNIT_MIB ) ;
return String::ucompose( _("%1 MiB"), ss .str() ) ;
}
else if ( size < TEBIBYTE )
{
ss << sector_to_unit( size, UNIT_GIB ) ;
ss << sector_to_unit( size, DEFAULT_SECTOR_SIZE, UNIT_GIB ) ;
return String::ucompose( _("%1 GiB"), ss .str() ) ;
}
else
{
ss << sector_to_unit( size, UNIT_TIB ) ;
ss << sector_to_unit( size, DEFAULT_SECTOR_SIZE, UNIT_TIB ) ;
return String::ucompose( _("%1 TiB"), ss .str() ) ;
}
}
@ -222,21 +222,21 @@ Glib::ustring Utils::format_time( std::time_t seconds )
return time ;
}
double Utils::sector_to_unit( Sector sectors, SIZE_UNIT size_unit )
double Utils::sector_to_unit( Sector sectors, Byte_Value sector_size, SIZE_UNIT size_unit )
{
switch ( size_unit )
{
case UNIT_BYTE :
return sectors * 512 ;
return sectors * sector_size ;
case UNIT_KIB :
return sectors / static_cast<double>( KIBIBYTE ) ;
return sectors / ( static_cast<double>( KIBI_FACTOR ) / sector_size );
case UNIT_MIB :
return sectors / static_cast<double>( MEBIBYTE ) ;
return sectors / ( static_cast<double>( MEBI_FACTOR ) / sector_size );
case UNIT_GIB :
return sectors / static_cast<double>( GIBIBYTE ) ;
return sectors / ( static_cast<double>( GIBI_FACTOR ) / sector_size );
case UNIT_TIB :
return sectors / static_cast<double>( TEBIBYTE ) ;
return sectors / ( static_cast<double>( TEBI_FACTOR ) / sector_size );
default:
return sectors ;

View file

@ -116,7 +116,7 @@ bool ext2::resize( const Partition & partition_new, OperationDetail & operationd
if ( ! fill_partition )
str_temp += " " + Utils::num_to_str( Utils::round( Utils::sector_to_unit(
partition_new .get_length(), UNIT_KIB ) ) -1 ) + "K" ;
partition_new .get_length(), DEFAULT_SECTOR_SIZE, UNIT_KIB ) ) -1 ) + "K" ;
return ! execute_command( str_temp, operationdetail ) ;
}

View file

@ -117,7 +117,7 @@ bool ext3::resize( const Partition & partition_new, OperationDetail & operationd
if ( ! fill_partition )
str_temp += " " + Utils::num_to_str( Utils::round( Utils::sector_to_unit(
partition_new .get_length(), GParted::UNIT_KIB ) ) -1 ) + "K" ;
partition_new .get_length(), DEFAULT_SECTOR_SIZE, GParted::UNIT_KIB ) ) -1 ) + "K" ;
return ! execute_command( str_temp, operationdetail ) ;
}

View file

@ -120,7 +120,7 @@ bool ext4::resize( const Partition & partition_new, OperationDetail & operationd
if ( ! fill_partition )
str_temp += " " + Utils::num_to_str( Utils::round( Utils::sector_to_unit(
partition_new .get_length(), GParted::UNIT_KIB ) ) -1 ) + "K" ;
partition_new .get_length(), DEFAULT_SECTOR_SIZE, GParted::UNIT_KIB ) ) -1 ) + "K" ;
return ! execute_command( str_temp, operationdetail ) ;
}

View file

@ -118,7 +118,7 @@ bool ntfs::resize( const Partition & partition_new, OperationDetail & operationd
{
str_temp += " -s " ;
str_temp += Utils::num_to_str( Utils::round( Utils::sector_to_unit(
partition_new .get_length(), GParted::UNIT_BYTE ) ) -1 ) ;
partition_new .get_length(), DEFAULT_SECTOR_SIZE, GParted::UNIT_BYTE ) ) -1 ) ;
}
//simulation..

View file

@ -125,7 +125,7 @@ bool reiserfs::resize( const Partition & partition_new, OperationDetail & operat
{
str_temp += " -s " ;
str_temp += Utils::num_to_str( Utils::round( Utils::sector_to_unit(
partition_new .get_length(), GParted::UNIT_BYTE ) ) -1 ) ;
partition_new .get_length(), DEFAULT_SECTOR_SIZE, GParted::UNIT_BYTE ) ) -1 ) ;
}
exit_status = execute_command( str_temp, operationdetail ) ;