]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: Add support for fixing MBR partitions CHS values
authorPali Rohár <pali.rohar@gmail.com>
Fri, 30 Jul 2021 09:19:20 +0000 (11:19 +0200)
committerPali Rohár <pali.rohar@gmail.com>
Fri, 30 Jul 2021 09:58:27 +0000 (11:58 +0200)
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 <pali.rohar@gmail.com>
disk-utils/fdisk-menu.c

index dcd9e796cae7f288fb3a33befcd574b6e6827f7e..2f22e59f433ba0d16f9a000da306dcbb88ae84e9 100644 (file)
@@ -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;
 }