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
This commit is contained in:
Pali Rohár 2017-09-02 18:38:50 +02:00 committed by Mike Fleetwood
parent 9b8e0acf38
commit e8f0504b13
3 changed files with 21 additions and 0 deletions

View File

@ -39,6 +39,7 @@ class FS_Info
{ {
public: public:
static void load_cache(); 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_fs_type( const Glib::ustring & path );
static Glib::ustring get_label( const Glib::ustring & path, bool & found ); static Glib::ustring get_label( const Glib::ustring & path, bool & found );
static Glib::ustring get_uuid( const Glib::ustring & path ); static Glib::ustring get_uuid( const Glib::ustring & path );

View File

@ -54,6 +54,21 @@ void FS_Info::load_cache()
fs_info_cache_initialized = true; 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 // Retrieve the file system type for the path
Glib::ustring FS_Info::get_fs_type( const Glib::ustring & path ) Glib::ustring FS_Info::get_fs_type( const Glib::ustring & path )
{ {

View File

@ -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++ ) for ( unsigned int t = 0 ; t < device_paths .size() ; t++ )
{ {
/*TO TRANSLATORS: looks like Searching /dev/sda partitions */ /*TO TRANSLATORS: looks like Searching /dev/sda partitions */