From: Pali Rohár Date: Mon, 5 Jul 2021 20:13:11 +0000 (+0200) Subject: libfdisk: (dos) Recalculate number of cylinders after changing number of heads and... X-Git-Tag: v2.38-rc1~362^2~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b27ebfe59a414471b4068947291b74e66472ce3a;p=thirdparty%2Futil-linux.git libfdisk: (dos) Recalculate number of cylinders after changing number of heads and sectors After geometry is changes it is required to recalculate total number of cylinders. Otherwise total disk capacity is either reduced or extended. Signed-off-by: Pali Rohár --- diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index ce545f8571..39dd9ef43c 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -846,6 +846,8 @@ static int dos_probe_label(struct fdisk_context *cxt) if (h && s) { cxt->geom.heads = h; cxt->geom.sectors = s; + cxt->geom.cylinders = cxt->total_sectors / + (cxt->geom.heads * cxt->geom.sectors); if (fdisk_has_user_device_geometry(cxt)) fdisk_apply_user_device_properties(cxt);