[gparted] Fix BlockSpecial comparison (#771670)



commit 253c4d641687f21a4656af0926af18371d47d654
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Wed Oct 5 10:49:45 2016 +0100

    Fix BlockSpecial comparison (#771670)
    
    Found that in some cases usage of active encrypted swap was not working,
    but only for the first encrypted swap partition.  This only failed on
    the first Device Mapper device, dm-0:
    
        # ls -l /dev/mapper/ /dev/dm-*
        brw-rw---- 1 root disk 254, 0 Oct  4 20:58 /dev/dm-0
        brw-rw---- 1 root disk 254, 1 Oct  4 20:58 /dev/dm-1
    
        /dev/mapper/:
        total 0
        crw------- 1 root root 10,236 Oct  4 19:48 control
        lrwxrwxrwx 1 root root      7 Oct  4 20:58 sdb1_crypt -> ../dm-0
        lrwxrwxrwx 1 root root      7 Oct  4 20:58 sdb2_crypt -> ../dm-1
    
        # cat /proc/swaps
        Filename                        Type        Size    Used    Priority
        /dev/sda1                       partition   1524732 92356   -1
        /dev/dm-0                       partition   1046524 0       -2
        /dev/dm-1                       partition   1046524 0       -3
    
    Was failing because the minor number of dm-0 was 0, causing BlockSpecial
    operator==() to fall back to name comparison rather than major, minor
    number, and GParted name /dev/mapper/sdb1_crypt doesn't match /dev/dm-0.
    
    Found on openSUSE and Ubuntu which don't use LVM by default and don't
    already have dm-0 used as an LVM Logical Volume which GParted doesn't
    support.
    
    The LINUX ALLOCATED DEVICES document [1] says block special device 0, 0
    (major, minor) is not used "reserved as null device number".   (Not to
    be confused with 1, 3 /dev/null the Null device).  All other
    non-negative pairs are valid block special device numbers.  Therefore
    update BlockSpecial operator==() accordingly; compare by major, minor
    number when either is greater than 0 falling back to string compare
    otherwise.  This still fits in with the BlockSpecial() constructor using
    major, minor numbers 0, 0 to represent plain files.
    
    [1] LINUX ALLOCATED DEVICES
        https://www.kernel.org/doc/Documentation/devices.txt
    
    Bug 771670 - Usage of active encrypted swap is not shown

 src/BlockSpecial.cc |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
---
diff --git a/src/BlockSpecial.cc b/src/BlockSpecial.cc
index 2481e02..e8e11eb 100644
--- a/src/BlockSpecial.cc
+++ b/src/BlockSpecial.cc
@@ -91,7 +91,7 @@ void BlockSpecial::register_block_special( const Glib::ustring & name,
 
 bool operator==( const BlockSpecial & lhs, const BlockSpecial & rhs )
 {
-       if ( lhs.m_major > 0UL && lhs.m_minor > 0UL )
+       if ( lhs.m_major > 0UL || lhs.m_minor > 0UL )
                // Match block special files by major, minor device numbers.
                return lhs.m_major == rhs.m_major && lhs.m_minor == rhs.m_minor;
        else


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