[gparted] Make sure that FS_Info cache is loaded for all named paths (#787181)



commit e8f0504b13d98e23e70021f70638184daab228ec
Author: Pali Rohár <pali rohar gmail com>
Date:   Sat Sep 2 18:38:50 2017 +0200

    Make sure that FS_Info cache is loaded for all named paths (#787181)
    
    Naming a file system image file on the command line is shown by GParted
    as unknown.
    
        $ truncate -s 100M /tmp/fat.img
        $ mkfs.vfat /tmp/fat.img
        $ sudo ./gpartedbin /tmp/fat.img
    
    Currently the FS_Info cache is loaded for all devices reported by
    blkid (plus all whole disk devices identified from /proc/partitions even
    if blkid reports nothing).  However file system images named on the
    command line are not queried so GParted can't identify them.
    
    Fix by ensuring that the FS_Info blkid cache is loaded for all named
    devices, including named file system image files.
    
    Note that Mount_Info::load_cache() depends on the contents of the
    FS_Info cache to lookup UUID= and LABEL= device names from /etc/fstab.
    However only file systems in block devices can be mounted like this, and
    never file system image files, so the fact that the cache may be
    extended afterwards by FS_Info::load_cache_for_paths() does not matter.
    
    History
    
    Prior to version 0.22.0, when unpartitioned drive support was added,
    GParted could recognise some file system image files using loop
    partition handling in libparted.  However libparted before version 3.2
    reported the loop partition name as the whole disk device name appended
    with "1" so all the query commands were provided a non-existent name to
    use.  Therefore no file system usage or the label was displayed.
    
    Bug 787181 - Fix detection of file system images

 include/FS_Info.h   |    1 +
 src/FS_Info.cc      |   15 +++++++++++++++
 src/GParted_Core.cc |    5 +++++
 3 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/include/FS_Info.h b/include/FS_Info.h
index d1ecf72..f9fa32f 100644
--- a/include/FS_Info.h
+++ b/include/FS_Info.h
@@ -39,6 +39,7 @@ class FS_Info
 {
 public:
        static void load_cache();
+       static void load_cache_for_paths( const std::vector<Glib::ustring> &device_paths );
        static Glib::ustring get_fs_type( const Glib::ustring & path );
        static Glib::ustring get_label( const Glib::ustring & path, bool & found );
        static Glib::ustring get_uuid( const Glib::ustring & path );
diff --git a/src/FS_Info.cc b/src/FS_Info.cc
index bdcbc7c..4c50a1f 100644
--- a/src/FS_Info.cc
+++ b/src/FS_Info.cc
@@ -54,6 +54,21 @@ void FS_Info::load_cache()
        fs_info_cache_initialized = true;
 }
 
+void FS_Info::load_cache_for_paths( const std::vector<Glib::ustring> &device_paths )
+{
+       initialize_if_required();
+       const BlockSpecial empty_bs = BlockSpecial();
+       for ( unsigned int i = 0 ; i < device_paths.size() ; i ++ )
+       {
+               const FS_Entry & fs_entry = get_cache_entry_by_path( device_paths[i] );
+               if ( fs_entry.path == empty_bs )
+               {
+                       // Run "blkid PATH" and load entry into cache for missing entries.
+                       load_fs_info_cache_extra_for_path( device_paths[i] );
+               }
+       }
+}
+
 // 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 76b6c03..216d519 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -257,6 +257,11 @@ void GParted_Core::set_devices_thread( std::vector<Device> * pdevices )
                }
        }
 
+       // Ensure all named paths have FS_Info blkid cache entries specifically so that
+       // command line named file system image files, which blkid can't otherwise know
+       // about, can be identified.
+       FS_Info::load_cache_for_paths( device_paths );
+
        for ( unsigned int t = 0 ; t < device_paths .size() ; t++ ) 
        {
                /*TO TRANSLATORS: looks like Searching /dev/sda partitions */ 


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