Switch to using struct FS_Limits inside Dialog_Partition_Resize_Move (#787204)

Changes the internal code in Dialog_Partition_Resize_Move to use
fs_limits instead of fs.MIN and fs.MAX.  The limits are still passed
into the constructor via struct FS and it's members .MIN and .MAX but
immediately used to assign to fs_limits.

Bug 787204 - Minimum and maximum size of the UDF partition/disk
This commit is contained in:
Mike Fleetwood 2018-01-12 11:24:11 +00:00 committed by Curtis Gedak
parent 285c24a82a
commit fe7b734792
1 changed files with 31 additions and 29 deletions

View File

@ -28,6 +28,7 @@ Dialog_Partition_Resize_Move::Dialog_Partition_Resize_Move( const FS & fs, const
const PartitionVector & partitions ) const PartitionVector & partitions )
{ {
this ->fs = fs ; this ->fs = fs ;
fs_limits = FS_Limits( fs.MIN, fs.MAX );
set_data( selected_partition, partitions ); set_data( selected_partition, partitions );
} }
@ -176,36 +177,36 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const PartitionVector & p
( fs.online_shrink && new_partition->busy ) ) ( fs.online_shrink && new_partition->busy ) )
{ {
//since some file systems have lower limits we need to check for this //since some file systems have lower limits we need to check for this
if ( min_resize > fs.MIN / new_partition->sector_size ) if ( min_resize > fs_limits.min_size / new_partition->sector_size )
fs.MIN = min_resize * new_partition->sector_size; fs_limits.min_size = min_resize * new_partition->sector_size;
//ensure that minimum size is at least one mebibyte //ensure that minimum size is at least one mebibyte
if ( ! fs .MIN || fs .MIN < MEBIBYTE ) if ( ! fs_limits.min_size || fs_limits.min_size < MEBIBYTE )
fs .MIN = MEBIBYTE ; fs_limits.min_size = MEBIBYTE;
} }
else else
fs.MIN = new_partition->get_byte_length(); {
fs_limits.min_size = new_partition->get_byte_length();
}
//set MAX //set MAX
if ( fs .grow ) if ( fs .grow )
fs .MAX = (TOTAL_MB - MIN_SPACE_BEFORE_MB) * MEBIBYTE ; fs_limits.max_size = (TOTAL_MB - MIN_SPACE_BEFORE_MB) * MEBIBYTE;
else else
fs.MAX = new_partition->get_byte_length(); fs_limits.max_size = new_partition->get_byte_length();
//set values of spinbutton_before //set values of spinbutton_before
if ( ! fixed_start ) if ( ! fixed_start )
{ {
spinbutton_before .set_range( MIN_SPACE_BEFORE_MB spinbutton_before.set_range( MIN_SPACE_BEFORE_MB,
, TOTAL_MB - ceil( fs .MIN / double(MEBIBYTE) ) TOTAL_MB - ceil( fs_limits.min_size / double(MEBIBYTE) ) );
) ;
spinbutton_before .set_value( spinbutton_before .set_value(
Utils::round( Utils::sector_to_unit( previous, new_partition->sector_size, UNIT_MIB ) ) ); Utils::round( Utils::sector_to_unit( previous, new_partition->sector_size, UNIT_MIB ) ) );
} }
//set values of spinbutton_size //set values of spinbutton_size
spinbutton_size .set_range( ceil( fs .MIN / double(MEBIBYTE) ) spinbutton_size.set_range( ceil( fs_limits.min_size / double(MEBIBYTE) ),
, ceil( fs .MAX / double(MEBIBYTE) ) ceil( fs_limits.max_size / double(MEBIBYTE) ) );
) ;
spinbutton_size .set_value( spinbutton_size .set_value(
Utils::round( Utils::sector_to_unit( new_partition->get_sector_length(), new_partition->sector_size, UNIT_MIB ) ) ); Utils::round( Utils::sector_to_unit( new_partition->get_sector_length(), new_partition->sector_size, UNIT_MIB ) ) );
@ -213,17 +214,16 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const PartitionVector & p
Sector after_min = ( ! fs .grow && ! fs .move ) ? next : 0 ; Sector after_min = ( ! fs .grow && ! fs .move ) ? next : 0 ;
spinbutton_after .set_range( spinbutton_after .set_range(
Utils::round( Utils::sector_to_unit( after_min, new_partition->sector_size, UNIT_MIB ) ), Utils::round( Utils::sector_to_unit( after_min, new_partition->sector_size, UNIT_MIB ) ),
TOTAL_MB - MIN_SPACE_BEFORE_MB - ceil( fs .MIN / double(MEBIBYTE) ) ) ; TOTAL_MB - MIN_SPACE_BEFORE_MB - ceil( fs_limits.min_size / double(MEBIBYTE) ) );
spinbutton_after .set_value( spinbutton_after .set_value(
Utils::round( Utils::sector_to_unit( next, new_partition->sector_size, UNIT_MIB ) ) ); Utils::round( Utils::sector_to_unit( next, new_partition->sector_size, UNIT_MIB ) ) );
frame_resizer_base ->set_size_limits( Utils::round( fs .MIN / (MB_PER_PIXEL * MEBIBYTE) ), frame_resizer_base->set_size_limits( Utils::round( fs_limits.min_size / (MB_PER_PIXEL * MEBIBYTE) ),
Utils::round( fs .MAX / (MB_PER_PIXEL * MEBIBYTE) ) ) ; Utils::round( fs_limits.max_size / (MB_PER_PIXEL * MEBIBYTE) ) );
//set contents of label_minmax //set contents of label_minmax
Set_MinMax_Text( ceil( fs .MIN / double(MEBIBYTE) ) Set_MinMax_Text( ceil( fs_limits.min_size / double(MEBIBYTE) ),
, ceil( fs .MAX / double(MEBIBYTE) ) ceil( fs_limits.max_size / double(MEBIBYTE) ) );
) ;
} }
void Dialog_Partition_Resize_Move::Resize_Move_Extended( const PartitionVector & partitions ) void Dialog_Partition_Resize_Move::Resize_Move_Extended( const PartitionVector & partitions )
@ -291,15 +291,13 @@ void Dialog_Partition_Resize_Move::Resize_Move_Extended( const PartitionVector &
} }
//set MIN //set MIN
if ( used == 0 ) if ( used == 0 )
{
//Reasonable minimum of 1 MiB for EBR plus 1 MiB for small partition //Reasonable minimum of 1 MiB for EBR plus 1 MiB for small partition
fs .MIN = MEBIBYTE ; fs_limits.min_size = MEBIBYTE;
}
else else
fs.MIN = used * new_partition->sector_size; fs_limits.min_size = used * new_partition->sector_size;
//set MAX //set MAX
fs .MAX = (TOTAL_MB - MIN_SPACE_BEFORE_MB) * MEBIBYTE ; fs_limits.max_size = (TOTAL_MB - MIN_SPACE_BEFORE_MB) * MEBIBYTE;
dynamic_cast<Frame_Resizer_Extended *>( frame_resizer_base ) -> dynamic_cast<Frame_Resizer_Extended *>( frame_resizer_base ) ->
set_used_start( Utils::round( (first - START) / ( total_length / 500.00 ) ) ) ; set_used_start( Utils::round( (first - START) / ( total_length / 500.00 ) ) ) ;
@ -307,7 +305,9 @@ void Dialog_Partition_Resize_Move::Resize_Move_Extended( const PartitionVector &
//set values of spinbutton_before (we assume there is no fixed start.) //set values of spinbutton_before (we assume there is no fixed start.)
if ( first == 0 ) //no logicals if ( first == 0 ) //no logicals
spinbutton_before .set_range( MIN_SPACE_BEFORE_MB, TOTAL_MB - MIN_SPACE_BEFORE_MB - ceil( fs .MIN / double(MEBIBYTE) ) ) ; spinbutton_before.set_range( MIN_SPACE_BEFORE_MB,
TOTAL_MB - MIN_SPACE_BEFORE_MB - ceil( fs_limits.min_size /
double(MEBIBYTE) ) );
else else
spinbutton_before.set_range( MIN_SPACE_BEFORE_MB, spinbutton_before.set_range( MIN_SPACE_BEFORE_MB,
Utils::round( Utils::sector_to_unit( first - START, Utils::round( Utils::sector_to_unit( first - START,
@ -318,15 +318,17 @@ void Dialog_Partition_Resize_Move::Resize_Move_Extended( const PartitionVector &
new_partition->sector_size, UNIT_MIB ) ) ); new_partition->sector_size, UNIT_MIB ) ) );
//set values of spinbutton_size //set values of spinbutton_size
spinbutton_size .set_range( ceil( fs .MIN / double(MEBIBYTE) ), TOTAL_MB - MIN_SPACE_BEFORE_MB ) ; spinbutton_size.set_range( ceil( fs_limits.min_size / double(MEBIBYTE) ),
TOTAL_MB - MIN_SPACE_BEFORE_MB );
spinbutton_size.set_value( Utils::round( Utils::sector_to_unit( new_partition->get_sector_length(), spinbutton_size.set_value( Utils::round( Utils::sector_to_unit( new_partition->get_sector_length(),
new_partition->sector_size, UNIT_MIB ) ) ); new_partition->sector_size, UNIT_MIB ) ) );
//set values of spinbutton_after //set values of spinbutton_after
if ( first == 0 ) //no logicals if ( first == 0 ) //no logicals
spinbutton_after .set_range( spinbutton_after.set_range( 0, TOTAL_MB -
0, TOTAL_MB - ceil( fs .MIN / double(MEBIBYTE) ) - MIN_SPACE_BEFORE_MB ) ; ceil( fs_limits.min_size / double(MEBIBYTE) ) -
MIN_SPACE_BEFORE_MB );
else else
spinbutton_after.set_range( 0, Utils::round( Utils::sector_to_unit( total_length + START - first - used, spinbutton_after.set_range( 0, Utils::round( Utils::sector_to_unit( total_length + START - first - used,
new_partition->sector_size, new_partition->sector_size,
@ -336,7 +338,7 @@ void Dialog_Partition_Resize_Move::Resize_Move_Extended( const PartitionVector &
new_partition->sector_size, UNIT_MIB ) ) ); new_partition->sector_size, UNIT_MIB ) ) );
//set contents of label_minmax //set contents of label_minmax
Set_MinMax_Text( ceil( fs.MIN / double(MEBIBYTE) ), Set_MinMax_Text( ceil( fs_limits.min_size / double(MEBIBYTE) ),
Utils::round( Utils::sector_to_unit( total_length - MIN_SPACE_BEFORE_MB * (MEBIBYTE / new_partition->sector_size), Utils::round( Utils::sector_to_unit( total_length - MIN_SPACE_BEFORE_MB * (MEBIBYTE / new_partition->sector_size),
new_partition->sector_size, UNIT_MIB ) ) ); new_partition->sector_size, UNIT_MIB ) ) );
} }