libfdisk: fix fdisk_reread_changes() for extended partitions

Linux kernel assumes only 1KiB extended partition to avoid overlapping
with nested logical partitions. We need to follow this rule for
BLKPG_ADD_PARTITION.

Addresses: https://github.com/karelzak/util-linux/issues/1112
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2020-08-06 11:32:33 +02:00
parent 359b522c39
commit 33f50706fd
1 changed files with 12 additions and 1 deletions

View File

@ -939,10 +939,21 @@ int fdisk_reread_changes(struct fdisk_context *cxt, struct fdisk_table *org)
}
}
for (i = 0; i < nadds; i++) {
uint64_t sz;
pa = add[i];
sz = pa->size * ssf;
DBG(PART, ul_debugobj(pa, "#%zu calling BLKPG_ADD_PARTITION", pa->partno));
if (fdisk_is_label(cxt, DOS) && fdisk_partition_is_container(pa))
/* Let's follow the Linux kernel and reduce
* DOS extended partition to 1 or 2 sectors.
*/
sz = min(sz, (uint64_t) 2);
if (partx_add_partition(cxt->dev_fd, pa->partno + 1,
pa->start * ssf, pa->size * ssf) != 0) {
pa->start * ssf, sz) != 0) {
fdisk_warn(cxt, _("Failed to add partition %zu to system"), pa->partno + 1);
err++;
}