Blame SOURCES/0066-libfdisk-fix-fdisk_reread_changes-for-extended-parti.patch

25f9c8
From aecaffc55dd763c34f61937b2047f0aaaeb4e6fc Mon Sep 17 00:00:00 2001
25f9c8
From: Karel Zak <kzak@redhat.com>
25f9c8
Date: Thu, 6 Aug 2020 11:32:33 +0200
25f9c8
Subject: [PATCH 66/74] libfdisk: fix fdisk_reread_changes() for extended
25f9c8
 partitions
25f9c8
25f9c8
Linux kernel assumes only 1KiB extended partition to avoid overlapping
25f9c8
with nested logical partitions. We need to follow this rule for
25f9c8
BLKPG_ADD_PARTITION.
25f9c8
25f9c8
Addresses: https://github.com/karelzak/util-linux/issues/1112
25f9c8
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2041498
25f9c8
Upstream: http://github.com/util-linux/util-linux/commit/33f50706fd7c1c5e53f8f355f12b685c6935f5a4
25f9c8
Signed-off-by: Karel Zak <kzak@redhat.com>
25f9c8
---
25f9c8
 libfdisk/src/context.c | 13 ++++++++++++-
25f9c8
 1 file changed, 12 insertions(+), 1 deletion(-)
25f9c8
25f9c8
diff --git a/libfdisk/src/context.c b/libfdisk/src/context.c
25f9c8
index fe7eb9e7e..114101980 100644
25f9c8
--- a/libfdisk/src/context.c
25f9c8
+++ b/libfdisk/src/context.c
25f9c8
@@ -867,10 +867,21 @@ int fdisk_reread_changes(struct fdisk_context *cxt, struct fdisk_table *org)
25f9c8
 		}
25f9c8
 	}
25f9c8
 	for (i = 0; i < nadds; i++) {
25f9c8
+		uint64_t sz;
25f9c8
+
25f9c8
 		pa = add[i];
25f9c8
+		sz = pa->size * ssf;
25f9c8
+
25f9c8
 		DBG(PART, ul_debugobj(pa, "#%zu calling BLKPG_ADD_PARTITION", pa->partno));
25f9c8
+
25f9c8
+		if (fdisk_is_label(cxt, DOS) && fdisk_partition_is_container(pa))
25f9c8
+			/* Let's follow the Linux kernel and reduce
25f9c8
+                         * DOS extended partition to 1 or 2 sectors.
25f9c8
+			 */
25f9c8
+			sz = min(sz, (uint64_t) 2);
25f9c8
+
25f9c8
 		if (partx_add_partition(cxt->dev_fd, pa->partno + 1,
25f9c8
-					pa->start * ssf, pa->size * ssf) != 0) {
25f9c8
+					pa->start * ssf, sz) != 0) {
25f9c8
 			fdisk_warn(cxt, _("Failed to add partition %zu to system"), pa->partno + 1);
25f9c8
 			err++;
25f9c8
 		}
25f9c8
-- 
25f9c8
2.31.1
25f9c8