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 get_all_mountpoints(); static const std::vector & get_mounted_mountpoints( const Glib::ustring & path ); static const std::vector & 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 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 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() ;