[gparted] Resolve UUID= and LABEL= refs when searching Mount_Info (#162)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Resolve UUID= and LABEL= refs when searching Mount_Info (#162)
- Date: Sat, 14 Aug 2021 16:22:09 +0000 (UTC)
commit 49747f656d40951d3cf81afb6a3d1fe5e0915226
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Tue Aug 10 21:08:06 2021 +0100
Resolve UUID= and LABEL= refs when searching Mount_Info (#162)
Implemented the second half of the solution described in the previous
commit. Resolve UUID= and LABEL= references when searching in the
Mount_Info cache so that mount points of encrypted file systems listed
in /etc/fstab can be found using the later added FS_Info details.
Closes #162 - It is no longer possible to mount a LUKS encrypted file
system
include/Mount_Info.h | 2 +-
src/Mount_Info.cc | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 53 insertions(+), 3 deletions(-)
---
diff --git a/include/Mount_Info.h b/include/Mount_Info.h
index a498e835..7e8fee88 100644
--- a/include/Mount_Info.h
+++ b/include/Mount_Info.h
@@ -66,7 +66,7 @@ private:
MountMapping & map );
static bool have_rootfs_dev( MountMapping & map );
static void read_mountpoints_from_mount_command( MountMapping & map );
- static const MountEntry & find( const MountMapping & map, const Glib::ustring & path );
+ static const MountEntry& find(MountMapping& map, const Glib::ustring& path);
};
} //GParted
diff --git a/src/Mount_Info.cc b/src/Mount_Info.cc
index fdf1141f..5a81276e 100644
--- a/src/Mount_Info.cc
+++ b/src/Mount_Info.cc
@@ -254,12 +254,62 @@ void Mount_Info::read_mountpoints_from_mount_command( MountMapping & map )
}
}
-const MountEntry & Mount_Info::find( const MountMapping & map, const Glib::ustring & path )
+
+const MountEntry& Mount_Info::find(MountMapping& map, const Glib::ustring& path)
{
- MountMapping::const_iterator iter_mp = map.find( BlockSpecial( path ) );
+ BlockSpecial bs_path = BlockSpecial(path);
+
+ // 1) Key look up by path. E.g. BlockSpecial("/dev/sda1").
+ MountMapping::const_iterator iter_mp = map.find(bs_path);
if ( iter_mp != map.end() )
return iter_mp->second;
+ // 2) Not found so iterate over all mount entries resolving UUID= and LABEL=
+ // references; checking after each for the requested mount entry.
+ // (Unresolved UUID= and LABEL= references are added by
+ // read_mountpoints_from_file("/etc/fstab", fstab_info) for open encryption
+ // mappings as the file system details are only added later into the FS_Info
+ // cache by GParted_Core::detect_filesystem_in_encryption_mappings()).
+ std::vector<BlockSpecial> ref_nodes;
+ for (iter_mp = map.begin(); iter_mp != map.end(); ++iter_mp)
+ {
+ if (iter_mp->first.m_name.compare(0, 5, "UUID=") == 0 ||
+ iter_mp->first.m_name.compare(0, 6, "LABEL=") == 0 )
+ {
+ ref_nodes.push_back(iter_mp->first);
+ }
+ }
+ for (unsigned i = 0; i < ref_nodes.size(); i++)
+ {
+ Glib::ustring node;
+ Glib::ustring uuid = Utils::regexp_label(ref_nodes[i].m_name, "^UUID=(.*)");
+ if (! uuid.empty())
+ {
+ Glib::ustring temp = FS_Info::get_path_by_uuid(uuid);
+ if (! temp.empty())
+ node = temp;
+ }
+
+ Glib::ustring label = Utils::regexp_label(ref_nodes[i].m_name, "^LABEL=(.*)");
+ if (! label.empty())
+ {
+ Glib::ustring temp = FS_Info::get_path_by_label(label);
+ if (! temp.empty())
+ node = temp;
+ }
+
+ if (! node.empty())
+ {
+ // Insert new mount entry and delete the old one.
+ map[BlockSpecial(node)] = map[ref_nodes[i]];
+ map.erase(ref_nodes[i]);
+
+ if (BlockSpecial(node) == bs_path)
+ // This resolved mount entry is the one being searched for.
+ return map[bs_path];
+ }
+ }
+
static MountEntry not_mounted = MountEntry();
return not_mounted;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]