From: Karel Zak Date: Thu, 26 Feb 2009 09:19:05 +0000 (+0100) Subject: fdisk: use real sector size in verify() and warn_cylinders() X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85a994c49f57470586463bdd6a2b15789d7955f8;p=util-linux fdisk: use real sector size in verify() and warn_cylinders() 4KiB-sector disk: Note: sector size is 4096 (not 512) Disk /dev/sdb: 8 MB, 8388608 bytes 8 heads, 32 sectors/track, 8 cylinders, total 2048 sectors Units = sectors of 1 * 4096 = 4096 bytes Disk identifier: 0x6aad54da Device Boot Start End Blocks Id System /dev/sdb1 32 2047 8064 83 Linux old version (mix 512 and real sectors): Command (m for help): v 14367 unallocated sectors new version: Command (m for help): v 31 unallocated 4096-byte sectors Signed-off-by: Karel Zak --- diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c index 0c837471..b7e517a9 100644 --- a/fdisk/fdisk.c +++ b/fdisk/fdisk.c @@ -217,7 +217,7 @@ unsigned int heads, units_per_sector = 1, display_in_cyl_units = 1; -unsigned long long total_number_of_sectors; +unsigned long long total_number_of_sectors; /* (!) 512-byte sectors */ #define dos_label (!sun_label && !sgi_label && !aix_label && !mac_label && !osf_label) int sun_label = 0; /* looking at sun disklabel */ @@ -682,10 +682,12 @@ warn_cylinders(void) { 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 drives for volumes\n" -"larger than 2.2 TB (2199023255040 bytes). Use parted(1) and GUID \n" +"larger than (%llu bytes) for %d-byte sectors. Use parted(1) and GUID \n" "partition table format (GPT).\n\n"), hectogiga / 10, hectogiga % 10, - total_number_of_sectors << 9); + total_number_of_sectors << 9, + (unsigned long long ) UINT_MAX * sector_size, + sector_size); } } @@ -906,7 +908,7 @@ get_partition_table_geometry(void) { void get_geometry(int fd, struct geom *g) { - unsigned long long llsectors, llcyls; + unsigned long long llcyls; get_sectorsize(fd); sector_factor = sector_size / 512; @@ -925,10 +927,8 @@ get_geometry(int fd, struct geom *g) { pt_sectors ? pt_sectors : kern_sectors ? kern_sectors : 63; - if (blkdev_get_sectors(fd, &llsectors) == -1) - llsectors = 0; - - total_number_of_sectors = llsectors; + if (blkdev_get_sectors(fd, &total_number_of_sectors) == -1) + total_number_of_sectors = 0; sector_offset = 1; if (dos_compatible_flag) @@ -1938,7 +1938,8 @@ check(int n, unsigned int h, unsigned int s, unsigned int c, static void verify(void) { int i, j; - unsigned long total = 1; + unsigned long long total = 1; + unsigned long long n_sectors = (total_number_of_sectors / sector_factor); unsigned long long first[partitions], last[partitions]; struct partition *p; @@ -2001,12 +2002,12 @@ verify(void) { } } - if (total > total_number_of_sectors) - printf(_("Total allocated sectors %ld greater than the maximum" - " %lld\n"), total, total_number_of_sectors); - else if (total < total_number_of_sectors) - printf(_("%lld unallocated sectors\n"), - total_number_of_sectors - total); + if (total > n_sectors) + printf(_("Total allocated sectors %llu greater than the maximum" + " %llu\n"), total, n_sectors); + else if (total < n_sectors) + printf(_("%lld unallocated %d-byte sectors\n"), + n_sectors - total, sector_size); } static void