[gparted] Set unallocated space when performing simple operations (#499202)



commit 04f5250644ecd47536910b5c3bd4bc6aa7b08d6e
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Wed Apr 11 21:07:52 2012 +0100

    Set unallocated space when performing simple operations (#499202)
    
    When pasting a copied partition into an existing partition set its space
    utilisation so that any unallocated space is displayed correctly before
    the operation is applied.  If the destination partition is larger the
    file system will be grown to fill the partition.
    
    NOTE:
    GParted will attempt to grow the the file system in this situation
    regardless of whether the file system supports it or not.  These file
    systems: exfat, hfs, hfs+, reiser4 and ufs can't be grown and will fail
    with "growing is not available for this file system".  The preview will
    also be wrong in this case for the same reason.  Everything will be
    depicted correctly after the refresh.
    
    When formatting an existing partition default its space utilisation to
    unknown for display before the operation is applied.
    
    Bug 499202 - gparted does not see the difference if partition size
                 differs from filesystem size

 src/Win_GParted.cc |   23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)
---
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index 683fb15..8c3be42 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -1641,7 +1641,24 @@ void Win_GParted::activate_paste()
 		partition_new .label = copied_partition .label ;
 		partition_new .uuid = copied_partition .uuid ;
 		partition_new .color = copied_partition .color ;
-		partition_new .set_used( copied_partition .sectors_used ) ;
+		Sector new_size = partition_new .get_sector_length() ;
+		if ( copied_partition .get_sector_length() == new_size )
+		{
+			//Pasting into same size existing partition, therefore only block copy operation
+			//  will be performed maintaining the file system size.
+			partition_new .set_sector_usage(
+					copied_partition .sectors_used + copied_partition. sectors_unused,
+					copied_partition. sectors_unused ) ;
+		}
+		else
+		{
+			//Pasting into larger existing partition, therefore block copy followed by file system
+			//  grow operations (if supported) will be performed making the file system fill the
+			//  partition.
+			partition_new .set_sector_usage(
+					new_size,
+					new_size - copied_partition .sectors_used ) ;
+		}
 		partition_new .messages .clear() ;
  
 		Operation * operation = new OperationCopy( devices[ current_device ],
@@ -1859,8 +1876,8 @@ void Win_GParted::activate_format( GParted::FILESYSTEM new_fs )
 			devices[ current_device ] .sector_size,
 			selected_partition .inside_extended,
 			false ) ;
-	part_temp .Set_Unused( selected_partition .sectors_unused );
-	part_temp .set_used( 0 );
+	//Leave sector usage figures to new Partition object defaults of
+	//  -1, -1, 0 (_used, _unused, _unallocated) representing unknown.
 	 
 	part_temp .status = GParted::STAT_FORMATTED ;
 	



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