Remove 512 byte based units and rename _FACTOR to BYTE

With the removal of the 512 byte constants, such as MEBIBYTE, it
was possible to rename the _FACTOR constants back to BYTE
constants.  The _FACTOR constants, such as MEBI_FACTOR, were a
temporary measure to help in the transition to support devices
with sector sizes > 512 bytes.
This commit is contained in:
Curtis Gedak 2010-04-26 13:40:38 -06:00
parent 81a903cda2
commit cb08e8c7dd
14 changed files with 53 additions and 59 deletions

View File

@ -40,17 +40,11 @@ namespace GParted
typedef long long Sector;
typedef long long Byte_Value;
//sizeunits defined in sectors of 512 bytes..
#define KIBIBYTE 2
#define MEBIBYTE 2048
#define GIBIBYTE 2097152
#define TEBIBYTE 2147483648U
//Size units defined in bytes
const Byte_Value KIBI_FACTOR=1024;
const Byte_Value MEBI_FACTOR=(KIBI_FACTOR * KIBI_FACTOR);
const Byte_Value GIBI_FACTOR=(MEBI_FACTOR * KIBI_FACTOR);
const Byte_Value TEBI_FACTOR=(GIBI_FACTOR * KIBI_FACTOR);
const Byte_Value KIBIBYTE=1024;
const Byte_Value MEBIBYTE=(KIBIBYTE * KIBIBYTE);
const Byte_Value GIBIBYTE=(MEBIBYTE * KIBIBYTE);
const Byte_Value TEBIBYTE=(GIBIBYTE * KIBIBYTE);
enum FILESYSTEM
{

View File

@ -127,11 +127,11 @@ Partition Dialog_Base_Partition::Get_New_Partition( Byte_Value sector_size )
//FIXME: Partition size is limited to just less than 1024 TeraBytes due
// to the maximum value of signed 4 byte integer.
if ( ORIG_BEFORE != spinbutton_before .get_value_as_int() )
selected_partition .sector_start = START + Sector(spinbutton_before .get_value_as_int()) * (MEBI_FACTOR / sector_size) ;
selected_partition .sector_start = START + Sector(spinbutton_before .get_value_as_int()) * (MEBIBYTE / sector_size) ;
if ( ORIG_AFTER != spinbutton_after .get_value_as_int() )
selected_partition .sector_end =
selected_partition .sector_start + Sector(spinbutton_size .get_value_as_int()) * (MEBI_FACTOR / sector_size) ;
selected_partition .sector_start + Sector(spinbutton_size .get_value_as_int()) * (MEBIBYTE / sector_size) ;
//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 solve this.
@ -141,9 +141,9 @@ Partition Dialog_Base_Partition::Get_New_Partition( Byte_Value sector_size )
selected_partition .sector_end = START + total_length -1 ;
//grow a bit into small freespace ( < 1MiB )
if ( (selected_partition .sector_start - START) < (MEBI_FACTOR / sector_size) )
if ( (selected_partition .sector_start - START) < (MEBIBYTE / sector_size) )
selected_partition .sector_start = START ;
if ( ( START + total_length -1 - selected_partition .sector_end ) < (MEBI_FACTOR / sector_size) )
if ( ( START + total_length -1 - selected_partition .sector_end ) < (MEBIBYTE / sector_size) )
selected_partition .sector_end = START + total_length -1 ;
//set new value of unused..

View File

@ -103,7 +103,7 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons
copied_partition .sectors_used, copied_partition .sector_size, 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 * selected_partition .sector_size) ;
fs .MAX = ( ! fs .MAX || fs .MAX > (TOTAL_MB * MEBIBYTE) ) ? (TOTAL_MB * MEBIBYTE) : fs .MAX - (BUF * selected_partition .sector_size) ;
else
fs .MAX = copied_partition .get_length() * copied_partition .sector_size ;
@ -111,7 +111,7 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons
if ( fs .filesystem == GParted::FS_XFS ) //bit hackisch, but most effective, since it's a unique situation
fs .MIN = ( copied_partition .sectors_used + (BUF * 2) ) * copied_partition .sector_size;
else
fs .MIN = COPIED_LENGTH_MB * MEBI_FACTOR ;
fs .MIN = COPIED_LENGTH_MB * MEBIBYTE ;
GRIP = true ;
//set values of spinbutton_before
@ -129,8 +129,8 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons
spinbutton_after .set_value( TOTAL_MB - COPIED_LENGTH_MB ) ;
GRIP = false ;
frame_resizer_base ->set_size_limits( Utils::round( fs .MIN / (MB_PER_PIXEL * MEBI_FACTOR) ),
Utils::round( fs .MAX / (MB_PER_PIXEL * MEBI_FACTOR) ) ) ;
frame_resizer_base ->set_size_limits( Utils::round( fs .MIN / (MB_PER_PIXEL * MEBIBYTE) ),
Utils::round( fs .MAX / (MB_PER_PIXEL * MEBIBYTE) ) ) ;
//set contents of label_minmax
Set_MinMax_Text(

View File

@ -155,7 +155,7 @@ void Dialog_Partition_New::Set_Data( const Partition & partition,
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)
if ( TOTAL_MB * (MEBI_FACTOR / this ->selected_partition .sector_size) < this ->cylinder_size )
if ( TOTAL_MB * (MEBIBYTE / this ->selected_partition .sector_size) < this ->cylinder_size )
frame_resizer_base ->set_sensitive( false ) ;
this ->show_all_children() ;
@ -178,8 +178,8 @@ Partition Dialog_Partition_New::Get_New_Partition( Byte_Value sector_size )
//FIXME: Partition size is limited to just less than 1024 TeraBytes due
// to the maximum value of signed 4 byte integer.
new_start = START + (Sector(spinbutton_before .get_value_as_int()) * (MEBI_FACTOR / sector_size)) ;
new_end = new_start + (Sector(spinbutton_size .get_value_as_int()) * (MEBI_FACTOR / sector_size)) - 1 ;
new_start = START + (Sector(spinbutton_before .get_value_as_int()) * (MEBIBYTE / sector_size)) ;
new_end = new_start + (Sector(spinbutton_size .get_value_as_int()) * (MEBIBYTE / sector_size)) - 1 ;
/* 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.*/
@ -201,9 +201,9 @@ Partition Dialog_Partition_New::Get_New_Partition( Byte_Value sector_size )
part_temp .label = Utils::trim( entry .get_text() );
//grow new partition a bit if freespaces are < 1 MiB
if ( (part_temp.sector_start - selected_partition.sector_start) < (MEBI_FACTOR / sector_size) )
if ( (part_temp.sector_start - selected_partition.sector_start) < (MEBIBYTE / sector_size) )
part_temp.sector_start = selected_partition.sector_start ;
if ( (selected_partition.sector_end - part_temp.sector_end) < (MEBI_FACTOR / sector_size) )
if ( (selected_partition.sector_end - part_temp.sector_end) < (MEBIBYTE / sector_size) )
part_temp.sector_end = selected_partition.sector_end ;
//if new is extended...
@ -256,16 +256,16 @@ void Dialog_Partition_New::optionmenu_changed( bool type )
if ( (fs .MIN / selected_partition .sector_size) < cylinder_size )
fs .MIN = cylinder_size * selected_partition .sector_size ;
}
else if ( fs .MIN < MEBI_FACTOR )
fs .MIN = MEBI_FACTOR ;
else if ( fs .MIN < MEBIBYTE )
fs .MIN = MEBIBYTE ;
if ( selected_partition .get_length() < (fs .MIN / selected_partition .sector_size) )
fs .MIN = selected_partition .get_length() * selected_partition .sector_size ;
fs .MAX = ( fs .MAX && ( fs .MAX < (TOTAL_MB * MEBI_FACTOR) ) ) ? fs .MAX : (TOTAL_MB * MEBI_FACTOR) ;
fs .MAX = ( fs .MAX && ( fs .MAX < (TOTAL_MB * MEBIBYTE) ) ) ? fs .MAX : (TOTAL_MB * MEBIBYTE) ;
frame_resizer_base ->set_size_limits( Utils::round( fs .MIN / (MB_PER_PIXEL * MEBI_FACTOR) ),
Utils::round( fs .MAX / (MB_PER_PIXEL * MEBI_FACTOR) ) ) ;
frame_resizer_base ->set_size_limits( Utils::round( fs .MIN / (MB_PER_PIXEL * MEBIBYTE) ),
Utils::round( fs .MAX / (MB_PER_PIXEL * MEBIBYTE) ) ) ;
//set new spinbutton ranges
spinbutton_before .set_range(

View File

@ -134,8 +134,8 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const std::vector<Partiti
//set MAX
if ( fs .grow )
{
if ( ! fs .MAX || fs .MAX > (TOTAL_MB * MEBI_FACTOR) )
fs .MAX = TOTAL_MB * MEBI_FACTOR ;
if ( ! fs .MAX || fs .MAX > (TOTAL_MB * MEBIBYTE) )
fs .MAX = TOTAL_MB * MEBIBYTE ;
else
fs .MAX -= (BUF/2 * selected_partition .sector_size) ;
}
@ -168,8 +168,8 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const std::vector<Partiti
spinbutton_after .set_value(
Utils::round( Utils::sector_to_unit( next, selected_partition .sector_size, 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) ) ) ;
frame_resizer_base ->set_size_limits( Utils::round( fs .MIN / (MB_PER_PIXEL * MEBIBYTE) ),
Utils::round( fs .MAX / (MB_PER_PIXEL * MEBIBYTE) ) ) ;
//set contents of label_minmax
Set_MinMax_Text(

View File

@ -305,8 +305,8 @@ void GParted_Core::set_devices( std::vector<Device> & devices )
temp_device .cylsize = temp_device .heads * temp_device .sectors ;
//make sure cylsize is at least 1 MiB
if ( temp_device .cylsize < (MEBI_FACTOR / temp_device .sector_size) )
temp_device .cylsize = (MEBI_FACTOR / temp_device .sector_size) ;
if ( temp_device .cylsize < (MEBIBYTE / temp_device .sector_size) )
temp_device .cylsize = (MEBIBYTE / temp_device .sector_size) ;
//normal harddisk
if ( lp_disk )
@ -1101,7 +1101,7 @@ void GParted_Core::insert_unallocated( const Glib::ustring & device_path,
}
//start <---> first partition start
if ( (partitions .front() .sector_start - start) >= (MEBI_FACTOR / sector_size) )
if ( (partitions .front() .sector_start - start) >= (MEBIBYTE / sector_size) )
{
partition_temp .sector_start = start ;
partition_temp .sector_end = partitions .front() .sector_start -1 ;
@ -1111,7 +1111,7 @@ void GParted_Core::insert_unallocated( const Glib::ustring & device_path,
//look for gaps in between
for ( unsigned int t =0 ; t < partitions .size() -1 ; t++ )
if ( ( partitions[ t +1 ] .sector_start - partitions[ t ] .sector_end ) >= (MEBI_FACTOR / sector_size) )
if ( ( partitions[ t +1 ] .sector_start - partitions[ t ] .sector_end ) >= (MEBIBYTE / sector_size) )
{
partition_temp .sector_start = partitions[ t ] .sector_end +1 ;
partition_temp .sector_end = partitions[ t +1 ] .sector_start -1 ;
@ -1120,7 +1120,7 @@ void GParted_Core::insert_unallocated( const Glib::ustring & device_path,
}
//last partition end <---> end
if ( (end - partitions .back() .sector_end ) >= (MEBI_FACTOR / sector_size) )
if ( (end - partitions .back() .sector_end ) >= (MEBIBYTE / sector_size) )
{
partition_temp .sector_start = partitions .back() .sector_end +1 ;
partition_temp .sector_end = end ;
@ -2142,7 +2142,7 @@ bool GParted_Core::copy_filesystem( const Glib::ustring & src_device,
operationdetail .add_child( OperationDetail( _("finding optimal block size"), STATUS_NONE ) ) ;
Byte_Value benchmark_blocksize = readonly ? (2 * MEBI_FACTOR) : (1 * MEBI_FACTOR), N = (16 * MEBI_FACTOR) ;
Byte_Value benchmark_blocksize = readonly ? (2 * MEBIBYTE) : (1 * MEBIBYTE), N = (16 * MEBIBYTE) ;
Byte_Value optimal_blocksize = benchmark_blocksize ;
Sector offset_read = src_start ;
Sector offset_write = dst_start ;

View File

@ -60,7 +60,7 @@ void Operation::insert_unallocated( std::vector<Partition> & partitions, Sector
}
//start <---> first partition start
if ( (partitions .front() .sector_start - start) >= (MEBI_FACTOR / sector_size) )
if ( (partitions .front() .sector_start - start) >= (MEBIBYTE / sector_size) )
{
UNALLOCATED .sector_start = start ;
UNALLOCATED .sector_end = partitions .front() .sector_start -1 ;
@ -70,7 +70,7 @@ void Operation::insert_unallocated( std::vector<Partition> & partitions, Sector
//look for gaps in between
for ( unsigned int t =0 ; t < partitions .size() -1 ; t++ )
if ( ( partitions[ t +1 ] .sector_start - partitions[ t ] .sector_end ) >= (MEBI_FACTOR / sector_size) )
if ( ( partitions[ t +1 ] .sector_start - partitions[ t ] .sector_end ) >= (MEBIBYTE / sector_size) )
{
UNALLOCATED .sector_start = partitions[ t ] .sector_end +1 ;
UNALLOCATED .sector_end = partitions[ t +1 ] .sector_start -1 ;
@ -79,7 +79,7 @@ void Operation::insert_unallocated( std::vector<Partition> & partitions, Sector
}
//last partition end <---> end
if ( (end - partitions .back() .sector_end ) >= (MEBI_FACTOR / sector_size) )
if ( (end - partitions .back() .sector_end ) >= (MEBIBYTE / sector_size) )
{
UNALLOCATED .sector_start = partitions .back() .sector_end +1 ;
UNALLOCATED .sector_end = end ;

View File

@ -172,22 +172,22 @@ Glib::ustring Utils::format_size( Sector sectors, Byte_Value sector_size )
std::stringstream ss ;
ss << std::setiosflags( std::ios::fixed ) << std::setprecision( 2 ) ;
if ( (sectors * sector_size) < KIBI_FACTOR )
if ( (sectors * sector_size) < KIBIBYTE )
{
ss << sector_to_unit( sectors, sector_size, UNIT_BYTE ) ;
return String::ucompose( _("%1 B"), ss .str() ) ;
}
else if ( (sectors * sector_size) < MEBI_FACTOR )
else if ( (sectors * sector_size) < MEBIBYTE )
{
ss << sector_to_unit( sectors, sector_size, UNIT_KIB ) ;
return String::ucompose( _("%1 KiB"), ss .str() ) ;
}
else if ( (sectors * sector_size) < GIBI_FACTOR )
else if ( (sectors * sector_size) < GIBIBYTE )
{
ss << sector_to_unit( sectors, sector_size, UNIT_MIB ) ;
return String::ucompose( _("%1 MiB"), ss .str() ) ;
}
else if ( (sectors * sector_size) < TEBI_FACTOR )
else if ( (sectors * sector_size) < TEBIBYTE )
{
ss << sector_to_unit( sectors, sector_size, UNIT_GIB ) ;
return String::ucompose( _("%1 GiB"), ss .str() ) ;
@ -230,13 +230,13 @@ double Utils::sector_to_unit( Sector sectors, Byte_Value sector_size, SIZE_UNIT
return sectors * sector_size ;
case UNIT_KIB :
return sectors / ( static_cast<double>( KIBI_FACTOR ) / sector_size );
return sectors / ( static_cast<double>( KIBIBYTE ) / sector_size );
case UNIT_MIB :
return sectors / ( static_cast<double>( MEBI_FACTOR ) / sector_size );
return sectors / ( static_cast<double>( MEBIBYTE ) / sector_size );
case UNIT_GIB :
return sectors / ( static_cast<double>( GIBI_FACTOR ) / sector_size );
return sectors / ( static_cast<double>( GIBIBYTE ) / sector_size );
case UNIT_TIB :
return sectors / ( static_cast<double>( TEBI_FACTOR ) / sector_size );
return sectors / ( static_cast<double>( TEBIBYTE ) / sector_size );
default:
return sectors ;

View File

@ -56,8 +56,8 @@ FS fat16::get_filesystem_support()
fs .copy = GParted::FS::GPARTED ;
fs .MIN = 16 * MEBI_FACTOR ;
fs .MAX = (4096 - 1) * MEBI_FACTOR ; //Maximum seems to be just less than 4096 MiB
fs .MIN = 16 * MEBIBYTE ;
fs .MAX = (4096 - 1) * MEBIBYTE ; //Maximum seems to be just less than 4096 MiB
return fs ;
}

View File

@ -56,7 +56,7 @@ FS fat32::get_filesystem_support()
fs .copy = GParted::FS::GPARTED ;
fs .MIN = 32 * MEBI_FACTOR ; //smaller fs'es will cause windows scandisk to fail..
fs .MIN = 32 * MEBIBYTE ; //smaller fs'es will cause windows scandisk to fail..
return fs ;
}

View File

@ -1,5 +1,5 @@
/* Copyright (C) 2004 Bart
* Copyright (C) 2008 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
@ -43,7 +43,7 @@ FS hfs::get_filesystem_support()
fs .copy = GParted::FS::GPARTED ;
fs .move = GParted::FS::GPARTED ;
fs .MAX = 2048 * MEBI_FACTOR ;
fs .MAX = 2048 * MEBIBYTE ;
return fs ;
}

View File

@ -1,5 +1,5 @@
/* Copyright (C) 2004 Bart
* Copyright (C) 2008 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
@ -71,7 +71,7 @@ FS jfs::get_filesystem_support()
fs .copy = GParted::FS::GPARTED ;
}
fs .MIN = 16 * MEBI_FACTOR ;
fs .MIN = 16 * MEBIBYTE ;
return fs ;
}

View File

@ -58,7 +58,7 @@ FS reiserfs::get_filesystem_support()
}
//Actual minimum is at least 18 blocks larger than 32 MiB for the journal offset
fs .MIN = 34 * MEBI_FACTOR ;
fs .MIN = 34 * MEBIBYTE ;
return fs ;
}

View File

@ -1,5 +1,5 @@
/* Copyright (C) 2004 Bart
* Copyright (C) 2008 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
@ -72,7 +72,7 @@ FS xfs::get_filesystem_support()
if ( fs .check )
fs .move = GParted::FS::GPARTED ;
fs .MIN = 32 * MEBI_FACTOR ;//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 ;
}