From 7ab459dff15b450d968db3af71c3cb6d7e55b60a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pali=20Roh=C3=A1r?= Date: Tue, 6 Jul 2021 14:08:42 +0200 Subject: [PATCH] libfdisk: (dos) Fix check error message when CHS calculated sector does not match LBA MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- libfdisk/src/dos.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index aeb819f1a1..e65088783a 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -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, -- 2.47.3