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
This commit is contained in:
Mike Fleetwood 2018-09-17 15:22:16 +01:00 committed by Curtis Gedak
parent 441b39347a
commit c82883d6a7
5 changed files with 20 additions and 0 deletions

View File

@ -49,6 +49,8 @@ public:
static void load_cache(); static void load_cache();
static bool is_dev_mounted( const Glib::ustring & path ); static bool is_dev_mounted( const Glib::ustring & path );
static bool is_dev_mounted( const BlockSpecial & bs ); 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 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_mounted_mountpoints( const Glib::ustring & path );
static const std::vector<Glib::ustring> & get_fstab_mountpoints( const Glib::ustring & path ); static const std::vector<Glib::ustring> & get_fstab_mountpoints( const Glib::ustring & path );

View File

@ -165,6 +165,7 @@ public:
Sector significant_threshold; //Threshold from intrinsic to significant unallocated sectors Sector significant_threshold; //Threshold from intrinsic to significant unallocated sectors
bool inside_extended; bool inside_extended;
bool busy; bool busy;
bool fs_readonly; // Is the file system mounted read-only?
std::vector<Glib::ustring> flags ; std::vector<Glib::ustring> flags ;
PartitionVector logicals; PartitionVector logicals;

View File

@ -1673,6 +1673,7 @@ bool GParted_Core::set_mountpoints_helper( Partition & partition, const Glib::us
if ( mountpoints.size() ) if ( mountpoints.size() )
{ {
partition.add_mountpoints( mountpoints ); partition.add_mountpoints( mountpoints );
partition.fs_readonly = Mount_Info::is_dev_mounted_readonly( search_path );
return true ; return true ;
} }

View File

@ -93,6 +93,21 @@ bool Mount_Info::is_dev_mounted( const BlockSpecial & bs )
return iter_mp != mount_info.end(); 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() std::vector<Glib::ustring> Mount_Info::get_all_mountpoints()
{ {
MountMapping::const_iterator iter_mp; MountMapping::const_iterator iter_mp;

View File

@ -52,6 +52,7 @@ void Partition::Reset()
sector_size = 0 ; sector_size = 0 ;
fs_block_size = -1; fs_block_size = -1;
inside_extended = busy = strict_start = false ; inside_extended = busy = strict_start = false ;
fs_readonly = false;
logicals .clear() ; logicals .clear() ;
flags .clear() ; flags .clear() ;
mountpoints .clear() ; mountpoints .clear() ;