[Parted-maintainers] Bug#279732: parted doesn't print large partitions correctly [PATCH]

Peter Chubb Peter Chubb <peterc@gelato.unsw.edu.au>, 279732@bugs.debian.org
Fri, 5 Nov 2004 09:44:59 +1100


Package: parted
Version: 1.6.11-7

If you have partitions bigger than 1TB, parted prints them
incorrectly, because it casts the partition size (in sectors) to int,
which is only 32-bits.

Here is a patch.  I also fixed up some rather strange casting.

Index: parted-1.6.11/parted/parted.c
===================================================================
--- parted-1.6.11.orig/parted/parted.c	2003-06-30 11:44:14.000000000 +1000
+++ parted-1.6.11/parted/parted.c	2004-11-05 09:41:28.153948819 +1100
@@ -810,8 +810,8 @@
 	printf (_("Flags: ")); partition_print_flags (part); printf("\n");
 	printf (_("File System: %s\n"), fs->type->name);
 	printf (_("Size:         %10.3fMb (%d%%)\n"),
-		part->geom.length * 1.0 / MEGABYTE_SECTORS,
-		(int) 100 * part->geom.length / part->disk->dev->length);
+		((double)part->geom.length) / MEGABYTE_SECTORS,
+		(int)(100.0 * part->geom.length / part->disk->dev->length));
 
 	resize_constraint = ped_file_system_get_resize_constraint (fs);
 	if (resize_constraint) {
@@ -889,8 +889,8 @@
 		printf ("%-5d ", part->num);
 
 		printf ("%10.3f %10.3f  ",
-			(int) part->geom.start * 1.0 / MEGABYTE_SECTORS,
-			(int) part->geom.end * 1.0 / MEGABYTE_SECTORS);
+			(double)part->geom.start / MEGABYTE_SECTORS,
+			(double)part->geom.end / MEGABYTE_SECTORS);
 
 		if (has_extended)
 			printf ("%-9s ",
@@ -967,8 +967,8 @@
 		  "Do you want to add it to the partition table?"),
 		fs_type->name,
 		ped_partition_type_get_name (part->type),
-		(int) probed->start * 1.0 / MEGABYTE_SECTORS,
-		(int) probed->end * 1.0 / MEGABYTE_SECTORS);
+		(double)probed->start / MEGABYTE_SECTORS,
+		(double)probed->end / MEGABYTE_SECTORS);
 
 	switch (ex_opt) {
 		case PED_EXCEPTION_CANCEL: return -1;