From 32b40fec8f64c05c130c7a96857ca2bf40ea9c0d Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 20 Aug 2008 23:27:50 +0200 Subject: [PATCH] fdisk: round reported sizes rather than truncate Exmaples (-old, +new): - Disk /dev/mapper/bar: 266.6 GB, 266666666496 bytes + Disk /dev/mapper/bar: 266.7 GB, 266666666496 bytes - WARNING: The size of this disk is 2.1 TB (2199023255552 bytes). + WARNING: The size of this disk is 2.2 TB (2199023255552 bytes). Reported-by: Stepan Kasal Signed-off-by: Karel Zak --- fdisk/fdisk.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c index 1af4103d..2651932a 100644 --- a/fdisk/fdisk.c +++ b/fdisk/fdisk.c @@ -676,12 +676,14 @@ warn_cylinders(void) { if (total_number_of_sectors > UINT_MAX) { int giga = (total_number_of_sectors << 9) / 1000000000; + int hectogiga = (giga + 50) / 100; + fprintf(stderr, _("\n" "WARNING: The size of this disk is %d.%d TB (%llu bytes).\n" -"DOS partition table format can not be used on drivers for volumes\n" +"DOS partition table format can not be used on drives for volumes\n" "larger than 2.2 TB (2199023255040 bytes). Use parted(1) and GUID \n" "partition table format (GPT).\n\n"), - giga/1000, (giga/100)%10, + hectogiga / 10, hectogiga % 10, total_number_of_sectors << 9); } } @@ -1627,9 +1629,11 @@ list_disk_geometry(void) { if (megabytes < 10000) printf(_("\nDisk %s: %ld MB, %lld bytes\n"), disk_device, megabytes, bytes); - else + else { + long hectomega = (megabytes + 50) / 100; printf(_("\nDisk %s: %ld.%ld GB, %lld bytes\n"), - disk_device, megabytes/1000, (megabytes/100)%10, bytes); + disk_device, hectomega / 10, hectomega % 10, bytes); + } printf(_("%d heads, %llu sectors/track, %d cylinders"), heads, sectors, cylinders); if (units_per_sector == 1) -- 2.39.5