[gparted] Extract common code into GParted_Core::get_filesystem_limits() (#787204)



commit 46bf5a383e56ec3478f45cfb2d644140fad829a1
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Mon Jan 15 21:25:55 2018 +0000

    Extract common code into GParted_Core::get_filesystem_limits() (#787204)
    
    There are multiple repetitions of the same code getting a FileSystem
    object, checking for NULL and then calling the file system specific
    get_filesystem_limits().  Extract that into a common function.
    
    GParted_Core::get_filesystem_limits() can't use the file system from the
    passed Partition object because that is the current file system which
    will be different from the intended file system for new and format
    operations.  So would look up the wrong derived FileSystem specific
    object and call the wrong get_filesystem_limits().  Hence still needing
    fstype as a separate parameter to pass the intended file system.
    
    Bug 787204 - Minimum and maximum size of the UDF partition/disk

 include/GParted_Core.h      |    2 ++
 src/Dialog_Partition_New.cc |   12 ++----------
 src/GParted_Core.cc         |   17 ++++++++++++-----
 src/Win_GParted.cc          |   19 ++++++-------------
 4 files changed, 22 insertions(+), 28 deletions(-)
---
diff --git a/include/GParted_Core.h b/include/GParted_Core.h
index e9f9117..d56835a 100644
--- a/include/GParted_Core.h
+++ b/include/GParted_Core.h
@@ -24,6 +24,7 @@
 #include "Partition.h"
 #include "PartitionLUKS.h"
 #include "PartitionVector.h"
+#include "Utils.h"
 
 #include <parted/parted.h>
 #include <vector>
@@ -66,6 +67,7 @@ public:
 
        static FileSystem * get_filesystem_object( FILESYSTEM filesystem );
        static bool supported_filesystem( FILESYSTEM fstype );
+       static FS_Limits get_filesystem_limits( FILESYSTEM fstype, const Partition & partition );
        static bool filesystem_resize_disallowed( const Partition & partition ) ;
        static void insert_unallocated( const Glib::ustring & device_path,
                                        PartitionVector & partitions,
diff --git a/src/Dialog_Partition_New.cc b/src/Dialog_Partition_New.cc
index b7dce44..2610c57 100644
--- a/src/Dialog_Partition_New.cc
+++ b/src/Dialog_Partition_New.cc
@@ -339,11 +339,7 @@ void Dialog_Partition_New::optionmenu_changed( bool type )
        if ( ! type )
        {
                fs = FILESYSTEMS[ optionmenu_filesystem .get_history() ] ;
-
-               FileSystem *filesystem_object = GParted_Core::get_filesystem_object( fs.filesystem );
-               fs_limits = FS_Limits();  // Copy new default no limits struct
-               if ( filesystem_object != NULL )
-                       fs_limits = filesystem_object->get_filesystem_limits( *new_partition );
+               fs_limits = GParted_Core::get_filesystem_limits( fs.filesystem, *new_partition );
 
                if ( fs_limits.min_size < MEBIBYTE )
                        fs_limits.min_size = MEBIBYTE;
@@ -435,11 +431,7 @@ void Dialog_Partition_New::Build_Filesystems_Menu( bool only_unformatted )
 
 Byte_Value Dialog_Partition_New::get_filesystem_min_limit( FILESYSTEM fstype )
 {
-       FileSystem *filesystem_object = GParted_Core::get_filesystem_object( fstype );
-       FS_Limits fs_limits;
-       if ( filesystem_object != NULL )
-               fs_limits = filesystem_object->get_filesystem_limits( *new_partition );
-       return fs_limits.min_size;
+       return GParted_Core::get_filesystem_limits( fstype, *new_partition ).min_size;
 }
 
 } //GParted
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 22345ac..1401c72 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -20,6 +20,7 @@
 #include "CopyBlocks.h"
 #include "BlockSpecial.h"
 #include "DMRaid.h"
+#include "FileSystem.h"
 #include "FS_Info.h"
 #include "LVM2_PV_Info.h"
 #include "LUKS_Info.h"
@@ -31,6 +32,7 @@
 #include "PartitionVector.h"
 #include "Proc_Partitions_Info.h"
 #include "SWRaid_Info.h"
+#include "Utils.h"
 
 #include "btrfs.h"
 #include "exfat.h"
@@ -1866,11 +1868,7 @@ bool GParted_Core::create( Partition & new_partition, OperationDetail & operatio
        }
        else
        {
-               FileSystem *p_filesystem = get_filesystem_object( new_partition.filesystem );
-               FS_Limits fs_limits;
-               if ( p_filesystem != NULL )
-                       fs_limits = p_filesystem->get_filesystem_limits( new_partition );
-
+               FS_Limits fs_limits = get_filesystem_limits( new_partition.filesystem, new_partition );
                success = create_partition( new_partition, operationdetail,
                                            fs_limits.min_size / new_partition.sector_size );
        }
@@ -3784,6 +3782,15 @@ bool GParted_Core::supported_filesystem( FILESYSTEM fstype )
        return get_filesystem_object( fstype ) != NULL;
 }
 
+FS_Limits GParted_Core::get_filesystem_limits( FILESYSTEM fstype, const Partition & partition )
+{
+       FileSystem *p_filesystem = get_filesystem_object( fstype );
+       FS_Limits fs_limits;
+       if ( p_filesystem != NULL )
+               fs_limits = p_filesystem->get_filesystem_limits( partition );
+       return fs_limits;
+}
+
 bool GParted_Core::filesystem_resize_disallowed( const Partition & partition )
 {
        if ( partition .filesystem == FS_LVM2_PV )
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index 00e2fb0..fa71c47 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -27,6 +27,7 @@
 #include "Dialog_FileSystem_Label.h"
 #include "Dialog_Partition_Name.h"
 #include "DialogManageFlags.h"
+#include "GParted_Core.h"
 #include "Mount_Info.h"
 #include "OperationCopy.h"
 #include "OperationCheck.h"
@@ -1797,10 +1798,7 @@ void Win_GParted::activate_resize()
        const Partition & selected_filesystem_ptn = selected_partition_ptr->get_filesystem_partition();
        const FILESYSTEM fstype = selected_filesystem_ptn.filesystem;
        FS fs_cap = gparted_core.get_fs( fstype );
-       const FileSystem *filesystem_object = gparted_core.get_filesystem_object( fstype );
-       FS_Limits fs_limits;
-       if ( filesystem_object != NULL )
-               fs_limits = filesystem_object->get_filesystem_limits( selected_filesystem_ptn );
+       FS_Limits fs_limits = gparted_core.get_filesystem_limits( fstype, selected_filesystem_ptn );
 
        if ( selected_partition_ptr->filesystem == FS_LUKS && selected_partition_ptr->busy )
        {
@@ -1942,11 +1940,9 @@ void Win_GParted::activate_paste()
        {
                if ( ! max_amount_prim_reached() )
                {
-                       const FileSystem *filesystem_object = gparted_core.get_filesystem_object(
-                                                                             
copied_filesystem_ptn.filesystem );
-                       FS_Limits fs_limits;
-                       if ( filesystem_object != NULL )
-                               fs_limits = filesystem_object->get_filesystem_limits( copied_filesystem_ptn );
+                       FS_Limits fs_limits = gparted_core.get_filesystem_limits(
+                                                             copied_filesystem_ptn.filesystem,
+                                                             copied_filesystem_ptn );
 
                        // We don't want the messages, mount points or name of the source
                        // partition for the new partition being created.
@@ -2313,10 +2309,7 @@ void Win_GParted::activate_format( GParted::FILESYSTEM new_fs )
        temp_ptn->status = STAT_FORMATTED;
 
        // Generate minimum and maximum partition size limits for the new file system.
-       const FileSystem *filesystem_object = gparted_core.get_filesystem_object( new_fs );
-       FS_Limits fs_limits;
-       if ( filesystem_object != NULL )
-               fs_limits = filesystem_object->get_filesystem_limits( temp_ptn->get_filesystem_partition() );
+       FS_Limits fs_limits = gparted_core.get_filesystem_limits( new_fs, 
temp_ptn->get_filesystem_partition() );
        bool encrypted = false;
        if ( selected_partition_ptr->filesystem == FS_LUKS && selected_partition_ptr->busy )
        {


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