[gparted] Set unallocated space for paste or resize/move operations (#499202)



commit 7ddbc9bd9281bab38ecb5e451f3a9e474a9df0d9
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Wed Mar 28 12:47:48 2012 +0100

    Set unallocated space for paste or resize/move operations (#499202)
    
    When pasting a copied partition into free space or move/resizing a
    partition set its space utilisation so that any unallocated space within
    the partition is displayed correctly before the operation is applied.
    
    NOTE:
    If the file system does not support file system resizing the Paste and
    Move/Resize dialogs don't allow resizing the partition so the preview
    will always be correct, unlike the case in the previous patch:
        Set unallocated space when performing simple operations (#499202)
    
    Also remove the deprecated and no longer used Partition::Set_Unused()
    and Partition::set_used() methods.
    
    Bug #499202 - gparted does not see the difference if partition size
                  differs from filesystem size

 include/Partition.h          |    2 --
 src/Dialog_Base_Partition.cc |   28 ++++++++++++++++++++++++----
 src/Dialog_Partition_Copy.cc |    9 ++++++---
 src/Partition.cc             |   28 ++--------------------------
 4 files changed, 32 insertions(+), 35 deletions(-)
---
diff --git a/include/Partition.h b/include/Partition.h
index 4466175..0b49855 100644
--- a/include/Partition.h
+++ b/include/Partition.h
@@ -72,8 +72,6 @@ public:
 			bool inside_extended,
 			bool busy ) ;
 
-	void Set_Unused( Sector sectors_unused ) ;
-	void set_used( Sector sectors_used ) ;
 	void set_sector_usage( Sector sectors_fs_size, Sector sectors_fs_unused ) ;
 	bool significant_unallocated_space() const ;
 
diff --git a/src/Dialog_Base_Partition.cc b/src/Dialog_Base_Partition.cc
index 0fcd3b0..df5666f 100644
--- a/src/Dialog_Base_Partition.cc
+++ b/src/Dialog_Base_Partition.cc
@@ -138,6 +138,7 @@ Partition Dialog_Base_Partition::Get_New_Partition( Byte_Value sector_size )
 {
 	//set sector size of new partition
 	selected_partition .sector_size = sector_size;
+	Sector old_size = selected_partition .get_sector_length() ;
 
 	//FIXME:  Partition size is limited to just less than 1024 TeraBytes due
 	//        to the maximum value of signed 4 byte integer.
@@ -163,10 +164,6 @@ Partition Dialog_Base_Partition::Get_New_Partition( Byte_Value 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..
-	if ( selected_partition .sectors_used != -1 )
-		selected_partition .sectors_unused = selected_partition .get_sector_length() - selected_partition .sectors_used ;
-
 	//set alignment
 	switch ( optionmenu_alignment .get_history() )
 	{
@@ -194,6 +191,29 @@ Partition Dialog_Base_Partition::Get_New_Partition( Byte_Value sector_size )
 		default :  selected_partition .alignment = ALIGN_MEBIBYTE ;
 	}
 
+	//update partition usage
+	if ( selected_partition .sectors_used != -1 && selected_partition .sectors_unused != -1 )
+	{
+		Sector new_size = selected_partition .get_sector_length() ;
+		if ( old_size == new_size )
+		{
+			//Pasting into new same sized partition or moving partition keeping the same size,
+			//  therefore only block copy operation will be performed maintaining file system size.
+			selected_partition .set_sector_usage(
+					selected_partition .sectors_used + selected_partition .sectors_unused,
+					selected_partition .sectors_unused ) ;
+		}
+		else
+		{
+			//Pasting into new larger partition or (moving and) resizing partition larger or smaller,
+			//  therefore block copy followed by file system grow or shrink operations will be
+			//  performed making the file system fill the partition.
+			selected_partition .set_sector_usage(
+					new_size,
+					new_size - selected_partition .sectors_used ) ;
+		}
+	}
+
 	selected_partition .free_space_before = Sector(spinbutton_before .get_value_as_int()) * (MEBIBYTE / sector_size) ;
 
 	//if the original before value has not changed, then set indicator to keep start sector unchanged
diff --git a/src/Dialog_Partition_Copy.cc b/src/Dialog_Partition_Copy.cc
index 2b18ff0..ed4179b 100644
--- a/src/Dialog_Partition_Copy.cc
+++ b/src/Dialog_Partition_Copy.cc
@@ -105,9 +105,12 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons
 	this ->selected_partition .type = 
 		selected_partition .inside_extended ? GParted::TYPE_LOGICAL : GParted::TYPE_PRIMARY ;
 	//Handle situation where src sector size is smaller than dst sector size and an additional partial dst sector is required.
-	this ->selected_partition .set_used(
-			( (copied_partition .sectors_used * copied_partition .sector_size)
-			  + (selected_partition .sector_size - 1)
+	this ->selected_partition .set_sector_usage(
+			(   ( ( copied_partition .sectors_used + copied_partition .sectors_unused ) * copied_partition .sector_size )
+			  + ( selected_partition .sector_size - 1 )
+			) / selected_partition .sector_size,
+			(   ( copied_partition .sectors_unused * copied_partition .sector_size )
+			  + ( selected_partition .sector_size - 1 )
 			) / selected_partition .sector_size ) ;
 
 	this ->show_all_children() ;
diff --git a/src/Partition.cc b/src/Partition.cc
index 971a36e..2fd1b6d 100644
--- a/src/Partition.cc
+++ b/src/Partition.cc
@@ -83,32 +83,8 @@ void Partition::Set(	const Glib::ustring & device_path,
 	this ->color .set( Utils::get_color( filesystem ) );
 }
 
-//Deprecated method of setting file system free space, which assumes
-//  the file system fills the partition.
-void Partition::Set_Unused( Sector sectors_unused )
-{
-	if ( sectors_unused <= get_sector_length() )
-	{
-		this ->sectors_unused = sectors_unused ;
-		this ->sectors_used = ( sectors_unused == -1 ) ? -1 : get_sector_length() - sectors_unused ;
-		this ->sectors_unallocated = 0 ;
-	}
-}
-
-//Deprecated method of setting file system used space, which assumes
-//  the file system fills the partition.
-void Partition::set_used( Sector sectors_used ) 
-{
-	if ( sectors_used < get_sector_length() )
-	{
-		this ->sectors_used = sectors_used ;
-		this ->sectors_unused = ( sectors_used == -1 ) ? -1 : get_sector_length() - sectors_used ;
-		this ->sectors_unallocated = 0 ;
-	}
-}
-
-//Preferred method of setting file system size and free space, which also
-//  calculates unallocated space.  Set sectors_fs_size = -1 for unknown.
+//Set file system size and free space, which also calculates unallocated
+//  space.  Set sectors_fs_size = -1 for unknown.
 void Partition::set_sector_usage( Sector sectors_fs_size, Sector sectors_fs_unused )
 {
 	Sector length = get_sector_length() ;



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