Fix paste destination partition smaller than source (#639393)

Re-work logic for copying a cylinder aligned partition to a new
MiB aligned partition.  Previously this was partially fixed in
bug #626946 - Destination partition smaller than source partition

Closes Bug #639393 - Redux: Destination partition smaller than
                     source partition
This commit is contained in:
Curtis Gedak 2011-01-15 11:00:42 -07:00
parent d5ab884633
commit 6ae39268f2
2 changed files with 14 additions and 7 deletions

View File

@ -173,13 +173,20 @@ Partition Dialog_Base_Partition::Get_New_Partition( Byte_Value sector_size )
case 0 : selected_partition .alignment = ALIGN_CYLINDER; break; case 0 : selected_partition .alignment = ALIGN_CYLINDER; break;
case 1 : selected_partition .alignment = ALIGN_MEBIBYTE; case 1 : selected_partition .alignment = ALIGN_MEBIBYTE;
{ {
//if start sector not MiB aligned and free space available then add ~1 MiB to partition so requested size is kept //if partition size is not an integer multiple of MiB
Sector diff = ( MEBIBYTE / selected_partition .sector_size ) - ( selected_partition .sector_end + 1 ) % ( MEBIBYTE / selected_partition .sector_size ) ; // or the start or end sectors are not MiB aligned,
if ( diff // and space is available,
&& ( selected_partition .sector_start % (MEBIBYTE / selected_partition .sector_size ) ) > 0 // then add 1 MiB to partition so requested size is kept
&& ( ( selected_partition .sector_end - START +1 + diff ) < total_length ) // after GParted_Core::snap_to_mebibyte method rounding
Sector partition_size = selected_partition .sector_end - selected_partition .sector_start + Sector(1) ;
Sector sectors_in_mib = MEBIBYTE / selected_partition .sector_size ;
if ( ( ( ( partition_size % sectors_in_mib ) > 0 )
|| ( ( selected_partition .sector_start % sectors_in_mib ) > 0 )
|| ( ( ( selected_partition .sector_end + Sector(1) ) % sectors_in_mib ) > 0 )
) )
selected_partition .sector_end += diff ; && ( ( partition_size + sectors_in_mib ) < total_length )
)
selected_partition .sector_end += sectors_in_mib ;
} }
break; break;
case 2 : selected_partition .alignment = ALIGN_STRICT; break; case 2 : selected_partition .alignment = ALIGN_STRICT; break;

View File

@ -49,7 +49,7 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons
// handle situation where src sector size is smaller than dst sector size and an additional partial dst sector is required. // handle situation where src sector size is smaller than dst sector size and an additional partial dst sector is required.
Sector copied_min_sectors = ( copied_partition .get_byte_length() + (selected_partition .sector_size - 1) ) / selected_partition .sector_size ; Sector copied_min_sectors = ( copied_partition .get_byte_length() + (selected_partition .sector_size - 1) ) / selected_partition .sector_size ;
long COPIED_LENGTH_MB = Utils::round( Utils::sector_to_unit( copied_min_sectors, selected_partition .sector_size, UNIT_MIB ) ) ; long COPIED_LENGTH_MB = ceil( Utils::sector_to_unit( copied_min_sectors, selected_partition .sector_size, UNIT_MIB ) ) ;
//now calculate proportional length of partition //now calculate proportional length of partition
frame_resizer_base ->set_x_min_space_before( Utils::round( MIN_SPACE_BEFORE_MB / MB_PER_PIXEL ) ) ; frame_resizer_base ->set_x_min_space_before( Utils::round( MIN_SPACE_BEFORE_MB / MB_PER_PIXEL ) ) ;