From e4a8530b1428bbd991d4e5b626377efc287e12b3 Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Sun, 3 Jul 2016 13:25:57 +0100 Subject: [PATCH] Overload is_dev_mounted() function (#767842) Small optimisation which avoids constructing an extra BlockSpecial object when determining if a btrfs member is mounted. Rather than extracting the name from the BlockSpecial object in btrfs::get_mount_device() and re-constructing another BlockSpecial object from that name in GParted_Core::is_dev_mounted(), pass the BlockSpecial object directly. Bug 767842 - File system usage missing when tools report alternate block device names --- include/GParted_Core.h | 1 + src/GParted_Core.cc | 10 ++++++++-- src/btrfs.cc | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/GParted_Core.h b/include/GParted_Core.h index 61a65bdf..ce6490db 100644 --- a/include/GParted_Core.h +++ b/include/GParted_Core.h @@ -61,6 +61,7 @@ public: const FS & get_fs( GParted::FILESYSTEM filesystem ) const ; static std::vector get_disklabeltypes() ; static bool is_dev_mounted( const Glib::ustring & path ) ; + static bool is_dev_mounted( const BlockSpecial & bs ); static std::vector get_all_mountpoints() ; std::map get_available_flags( const Partition & partition ) ; Glib::ustring get_libparted_version() ; diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index ed035f25..6d7bc9dd 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -970,8 +970,14 @@ std::vector GParted_Core::get_disklabeltypes() //Return whether the device path, such as /dev/sda3, is mounted or not bool GParted_Core::is_dev_mounted( const Glib::ustring & path ) { - MountMapping::iterator iter_mp = mount_info.find( BlockSpecial( path ) ); - return iter_mp != mount_info .end() ; + return is_dev_mounted( BlockSpecial( path ) ); +} + +// Return whether the BlockSpecial object, such as {"/dev/sda3", 8, 3}, is mounted or not +bool GParted_Core::is_dev_mounted( const BlockSpecial & bs ) +{ + MountMapping::const_iterator iter_mp = mount_info.find( bs ); + return iter_mp != mount_info.end(); } std::vector GParted_Core::get_all_mountpoints() diff --git a/src/btrfs.cc b/src/btrfs.cc index 60e65513..abee7f04 100644 --- a/src/btrfs.cc +++ b/src/btrfs.cc @@ -462,7 +462,7 @@ Glib::ustring btrfs::get_mount_device( const Glib::ustring & path ) } for ( unsigned int i = 0 ; i < btrfs_dev .members .size() ; i ++ ) - if ( GParted_Core::is_dev_mounted( btrfs_dev.members[i].m_name ) ) + if ( GParted_Core::is_dev_mounted( btrfs_dev.members[i] ) ) return btrfs_dev.members[i].m_name; return "" ; }