fdisk: Add support for fixing MBR partitions CHS values

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>
This commit is contained in:
Pali Rohár 2021-07-30 11:19:20 +02:00
parent dac364addb
commit 973c3fc753
1 changed files with 8 additions and 0 deletions

View 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;
}