[gparted] Correctly preview unknown FS usage when pasting into a new partition (!13)



commit f098cd414cf1974cf787bfb9c1196e8c51e83516
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Mon Sep 3 16:13:29 2018 +0100

    Correctly preview unknown FS usage when pasting into a new partition (!13)
    
    GParted previews copying a partition of unknown file system usage into a
    new partition as 100% used.  This affects existing supported file
    systems EXFAT, F2FS, MINIX and UFS and the new basic supported ones too,
    all for which GParted can't read the file system usage.
    
    When preparing the working new_partition object in the Copy / Paste
    dialog, the maths for the known file system usage happened to convert
    the figures of used = -1 and unused = -1 into set_sector_usage(-1, 0).
    Those values passed to set_sector_usage() mean unable to query the file
    system size so assume it fills the partition and unused is 0, hence 100%
    used.
    
    Fix this by specifically handling the copying of file systems with
    unknown usage, setting the pasted file system usage to unknown too,
    used = -1 and unused = -1.
    
    Closes !13 - Support copying and moving of unsupported partition content

 src/Dialog_Partition_Copy.cc | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
---
diff --git a/src/Dialog_Partition_Copy.cc b/src/Dialog_Partition_Copy.cc
index 0b7037c9..f3aa8ce9 100644
--- a/src/Dialog_Partition_Copy.cc
+++ b/src/Dialog_Partition_Copy.cc
@@ -118,14 +118,24 @@ void Dialog_Partition_Copy::set_data( const Partition & selected_partition, cons
        new_partition->inside_extended = selected_partition.inside_extended;
        new_partition->type            = selected_partition.inside_extended ? TYPE_LOGICAL : TYPE_PRIMARY;
        new_partition->sector_size     = selected_partition.sector_size;
-       //Handle situation where src sector size is smaller than dst sector size and an additional partial 
dst sector is required.
-       new_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 ) ;
+       if ( copied_partition.sector_usage_known() )
+       {
+               // Handle situation where src sector size is smaller than dst sector size
+               // and an additional partial dst sector is required.
+               Byte_Value src_fs_bytes     = ( copied_partition.sectors_used + 
copied_partition.sectors_unused ) *
+                                             copied_partition.sector_size;
+               Byte_Value src_unused_bytes = copied_partition.sectors_unused * copied_partition.sector_size;
+               Sector dst_fs_sectors       = ( src_fs_bytes + selected_partition.sector_size - 1 ) /
+                                             selected_partition.sector_size;
+               Sector dst_unused_sectors   = ( src_unused_bytes + selected_partition.sector_size - 1 ) /
+                                             selected_partition.sector_size;
+               new_partition->set_sector_usage( dst_fs_sectors, dst_unused_sectors );
+       }
+       else
+       {
+               // FS usage of src is unknown so set dst usage unknown too.
+               new_partition->set_sector_usage( -1, -1 );
+       }
 
        this ->show_all_children() ;
 }


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