summaryrefslogtreecommitdiffstats
path: root/libfdisk/src/partition.c
diff options
context:
space:
mode:
authorKarel Zak2017-07-19 11:30:57 +0200
committerKarel Zak2017-07-19 11:30:57 +0200
commit992f7cbae420ab1b71fd9f2c2ae10c9804c1d213 (patch)
tree0ddb41ced462bf3fc0feebc1b5a14df76b4966aa /libfdisk/src/partition.c
parentlibfdisk: (dos) return EINVAL when delete unused partition (diff)
downloadkernel-qcow2-util-linux-992f7cbae420ab1b71fd9f2c2ae10c9804c1d213.tar.gz
kernel-qcow2-util-linux-992f7cbae420ab1b71fd9f2c2ae10c9804c1d213.tar.xz
kernel-qcow2-util-linux-992f7cbae420ab1b71fd9f2c2ae10c9804c1d213.zip
libfdisk: add fdisk_disable_dialogs()
The default (for historical reasons) is to use dialog driven partitioning. It's possible to avoid dialogs by fdisk_partition template for fdisk_add_partition(). Unfortunately in some case (mostly DOS driver) it's not enough, because we need to distinguish between logical and primary partitions. If we know that dialogs are unwanted then we can default to primary partition, etc. This function simplify semantic of the library for non-interactive programs. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk/src/partition.c')
-rw-r--r--libfdisk/src/partition.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/libfdisk/src/partition.c b/libfdisk/src/partition.c
index daa73a4ed..bc52ea573 100644
--- a/libfdisk/src/partition.c
+++ b/libfdisk/src/partition.c
@@ -705,9 +705,9 @@ int fdisk_partition_is_wholedisk(struct fdisk_partition *pa)
* If @pa specified and partno-follow-default (see fdisk_partition_partno_follow_default())
* enabled then returns next expected partno or -ERANGE on error.
*
- * If @pa is NULL, or @pa does not specify any sepamntic for the next partno
+ * If @pa is NULL, or @pa does not specify any semantic for the next partno
* then use Ask API to ask user for the next partno. In this case returns 1 if
- * no free partition avaialble.
+ * no free partition avaialble. If fdisk dialogs are disabled then returns -EINVAL.
*
* Returns: 0 on success, <0 on error, or 1 for non-free partno by Ask API.
*/
@@ -740,10 +740,12 @@ int fdisk_partition_next_partno(
fdisk_is_partition_used(cxt, pa->partno))
return -ERANGE;
*n = pa->partno;
- } else
+ return 0;
+
+ } else if (fdisk_has_dialogs(cxt))
return fdisk_ask_partnum(cxt, n, 1);
- return 0;
+ return -EINVAL;
}
static int probe_partition_content(struct fdisk_context *cxt, struct fdisk_partition *pa)