Stop showing duplicate mount points for unmounted encrypted file systems (#771323)

Have an unmounted file system within an open encrypted mapping and an
entry in /etc/fstab for the file system like this:

    # lsblk
    NAME           MAJ:MIN RM   SIZE RO TYPE   MOUNTPOINT
    ...
    sdb              8:16   0     8G  0 disk
    +-sdb1           8:17   0     1G  0 part
      +-sdb1_crypt 253:0    0  1022M  0 crypt
    # blkid | grep sdb1
    /dev/sdb1: TYPE="crypto_LUKS" ...
    /dev/mapper/sdb1_crypt: TYPE="ext4" ...
    # ls -l /dev/mapper/sdb1_crypt /dev/dm-0
    brw-rw----. 1 root disk 253, 0 Sep 12 19:09 /dev/dm-0
    lrwxrwxrwx. 1 root root      7 Sep 12 19:09 /dev/mapper/sdb1_crypt -> ../dm-0
    # grep sdb1 /etc/fstab
    /dev/mapper/sdb1_crypt   /mnt/1   ext4   defaults    0 0

The mount point will be shown twice for the partition:
    /mnt/1, /mnt/1

This is because add_node_and_mountpoint() adds two entries for both the
symbolic and real block special names:
    map["/dev/mapper/sdb1_crypt"] = ["/mnt/1"]
    map["/dev/dm-0"]              = ["/mnt/1"]
This was needed for the old code which used string compare to match
block devices so that the mount point could be looked up by either name.
However since bug 767842 introduced major, minor number comparison it
became unnecessary.  As both names refer to the same device the mount
point gets added twice to the same entry.  Hence display of the double
mount.
    map[BlockSpecial{"/dev/mapper/sdb1_crypt", 253, 0}] =
                                                    ["/mnt/1", "/mnt/1"]

It is always going to be the case that the symbolic link and real block
special names have the same major, minor numbers.  That was the
requirement of the BlockSpecial class and the reason for using stat() to
lookup the numbers.  Therefore adding entries for both names will always
add duplicate entries.  Fix by stop using realpath() to lookup the real
name and adding the duplicate entry.

Introduced by:
    a800ca8b68
    Add BlockSpecial into mount_info and fstab_info (#767842)

Bug 771323 - GParted is showing duplicate mount points for unmounted
             encrypted file systems
This commit is contained in:
Mike Fleetwood 2016-09-12 19:58:36 +01:00 committed by Curtis Gedak
parent 7a2e95c4b5
commit 8c870cf72f
1 changed files with 1 additions and 15 deletions

View File

@ -144,23 +144,9 @@ void Mount_Info::add_node_and_mountpoint( MountMapping & map,
Glib::ustring & node,
Glib::ustring & mountpoint )
{
// Only add node path(s) if mount point exists
// Only add node path if mount point exists
if ( file_test( mountpoint, Glib::FILE_TEST_EXISTS ) )
{
map[BlockSpecial( node )].push_back( mountpoint );
// If node is a symbolic link (e.g., /dev/root)
// then find real path and add entry too
if ( file_test( node, Glib::FILE_TEST_IS_SYMLINK ) )
{
char * rpath = realpath( node.c_str(), NULL );
if ( rpath != NULL )
{
map[BlockSpecial( rpath )].push_back( mountpoint );
free( rpath );
}
}
}
}
void Mount_Info::read_mountpoints_from_file_swaps( const Glib::ustring & filename, MountMapping & map )