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
|
|
|
*/
|
|
|
|
|
2016-10-18 16:45:28 -06:00
|
|
|
#include "Dialog_Partition_Copy.h"
|
2018-01-18 09:26:20 -07:00
|
|
|
#include "FileSystem.h"
|
2016-10-18 16:45:28 -06:00
|
|
|
#include "GParted_Core.h"
|
|
|
|
#include "Partition.h"
|
|
|
|
#include "Utils.h"
|
2004-09-19 14:24:53 -06:00
|
|
|
|
|
|
|
namespace GParted
|
|
|
|
{
|
|
|
|
|
2018-01-12 03:56:53 -07:00
|
|
|
Dialog_Partition_Copy::Dialog_Partition_Copy( const FS & fs, const FS_Limits & fs_limits,
|
|
|
|
const Partition & selected_partition,
|
2015-06-02 06:10:45 -06:00
|
|
|
const Partition & copied_partition )
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
2004-12-15 14:53:14 -07:00
|
|
|
this ->fs = fs ;
|
2018-01-12 03:56:53 -07:00
|
|
|
this->fs_limits = fs_limits;
|
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
|
2015-11-19 09:22:23 -07:00
|
|
|
Gdk::Color partition_color( Utils::get_color( copied_partition.filesystem ) );
|
|
|
|
frame_resizer_base->set_rgb_partition_color( partition_color );
|
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
//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
|
|
|
{
|
2018-01-12 03:04:37 -07:00
|
|
|
if ( ! fs_limits.max_size || fs_limits.max_size > ((TOTAL_MB - MIN_SPACE_BEFORE_MB) * MEBIBYTE) )
|
|
|
|
fs_limits.max_size = (TOTAL_MB - MIN_SPACE_BEFORE_MB) * MEBIBYTE;
|
2015-05-25 13:09:46 -06:00
|
|
|
}
|
2006-04-05 09:34:06 -06:00
|
|
|
else
|
2018-01-12 03:04:37 -07:00
|
|
|
{
|
|
|
|
fs_limits.max_size = copied_partition.get_byte_length();
|
|
|
|
}
|
2006-04-05 09:34:06 -06:00
|
|
|
|
2018-10-14 06:37:34 -06:00
|
|
|
if (fs.filesystem == FS_XFS) // Bit hackish, but most effective, since it's a unique situation.
|
2018-01-12 03:04:37 -07:00
|
|
|
fs_limits.min_size = std::max( fs_limits.min_size, min_resize * copied_partition.sector_size );
|
2004-12-20 12:09:48 -07:00
|
|
|
else
|
2018-01-12 03:04:37 -07:00
|
|
|
fs_limits.min_size = COPIED_LENGTH_MB * MEBIBYTE;
|
|
|
|
|
2004-12-20 12:09:48 -07:00
|
|
|
GRIP = true ;
|
2004-09-19 14:24:53 -06:00
|
|
|
//set values of spinbutton_before
|
2018-01-12 03:04:37 -07:00
|
|
|
spinbutton_before.set_range( MIN_SPACE_BEFORE_MB, TOTAL_MB - ceil( fs_limits.min_size / double(MEBIBYTE) ) );
|
2010-05-20 10:00:14 -06:00
|
|
|
spinbutton_before .set_value( MIN_SPACE_BEFORE_MB ) ;
|
|
|
|
|
2004-12-09 15:56:33 -07:00
|
|
|
//set values of spinbutton_size
|
2018-01-12 03:04:37 -07:00
|
|
|
spinbutton_size.set_range( ceil( fs_limits.min_size / double(MEBIBYTE) ),
|
|
|
|
ceil( fs_limits.max_size / 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
|
2018-01-12 03:04:37 -07:00
|
|
|
spinbutton_after.set_range( 0, TOTAL_MB - MIN_SPACE_BEFORE_MB - ceil( fs_limits.min_size / double(MEBIBYTE) ) );
|
2010-05-20 10:00:14 -06:00
|
|
|
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
|
|
|
|
2018-01-12 03:04:37 -07:00
|
|
|
frame_resizer_base->set_size_limits( Utils::round( fs_limits.min_size / (MB_PER_PIXEL * MEBIBYTE) ),
|
|
|
|
Utils::round( fs_limits.max_size / (MB_PER_PIXEL * MEBIBYTE) ) );
|
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
//set contents of label_minmax
|
2018-01-12 03:04:37 -07:00
|
|
|
Set_MinMax_Text( ceil( fs_limits.min_size / double(MEBIBYTE) ),
|
|
|
|
ceil( fs_limits.max_size / 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-05 09:26:30 -07:00
|
|
|
new_partition = copied_partition.clone();
|
2015-12-13 07:38:30 -07:00
|
|
|
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;
|
2015-12-16 13:15:58 -07:00
|
|
|
new_partition->sector_size = selected_partition.sector_size;
|
2018-09-03 09:13:29 -06:00
|
|
|
if ( copied_partition.sector_usage_known() )
|
|
|
|
{
|
|
|
|
// Handle situation where src sector size is smaller than dst sector size
|
|
|
|
// and an additional partial dst sector is required.
|
|
|
|
Byte_Value src_fs_bytes = ( copied_partition.sectors_used + copied_partition.sectors_unused ) *
|
|
|
|
copied_partition.sector_size;
|
|
|
|
Byte_Value src_unused_bytes = copied_partition.sectors_unused * copied_partition.sector_size;
|
|
|
|
Sector dst_fs_sectors = ( src_fs_bytes + selected_partition.sector_size - 1 ) /
|
|
|
|
selected_partition.sector_size;
|
|
|
|
Sector dst_unused_sectors = ( src_unused_bytes + selected_partition.sector_size - 1 ) /
|
|
|
|
selected_partition.sector_size;
|
|
|
|
new_partition->set_sector_usage( dst_fs_sectors, dst_unused_sectors );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// FS usage of src is unknown so set dst usage unknown too.
|
|
|
|
new_partition->set_sector_usage( -1, -1 );
|
|
|
|
}
|
2006-05-27 13:51:55 -06:00
|
|
|
|
|
|
|
this ->show_all_children() ;
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
|
2015-12-16 13:15:58 -07:00
|
|
|
const Partition & Dialog_Partition_Copy::Get_New_Partition()
|
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-12-16 13:15:58 -07:00
|
|
|
Dialog_Base_Partition::prepare_new_partition();
|
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
|