]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (dos) Fix setting CHS values when creating new partition
authorPali Rohár <pali.rohar@gmail.com>
Tue, 6 Jul 2021 15:12:13 +0000 (17:12 +0200)
committerPali Rohár <pali.rohar@gmail.com>
Thu, 15 Jul 2021 19:49:30 +0000 (21:49 +0200)
It does not matter if dos compatibility flag is turned on or off. CHS
values in partition entry can overflow also when dos compatibility flag is
turned off. In this case maximal representable CHS values should be used.

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

index 1a2b58f99f23929b4c9141521ebb922e4ed5f26e..f4ac1e27a839ec855775acbdaba6d5da4fd43925 100644 (file)
@@ -926,10 +926,10 @@ static void set_partition(struct fdisk_context *cxt,
        dos_partition_set_start(p, start - offset);
        dos_partition_set_size(p, stop - start + 1);
 
-       if (is_dos_compatible(cxt) && (start/(cxt->geom.sectors*cxt->geom.heads) > 1023))
+       if (start/(cxt->geom.sectors*cxt->geom.heads) > 1023)
                start = cxt->geom.heads*cxt->geom.sectors*1024 - 1;
        set_hsc(p->bh, p->bs, p->bc, start);
-       if (is_dos_compatible(cxt) && (stop/(cxt->geom.sectors*cxt->geom.heads) > 1023))
+       if (stop/(cxt->geom.sectors*cxt->geom.heads) > 1023)
                stop = cxt->geom.heads*cxt->geom.sectors*1024 - 1;
        set_hsc(p->eh, p->es, p->ec, stop);
        partition_set_changed(cxt, i, 1);