]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (dos) calculation of total size based on CHS in check function
authorThorsten Wilmer <wilmer.thorsten@gmail.com>
Tue, 24 Jun 2014 07:38:30 +0000 (09:38 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 24 Jun 2014 07:40:06 +0000 (09:40 +0200)
Many people report a problem with the message if (cylinders <= 1024 &&
start != total) fprintf(stderr, _("Partition %d: previous sectors %d
disagrees with " "total %d\n"), n, start, total);

This message comes from the fact that the previous code caluclates the
total number of sectors in the wrong way.

The formula should be total = (real_c * heads + h) * sectors + real_s;

As a Cylinder consists of some heads * sectors A Head consists of some
sectors and finally sectors are the smallest unit

Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/dos.c

index e365e722d0cb0b4e0871d90bcffdd2c5dcae91ca..f3b162af17f78b0186d5e29785f78bb6675ccd62 100644 (file)
@@ -1155,7 +1155,7 @@ static void check(struct fdisk_context *cxt, size_t n,
 
        real_s = sector(s) - 1;
        real_c = cylinder(s, c);
-       total = (real_c * cxt->geom.sectors + real_s) * cxt->geom.heads + h;
+       total = (real_c * cxt->geom.heads + h) * cxt->geom.sectors + real_s;
 
        if (!total)
                fdisk_warnx(cxt, _("Partition %zu: contains sector 0"), n);