[gparted] Replace sector math with get_byte_length method where appropriate



commit 70448f4fb0953794e9ddf77100813687ac620504
Author: Curtis Gedak <gedakc gmail com>
Date:   Tue Apr 27 12:54:14 2010 -0600

    Replace sector math with get_byte_length method where appropriate
    
    This change is in preparation for supporting sectors sizes > 512 bytes.

 src/Dialog_Partition_Copy.cc        |    4 ++--
 src/Dialog_Partition_New.cc         |    6 +++---
 src/Dialog_Partition_Resize_Move.cc |    8 ++++----
 src/GParted_Core.cc                 |    8 ++++----
 src/Win_GParted.cc                  |    6 +++---
 5 files changed, 16 insertions(+), 16 deletions(-)
---
diff --git a/src/Dialog_Partition_Copy.cc b/src/Dialog_Partition_Copy.cc
index 442c3c0..11bf29e 100644
--- a/src/Dialog_Partition_Copy.cc
+++ b/src/Dialog_Partition_Copy.cc
@@ -46,7 +46,7 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons
 
 	//Determine minimum number of sectors needed in destination (selected) partition and
 	//  handle situation where src sector size is smaller than dst sector size and an additional partial dst sector is required.
-	Sector copied_min_sectors = ( copied_partition .get_length() * copied_partition .sector_size + (selected_partition .sector_size - 1) ) / selected_partition .sector_size ;
+	Sector copied_min_sectors = ( copied_partition .get_byte_length() + (selected_partition .sector_size - 1) ) / selected_partition .sector_size ;
 
 	long COPIED_LENGTH_MB = Utils::round( Utils::sector_to_unit( copied_min_sectors, copied_partition .sector_size, UNIT_MIB ) ) ; 
 	//  /* Copy Primary not at start of disk to within Extended partition */
@@ -105,7 +105,7 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons
 	if ( fs .grow )
 		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 ;
+		fs .MAX = copied_partition .get_byte_length() ;
 
 	//TODO: Since BUF is the cylinder size of the current device, the cylinder size of the copied device could differ for small disks
 	if ( fs .filesystem == GParted::FS_XFS ) //bit hackisch, but most effective, since it's a unique situation
diff --git a/src/Dialog_Partition_New.cc b/src/Dialog_Partition_New.cc
index 94fa377..fa04b0a 100644
--- a/src/Dialog_Partition_New.cc
+++ b/src/Dialog_Partition_New.cc
@@ -259,8 +259,8 @@ void Dialog_Partition_New::optionmenu_changed( bool type )
 		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 ;
+		if ( selected_partition .get_byte_length() < fs .MIN )
+			fs .MIN = selected_partition .get_byte_length() ;
 				
 		fs .MAX = ( fs .MAX && ( fs .MAX < (TOTAL_MB * MEBIBYTE) ) ) ? fs .MAX : (TOTAL_MB * MEBIBYTE) ;
 		
@@ -306,7 +306,7 @@ void Dialog_Partition_New::Build_Filesystems_Menu( bool only_unformatted )
 			Gtk::Menu_Helpers::MenuElem( Utils::get_filesystem_string( FILESYSTEMS[ t ] .filesystem ) ) ) ;
 		menu_filesystem .items() .back() .set_sensitive(
 			! only_unformatted && FILESYSTEMS[ t ] .create &&
-			this ->selected_partition .get_length() >= (FILESYSTEMS[ t ] .MIN / this ->selected_partition .sector_size) ) ;
+			this ->selected_partition .get_byte_length() >= FILESYSTEMS[ t ] .MIN ) ;
 	}
 	
 	//unformatted is always available
diff --git a/src/Dialog_Partition_Resize_Move.cc b/src/Dialog_Partition_Resize_Move.cc
index 12e2da4..f7c335b 100644
--- a/src/Dialog_Partition_Resize_Move.cc
+++ b/src/Dialog_Partition_Resize_Move.cc
@@ -125,11 +125,11 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const std::vector<Partiti
 		fs .MIN += fs .MIN ? (BUF * selected_partition .sector_size) : (BUF/2 * selected_partition .sector_size) ;
 
 		//in certain (rare) cases fs .MIN is (now) larger than 'selected_partition'..
-		if ( (fs .MIN / selected_partition .sector_size) > selected_partition .get_length() )
-			fs .MIN = selected_partition .get_length() * selected_partition .sector_size ;
+		if ( fs .MIN > selected_partition .get_byte_length() )
+			fs .MIN = selected_partition .get_byte_length() ;
 	}
 	else
-		fs .MIN = selected_partition .get_length() * selected_partition .sector_size ;
+		fs .MIN = selected_partition .get_byte_length() ;
 
 	//set MAX
 	if ( fs .grow )
@@ -140,7 +140,7 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const std::vector<Partiti
 			fs .MAX -= (BUF/2 * selected_partition .sector_size) ;
 	}
 	else
-		fs .MAX = selected_partition .get_length() * selected_partition .sector_size ;
+		fs .MAX = selected_partition .get_byte_length() ;
 
 	
 	//set values of spinbutton_before
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 0d86285..66cfab9 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -480,7 +480,7 @@ bool GParted_Core::apply_operation_to_disk( Operation * operation )
 
 					 copy( static_cast<OperationCopy*>( operation ) ->partition_copied,
 					       operation ->partition_new,
-					       static_cast<OperationCopy*>( operation ) ->partition_copied .get_length() * static_cast<OperationCopy*>( operation ) ->partition_copied .sector_size,
+					       static_cast<OperationCopy*>( operation ) ->partition_copied .get_byte_length(),
 					       operation ->operation_detail ) ;
 				break ;
 			case OPERATION_LABEL_PARTITION:
@@ -2012,7 +2012,7 @@ bool GParted_Core::copy( const Partition & partition_src,
 			 Byte_Value min_size,
 			 OperationDetail & operationdetail ) 
 {
-	if ( partition_dst .get_length() < partition_src .get_length() )
+	if ( partition_dst .get_byte_length() < partition_src .get_byte_length() )
 	{	
 		operationdetail .add_child( OperationDetail( 
 			_("the destination is smaller than the source partition"), STATUS_ERROR, FONT_ITALIC ) ) ;
@@ -2096,7 +2096,7 @@ bool GParted_Core::copy_filesystem( const Partition & partition_src,
 				partition_dst .sector_start,
 				partition_src .sector_size,
 				partition_dst .sector_size,
-				partition_src .get_length() * partition_src .sector_size,
+				partition_src .get_byte_length(),
 				operationdetail,
 				readonly,
 				dummy ) ;
@@ -2113,7 +2113,7 @@ bool GParted_Core::copy_filesystem( const Partition & partition_src,
 				partition_dst .sector_start,
 				partition_src .sector_size,
 				partition_dst .sector_size,
-				partition_src .get_length() * partition_src .sector_size,
+				partition_src .get_byte_length(),
 				operationdetail,
 				false,
 				total_done ) ;
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index 3e0a79f..8e19ad2 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -1641,8 +1641,8 @@ void Win_GParted::activate_format( GParted::FILESYSTEM new_fs )
 	//check for some limits...
 	fs = gparted_core .get_fs( new_fs ) ;
 	
-	if ( ( selected_partition .get_length() < (fs .MIN / selected_partition .sector_size) ) ||
-	     ( fs .MAX && selected_partition .get_length() > (fs .MAX / selected_partition .sector_size) ) )
+	if ( ( selected_partition .get_byte_length() < fs .MIN ) ||
+	     ( fs .MAX && selected_partition .get_byte_length() > fs .MAX ) )
 	{
 		Gtk::MessageDialog dialog( *this,
 					   String::ucompose( _("Cannot format this file system to %1."),
@@ -1652,7 +1652,7 @@ void Win_GParted::activate_format( GParted::FILESYSTEM new_fs )
 					   Gtk::BUTTONS_OK,
 					   true );
 
-		if ( selected_partition .get_length() < (fs .MIN / selected_partition .sector_size) )
+		if ( selected_partition .get_byte_length() < fs .MIN )
 			dialog .set_secondary_text( String::ucompose( 
 						_( "A %1 file system requires a partition of at least %2."),
 						Utils::get_filesystem_string( new_fs ),



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]