[gparted] Combine duplicate code for fat16/32



commit 519af1a7c08667c53e602012e2a49cbf5301f40c
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Tue May 14 09:30:55 2013 +0100

    Combine duplicate code for fat16/32
    
    There was virtually no difference between the separate modules for fat16
    and fat32.  Remove module fat32 and patch fat16 to serve both file
    system subtypes.  This is equivalent to what was previously done for
    ext[234] by commit:
    
        38dc55d49c062cb8e93c797f9bf166d3abc3456e
        Combine duplicate code for ext[234]

 include/Makefile.am |    1 -
 include/fat16.h     |    3 +
 include/fat32.h     |   46 ----------
 src/GParted_Core.cc |    5 +-
 src/Makefile.am     |    1 -
 src/fat16.cc        |   20 +++--
 src/fat32.cc        |  234 ---------------------------------------------------
 7 files changed, 19 insertions(+), 291 deletions(-)
---
diff --git a/include/Makefile.am b/include/Makefile.am
index d711674..661b4b8 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -42,7 +42,6 @@ EXTRA_DIST = \
        ext2.h                          \
        f2fs.h                          \
        fat16.h                         \
-       fat32.h                         \
        hfs.h                           \
        hfsplus.h                       \
        i18n.h                          \
diff --git a/include/fat16.h b/include/fat16.h
index bfc4be4..5dc28af 100644
--- a/include/fat16.h
+++ b/include/fat16.h
@@ -27,7 +27,9 @@ namespace GParted
 
 class fat16 : public FileSystem
 {
+       const enum FILESYSTEM specific_type ;
 public:
+       fat16( enum FILESYSTEM type ) : specific_type( type ) {} ;
        const Glib::ustring get_custom_text( CUSTOM_TEXT ttype, int index = 0 ) ;
        FS get_filesystem_support() ;
        void set_used_sectors( Partition & partition ) ;
@@ -38,6 +40,7 @@ public:
        bool create( const Partition & new_partition, OperationDetail & operationdetail ) ;
        bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
 
+private:
        static const Glib::ustring Change_UUID_Warning [] ;
 };
 
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 327a9bd..0d1aed3 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -35,7 +35,6 @@
 #include "../include/ext2.h"
 #include "../include/f2fs.h"
 #include "../include/fat16.h"
-#include "../include/fat32.h"
 #include "../include/linux_swap.h"
 #include "../include/lvm2_pv.h"
 #include "../include/reiserfs.h"
@@ -105,8 +104,8 @@ void GParted_Core::find_supported_filesystems()
        FILESYSTEM_MAP[ FS_EXT3 ]       = new ext2( FS_EXT3 ) ;
        FILESYSTEM_MAP[ FS_EXT4 ]       = new ext2( FS_EXT4 ) ;
        FILESYSTEM_MAP[ FS_F2FS ]       = new f2fs() ;
-       FILESYSTEM_MAP[ FS_FAT16 ]      = new fat16() ;
-       FILESYSTEM_MAP[ FS_FAT32 ]      = new fat32() ;
+       FILESYSTEM_MAP[ FS_FAT16 ]      = new fat16( FS_FAT16 ) ;
+       FILESYSTEM_MAP[ FS_FAT32 ]      = new fat16( FS_FAT32 ) ;
        FILESYSTEM_MAP[ FS_HFS ]        = new hfs() ;
        FILESYSTEM_MAP[ FS_HFSPLUS ]    = new hfsplus() ;
        FILESYSTEM_MAP[ FS_JFS ]        = new jfs() ;
diff --git a/src/Makefile.am b/src/Makefile.am
index 313f895..138ccb7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -53,7 +53,6 @@ gpartedbin_SOURCES = \
        ext2.cc                         \
        f2fs.cc                         \
        fat16.cc                        \
-       fat32.cc                        \
        hfs.cc                          \
        hfsplus.cc                      \
        jfs.cc                          \
diff --git a/src/fat16.cc b/src/fat16.cc
index 18f7d83..a194a15 100644
--- a/src/fat16.cc
+++ b/src/fat16.cc
@@ -61,12 +61,12 @@ const Glib::ustring fat16::get_custom_text( CUSTOM_TEXT ttype, int index )
 FS fat16::get_filesystem_support()
 {
        FS fs ;
-       fs .filesystem = GParted::FS_FAT16 ;
+       fs .filesystem = specific_type ;
                
        // hack to disable silly mtools warnings
        setenv( "MTOOLS_SKIP_CHECK", "1", 0 );
 
-       //find out if we can create fat16 file systems
+       //find out if we can create fat file systems
        if ( ! Glib::find_program_in_path( "mkdosfs" ) .empty() )
                fs .create = GParted::FS::EXTERNAL ;
        
@@ -99,9 +99,16 @@ FS fat16::get_filesystem_support()
        fs .copy = GParted::FS::GPARTED ;
        fs .online_read = FS::GPARTED ;
 
-       fs .MIN = 16 * MEBIBYTE ;
-       fs .MAX = (4096 - 1) * MEBIBYTE ;  //Maximum seems to be just less than 4096 MiB
-       
+       if ( fs .filesystem == FS_FAT16 )
+       {
+               fs .MIN = 16 * MEBIBYTE ;
+               fs .MAX = (4096 - 1) * MEBIBYTE ;  //Maximum seems to be just less than 4096 MiB
+       }
+       else //FS_FAT32
+       {
+               fs .MIN = 33 * MEBIBYTE ; //Smaller file systems will cause windows scandisk to fail.
+       }
+
        return fs ;
 }
 
@@ -227,7 +234,8 @@ bool fat16::write_uuid( const Partition & partition, OperationDetail & operation
 
 bool fat16::create( const Partition & new_partition, OperationDetail & operationdetail )
 {
-       return ! execute_command( "mkdosfs -F16 -v -I -n \"" + new_partition .get_label() +
+       Glib::ustring fat_size = specific_type == FS_FAT16 ? "16" : "32" ;
+       return ! execute_command( "mkdosfs -F" + fat_size + " -v -I -n \"" + new_partition .get_label() +
                                  "\" " + new_partition .get_path(),
                                  operationdetail,
                                  false,


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