[gparted] Only enable ext4 64bit feature when required (#766910)



commit cc7e412bc6ec2e27d049438d2a5d4cf2548cbaae
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Sun May 29 13:42:03 2016 +0100

    Only enable ext4 64bit feature when required (#766910)
    
    E2fsprogs version 1.43 always creates 64bit ext4 file systems by default
    [1][2] regardless of the partition size.  Previously it only enabled the
    64bit feature when required on ext4 volumes 16 TiB and larger.  Also
    note that RHEL / CentOS 7 always create 64bit ext4 file systems by
    default from e2fsprogs 1.42.9 [3].
    
    (At least some versions of) Grub 2 and syslinux boot loaders don't work
    with 64bit ext4 file systems [4][5][6].  For maximum boot loader
    compatibility make GParted implement what mke2fs previously did, only
    setting the 64bit feature on volumes 16 TiB and larger and clearing it
    otherwise.  Only applied to mkfs.ext4 version 1.42 and later.
    
    [1] Release notes, E2fsprogs 1.43 (May 17, 2016)
        http://e2fsprogs.sourceforge.net/e2fsprogs-release.html#1.43
    
        "Mke2fs will now create file systems with the metadata_csum and
        64bit features enabled by default".
    
    [2] http://git.kernel.org/cgit/fs/ext2/e2fsprogs.git/commit/?id=cd27af3ecb83e8fd1e3eaa14994284a1818c7c15
        mke2fs: enable the metadata_csum and 64bit features by default
    
    [3] Comment 20 and 21 in Red Hat bug 1099237
        https://bugzilla.redhat.com/show_bug.cgi?id=1099237#c20
    
        "..., is rhel7 default behavior w.r.t. 64 bit really different from
        upstream ?
    
        Yes it is. This is what we have in RHEL7:
        Patch6: e2fsprogs-1.42.9-enable-64bit-feature-by-default.patch
        it fixed this bz: https://bugzilla.redhat.com/show_bug.cgi?id=982871
        and this is upstream proposal:
        http://www.spinics.net/lists/linux-ext4/msg42294.html";
    
    [4] Grub 2 not working on Slackware with 64bit EXT4
        
http://www.linuxquestions.org/questions/slackware-14/grub-mkconfig-error-in-slackware-current-64-bit-4175580544/
    
    [5] Syslinux not working on Slackware with 64bit EXT4
        
http://www.linuxquestions.org/questions/slackware-14/slackware64-current-5-20-2016-syslinux-booting-and-ext4-formatting-4175580324/
    
    [6] Syslinux not working on RHEL 7 with 64bit EXT4
        Bug 1099237 - rhel7 ext4 defaults to 64 bit, which extlinux can't reliably read
        https://bugzilla.redhat.com/show_bug.cgi?id=1099237
    
    Bug 766910 - Multiple boot loaders don't work on 64bit EXT4 file systems

 include/ext2.h |    4 +++-
 src/ext2.cc    |   31 +++++++++++++++++++++++++++----
 2 files changed, 30 insertions(+), 5 deletions(-)
---
diff --git a/include/ext2.h b/include/ext2.h
index 584bdf2..69302c7 100644
--- a/include/ext2.h
+++ b/include/ext2.h
@@ -41,7 +41,8 @@ class ext2 : public FileSystem
        Glib::ustring tune_cmd;
 public:
        ext2( enum FILESYSTEM type ) : specific_type( type ), dump_cmd( "" ), fsck_cmd( "" ), image_cmd( "" ),
-                                      label_cmd( "" ), mkfs_cmd( "" ), resize_cmd( "" ), tune_cmd( "" ) {};
+                                      label_cmd( "" ), mkfs_cmd( "" ), resize_cmd( "" ), tune_cmd( "" ),
+                                      force_auto_64bit( false ) {};
        FS get_filesystem_support() ;
        void set_used_sectors( Partition & partition ) ;
        void read_label( Partition & partition ) ;
@@ -65,6 +66,7 @@ private:
        void copy_progress( OperationDetail *operationdetail );
 
        Byte_Value fs_block_size;  // Holds file system block size for the copy_progress() callback
+       bool force_auto_64bit;     // Manually setting ext4 64bit feature on creation
 };
 
 } //GParted
diff --git a/src/ext2.cc b/src/ext2.cc
index 0d4486e..dfb9653 100644
--- a/src/ext2.cc
+++ b/src/ext2.cc
@@ -43,15 +43,16 @@ FS ext2::get_filesystem_support()
                fs .create = FS::EXTERNAL ;
                fs .create_with_label = FS::EXTERNAL ;
 
-               // Determine availability of ext4 64bit feature
+               // Determine mkfs.ext4 version specific capabilities.
                bool have_64bit_feature = false;
+               force_auto_64bit = false;
                if ( specific_type == FS_EXT4 )
                {
                        Utils::execute_command( mkfs_cmd + " -V", output, error, true );
                        int mke4fs_major_ver = 0;
                        int mke4fs_minor_ver = 0;
                        int mke4fs_patch_ver = 0;
-                       if ( sscanf( error.c_str(), "mke2fs %d.%d.%d",
+                       if ( sscanf( error.c_str(), "mke%*[24]fs %d.%d.%d",
                                     &mke4fs_major_ver, &mke4fs_minor_ver, &mke4fs_patch_ver ) >= 2 )
                        {
                                // Ext4 64bit feature was added in e2fsprogs 1.42, but
@@ -64,6 +65,17 @@ FS ext2::get_filesystem_support()
                                have_64bit_feature =    ( mke4fs_major_ver > 1 )
                                                     || ( mke4fs_major_ver == 1 && mke4fs_minor_ver > 42 )
                                                     || ( mke4fs_major_ver == 1 && mke4fs_minor_ver == 42 && 
mke4fs_patch_ver >= 9 );
+
+                               // (#766910) E2fsprogs 1.43 creates 64bit ext4 file
+                               // systems by default.  RHEL/CentOS 7 configured e2fsprogs
+                               // 1.42.9 to create 64bit ext4 file systems by default.
+                               // Theoretically this can be done when 64bit feature was
+                               // added in e2fsprogs 1.42.  GParted will re-implement the
+                               // removed mke2fs.conf(5) auto_64-bit_support option to
+                               // avoid the issues with multiple boot loaders not working
+                               // with 64bit ext4 file systems.
+                               force_auto_64bit =    ( mke4fs_major_ver > 1 )
+                                                  || ( mke4fs_major_ver == 1 && mke4fs_minor_ver >= 42 );
                        }
                }
 
@@ -265,8 +277,19 @@ bool ext2::write_uuid( const Partition & partition, OperationDetail & operationd
 
 bool ext2::create( const Partition & new_partition, OperationDetail & operationdetail )
 {
-       return ! execute_command( mkfs_cmd + " -F -L \"" + new_partition.get_filesystem_label() + "\" " +
-                                 new_partition.get_path(),
+       Glib::ustring features;
+       if ( force_auto_64bit )
+       {
+               // (#766910) Manually implement mke2fs.conf(5) auto_64-bit_support option
+               // by setting or clearing the 64bit feature on the command line depending
+               // of the partition size.
+               if ( new_partition.get_byte_length() >= 16 * TEBIBYTE )
+                       features = " -O 64bit";
+               else
+                       features = " -O ^64bit";
+       }
+       return ! execute_command( mkfs_cmd + " -F" + features +
+                                 " -L \"" + new_partition.get_filesystem_label() + "\" " + 
new_partition.get_path(),
                                  operationdetail, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE|EXEC_PROGRESS_STDOUT,
                                  static_cast<StreamSlot>( sigc::mem_fun( *this, &ext2::create_progress ) ) );
 }


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