]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (dos) Fix check error message when CHS calculated sector does not match LBA
authorPali Rohár <pali.rohar@gmail.com>
Tue, 6 Jul 2021 12:08:42 +0000 (14:08 +0200)
committerPali Rohár <pali.rohar@gmail.com>
Thu, 15 Jul 2021 19:49:30 +0000 (21:49 +0200)
Function check() checks that LBA addresses sector number matches CHS sector
number. But error message contains information about "previous sectors" and
"total sectors" which is misleading so change it.

Also rename variables 'start' and 'total' to make it clear what value is
stored in them. Note that in 'start' variable is currently stored last LBA
partition sector and in 'total' is stored last CHS partition sector. So
neither sector where partition starts nor total sectors of partition.

Code and check logic looks to be correct, just error message and variable
names are misleading. Therefore no functional changes in this patch.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
libfdisk/src/dos.c

index aeb819f1a1fc2eeddb882dcf323f5c67acc4c990..e65088783a0c9bb4eef5a850d2bddb9784e0e9ac 100644 (file)
@@ -1498,18 +1498,18 @@ static int add_logical(struct fdisk_context *cxt,
 
 static void check(struct fdisk_context *cxt, size_t n,
           unsigned int h, unsigned int s, unsigned int c,
-          unsigned int start)
+          unsigned int lba_sector)
 {
-       unsigned int total, real_s, real_c;
+       unsigned int chs_sector, real_s, real_c;
 
        if (!is_dos_compatible(cxt))
                return;
 
        real_s = sector(s) - 1;
        real_c = cylinder(s, c);
-       total = (real_c * cxt->geom.heads + h) * cxt->geom.sectors + real_s;
+       chs_sector = (real_c * cxt->geom.heads + h) * cxt->geom.sectors + real_s;
 
-       if (!total)
+       if (!chs_sector)
                fdisk_warnx(cxt, _("Partition %zu: contains sector 0"), n);
        if (h >= cxt->geom.heads)
                fdisk_warnx(cxt, _("Partition %zu: head %d greater than "
@@ -1524,9 +1524,10 @@ static void check(struct fdisk_context *cxt, size_t n,
                                n, real_c + 1,
                                (uintmax_t) cxt->geom.cylinders);
 
-       if (cxt->geom.cylinders <= 1024 && start != total)
-               fdisk_warnx(cxt, _("Partition %zu: previous sectors %u "
-                                  "disagrees with total %u"), n, start, total);
+       if (cxt->geom.cylinders <= 1024 && lba_sector != chs_sector)
+               fdisk_warnx(cxt, _("Partition %zu: LBA sector %u "
+                                  "disagrees with C/H/S calculated sector %u"),
+                               n, lba_sector, chs_sector);
 }
 
 /* check_consistency() and long2chs() added Sat Mar 6 12:28:16 1993,