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>
fdisk_enable_details
fdisk_enable_listonly
fdisk_enable_wipe
+fdisk_disable_dialogs
fdisk_get_alignment_offset
fdisk_get_collision
fdisk_get_devfd
fdisk_get_size_unit
fdisk_get_unit
fdisk_get_units_per_sector
+fdisk_has_dialogs
fdisk_has_label
fdisk_has_protected_bootbits
fdisk_has_wipe
ask->type == FDISK_ASKTYPE_WARN ? "warn" :
"?nothing?"));
+ if (!fdisk_has_dialogs(cxt) &&
+ !(ask->type == FDISK_ASKTYPE_INFO ||
+ ask->type == FDISK_ASKTYPE_WARNX ||
+ ask->type == FDISK_ASKTYPE_WARN)) {
+ DBG(ASK, ul_debugobj(ask, "dialogs disabled"));
+ return -EINVAL;
+ }
+
if (!cxt->ask_cb) {
DBG(ASK, ul_debugobj(ask, "no ask callback specified!"));
return -EINVAL;
cxt->protect_bootbits = enable ? 1 : 0;
return 0;
}
+/**
+ * fdisk_disable_dialogs
+ * @cxt: fdisk context
+ * @enable: 1 or 0
+ *
+ * The library uses dialog driven partitioning by default.
+ *
+ * Returns: 0 on success, < 0 on error.
+ *
+ * Since: 2.31
+ */
+int fdisk_disable_dialogs(struct fdisk_context *cxt, int disable)
+{
+ if (!cxt)
+ return -EINVAL;
+
+ cxt->no_disalogs = disable;
+ return 0;
+}
+
+/**
+ * fdisk_has_dialogs
+ * @cxt: fdisk context
+ *
+ * See fdisk_disable_dialogs()
+ *
+ * Returns: 1 if dialog driven partitioning enabled (default), or 0.
+ *
+ * Since: 2.31
+ */
+int fdisk_has_dialogs(struct fdisk_context *cxt)
+{
+ return cxt->no_disalogs == 0;
+}
/**
* fdisk_enable_wipe
DBG(LABEL, ul_debug("DOS: pa template specifies partno>=4 for primary partition"));
return -EINVAL;
}
- if (pa->type && IS_EXTENDED(pa->type->code)) {
+ if (ext_pe && pa->type && IS_EXTENDED(pa->type->code)) {
fdisk_warnx(cxt, _("Extended partition already exists."));
return -EINVAL;
}
DBG(LABEL, ul_debug("DOS: primary impossible, add logical"));
if (l->ext_offset) {
if (!pa || fdisk_partition_has_start(pa)) {
+ /* See above case A); here we have start, but
+ * out of extended partition */
const char *msg;
if (!free_primary)
msg = _("All primary partitions are in use.");
int c;
/* the default layout for scripts is to create primary partitions */
- if (cxt->script) {
+ if (cxt->script || !fdisk_has_dialogs(cxt)) {
rc = get_partition_unused_primary(cxt, pa, &res);
if (rc == 0)
rc = add_partition(cxt, res, pa);
display_details : 1, /* expert display mode */
protect_bootbits : 1, /* don't zeroize first sector */
pt_collision : 1, /* another PT detected by libblkid */
+ no_disalogs : 1, /* disable dialog-driven partititoning */
listonly : 1; /* list partition, nothing else */
char *collision; /* name of already existing FS/PT */
int fdisk_is_regfile(struct fdisk_context *cxt);
int fdisk_device_is_used(struct fdisk_context *cxt);
+int fdisk_disable_dialogs(struct fdisk_context *cxt, int disable);
+int fdisk_has_dialogs(struct fdisk_context *cxt);
+
int fdisk_enable_details(struct fdisk_context *cxt, int enable);
int fdisk_is_details(struct fdisk_context *cxt);
fdisk_reassign_device;
fdisk_device_is_used;
fdisk_reread_changes;
+ fdisk_disable_dialogs;
+ fdisk_has_dialogs;
} FDISK_2.30;
* 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.
*/
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)