From 973c3fc7531ded5469de58aa7ff56fe31ea439b1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pali=20Roh=C3=A1r?= Date: Fri, 30 Jul 2021 11:19:20 +0200 Subject: [PATCH] fdisk: Add support for fixing MBR partitions CHS values MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add a new extended option 'F' to fdisk which recalculates and fixes CHS values for each partition in MBR table according to current fdisk settings for number of heads and sectors per track. This allows in interactive mode to repair existing partitions to be compatible with CHS addressing after changing extended option 'h' (number of heads) or 's' (sectors per track) as these options do not modify content of existing partitions. Signed-off-by: Pali Rohár --- disk-utils/fdisk-menu.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/disk-utils/fdisk-menu.c b/disk-utils/fdisk-menu.c index dcd9e796ca..2f22e59f43 100644 --- a/disk-utils/fdisk-menu.c +++ b/disk-utils/fdisk-menu.c @@ -221,6 +221,7 @@ static const struct menu menu_dos = { MENU_ENT('c', N_("toggle the dos compatibility flag")), MENU_XENT('b', N_("move beginning of data in a partition")), + MENU_XENT('F', N_("fix partitions C/H/S values")), MENU_XENT('i', N_("change the disk identifier")), MENU_BENT_NEST_H('M', N_("return from protective/hybrid MBR to GPT"), FDISK_DISKLABEL_DOS, FDISK_DISKLABEL_GPT), @@ -869,6 +870,13 @@ static int dos_menu_cb(struct fdisk_context **cxt0, fdisk_unref_context(cxt); } break; + case 'F': + rc = fdisk_dos_fix_chs(cxt); + if (rc) + fdisk_info(cxt, _("C/H/S values fixed.")); + else + fdisk_info(cxt, _("Nothing to do. C/H/S values are correct already.")); + break; } return rc; } -- 2.47.3