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
This commit is contained in:
Mike Fleetwood 2018-01-15 21:25:55 +00:00 committed by Curtis Gedak
parent ae2a8723b5
commit 46bf5a383e
4 changed files with 22 additions and 28 deletions

View File

@ -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,

View File

@ -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

View File

@ -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 )

View File

@ -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 )
{