[gparted] Implement usage reporting of active encrypted swap partitions (#771670)



commit 3966cc3e6f6d7fefcf786ddb033973d4a8b8fdfb
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Wed Sep 14 14:18:17 2016 +0100

    Implement usage reporting of active encrypted swap partitions (#771670)
    
    GParted does not show the usage of active encrypted swap partitions,
    instead showing partition warning "Unable to read the contents of this
    file system! ...".  OS setup:
    
        # ls -l /dev/mapper/sdb4_crypt /dev/dm-3
        brw-rw----. 1 root disk 253, 3 Sep 14 07:26 /dev/dm-3
        lrwxrwxrwx. 1 root root      7 Sep 14 07:26 /dev/mapper/sdb4_crypt -> ../dm-3
        # mkswap -L encrypted_swap /dev/mapper/sdb4_crypt
        # swapon /dev/mapper/sdb4_crypt
        # cat /proc/swaps
        Filename                        Type        Size    Used    Priority
        /dev/sda2                       partition   2097148 237632  -1
        /dev/dm-3                       partition   1046524 0       -2
    
    This is because the code was performing a string compare between the
    canonical /dev/mapper/sdb4_crypt name GParted is using and the /dev/dm-3
    name reported by the kernel via /proc/swaps.  Fix by creating
    BlockSpecial objects from the names and compare those so that comparison
    is done correctly using major, minor numbers.
    
    Bug 771670 - Usage of active encrypted swap is not shown

 src/linux_swap.cc |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
---
diff --git a/src/linux_swap.cc b/src/linux_swap.cc
index 9c513ff..e5ac623 100644
--- a/src/linux_swap.cc
+++ b/src/linux_swap.cc
@@ -17,6 +17,7 @@
  
  
 #include "../include/linux_swap.h"
+#include "../include/BlockSpecial.h"
 #include "../include/Partition.h"
 
 #include <cerrno>
@@ -79,13 +80,13 @@ void linux_swap::set_used_sectors( Partition & partition )
                std::ifstream input( "/proc/swaps" ) ;
                if ( input )
                {
-                       Glib::ustring path = partition .get_path() ;
-                       Glib::ustring::size_type path_len = path.length() ;
+                       BlockSpecial bs_path = BlockSpecial( partition.get_path() );
                        while ( getline( input, line ) )
                        {
-                               if ( line .substr( 0, path_len ) == path )
+                               Glib::ustring filename = Utils::regexp_label( line, "^([[:graph:]]+)" );
+                               if ( bs_path == BlockSpecial( filename ) )
                                {
-                                       sscanf( line.substr( path_len ).c_str(), " %*s %*d %lld", &N );
+                                       sscanf( line.c_str(), "%*s %*s %*d %lld", &N );
                                        break ;
                                }
                        }


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