gparted/src/Dialog_Partition_Copy.cc

141 lines
6.0 KiB
C++
Raw Normal View History

/* 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
* 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
* 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"
#include "../include/GParted_Core.h"
#include "../include/Partition.h"
2004-09-19 14:24:53 -06:00
namespace GParted
{
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
{
this ->fs = fs ;
Remove cylinder size adjustments in the copy dialog (#749867) BUF in the copy dialog class, Dialog_Partition_Copy, is use to adjust limits in 2 cases: 1) Minimum size when copying an XFS file system Minimum size was set to the used space + 2 * cylinder size (typically plus ~16 MiB). This commit from 2004-12-20 added it: a54b52ea33abb1f5a44b52bcad5858ba41cd135d xfs copy now uses xfsdump and xfsrestore. icw some hacks in the other 2 Issues: * This is increasing the minimum XFS file system size when copying it, which doesn't happen in the resize case for other file systems. * It allows an XFS file system to be created which is smaller than the minimum size allowed by GParted. Copying an empty XFS file system can create a new file system as small as 26 MiB. This is smaller than the minimum GParted allows of 32 MiB because that is the minimum xfs_repair can handle. Remove this addition when copying an XFS file system and enforce minimum file system size. 2) Maximum size when copying a file system into empty space larger than it's maximum size Maximum size was set to maximum file system size - cylinder size (typically minus ~8 MiB). Only applied to FAT16 which has a maximum file system size set in and can be grown. Added by this commit from 2004-12-15: 10e8f3338d76e74c5fba22ff6c86888a67b99ae9 :get_fs now returns a const reference. in copy and resizedialog ... * in copy and resizedialog filesystems with MAX set now have a max size of MAX - one cylinder . Issue: * This is applying a lower maximum resize when copying the file system compared to that when creating the file system. NOTE: GParted currently allows all file systems to be resize to any size, regardless of the maximum file system size. This is probably an oversight, but it does allow libparted to convert FAT16 to FAT32 file system when resizing. Remove this lower maximum file system size when copying and resizing, compared to creating. Bug 749867 - Some limits are adjusted by arcane cylinder size amount when copying and resizing in a single operation
2015-05-25 13:09:46 -06:00
2004-09-19 14:24:53 -06:00
Set_Resizer( false ) ;
Set_Confirm_Button( PASTE ) ;
set_data( selected_partition, copied_partition );
2004-09-19 14:24:53 -06:00
}
Dialog_Partition_Copy::~Dialog_Partition_Copy()
{
delete new_partition;
new_partition = NULL;
}
void Dialog_Partition_Copy::set_data( const Partition & selected_partition, const Partition & copied_partition )
2004-09-19 14:24:53 -06: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...
MIN_SPACE_BEFORE_MB = Dialog_Base_Partition::MB_Needed_for_Boot_Record( selected_partition ) ;
START = selected_partition .sector_start ;
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 ) ) ;
MB_PER_PIXEL = TOTAL_MB / 500.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.
Sector copied_min_sectors = ( copied_partition .get_byte_length() + (selected_partition .sector_size - 1) ) / selected_partition .sector_size ;
long COPIED_LENGTH_MB = ceil( Utils::sector_to_unit( copied_min_sectors, selected_partition .sector_size, UNIT_MIB ) ) ;
2004-09-19 14:24:53 -06:00
//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_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...
frame_resizer_base ->set_x_end( x_end > 500 ? 500 : x_end ) ;
Sector min_resize = copied_partition .estimated_min_size() ;
frame_resizer_base ->set_used(
Utils::round( Utils::sector_to_unit( min_resize, copied_partition .sector_size, UNIT_MIB ) / (TOTAL_MB/500.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 ) )
Remove cylinder size adjustments in the copy dialog (#749867) BUF in the copy dialog class, Dialog_Partition_Copy, is use to adjust limits in 2 cases: 1) Minimum size when copying an XFS file system Minimum size was set to the used space + 2 * cylinder size (typically plus ~16 MiB). This commit from 2004-12-20 added it: a54b52ea33abb1f5a44b52bcad5858ba41cd135d xfs copy now uses xfsdump and xfsrestore. icw some hacks in the other 2 Issues: * This is increasing the minimum XFS file system size when copying it, which doesn't happen in the resize case for other file systems. * It allows an XFS file system to be created which is smaller than the minimum size allowed by GParted. Copying an empty XFS file system can create a new file system as small as 26 MiB. This is smaller than the minimum GParted allows of 32 MiB because that is the minimum xfs_repair can handle. Remove this addition when copying an XFS file system and enforce minimum file system size. 2) Maximum size when copying a file system into empty space larger than it's maximum size Maximum size was set to maximum file system size - cylinder size (typically minus ~8 MiB). Only applied to FAT16 which has a maximum file system size set in and can be grown. Added by this commit from 2004-12-15: 10e8f3338d76e74c5fba22ff6c86888a67b99ae9 :get_fs now returns a const reference. in copy and resizedialog ... * in copy and resizedialog filesystems with MAX set now have a max size of MAX - one cylinder . Issue: * This is applying a lower maximum resize when copying the file system compared to that when creating the file system. NOTE: GParted currently allows all file systems to be resize to any size, regardless of the maximum file system size. This is probably an oversight, but it does allow libparted to convert FAT16 to FAT32 file system when resizing. Remove this lower maximum file system size when copying and resizing, compared to creating. Bug 749867 - Some limits are adjusted by arcane cylinder size amount when copying and resizing in a single operation
2015-05-25 13:09:46 -06:00
{
if ( ! fs .MAX || fs .MAX > ((TOTAL_MB - MIN_SPACE_BEFORE_MB) * MEBIBYTE) )
fs .MAX = ((TOTAL_MB - MIN_SPACE_BEFORE_MB) * MEBIBYTE) ;
Remove cylinder size adjustments in the copy dialog (#749867) BUF in the copy dialog class, Dialog_Partition_Copy, is use to adjust limits in 2 cases: 1) Minimum size when copying an XFS file system Minimum size was set to the used space + 2 * cylinder size (typically plus ~16 MiB). This commit from 2004-12-20 added it: a54b52ea33abb1f5a44b52bcad5858ba41cd135d xfs copy now uses xfsdump and xfsrestore. icw some hacks in the other 2 Issues: * This is increasing the minimum XFS file system size when copying it, which doesn't happen in the resize case for other file systems. * It allows an XFS file system to be created which is smaller than the minimum size allowed by GParted. Copying an empty XFS file system can create a new file system as small as 26 MiB. This is smaller than the minimum GParted allows of 32 MiB because that is the minimum xfs_repair can handle. Remove this addition when copying an XFS file system and enforce minimum file system size. 2) Maximum size when copying a file system into empty space larger than it's maximum size Maximum size was set to maximum file system size - cylinder size (typically minus ~8 MiB). Only applied to FAT16 which has a maximum file system size set in and can be grown. Added by this commit from 2004-12-15: 10e8f3338d76e74c5fba22ff6c86888a67b99ae9 :get_fs now returns a const reference. in copy and resizedialog ... * in copy and resizedialog filesystems with MAX set now have a max size of MAX - one cylinder . Issue: * This is applying a lower maximum resize when copying the file system compared to that when creating the file system. NOTE: GParted currently allows all file systems to be resize to any size, regardless of the maximum file system size. This is probably an oversight, but it does allow libparted to convert FAT16 to FAT32 file system when resizing. Remove this lower maximum file system size when copying and resizing, compared to creating. Bug 749867 - Some limits are adjusted by arcane cylinder size amount when copying and resizing in a single operation
2015-05-25 13:09:46 -06:00
}
else
fs .MAX = copied_partition .get_byte_length() ;
if ( fs .filesystem == GParted::FS_XFS ) //bit hackisch, but most effective, since it's a unique situation
Remove cylinder size adjustments in the copy dialog (#749867) BUF in the copy dialog class, Dialog_Partition_Copy, is use to adjust limits in 2 cases: 1) Minimum size when copying an XFS file system Minimum size was set to the used space + 2 * cylinder size (typically plus ~16 MiB). This commit from 2004-12-20 added it: a54b52ea33abb1f5a44b52bcad5858ba41cd135d xfs copy now uses xfsdump and xfsrestore. icw some hacks in the other 2 Issues: * This is increasing the minimum XFS file system size when copying it, which doesn't happen in the resize case for other file systems. * It allows an XFS file system to be created which is smaller than the minimum size allowed by GParted. Copying an empty XFS file system can create a new file system as small as 26 MiB. This is smaller than the minimum GParted allows of 32 MiB because that is the minimum xfs_repair can handle. Remove this addition when copying an XFS file system and enforce minimum file system size. 2) Maximum size when copying a file system into empty space larger than it's maximum size Maximum size was set to maximum file system size - cylinder size (typically minus ~8 MiB). Only applied to FAT16 which has a maximum file system size set in and can be grown. Added by this commit from 2004-12-15: 10e8f3338d76e74c5fba22ff6c86888a67b99ae9 :get_fs now returns a const reference. in copy and resizedialog ... * in copy and resizedialog filesystems with MAX set now have a max size of MAX - one cylinder . Issue: * This is applying a lower maximum resize when copying the file system compared to that when creating the file system. NOTE: GParted currently allows all file systems to be resize to any size, regardless of the maximum file system size. This is probably an oversight, but it does allow libparted to convert FAT16 to FAT32 file system when resizing. Remove this lower maximum file system size when copying and resizing, compared to creating. Bug 749867 - Some limits are adjusted by arcane cylinder size amount when copying and resizing in a single operation
2015-05-25 13:09:46 -06:00
fs.MIN = std::max( fs.MIN, min_resize * copied_partition.sector_size );
else
fs .MIN = COPIED_LENGTH_MB * MEBIBYTE ;
GRIP = true ;
2004-09-19 14:24:53 -06:00
//set values of spinbutton_before
spinbutton_before .set_range( MIN_SPACE_BEFORE_MB, TOTAL_MB - ceil( fs .MIN / double(MEBIBYTE) ) ) ;
spinbutton_before .set_value( MIN_SPACE_BEFORE_MB ) ;
//set values of spinbutton_size
spinbutton_size .set_range( ceil( fs .MIN / double(MEBIBYTE) )
, ceil( fs .MAX / double(MEBIBYTE) )
) ;
spinbutton_size .set_value( COPIED_LENGTH_MB ) ;
2004-09-19 14:24:53 -06:00
//set values of spinbutton_after
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 ) ;
GRIP = false ;
2004-09-19 14:24:53 -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-09-19 14:24:53 -06:00
//set contents of label_minmax
Set_MinMax_Text( ceil( fs .MIN / double(MEBIBYTE) )
, ceil( fs .MAX / double(MEBIBYTE) )
) ;
// Set member variable used in Dialog_Base_Partition::prepare_new_partition()
new_partition = copied_partition.clone();
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;
//Handle situation where src sector size is smaller than dst sector size and an additional partial dst sector is required.
new_partition->set_sector_usage(
( ( ( 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 )
) / selected_partition .sector_size ) ;
this ->show_all_children() ;
2004-09-19 14:24:53 -06:00
}
const Partition & Dialog_Partition_Copy::Get_New_Partition( Byte_Value sector_size )
2004-09-25 08:12:07 -06: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
Dialog_Base_Partition::prepare_new_partition( sector_size );
2004-09-25 08:12:07 -06:00
//set proper name and status for partition
new_partition->status = STAT_COPY;
return *new_partition;
2004-09-25 08:12:07 -06:00
}
2004-09-19 14:24:53 -06:00
} //GParted