[gparted/ro-mount: 4/5] Prevent online resizing of file systems mounted read-only (#10)



commit 240775c9152c4c934b34d2515a666f9384826317
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Mon Sep 17 17:20:03 2018 +0100

    Prevent online resizing of file systems mounted read-only (#10)
    
    Resizing a file system mounted read-only fails.  Example:
    
        # mkfs.btrfs /dev/sdb1
        # mount -o ro /dev/sdb1 /mnt/1
    
    In GParted try to resize partition sdb1.  The operation fails like this:
    
        Grow /dev/sdb1 from 512.00 MiB to 1.00 GiB                 (ERROR)
        * calibrate /dev/sdb1                                      (SUCCESS)
        * grow partition from 512.00 MiB to 1.00 GiB               (SUCCESS)
        * grow filesystem to fill the partition                    (ERROR)
          * btrfs filesystem resize 1:max '/mnt/1'                 (ERROR)
              Resize '/mnt/1' of '1:max'
              ERROR: unable to resize '/mnt/1': Read-only file system
    
    See GitLab issue for the testing results of attempting to online resize
    all supporting file system while mounted read-only.  No file system
    allows online resizing while mounted read-only, except for reiserfs.
        Issue #10 - Gparted fails to resize btrfs partition that is mounted
        read-only
        https://gitlab.gnome.org/GNOME/gparted/issues/10
    
    Fix by preventing online resizing of *all* file systems mounted
    read-only, including reiserfs.  Instead of displaying the resize dialog
    in this case, display an information dialog explaining why the partition
    can't be resized.  This is similar to what happens when attempting to
    create a new partition on a disk without a partition table.  The new
    dialog looks like:
    
        (!) Unable to resize read-only file system /dev/sdb1
            The file system can not be resized while it is mounted read-only.
            Either unmount the file system or remount it read-write.
                                                                       [ OK ]
    
    Closes #10 - Gparted fails to resize btrfs partition that is mounted
                 read-only

 include/Win_GParted.h |  1 +
 src/Win_GParted.cc    | 26 +++++++++++++++++++++++++-
 2 files changed, 26 insertions(+), 1 deletion(-)
---
diff --git a/include/Win_GParted.h b/include/Win_GParted.h
index c114e6e1..59a9ab75 100644
--- a/include/Win_GParted.h
+++ b/include/Win_GParted.h
@@ -163,6 +163,7 @@ private:
        void menu_view_harddisk_info();
        void menu_view_operations();
        void show_disklabel_unrecognized( Glib::ustring device_name );
+       void show_resize_readonly( const Glib::ustring & path );
        void show_help_dialog( const Glib::ustring & filename, const Glib::ustring & link_id );
        void menu_help_contents();
        void menu_help_about();
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index 16c09254..8c1efea1 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -1646,6 +1646,22 @@ void Win_GParted::show_disklabel_unrecognized ( Glib::ustring device_name )
        dialog .run() ;
 }
 
+void Win_GParted::show_resize_readonly( const Glib::ustring & path )
+{
+       Gtk::MessageDialog dialog( *this,
+                                  /* TO TRANSLATORS: looks like   Unable to resize read-only file system 
/dev/sda1 */
+                                  String::ucompose( _("Unable to resize read-only file system %1"), path ),
+                                  false,
+                                  Gtk::MESSAGE_INFO,
+                                  Gtk::BUTTONS_OK,
+                                  true );
+       Glib::ustring msg = _("The file system can not be resized while it is mounted read-only.");
+       msg += "\n";
+       msg += _("Either unmount the file system or remount it read-write.");
+       dialog.set_secondary_text( msg );
+       dialog.run();
+}
+
 void Win_GParted::show_help_dialog( const Glib::ustring & filename /* E.g., gparted */
                                   , const Glib::ustring & link_id  /* For context sensitive help */
                                   )
@@ -1825,6 +1841,15 @@ void Win_GParted::activate_resize()
        g_assert( selected_partition_ptr != NULL );  // Bug: Partition callback without a selected partition
        g_assert( valid_display_partition_ptr( selected_partition_ptr ) );  // Bug: Not pointing at a valid 
display partition object
 
+       const Partition & selected_filesystem_ptn = selected_partition_ptr->get_filesystem_partition();
+       if ( selected_filesystem_ptn.busy && selected_filesystem_ptn.fs_readonly )
+       {
+               // Disallow online resizing of *all* file systems mounted read-only as
+               // none of them allow it, except for reiserfs.
+               show_resize_readonly( selected_partition_ptr->get_path() );
+               return;
+       }
+
        PartitionVector * display_partitions_ptr = &display_partitions;
        if ( selected_partition_ptr->type == TYPE_LOGICAL )
        {
@@ -1834,7 +1859,6 @@ void Win_GParted::activate_resize()
        }
 
        Partition * working_ptn;
-       const Partition & selected_filesystem_ptn = selected_partition_ptr->get_filesystem_partition();
        const FSType fstype = selected_filesystem_ptn.filesystem;
        FS fs_cap = gparted_core.get_fs( fstype );
        FS_Limits fs_limits = gparted_core.get_filesystem_limits( fstype, selected_filesystem_ptn );


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