]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: use real sector size in verify() and warn_cylinders()
authorKarel Zak <kzak@redhat.com>
Thu, 26 Feb 2009 09:19:05 +0000 (10:19 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 26 Feb 2009 14:58:19 +0000 (15:58 +0100)
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 <kzak@redhat.com>
fdisk/fdisk.c

index 0c837471428978d62d77587de264dfe52b4228c3..b7e517a95eb857078b82646d7d7609a644d22881 100644 (file)
@@ -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