[gparted/ro-mount: 6/8] Add and set read-only mount flag in the Partition object (#10)



commit c82883d6a7505a1eaf422662d8d82260b1313d82
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Mon Sep 17 15:22:16 2018 +0100

    Add and set read-only mount flag in the Partition object (#10)
    
    Set the partition read-only mount flag at the same time as setting the
    file system mount points.
    
    Closes #10 - Gparted fails to resize btrfs partition that is mounted
                 read-only

 include/Mount_Info.h |  2 ++
 include/Partition.h  |  1 +
 src/GParted_Core.cc  |  1 +
 src/Mount_Info.cc    | 15 +++++++++++++++
 src/Partition.cc     |  1 +
 5 files changed, 20 insertions(+)
---
diff --git a/include/Mount_Info.h b/include/Mount_Info.h
index f3d2ca1b..a498e835 100644
--- a/include/Mount_Info.h
+++ b/include/Mount_Info.h
@@ -49,6 +49,8 @@ public:
        static void load_cache();
        static bool is_dev_mounted( const Glib::ustring & path );
        static bool is_dev_mounted( const BlockSpecial & bs );
+       static bool is_dev_mounted_readonly( const Glib::ustring & path );
+       static bool is_dev_mounted_readonly( const BlockSpecial & bs );
        static std::vector<Glib::ustring> get_all_mountpoints();
        static const std::vector<Glib::ustring> & get_mounted_mountpoints( const Glib::ustring & path );
        static const std::vector<Glib::ustring> & get_fstab_mountpoints( const Glib::ustring & path );
diff --git a/include/Partition.h b/include/Partition.h
index 6322210e..da2dac2b 100644
--- a/include/Partition.h
+++ b/include/Partition.h
@@ -165,6 +165,7 @@ public:
        Sector significant_threshold;  //Threshold from intrinsic to significant unallocated sectors
        bool inside_extended;
        bool busy;
+       bool fs_readonly;  // Is the file system mounted read-only?
        std::vector<Glib::ustring> flags ;
 
        PartitionVector logicals;
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 8b33eed3..88036405 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -1673,6 +1673,7 @@ bool GParted_Core::set_mountpoints_helper( Partition & partition, const Glib::us
        if ( mountpoints.size() )
        {
                partition.add_mountpoints( mountpoints );
+               partition.fs_readonly = Mount_Info::is_dev_mounted_readonly( search_path );
                return true ;
        }
 
diff --git a/src/Mount_Info.cc b/src/Mount_Info.cc
index 50e6dca6..0981c5e6 100644
--- a/src/Mount_Info.cc
+++ b/src/Mount_Info.cc
@@ -93,6 +93,21 @@ bool Mount_Info::is_dev_mounted( const BlockSpecial & bs )
        return iter_mp != mount_info.end();
 }
 
+// Return whether the device path, such as /dev/sda3, is mounted read-only or not
+bool Mount_Info::is_dev_mounted_readonly( const Glib::ustring & path )
+{
+       return is_dev_mounted_readonly( BlockSpecial( path ) );
+}
+
+// Return whether the BlockSpecial object, such as {"/dev/sda3", 8, 3}, is mounted read-only or not
+bool Mount_Info::is_dev_mounted_readonly( const BlockSpecial & bs )
+{
+       MountMapping::const_iterator iter_mp = mount_info.find( bs );
+       if ( iter_mp == mount_info.end() )
+               return false;
+       return iter_mp->second.readonly;
+}
+
 std::vector<Glib::ustring> Mount_Info::get_all_mountpoints()
 {
        MountMapping::const_iterator iter_mp;
diff --git a/src/Partition.cc b/src/Partition.cc
index 71f59e1e..13058772 100644
--- a/src/Partition.cc
+++ b/src/Partition.cc
@@ -52,6 +52,7 @@ void Partition::Reset()
        sector_size = 0 ;
        fs_block_size = -1;
        inside_extended = busy = strict_start = false ;
+       fs_readonly = false;
        logicals .clear() ;
        flags .clear() ;
        mountpoints .clear() ;


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