]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (dos) make it possible to create primary/logical by template
authorKarel Zak <kzak@redhat.com>
Fri, 17 Feb 2017 15:11:37 +0000 (16:11 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 17 Feb 2017 15:11:37 +0000 (16:11 +0100)
Let's check partition partno if specified to create logical or primary
partition.

Addresses: https://github.com/karelzak/util-linux/issues/204
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/dos.c

index 0c2006ed6f593a9e1f1d2ce3aa79801c8c9fd2d7..69090706a87acec8834f4fdfd7f950cbdbf6c4b4 100644 (file)
@@ -1551,10 +1551,28 @@ static int dos_add_partition(struct fdisk_context *cxt,
        } else if (pa && fdisk_partition_has_start(pa)) {
                DBG(LABEL, ul_debug("DOS: pa template %p: add primary", pa));
                rc = get_partition_unused_primary(cxt, pa, &res);
-               if (rc == 0) {
+               if (rc == 0)
                        rc = add_partition(cxt, res, pa);
-                       goto done;
-               }
+               goto done;
+
+       /* pa follows default, but partno < 4, it means primary partition */
+       } else if (pa && fdisk_partition_start_is_default(pa)
+                  && fdisk_partition_has_partno(pa)
+                   && pa->partno < 4) {
+               DBG(LABEL, ul_debug("DOS: pa template %p: add primary (partno < 4)", pa));
+               rc = get_partition_unused_primary(cxt, pa, &res);
+               if (rc == 0)
+                       rc = add_partition(cxt, res, pa);
+               goto done;
+
+       /* pa follows default, but partno >= 4, it means logical partition */
+       } else if (pa && fdisk_partition_start_is_default(pa)
+                  && ext_pe
+                  && fdisk_partition_has_partno(pa)
+                  && pa->partno >= 4) {
+               DBG(LABEL, ul_debug("DOS: pa template %p: add logical (partno >= 4)", pa));
+               rc = add_logical(cxt, pa, &res);
+               goto done;
        }
 
        /*