[gparted] Add is_dev_mounted() to expose core partition is mounted test (#723842)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Add is_dev_mounted() to expose core partition is mounted test (#723842)
- Date: Wed, 30 Jul 2014 17:34:33 +0000 (UTC)
commit a0c0533e3ed24a931ea18c860749303882ae4b33
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Sun Feb 16 13:29:33 2014 +0000
Add is_dev_mounted() to expose core partition is mounted test (#723842)
Add static member function GParted_Core::is_dev_mounted() so that other
modules can determine if a particular partition contains a mounted file
system or not.
Make it a static member function so that it can be called without
needing the gparted_core object. Extend to make the group of
manipulated variables (mount_info, fstab_info) and manipulating
functions (init_maps(), read_mountpoints_from_file(),
read_mountpoints_from_file_swaps(), get_all_mountpoints()) static too.
Bug #723842 - GParted resizes the wrong filesystem (does not pass the
devid to btrfs filesystem resize)
include/GParted_Core.h | 20 +++++++++-----------
src/GParted_Core.cc | 30 ++++++++++++++++++++++++------
src/Win_GParted.cc | 2 +-
3 files changed, 34 insertions(+), 18 deletions(-)
---
diff --git a/include/GParted_Core.h b/include/GParted_Core.h
index 2431bcc..beb11e9 100644
--- a/include/GParted_Core.h
+++ b/include/GParted_Core.h
@@ -57,7 +57,8 @@ public:
const std::vector<FS> & get_filesystems() const ;
const FS & get_fs( GParted::FILESYSTEM filesystem ) const ;
static std::vector<Glib::ustring> get_disklabeltypes() ;
- std::vector<Glib::ustring> get_all_mountpoints() ;
+ static bool is_dev_mounted( const Glib::ustring & path ) ;
+ static std::vector<Glib::ustring> get_all_mountpoints() ;
std::map<Glib::ustring, bool> get_available_flags( const Partition & partition ) ;
Glib::ustring get_libparted_version() ;
Glib::ustring get_thread_status_message() ;
@@ -66,13 +67,14 @@ public:
static bool filesystem_resize_disallowed( const Partition & partition ) ;
private:
//detectionstuff..
- void init_maps() ;
+ static void init_maps() ;
void set_thread_status_message( Glib::ustring msg ) ;
- void read_mountpoints_from_file( const Glib::ustring & filename,
- std::map< Glib::ustring, std::vector<Glib::ustring> > & map ) ;
- void read_mountpoints_from_file_swaps(
- const Glib::ustring & filename,
- std::map< Glib::ustring, std::vector<Glib::ustring> > & map ) ;
+ static void read_mountpoints_from_file( const Glib::ustring & filename,
+ std::map< Glib::ustring,
+ std::vector<Glib::ustring> > & map ) ;
+ static void read_mountpoints_from_file_swaps( const Glib::ustring & filename,
+ std::map< Glib::ustring,
+ std::vector<Glib::ustring> > & map ) ;
Glib::ustring get_partition_path( PedPartition * lp_partition ) ;
void set_device_partitions( Device & device, PedDevice* lp_device, PedDisk* lp_disk ) ;
GParted::FILESYSTEM get_filesystem( PedDevice* lp_device, PedPartition* lp_partition,
@@ -193,10 +195,6 @@ private:
bool probe_devices ;
Glib::ustring thread_status_message; //Used to pass data to show_pulsebar method
Glib::RefPtr<Glib::IOChannel> iocInput, iocOutput; // Used to send data to gpart command
-
- std::map< Glib::ustring, std::vector<Glib::ustring> > mount_info ;
- std::map< Glib::ustring, std::vector<Glib::ustring> > fstab_info ;
- std::map< Glib::ustring, std::vector<Glib::ustring> >::iterator iter_mp ;
};
} //GParted
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index b0cf751..3b3d092 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -62,6 +62,18 @@ std::vector<Glib::ustring> libparted_messages ; //see ped_exception_handler()
namespace GParted
{
+//mount_info - Associative array mapping currently mounted devices to
+// one or more mount points. E.g.
+// mount_info["/dev/sda1"] -> ["/boot"]
+// mount_info["/dev/sda2"] -> [""] (swap)
+// mount_info["/dev/sda3"] -> ["/"]
+//fstab_info - Associative array mapping configured devices to one or
+// more mount points read from /etc/fstab. E.g.
+// fstab_info["/dev/sda1"] -> ["/boot"]
+// fstab_info["/dev/sda3"] -> ["/"]
+static std::map< Glib::ustring, std::vector<Glib::ustring> > mount_info ;
+static std::map< Glib::ustring, std::vector<Glib::ustring> > fstab_info ;
+
GParted_Core::GParted_Core()
{
thread_status_message = "" ;
@@ -836,8 +848,16 @@ std::vector<Glib::ustring> GParted_Core::get_disklabeltypes()
return disklabeltypes ;
}
+//Return whether the device path, such as /dev/sda3, is mounted or not
+bool GParted_Core::is_dev_mounted( const Glib::ustring & path )
+{
+ std::map< Glib::ustring, std::vector<Glib::ustring> >::iterator iter_mp = mount_info .find( path ) ;
+ return iter_mp != mount_info .end() ;
+}
+
std::vector<Glib::ustring> GParted_Core::get_all_mountpoints()
{
+ std::map< Glib::ustring, std::vector<Glib::ustring> >::iterator iter_mp ;
std::vector<Glib::ustring> mountpoints ;
for ( iter_mp = mount_info .begin() ; iter_mp != mount_info .end() ; ++iter_mp )
@@ -892,6 +912,7 @@ void GParted_Core::init_maps()
read_mountpoints_from_file( "/etc/fstab", fstab_info ) ;
//sort the mount points and remove duplicates.. (no need to do this for fstab_info)
+ std::map< Glib::ustring, std::vector<Glib::ustring> >::iterator iter_mp ;
for ( iter_mp = mount_info .begin() ; iter_mp != mount_info .end() ; ++iter_mp )
{
std::sort( iter_mp ->second .begin(), iter_mp ->second .end() ) ;
@@ -1493,6 +1514,7 @@ void GParted_Core::set_mountpoints( std::vector<Partition> & partitions )
partitions[ t ] .filesystem != FS_LINUX_SWSUSPEND
)
{
+ std::map< Glib::ustring, std::vector<Glib::ustring> >::iterator iter_mp ;
if ( partitions[ t ] .busy )
{
#ifndef USE_LIBPARTED_DMRAID
@@ -1572,9 +1594,7 @@ bool GParted_Core::is_busy( FILESYSTEM fstype, const Glib::ustring & path )
{
case FS::GPARTED:
//Search GParted internal mounted partitions map
- iter_mp = mount_info .find( path ) ;
- if ( iter_mp != mount_info .end() )
- busy = true ;
+ busy = is_dev_mounted( path ) ;
break ;
case FS::EXTERNAL:
@@ -1592,9 +1612,7 @@ bool GParted_Core::is_busy( FILESYSTEM fstype, const Glib::ustring & path )
{
//Still search GParted internal mounted partitions map in case an
// unknown file system is mounted
- iter_mp = mount_info .find( path ) ;
- if ( iter_mp != mount_info .end() )
- busy = true ;
+ busy = is_dev_mounted( path ) ;
//Custom checks for recognised but other not-supported file system types
busy |= ( fstype == FS_LINUX_SWRAID && Utils::swraid_member_is_active( path ) ) ;
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index 616c9c5..6c3ac52 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -2041,7 +2041,7 @@ void Win_GParted::activate_format( GParted::FILESYSTEM new_fs )
void Win_GParted::unmount_partition( bool * succes, Glib::ustring * error )
{
- std::vector<Glib::ustring> errors, failed_mountpoints, mountpoints = gparted_core
.get_all_mountpoints() ;
+ std::vector<Glib::ustring> errors, failed_mountpoints, mountpoints =
GParted_Core::get_all_mountpoints() ;
Glib::ustring dummy ;
*succes = true ;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]