From: Pali Rohár Date: Tue, 6 Jul 2021 15:12:13 +0000 (+0200) Subject: libfdisk: (dos) Fix setting CHS values when creating new partition X-Git-Tag: v2.38-rc1~362^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ed5a0f331bd825b9613445fdf2032b6af8ef7949;p=thirdparty%2Futil-linux.git libfdisk: (dos) Fix setting CHS values when creating new partition 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 --- diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index 1a2b58f99f..f4ac1e27a8 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -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);