2009-11-05 11:08:32 -07:00
|
|
|
/* Copyright (C) 2004 Bart
|
2011-01-16 10:45:25 -07:00
|
|
|
* Copyright (C) 2008, 2009, 2010, 2011 Curtis Gedak
|
2004-09-19 14:24:53 -06:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2014-01-23 03:59:48 -07:00
|
|
|
* GNU General Public License for more details.
|
2004-09-19 14:24:53 -06:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2014-01-23 03:59:48 -07:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2004-09-19 14:24:53 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../include/Dialog_Partition_Copy.h"
|
2012-08-25 13:49:10 -06:00
|
|
|
#include "../include/GParted_Core.h"
|
2015-11-25 07:55:19 -07:00
|
|
|
#include "../include/Partition.h"
|
2004-09-19 14:24:53 -06:00
|
|
|
|
|
|
|
namespace GParted
|
|
|
|
{
|
|
|
|
|
2015-06-02 06:10:45 -06:00
|
|
|
Dialog_Partition_Copy::Dialog_Partition_Copy( const FS & fs, const Partition & selected_partition,
|
|
|
|
const Partition & copied_partition )
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
2004-12-15 14:53:14 -07:00
|
|
|
this ->fs = fs ;
|
2015-05-25 13:09:46 -06:00
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
Set_Resizer( false ) ;
|
|
|
|
Set_Confirm_Button( PASTE ) ;
|
2015-06-02 06:10:45 -06:00
|
|
|
|
|
|
|
set_data( selected_partition, copied_partition );
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
|
2015-12-13 07:38:30 -07:00
|
|
|
Dialog_Partition_Copy::~Dialog_Partition_Copy()
|
|
|
|
{
|
|
|
|
delete new_partition;
|
|
|
|
new_partition = NULL;
|
|
|
|
}
|
|
|
|
|
2015-06-02 06:10:45 -06:00
|
|
|
void Dialog_Partition_Copy::set_data( const Partition & selected_partition, const Partition & copied_partition )
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
2006-03-14 14:37:47 -07:00
|
|
|
this ->set_title( String::ucompose( _("Paste %1"), copied_partition .get_path() ) ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
|
|
|
|
//set partition color
|
|
|
|
frame_resizer_base ->set_rgb_partition_color( copied_partition .color ) ;
|
|
|
|
|
|
|
|
//set some widely used values...
|
2010-05-20 10:00:14 -06:00
|
|
|
MIN_SPACE_BEFORE_MB = Dialog_Base_Partition::MB_Needed_for_Boot_Record( selected_partition ) ;
|
2004-11-21 14:49:38 -07:00
|
|
|
START = selected_partition .sector_start ;
|
2010-04-28 09:11:44 -06:00
|
|
|
total_length = selected_partition .get_sector_length() ;
|
|
|
|
TOTAL_MB = Utils::round( Utils::sector_to_unit( selected_partition .get_sector_length(), selected_partition .sector_size, UNIT_MIB ) ) ;
|
2005-01-19 13:01:39 -07:00
|
|
|
MB_PER_PIXEL = TOTAL_MB / 500.00 ;
|
2010-04-23 13:28:41 -06:00
|
|
|
|
|
|
|
//Determine minimum number of sectors needed in destination (selected) partition and
|
|
|
|
// handle situation where src sector size is smaller than dst sector size and an additional partial dst sector is required.
|
2010-04-27 12:54:14 -06:00
|
|
|
Sector copied_min_sectors = ( copied_partition .get_byte_length() + (selected_partition .sector_size - 1) ) / selected_partition .sector_size ;
|
2010-04-23 13:28:41 -06:00
|
|
|
|
2011-01-15 11:00:42 -07:00
|
|
|
long COPIED_LENGTH_MB = ceil( Utils::sector_to_unit( copied_min_sectors, selected_partition .sector_size, UNIT_MIB ) ) ;
|
2008-11-05 10:55:38 -07:00
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
//now calculate proportional length of partition
|
2010-05-25 16:25:21 -06:00
|
|
|
frame_resizer_base ->set_x_min_space_before( Utils::round( MIN_SPACE_BEFORE_MB / MB_PER_PIXEL ) ) ;
|
|
|
|
frame_resizer_base ->set_x_start( Utils::round(MIN_SPACE_BEFORE_MB / MB_PER_PIXEL) ) ;
|
|
|
|
int x_end = Utils::round( (MIN_SPACE_BEFORE_MB + COPIED_LENGTH_MB) / ( TOTAL_MB/500.00 ) ) ; //> 500 px only possible with xfs...
|
2004-12-20 12:09:48 -07:00
|
|
|
frame_resizer_base ->set_x_end( x_end > 500 ? 500 : x_end ) ;
|
2012-06-02 13:02:09 -06:00
|
|
|
Sector min_resize = copied_partition .estimated_min_size() ;
|
2006-02-25 03:09:30 -07:00
|
|
|
frame_resizer_base ->set_used(
|
2012-06-02 13:02:09 -06:00
|
|
|
Utils::round( Utils::sector_to_unit( min_resize, copied_partition .sector_size, UNIT_MIB ) / (TOTAL_MB/500.00) ) ) ;
|
2010-04-23 13:28:41 -06:00
|
|
|
|
2012-08-25 13:49:10 -06:00
|
|
|
//Only allow pasting into a new larger partition if growing the file
|
|
|
|
// system is implemented and resizing it is currently allowed.
|
|
|
|
if ( fs .grow && ! GParted_Core::filesystem_resize_disallowed( copied_partition ) )
|
2015-05-25 13:09:46 -06:00
|
|
|
{
|
2010-05-20 10:00:14 -06:00
|
|
|
if ( ! fs .MAX || fs .MAX > ((TOTAL_MB - MIN_SPACE_BEFORE_MB) * MEBIBYTE) )
|
|
|
|
fs .MAX = ((TOTAL_MB - MIN_SPACE_BEFORE_MB) * MEBIBYTE) ;
|
2015-05-25 13:09:46 -06:00
|
|
|
}
|
2006-04-05 09:34:06 -06:00
|
|
|
else
|
2010-04-27 12:54:14 -06:00
|
|
|
fs .MAX = copied_partition .get_byte_length() ;
|
2006-04-05 09:34:06 -06:00
|
|
|
|
2005-12-07 04:21:27 -07:00
|
|
|
if ( fs .filesystem == GParted::FS_XFS ) //bit hackisch, but most effective, since it's a unique situation
|
2015-05-25 13:09:46 -06:00
|
|
|
fs.MIN = std::max( fs.MIN, min_resize * copied_partition.sector_size );
|
2004-12-20 12:09:48 -07:00
|
|
|
else
|
2010-04-26 13:40:38 -06:00
|
|
|
fs .MIN = COPIED_LENGTH_MB * MEBIBYTE ;
|
2004-12-15 04:02:54 -07:00
|
|
|
|
2004-12-20 12:09:48 -07:00
|
|
|
GRIP = true ;
|
2004-09-19 14:24:53 -06:00
|
|
|
//set values of spinbutton_before
|
2010-05-20 10:00:14 -06:00
|
|
|
spinbutton_before .set_range( MIN_SPACE_BEFORE_MB, TOTAL_MB - ceil( fs .MIN / double(MEBIBYTE) ) ) ;
|
|
|
|
spinbutton_before .set_value( MIN_SPACE_BEFORE_MB ) ;
|
|
|
|
|
2004-12-09 15:56:33 -07:00
|
|
|
//set values of spinbutton_size
|
2010-05-20 10:00:14 -06:00
|
|
|
spinbutton_size .set_range( ceil( fs .MIN / double(MEBIBYTE) )
|
|
|
|
, ceil( fs .MAX / double(MEBIBYTE) )
|
|
|
|
) ;
|
2004-12-20 12:09:48 -07:00
|
|
|
spinbutton_size .set_value( COPIED_LENGTH_MB ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
|
|
|
|
//set values of spinbutton_after
|
2010-05-20 10:00:14 -06:00
|
|
|
spinbutton_after .set_range( 0, TOTAL_MB - MIN_SPACE_BEFORE_MB - ceil( fs .MIN / double(MEBIBYTE) ) ) ;
|
|
|
|
spinbutton_after .set_value( TOTAL_MB - MIN_SPACE_BEFORE_MB - COPIED_LENGTH_MB ) ;
|
2004-12-20 12:09:48 -07:00
|
|
|
GRIP = false ;
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2010-04-26 13:40:38 -06:00
|
|
|
frame_resizer_base ->set_size_limits( Utils::round( fs .MIN / (MB_PER_PIXEL * MEBIBYTE) ),
|
|
|
|
Utils::round( fs .MAX / (MB_PER_PIXEL * MEBIBYTE) ) ) ;
|
2004-12-12 07:57:04 -07:00
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
//set contents of label_minmax
|
2010-05-20 10:00:14 -06:00
|
|
|
Set_MinMax_Text( ceil( fs .MIN / double(MEBIBYTE) )
|
|
|
|
, ceil( fs .MAX / double(MEBIBYTE) )
|
|
|
|
) ;
|
2006-05-27 13:51:55 -06:00
|
|
|
|
2015-05-26 14:52:04 -06:00
|
|
|
// Set member variable used in Dialog_Base_Partition::prepare_new_partition()
|
2015-12-13 07:38:30 -07:00
|
|
|
new_partition = new Partition( copied_partition );
|
|
|
|
new_partition->device_path = selected_partition.device_path;
|
|
|
|
new_partition->inside_extended = selected_partition.inside_extended;
|
|
|
|
new_partition->type = selected_partition.inside_extended ? TYPE_LOGICAL : TYPE_PRIMARY;
|
2010-05-04 15:18:43 -06:00
|
|
|
//Handle situation where src sector size is smaller than dst sector size and an additional partial dst sector is required.
|
2015-12-13 07:38:30 -07:00
|
|
|
new_partition->set_sector_usage(
|
2012-03-28 05:47:48 -06:00
|
|
|
( ( ( copied_partition .sectors_used + copied_partition .sectors_unused ) * copied_partition .sector_size )
|
|
|
|
+ ( selected_partition .sector_size - 1 )
|
|
|
|
) / selected_partition .sector_size,
|
|
|
|
( ( copied_partition .sectors_unused * copied_partition .sector_size )
|
|
|
|
+ ( selected_partition .sector_size - 1 )
|
2010-05-04 15:18:43 -06:00
|
|
|
) / selected_partition .sector_size ) ;
|
2006-05-27 13:51:55 -06:00
|
|
|
|
|
|
|
this ->show_all_children() ;
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
|
2015-11-05 02:00:09 -07:00
|
|
|
const Partition & Dialog_Partition_Copy::Get_New_Partition( Byte_Value sector_size )
|
2004-09-25 08:12:07 -06:00
|
|
|
{
|
2015-12-13 07:38:30 -07:00
|
|
|
g_assert( new_partition != NULL ); // Bug: Not initialised by constructor calling set_data()
|
|
|
|
|
2004-09-25 08:12:07 -06:00
|
|
|
//first call baseclass to get the correct new partition
|
2015-05-26 14:52:04 -06:00
|
|
|
Dialog_Base_Partition::prepare_new_partition( sector_size );
|
2010-04-19 19:22:31 -06:00
|
|
|
|
2004-09-25 08:12:07 -06:00
|
|
|
//set proper name and status for partition
|
2015-12-13 07:38:30 -07:00
|
|
|
new_partition->status = STAT_COPY;
|
2010-04-19 19:22:31 -06:00
|
|
|
|
2015-12-13 07:38:30 -07:00
|
|
|
return *new_partition;
|
2004-09-25 08:12:07 -06:00
|
|
|
}
|
2004-09-19 14:24:53 -06:00
|
|
|
|
|
|
|
} //GParted
|