gparted r1040 - in trunk: . src



Author: gedakc
Date: Sat Jan 24 17:16:57 2009
New Revision: 1040
URL: http://svn.gnome.org/viewvc/gparted?rev=1040&view=rev

Log:
Enhanced copy/paste checks when MBR/EBR involved.

Modified:
   trunk/ChangeLog
   trunk/src/Dialog_Partition_Copy.cc
   trunk/src/Win_GParted.cc

Modified: trunk/src/Dialog_Partition_Copy.cc
==============================================================================
--- trunk/src/Dialog_Partition_Copy.cc	(original)
+++ trunk/src/Dialog_Partition_Copy.cc	Sat Jan 24 17:16:57 2009
@@ -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 @@
 	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 @@
 	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

Modified: trunk/src/Win_GParted.cc
==============================================================================
--- trunk/src/Win_GParted.cc	(original)
+++ trunk/src/Win_GParted.cc	Sat Jan 24 17:16:57 2009
@@ -836,9 +836,50 @@
 			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 ;
 	}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]