]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: fix fdisk_reread_changes() for extended partitions
authorKarel Zak <kzak@redhat.com>
Thu, 6 Aug 2020 09:32:33 +0000 (11:32 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 6 Aug 2020 09:32:33 +0000 (11:32 +0200)
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>
libfdisk/src/context.c

index 363db30f45d3776ea9c0e14f70bfad8ceb8c74f4..327e03b42b214381e69e4a01bb5364030061fad5 100644 (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++;
                }