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
This commit is contained in:
Mike Fleetwood 2021-08-10 20:16:33 +01:00 committed by Curtis Gedak
parent a87ae479c7
commit 5bede18e58
1 changed files with 12 additions and 4 deletions

View File

@ -147,19 +147,27 @@ void Mount_Info::read_mountpoints_from_file( const Glib::ustring & filename, Mou
Glib::ustring uuid = Utils::regexp_label( node, "^UUID=(.*)" ); Glib::ustring uuid = Utils::regexp_label( node, "^UUID=(.*)" );
if ( ! uuid.empty() ) 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=(.*)" ); Glib::ustring label = Utils::regexp_label( node, "^LABEL=(.*)" );
if ( ! label.empty() ) 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 ); endmntent( fp );
} }
void Mount_Info::add_mountpoint_entry( MountMapping & map, void Mount_Info::add_mountpoint_entry( MountMapping & map,
Glib::ustring & node, Glib::ustring & node,
Glib::ustring & mountpoint, Glib::ustring & mountpoint,