[gparted/psusi/refactor: 20/20] Handle old versions of e2fsprogs without ext4 support



commit a458a6df8b5f9334dd60f08adb05825fd54129f0
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Fri Feb 15 23:02:57 2013 +0000

    Handle old versions of e2fsprogs without ext4 support
    
    Address issues with:
        4fcfc88290874412f144db7070326237567a0ca5
        Combine duplicate code for ext[234]
    
    E2fsprogs 1.39, as found on RHEL/CentOS 5.x, doesn't support ext4 file
    systems.  However GParted assumes it does when the none version specific
    ext commands are found.  Also the interpretation of options to the
    mke2fs command has changed.
    
        # mke2fs -t ext3 /dev/sdb1
        mke2fs 1.39 (29-May-2006)
        mke2fs: invalid blocks count - /dev/sdb1
    
    In e2fsprogs 1.39 this means check for bad blocks and create a file
    system on device "ext3" of size "/dev/sdb1" blocks, not the intended
    create an "ext3" file system on device "/dev/sdb1".  Naturally this
    fails.
    
    1) Re-instate checking for mkfs.ext4 command before enabling any ext4
       features;
    2) Revert to using mkfs.ext[234] for file system creation to avoid
       differing meanings of the -t option.

 include/ext2.h |    3 ++
 src/ext2.cc    |   68 ++++++++++++++++++++++++++++++-------------------------
 2 files changed, 40 insertions(+), 31 deletions(-)
---
diff --git a/include/ext2.h b/include/ext2.h
index 5e4b53b..5c3aa0d 100644
--- a/include/ext2.h
+++ b/include/ext2.h
@@ -39,6 +39,9 @@ public:
        bool create( const Partition & new_partition, OperationDetail & operationdetail ) ;
        bool resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition 
= false ) ;
        bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
+
+private:
+       Glib::ustring mkfs_cmd ;
 };
 
 } //GParted
diff --git a/src/ext2.cc b/src/ext2.cc
index f4628de..b2a34f4 100644
--- a/src/ext2.cc
+++ b/src/ext2.cc
@@ -25,41 +25,48 @@ FS ext2::get_filesystem_support()
 {
        FS fs ;
        fs .filesystem = specific_type;
+       mkfs_cmd = "mkfs." + Utils::get_filesystem_string( specific_type ) ;
 
-       if ( ! Glib::find_program_in_path( "dumpe2fs" ) .empty() )
-               fs .read = FS::EXTERNAL ;
+       //Only enable any functionality if the relevant mkfs.extX command is
+       //  found to ensure that the version of e2fsprogs is new enough to
+       //  support ext4.  Applying to ext2/3 too is OK as relevant mkfs.ext2/3
+       //  commands exist.
+       if ( ! Glib::find_program_in_path( mkfs_cmd ) .empty() )
+       {
+               fs .create = FS::EXTERNAL ;
 
-       if ( ! Glib::find_program_in_path( "tune2fs" ) .empty() ) {
-               fs .read_uuid = FS::EXTERNAL ;
-               fs .write_uuid = FS::EXTERNAL ;
-       }
+               if ( ! Glib::find_program_in_path( "dumpe2fs" ) .empty() )
+                       fs .read = FS::EXTERNAL ;
 
-       if ( ! Glib::find_program_in_path( "e2label" ) .empty() ) {
-               fs .read_label = FS::EXTERNAL ;
-               fs .write_label = FS::EXTERNAL ;
-       }
-       
-       if ( ! Glib::find_program_in_path( "mke2fs" ) .empty() )
-               fs .create = FS::EXTERNAL ;
-       
-       if ( ! Glib::find_program_in_path( "e2fsck" ) .empty() )
-               fs .check = FS::EXTERNAL ;
+               if ( ! Glib::find_program_in_path( "tune2fs" ) .empty() ) {
+                       fs .read_uuid = FS::EXTERNAL ;
+                       fs .write_uuid = FS::EXTERNAL ;
+               }
+
+               if ( ! Glib::find_program_in_path( "e2label" ) .empty() ) {
+                       fs .read_label = FS::EXTERNAL ;
+                       fs .write_label = FS::EXTERNAL ;
+               }
+
+               if ( ! Glib::find_program_in_path( "e2fsck" ) .empty() )
+                       fs .check = FS::EXTERNAL ;
        
-       if ( ! Glib::find_program_in_path( "resize2fs" ) .empty() && fs .check )
-       {
-               fs .grow = FS::EXTERNAL ;
-               
-               if ( fs .read ) //needed to determine a min file system size..
-                       fs .shrink = FS::EXTERNAL ;
-       }
+               if ( ! Glib::find_program_in_path( "resize2fs" ) .empty() && fs .check )
+               {
+                       fs .grow = FS::EXTERNAL ;
 
-       if ( fs .check )
-       {
-               fs .copy = FS::GPARTED ;
-               fs .move = FS::GPARTED ;
-       }
+                       if ( fs .read ) //needed to determine a min file system size..
+                               fs .shrink = FS::EXTERNAL ;
+               }
 
-       fs .online_read = FS::EXTERNAL ;
+               if ( fs .check )
+               {
+                       fs .copy = FS::GPARTED ;
+                       fs .move = FS::GPARTED ;
+               }
+
+               fs .online_read = FS::EXTERNAL ;
+       }
 
        return fs ;
 }
@@ -167,8 +174,7 @@ bool ext2::write_uuid( const Partition & partition, OperationDetail & operationd
 
 bool ext2::create( const Partition & new_partition, OperationDetail & operationdetail )
 {
-       return ! execute_command( "mke2fs -t " +
-                                 Utils::get_filesystem_string( specific_type ) +
+       return ! execute_command( mkfs_cmd +
                                  " -L \"" + new_partition.get_label() + "\" " + new_partition.get_path(),
                                  operationdetail,
                                  false,


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