[gparted] Load unresolved UUID= and LABEL= refs into Mount_Info cache (#162)



commit 5bede18e580af255fb3e559b3233b644f726e7de
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Tue Aug 10 20:16:33 2021 +0100

    Load unresolved UUID= and LABEL= refs into Mount_Info cache (#162)
    
    ISSUE DETAILS
    
    GParted no longer enables Partition > Mount on, for unmounted encrypted
    file systems listed in /etc/fstab.
    
    Steps to reproduce:
    
    1. Create LUKS mapping and open.
       # cryptsetup luksFormat /dev/sdb1 -
       # cryptsetup luksOpen /dev/sdb1 sdb1_crypt
    
    2. Create any file system.
       # mkfs.ext4 /dev/mapper/sdb1_crypt
       # uuid=`blkid -o value -s UUID /dev/mapper/sdb1_crypt`
    
    3. Add /etc/fstab entry.
       # mkdir /mnt/1
       # echo "UUID=$uuid /mnt/1 ext4 defaults 0 0" >> /etc/fstab
    
    4. Run GParted and try Partition > Mount on.
    
    With GParted >= 1.3 no mount point is available.  With GParted <= 1.2
    mount point /mnt/1 is available.
    
    EXPLANATION
    
    Up until GParted 1.2.0 it worked like this:
    1. Ran blkid and loaded the details for every file system into the
       FS_Info cache.  This included results for file systems in open LUKS
       mappings, such as /dev/mapper/sdb1_crypt in the above example.
    2. Read /etc/fstab, resolved UUID= and LABEL= references into block
       device names and added those into the Mount_Info cache.
    3. Looped through all partitions adding mount points known by the
       Mount_Info cache.
    
    After the changes for issue #131 "GParted hangs when non-named device is
    hung" and issue #148 "Encrypted file systems are no longer recognised"
    it works like this instead:
    1. Runs blkid for specified devices and partitions only and loads file
       system details into the FS_Info cache.  Does not include open LUKS
       mappings so no results for those file systems.
    2. Loading of /etc/fstab into the Mount_Info cache is unable to resolve
       UUID= and LABEL= references for file systems in LUKS mappings, so
       they aren't included.
    3. No mount points known for encrypted file systems.
    
    Note that currently when an encrypted file system is added into the data
    model it extends the FS_Info cache <2>, but this is after the Mount_Info
    cache has been loaded <1>.  Call flow is like this:
    
      GParted_Core::set_devices_thread()
        FS_Info::clear_cache()
        FS_Info::load_cache_for_paths()
    1>  Mount_Info::load_cache()
        ...
        set_device_from_disk()
          set_device_one_partition() / set_device_partitions()
            set_luks_partition()
              detect_filesystem_in_encryption_mapping()
    2>          FS_Info::load_cache_for_paths()
              ...
              set_mountpoints()
                partition.add_mountpoints(Mount_Info::get_fstab_mountpoints())
    
    SOLUTION
    
    Also save unresolved UUID= and LABEL= references from /etc/fstab into
    the Mount_Info cache.  Then when searching the Mount_Info /etc/fstab
    cache resolve encountered UUID= and LABEL= references.
    
    THIS COMMIT
    
    Also save unresolved UUID= and LABEL= references into the Mount_Info
    cache.
    
    Closes #162 - It is no longer possible to mount a LUKS encrypted file
                  system

 src/Mount_Info.cc | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
---
diff --git a/src/Mount_Info.cc b/src/Mount_Info.cc
index 9ef69f1a..fdf1141f 100644
--- a/src/Mount_Info.cc
+++ b/src/Mount_Info.cc
@@ -147,19 +147,27 @@ void Mount_Info::read_mountpoints_from_file( const Glib::ustring & filename, Mou
 
                Glib::ustring uuid = Utils::regexp_label( node, "^UUID=(.*)" );
                if ( ! uuid.empty() )
-                       node = FS_Info::get_path_by_uuid( uuid );
+               {
+                       Glib::ustring temp = FS_Info::get_path_by_uuid(uuid);
+                       if (! temp.empty())
+                               node = temp;
+               }
 
                Glib::ustring label = Utils::regexp_label( node, "^LABEL=(.*)" );
                if ( ! label.empty() )
-                       node = FS_Info::get_path_by_label( label );
+               {
+                       Glib::ustring temp = FS_Info::get_path_by_label(label);
+                       if (! temp.empty())
+                               node = temp;
+               }
 
-               if ( ! node.empty() )
-                       add_mountpoint_entry( map, node, mountpoint, parse_readonly_flag( p->mnt_opts ) );
+               add_mountpoint_entry(map, node, mountpoint, parse_readonly_flag(p->mnt_opts));
        }
 
        endmntent( fp );
 }
 
+
 void Mount_Info::add_mountpoint_entry( MountMapping & map,
                                        Glib::ustring & node,
                                        Glib::ustring & mountpoint,


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