From: Karel Zak Date: Fri, 17 Feb 2017 15:11:37 +0000 (+0100) Subject: libfdisk: (dos) make it possible to create primary/logical by template X-Git-Tag: v2.30-rc1~232 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8d03f4af49a7efe894cb7c68c84649fb889ba741;p=thirdparty%2Futil-linux.git libfdisk: (dos) make it possible to create primary/logical by template 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 --- diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index 0c2006ed6f..69090706a8 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -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; } /*