[git commit] fdisk: tweak some messages

Denys Vlasenko vda.linux at googlemail.com
Tue Aug 23 15:18:45 UTC 2016


commit: https://git.busybox.net/busybox/commit/?id=29483ffb075f1a64d2183ebe188b83f5704ba637
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

"Total allocated sectors 2021315 greater than the maximum 2020356"

maximum what?

Turns out, that's the CHS size of the disk.

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 util-linux/fdisk.c | 43 ++++++++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index 6b5e388..a048dd9 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -1897,22 +1897,23 @@ static void
 list_disk_geometry(void)
 {
 	ullong bytes = ((ullong)total_number_of_sectors << 9);
-	long megabytes = bytes / 1000000;
-
-	if (megabytes < 10000)
-		printf("\nDisk %s: %lu MB, %llu bytes\n",
-			disk_device, megabytes, bytes);
-	else
-		printf("\nDisk %s: %lu.%lu GB, %llu bytes\n",
-			disk_device, megabytes/1000, (megabytes/100)%10, bytes);
-	printf("%u heads, %u sectors/track, %u cylinders",
-		   g_heads, g_sectors, g_cylinders);
-	if (units_per_sector == 1)
-		printf(", total %"SECT_FMT"u sectors",
-			total_number_of_sectors / (sector_size/512));
-	printf("\nUnits = %s of %u * %u = %u bytes\n\n",
+	ullong xbytes = bytes / (1024*1024);
+	char x = 'M';
+
+	if (xbytes >= 10000) {
+		xbytes += 512; /* fdisk util-linux 2.28 does this */
+		xbytes /= 1024;
+		x = 'G';
+	}
+	printf("Disk %s: %llu %cB, %llu bytes, %"SECT_FMT"u sectors\n"
+		"%u cylinders, %u heads, %u sectors/track\n"
+		"Units: %s of %u * %u = %u bytes\n\n",
+		disk_device, xbytes, x,
+		bytes, total_number_of_sectors,
+		g_cylinders, g_heads, g_sectors,
 		str_units(PLURAL),
-		units_per_sector, sector_size, units_per_sector * sector_size);
+		units_per_sector, sector_size, units_per_sector * sector_size
+	);
 }
 
 /*
@@ -2277,6 +2278,7 @@ verify(void)
 {
 	int i, j;
 	sector_t total = 1;
+	sector_t chs_size;
 	sector_t first[g_partitions], last[g_partitions];
 	struct partition *p;
 
@@ -2338,11 +2340,14 @@ verify(void)
 		}
 	}
 
-	if (total > g_heads * g_sectors * g_cylinders)
-		printf("Total allocated sectors %u greater than the maximum "
-			"%u\n", total, g_heads * g_sectors * g_cylinders);
+	chs_size = (sector_t)g_heads * g_sectors * g_cylinders;
+	if (total > chs_size)
+		printf("Total allocated sectors %u"
+			" greater than CHS size %"SECT_FMT"u\n",
+			total, chs_size
+		);
 	else {
-		total = g_heads * g_sectors * g_cylinders - total;
+		total = chs_size - total;
 		if (total != 0)
 			printf("%"SECT_FMT"u unallocated sectors\n", total);
 	}


More information about the busybox-cvs mailing list