After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 596552 - Create new partition: size off by one sector
Create new partition: size off by one sector
Status: RESOLVED FIXED
Product: gparted
Classification: Other
Component: application
0.4.6
Other Linux
: Normal normal
: ---
Assigned To: gparted maintainers alias
gparted maintainers alias
Depends on:
Blocks:
 
 
Reported: 2009-09-28 00:29 UTC by Seth Hunter
Modified: 2009-09-28 22:43 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GParted Details for creating three consecutive 8 MB partitions (6.55 KB, text/html)
2009-09-28 21:42 UTC, Curtis Gedak
Details
GParted Details confirming partition creation off by one sector with 0.4.6 (6.55 KB, text/html)
2009-09-28 22:02 UTC, Curtis Gedak
Details

Description Seth Hunter 2009-09-28 00:29:18 UTC
When creating a new partition, the resulting partition ends up one sector larger than what was requested.  For example, requesting an 8 MiB partition results in a partition being created that is 16385 sectors instead of the expected size of 16384.  This is problematic when trying to maintain raid/ssd alignment after the first partition.

This appears to be a simple off-by-one in Dialog_Parition_New.cc, where the end sector should (start + size - 1) instead of (start + size).  Patch (untested):

diff --git a/src/Dialog_Partition_New.cc b/src/Dialog_Partition_New.cc
index 7104601..7990081 100644
--- a/src/Dialog_Partition_New.cc
+++ b/src/Dialog_Partition_New.cc
@@ -171,7 +171,7 @@ Partition Dialog_Partition_New::Get_New_Partition()
 	//FIXME:  Partition size is limited to just less than 1024 TeraBytes due
 	//        to the maximum value of signed 4 byte integer.
 	new_start = START + (Sector(spinbutton_before .get_value_as_int()) * MEBIBYTE) ;
-	new_end  = new_start + (Sector(spinbutton_size .get_value_as_int()) * MEBIBYTE) ;
+	new_end  = new_start + (Sector(spinbutton_size .get_value_as_int()) * MEBIBYTE) - 1 ;
 	
 	/* due to loss of precision during calcs from Sector -> MiB and back, it is possible the new 
 	 * partition thinks it's bigger then it can be. Here we try to solve this.*/
Comment 1 Curtis Gedak 2009-09-28 21:16:28 UTC
Thank you Seth for posting this report.

Do you have "Round to cylinders" enabled or disabled when creating the new partition?
Comment 2 Curtis Gedak 2009-09-28 21:42:34 UTC
Created attachment 144206 [details]
GParted Details for creating three consecutive 8 MB partitions

The attachment shows the log of using GParted to create three consecutive 8 MB ext2 formatted partitions under an MSDOS partition table.

The first partition was created starting at 1 MB into the drive to leave space for the Master Boot Record.  The remaining two partitions were created immediately after the prior partition.  In all three new partition creations, the "Round to cylinders" check box was disabled.

After applying all of the GParted steps, parted was used to generate the following information:

$ sudo parted -s /dev/sdd u s p
Model: ATA ST3160022ACE (scsi)
Disk /dev/sdd: 312581808s
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      2048s   18431s  16384s  primary  ext2
 2      18432s  34815s  16384s  primary  ext2
 3      34816s  51199s  16384s  primary  ext2


As can be seen above, each partition is exactly 8 MB in size (no extra sector).
Comment 3 Curtis Gedak 2009-09-28 21:49:20 UTC
Please note that the above GParted Details log in Comment #2 was created using the patch as suggested by Seth.
Comment 4 Curtis Gedak 2009-09-28 22:02:05 UTC
Created attachment 144208 [details]
GParted Details confirming partition creation off by one sector with 0.4.6

This attachment confirms the problem as noted by Seth regarding the extra sector in the newly created partition.

The output from parted after the GParted steps were applies is as follows:

6$ sudo parted -s /dev/sdd u s p
Model: ATA ST3160022ACE (scsi)
Disk /dev/sdd: 312581808s
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      2048s   18432s  16385s  primary  ext2
 2      18433s  34817s  16385s  primary  ext2
 3      34818s  51202s  16385s  primary  ext2


Please note the the extra sector in the size of each partition (16385 versus 16384).
Comment 5 Seth Hunter 2009-09-28 22:24:09 UTC
(In reply to comment #1)
> Thank you Seth for posting this report.
> 
> Do you have "Round to cylinders" enabled or disabled when creating the new
> partition?

"Round to cylinders" was disabled in my testing, which was done with the latest LiveCD.  It looks from your followup messages that you were able to reproduce the issue and verify that my proposed patch works -- thank you.
Comment 6 Curtis Gedak 2009-09-28 22:43:18 UTC
Thank you Seth for confirming that "Round to cylinders" was disabled, and for providing a patch.

The patch you created has been committed to the GNOME git repository for inclusion in the next release of GParted.
See:
http://git.gnome.org/cgit/gparted/commit/?id=df541b898623a74c000e84d8535215468232f2e0

Closing this bug.