[gparted] Make swap usage match figures reported by swapon -s (#742647)



commit 8b45219a2daee714ecd78ab163ff01a39c05d66c
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Fri Jan 9 14:07:25 2015 +0000

    Make swap usage match figures reported by swapon -s (#742647)
    
    GParted reports used figure of active swap space from 4 KiB upwards,
    actually 1 page, where as 'swapon -s' reports figures from 0 upwards.
    This is because GParted is counting the 1 page swap space overhead as
    used space.
    
        # sfdisk -s /dev/sdb1
        262144
        # mkswap /dev/sdb1
        # swapon /dev/sdb1
        # swapon -s
        Filename                Type            Size    Used    Priority
        /dev/sdb1               partition       262140  0       -1
    
    For this case GParted reports used as 4 KiB.
    (ptn size - swap size = 262144 - 262140 = 4)
    
    Instead make GParted report used figure without any overhead from 0
    upwards, matching what 'swapon -s' reports.
    
    Bug 742647 - Swap usage doesn't match figures reported by swapon -s

 src/linux_swap.cc |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/src/linux_swap.cc b/src/linux_swap.cc
index d674848..11f4c72 100644
--- a/src/linux_swap.cc
+++ b/src/linux_swap.cc
@@ -74,7 +74,7 @@ void linux_swap::set_used_sectors( Partition & partition )
 {
        if ( partition .busy )
        {
-               T = -1 ; N = -1 ;
+               N = -1;
                std::string line ;
                std::ifstream input( "/proc/swaps" ) ;
                if ( input )
@@ -85,7 +85,7 @@ void linux_swap::set_used_sectors( Partition & partition )
                        {
                                if ( line .substr( 0, path_len ) == path )
                                {
-                                       sscanf( line .substr( path_len ) .c_str(), " %*s %Ld %Ld", &T, &N ) ;
+                                       sscanf( line.substr( path_len ).c_str(), " %*s %*d %Ld", &N );
                                        break ;
                                }
                        }
@@ -95,9 +95,13 @@ void linux_swap::set_used_sectors( Partition & partition )
                {
                        partition .messages .push_back( "open(\"/proc/swaps\", O_RDONLY): " + Glib::strerror( 
errno ) ) ;
                }
-               if ( T > -1 && N > -1 )
+               if ( N > -1 )
                {
-                       T = Utils::round( T * ( KIBIBYTE / double(partition .sector_size) ) ) ;
+                       // Ignore swap space reported size to ignore 1 page format
+                       // overhead.  Instead use partition size as sectors_fs_size so
+                       // reported used figure for active swap space starts from 0
+                       // upwards, matching what 'swapon -s' reports.
+                       T = partition.get_sector_length();
                        N = Utils::round( N * ( KIBIBYTE / double(partition .sector_size) ) ) ;
                        partition .set_sector_usage( T, T - N ) ;
                }


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