From e77e1e3dbcdd9ffadc910e58699565dc36ba9434 Mon Sep 17 00:00:00 2001 From: Curtis Gedak Date: Sat, 24 Jan 2009 17:16:57 +0000 Subject: [PATCH] Enhanced copy/paste checks when MBR/EBR involved. svn path=/trunk/; revision=1040 --- ChangeLog | 6 ++++ src/Dialog_Partition_Copy.cc | 56 +++++++++++++++++++++++++----------- src/Win_GParted.cc | 45 +++++++++++++++++++++++++++-- 3 files changed, 89 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index b645bc2a..0d368640 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-01-24 Curtis Gedak + + * src/Dialog_Partition_Copy.cc, + src/Win_GParted.cc: Enhanced copy/paste checks when MBR/EBR involved. + - Related to GParted bug #567402 + 2009-01-20 Curtis Gedak * doc/gparted.8: Updated manual page. diff --git a/src/Dialog_Partition_Copy.cc b/src/Dialog_Partition_Copy.cc index cc50b004..668f734e 100644 --- a/src/Dialog_Partition_Copy.cc +++ b/src/Dialog_Partition_Copy.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2004, 2005, 2006, 2007, 2008 Bart Hakvoort +/* Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Bart Hakvoort * * 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 @@ -44,26 +44,50 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons MB_PER_PIXEL = TOTAL_MB / 500.00 ; long COPIED_LENGTH_MB = Utils::round( Utils::sector_to_unit( copied_partition .get_length(), GParted::UNIT_MIB ) ) ; - //Adjust for situation when an MSDOS partition table is in - // use and a primary partition is copied and pasted into - // an unallocated space in an extended partition. + // /* 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. // Since the Extended Boot Record requires an additional track, - // we need to add this to the destination (selected) partition. - // Because GUI selection of partition size is in MB and we round - // to the cylinder size, we will increase the partition by an - // additional 8 MB. 8 MB is typical cylinder size with - // todays larger disks. - // 8 MB = (255 heads) * (63 sectors) * (512 bytes) + // this must be considered in the required space for the + // destination (selected) partition. // 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. + // + // /* 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) + // //FIXME: Should confirm MSDOS partition table type, track sector size, and use cylinder size from device - if ( copied_partition .type == TYPE_PRIMARY - && copied_partition .sector_start != 63 - && selected_partition .type == TYPE_UNALLOCATED - && selected_partition .inside_extended + 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 + ) ) - COPIED_LENGTH_MB += 8 ; + COPIED_LENGTH_MB += 4 ; //now calculate proportional length of partition frame_resizer_base ->set_x_start( 0 ) ; @@ -82,7 +106,7 @@ void Dialog_Partition_Copy::Set_Data( const Partition & selected_partition, cons if ( fs .filesystem == GParted::FS_XFS ) //bit hackisch, but most effective, since it's a unique situation fs .MIN = copied_partition .sectors_used + (BUF * 2) ; else - fs .MIN = (COPIED_LENGTH_MB +1) * MEBIBYTE ; + fs .MIN = COPIED_LENGTH_MB * MEBIBYTE ; GRIP = true ; //set values of spinbutton_before diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc index c9cf7b5b..c65ac6b1 100644 --- a/src/Win_GParted.cc +++ b/src/Win_GParted.cc @@ -836,9 +836,50 @@ void Win_GParted::set_valid_operations() else required_size = copied_partition .get_length() ; - if ( ( required_size + devices[ current_device ] .cylsize ) <= selected_partition .get_length() ) + // /* 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. + // Since the Extended Boot Record requires an additional track, + // this must be considered in the required space for the + // destination (selected) partition. + // 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. + // + // /* 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 one cylinder size. + if ( (/* Copy Primary not at start of disk to within Extended partition */ + copied_partition .type == TYPE_PRIMARY + && copied_partition .sector_start > devices[ current_device ] .sectors /* 63 for MSDOS Partition Table */ + && devices[ current_device ] .disktype == "msdos" + && 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 > devices[ current_device ] .sectors /* 63 for MSDOS Partition Table */ + && devices[ current_device ] .disktype == "msdos" + && selected_partition .type == TYPE_UNALLOCATED + && selected_partition .sector_start <= devices[ current_device ] .sectors /* Beginning of disk device */ + && ! selected_partition .inside_extended + ) + ) + required_size += devices[ current_device ] .cylsize ; + + if ( required_size <= selected_partition .get_length() ) allow_paste( true ) ; - } + } return ; }