From 1e813d83a5088d3afaaac96dd1bacba3d146f282 Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Mon, 29 Mar 2021 20:31:48 +0100 Subject: [PATCH] Make FS_Info (blkid) cache incrementally loadable (#148) Since changes for issue #131 "GParted hangs when non-named device is hung" FS_Info cache is initialised, cleared and loaded via one call to load_cache_for_paths(). It runs blkid for named or found disk devices and associated found partitions from /proc/partitions, rather than running blkid and letting it report for all block devices. To avoid the possibility of using blkid on an encryption mapping on a non-specified and possibly hung block device GParted can't just specify all encryption mappings. Instead only encryption mappings which belong to the above identified block devices should be probed. That requires identifying LUKS encryption data in the block devices first so will require subsequently loading additional data into the FS_Info cache and running blkid again. To accommodate this make the FS_Info cache incrementally loadable, rather than doing everything in a single call to load_cache_for_paths(). Have a separate clear_cache() call which initialises and clears the cache and make load_cache_for_paths() just run blkid and insert data for the named paths. Closes 148 - Encrypted file systems are no longer recognised --- include/FS_Info.h | 1 + src/FS_Info.cc | 12 ++++++++++-- src/GParted_Core.cc | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/FS_Info.h b/include/FS_Info.h index 5421ab87..e0a40c19 100644 --- a/include/FS_Info.h +++ b/include/FS_Info.h @@ -38,6 +38,7 @@ struct FS_Entry class FS_Info { public: + static void clear_cache(); static void load_cache_for_paths(const std::vector& paths); static Glib::ustring get_fs_type( const Glib::ustring & path ); static Glib::ustring get_label( const Glib::ustring & path, bool & found ); diff --git a/src/FS_Info.cc b/src/FS_Info.cc index c095db13..4bd22165 100644 --- a/src/FS_Info.cc +++ b/src/FS_Info.cc @@ -51,15 +51,23 @@ bool FS_Info::need_blkid_vfat_cache_update_workaround = true; std::vector FS_Info::fs_info_cache; -void FS_Info::load_cache_for_paths(const std::vector& paths) +void FS_Info::clear_cache() { set_commands_found(); fs_info_cache.clear(); - run_blkid_load_cache(paths); fs_info_cache_initialized = true; } +void FS_Info::load_cache_for_paths(const std::vector& paths) +{ + if (not_initialised_then_error()) + return; + + run_blkid_load_cache(paths); +} + + // Retrieve the file system type for the path Glib::ustring FS_Info::get_fs_type( const Glib::ustring & path ) { diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index 7841868d..afbd116a 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -248,6 +248,7 @@ void GParted_Core::set_devices_thread( std::vector * pdevices ) } // Initialise and load caches needed for content discovery. + FS_Info::clear_cache(); const std::vector& device_and_partition_paths = Proc_Partitions_Info::get_device_and_partition_paths_for(device_paths); FS_Info::load_cache_for_paths(device_and_partition_paths);