2009-11-05 11:08:32 -07:00
|
|
|
/* Copyright (C) 2004 Bart
|
2010-03-23 12:14:53 -06:00
|
|
|
* Copyright (C) 2008, 2009, 2010 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
|
|
|
|
* GNU Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../include/Dialog_Partition_Copy.h"
|
|
|
|
|
|
|
|
namespace GParted
|
|
|
|
{
|
|
|
|
|
2006-02-25 03:09:30 -07:00
|
|
|
Dialog_Partition_Copy::Dialog_Partition_Copy( const FS & fs, Sector cylinder_size )
|
2004-09-19 14:24:53 -06:00
|
|
|
{
|
2004-12-15 14:53:14 -07:00
|
|
|
this ->fs = fs ;
|
2004-12-09 15:56:33 -07:00
|
|
|
|
2004-12-27 05:08:01 -07:00
|
|
|
BUF = cylinder_size ;
|
2004-12-15 13:43:58 -07:00
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
Set_Resizer( false ) ;
|
|
|
|
Set_Confirm_Button( PASTE ) ;
|
|
|
|
}
|
|
|
|
|
2004-11-21 14:49:38 -07: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...
|
2004-11-21 14:49:38 -07:00
|
|
|
START = selected_partition .sector_start ;
|
2006-03-07 07:55:35 -07:00
|
|
|
total_length = selected_partition .get_length() ;
|
2010-03-23 12:21:57 -06:00
|
|
|
TOTAL_MB = Utils::round( Utils::sector_to_unit( selected_partition .get_length(), DEFAULT_SECTOR_SIZE, UNIT_MIB ) ) ;
|
2005-01-19 13:01:39 -07:00
|
|
|
MB_PER_PIXEL = TOTAL_MB / 500.00 ;
|
|
|
|
|
2010-03-23 12:21:57 -06:00
|
|
|
long COPIED_LENGTH_MB = Utils::round( Utils::sector_to_unit( copied_partition .get_length(), DEFAULT_SECTOR_SIZE, UNIT_MIB ) ) ;
|
2009-01-24 10:16:57 -07:00
|
|
|
// /* Copy Primary not at start of disk to within Extended partition */
|
|
|
|
// Adjust when a primary partition is copied and pasted
|
|
|
|
// into an unallocated space in an extended partition
|
|
|
|
// of an MSDOS partition table.
|
2008-11-05 10:55:38 -07:00
|
|
|
// Since the Extended Boot Record requires an additional track,
|
2009-01-24 10:16:57 -07:00
|
|
|
// this must be considered in the required space for the
|
|
|
|
// destination (selected) partition.
|
2008-11-05 13:18:52 -07:00
|
|
|
// NOTE: This problem does not occur for a primary partition
|
|
|
|
// at the the start of the disk because the size of the EBR and
|
|
|
|
// Master Boot Record are the same.
|
2009-01-24 10:16:57 -07:00
|
|
|
//
|
|
|
|
// /* Copy Primary not at start of disk to Primary at start of disk */
|
|
|
|
// Also Adjust when a primary partition that does not start at the
|
|
|
|
// beginning of the disk is copied and pasted
|
|
|
|
// into an unallocated space at the start of the disk device.
|
|
|
|
// Since the Master Boot Record requires an additional track,
|
|
|
|
// this must be considered in the required space for the
|
|
|
|
// destination (selected) partition.
|
|
|
|
//
|
|
|
|
// Because the largest unit used in the GUI is one
|
|
|
|
// cylinder size (round to cylinders), the space
|
|
|
|
// needed in the destination partition needs to be increased
|
|
|
|
// by enough to round up one cylinder size.
|
|
|
|
// Increase by half a cylinder size (or 4 MB) because this
|
|
|
|
// will round up to the next cylinder size.
|
|
|
|
// 8 MB is typical cylinder size with todays larger disks.
|
|
|
|
// 8 MB = (255 heads) * (63 sectors) * (512 bytes)
|
|
|
|
//
|
2008-11-05 13:18:52 -07:00
|
|
|
//FIXME: Should confirm MSDOS partition table type, track sector size, and use cylinder size from device
|
2009-01-24 10:16:57 -07:00
|
|
|
if ( (/* Copy Primary not at start of disk to within Extended partition */
|
|
|
|
copied_partition .type == TYPE_PRIMARY
|
|
|
|
&& copied_partition .sector_start > 63
|
|
|
|
&& selected_partition .type == TYPE_UNALLOCATED
|
|
|
|
&& selected_partition .inside_extended
|
|
|
|
)
|
|
|
|
|| ( /* Copy Primary not at start of disk to Primary at start of disk */
|
|
|
|
copied_partition .type == TYPE_PRIMARY
|
|
|
|
&& copied_partition .sector_start > 63
|
|
|
|
&& selected_partition .type == TYPE_UNALLOCATED
|
|
|
|
&& selected_partition .sector_start <=63 /* Beginning of disk device */
|
|
|
|
&& ! selected_partition .inside_extended
|
|
|
|
)
|
2008-11-05 10:55:38 -07:00
|
|
|
)
|
2009-01-24 10:16:57 -07:00
|
|
|
COPIED_LENGTH_MB += 4 ;
|
2008-11-05 10:55:38 -07:00
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
//now calculate proportional length of partition
|
|
|
|
frame_resizer_base ->set_x_start( 0 ) ;
|
2006-03-28 05:40:29 -07:00
|
|
|
int x_end = Utils::round( 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 ) ;
|
2006-02-25 03:09:30 -07:00
|
|
|
frame_resizer_base ->set_used(
|
2006-03-28 05:40:29 -07:00
|
|
|
Utils::round( Utils::sector_to_unit(
|
2010-03-23 12:21:57 -06:00
|
|
|
copied_partition .sectors_used, DEFAULT_SECTOR_SIZE, UNIT_MIB ) / (TOTAL_MB/500.00) ) ) ;
|
2005-01-19 13:01:39 -07:00
|
|
|
|
2006-04-05 09:34:06 -06:00
|
|
|
if ( fs .grow )
|
2010-03-16 13:25:58 -06:00
|
|
|
fs .MAX = ( ! fs .MAX || fs .MAX > (TOTAL_MB * MEBI_FACTOR) ) ? (TOTAL_MB * MEBI_FACTOR) : fs .MAX - (BUF * DEFAULT_SECTOR_SIZE) ;
|
2006-04-05 09:34:06 -06:00
|
|
|
else
|
2010-03-16 13:25:58 -06:00
|
|
|
fs .MAX = copied_partition .get_length() * DEFAULT_SECTOR_SIZE ;
|
2006-04-05 09:34:06 -06:00
|
|
|
|
2004-10-08 13:53:35 -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
|
2010-03-16 11:24:08 -06:00
|
|
|
fs .MIN = ( copied_partition .sectors_used + (BUF * 2) ) * DEFAULT_SECTOR_SIZE;
|
2004-12-20 12:09:48 -07:00
|
|
|
else
|
2010-03-16 11:24:08 -06:00
|
|
|
fs .MIN = COPIED_LENGTH_MB * MEBI_FACTOR ;
|
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-03-23 12:21:57 -06:00
|
|
|
spinbutton_before .set_range( 0, TOTAL_MB - Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, UNIT_MIB ) ) ) ;
|
2004-09-19 14:24:53 -06:00
|
|
|
spinbutton_before .set_value( 0 ) ;
|
|
|
|
|
2004-12-09 15:56:33 -07:00
|
|
|
//set values of spinbutton_size
|
2006-02-25 03:09:30 -07:00
|
|
|
spinbutton_size .set_range(
|
2010-03-23 12:21:57 -06:00
|
|
|
Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, UNIT_MIB ) ),
|
|
|
|
Utils::round( Utils::sector_to_unit( (fs .MAX / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, UNIT_MIB ) ) ) ;
|
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-03-23 12:21:57 -06:00
|
|
|
spinbutton_after .set_range( 0, TOTAL_MB - Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, UNIT_MIB ) ) ) ;
|
2004-12-20 12:09:48 -07:00
|
|
|
spinbutton_after .set_value( TOTAL_MB - COPIED_LENGTH_MB ) ;
|
|
|
|
GRIP = false ;
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2010-03-16 11:24:08 -06:00
|
|
|
frame_resizer_base ->set_size_limits( Utils::round( fs .MIN / (MB_PER_PIXEL * MEBI_FACTOR) ),
|
2010-03-16 13:25:58 -06:00
|
|
|
Utils::round( fs .MAX / (MB_PER_PIXEL * MEBI_FACTOR) ) ) ;
|
2004-12-12 07:57:04 -07:00
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
//set contents of label_minmax
|
2006-02-25 03:09:30 -07:00
|
|
|
Set_MinMax_Text(
|
2010-03-23 12:21:57 -06:00
|
|
|
Utils::round( Utils::sector_to_unit( (fs .MIN / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, UNIT_MIB ) ),
|
|
|
|
Utils::round( Utils::sector_to_unit( (fs .MAX / DEFAULT_SECTOR_SIZE), DEFAULT_SECTOR_SIZE, UNIT_MIB ) ) ) ;
|
2006-05-27 13:51:55 -06:00
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
//set global selected_partition (see Dialog_Base_Partition::Get_New_Partition )
|
|
|
|
this ->selected_partition = copied_partition ;
|
2006-03-14 14:37:47 -07:00
|
|
|
this ->selected_partition .device_path = selected_partition .device_path ;
|
2004-10-02 03:39:16 -06:00
|
|
|
this ->selected_partition .inside_extended = selected_partition .inside_extended ;
|
2006-03-01 12:16:13 -07:00
|
|
|
this ->selected_partition .type =
|
|
|
|
selected_partition .inside_extended ? GParted::TYPE_LOGICAL : GParted::TYPE_PRIMARY ;
|
2006-05-27 13:51:55 -06:00
|
|
|
|
|
|
|
this ->show_all_children() ;
|
2004-09-19 14:24:53 -06:00
|
|
|
}
|
|
|
|
|
2010-04-19 19:22:31 -06:00
|
|
|
Partition Dialog_Partition_Copy::Get_New_Partition( Byte_Value sector_size )
|
2004-09-25 08:12:07 -06:00
|
|
|
{
|
|
|
|
//first call baseclass to get the correct new partition
|
2010-04-19 19:22:31 -06:00
|
|
|
selected_partition = Dialog_Base_Partition::Get_New_Partition( sector_size ) ;
|
|
|
|
|
2004-09-25 08:12:07 -06:00
|
|
|
//set proper name and status for partition
|
2006-08-01 06:16:22 -06:00
|
|
|
selected_partition .status = GParted::STAT_COPY ;
|
2010-04-19 19:22:31 -06:00
|
|
|
|
2004-09-25 08:12:07 -06:00
|
|
|
return selected_partition ;
|
|
|
|
}
|
2004-09-19 14:24:53 -06:00
|
|
|
|
|
|
|
} //GParted
|