util-linux/backport-libfdisk-fix-fdisk_reread_changes-for-extended-partitions.patch

41 lines
1.3 KiB
Diff

commit b0098c1ebd3bd068edaa38be67ac48b6c1218e98
Author: Karel Zak <kzak@redhat.com>
Date: Thu Aug 6 11:32:33 2020 +0200
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>
diff --git a/libfdisk/src/context.c b/libfdisk/src/context.c
index 363db30f4..327e03b42 100644
--- a/libfdisk/src/context.c
+++ b/libfdisk/src/context.c
@@ -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++;
}