summaryrefslogtreecommitdiffstats
path: root/libfdisk/src/script.c
diff options
context:
space:
mode:
authorKarel Zak2016-11-30 12:43:10 +0100
committerKarel Zak2016-11-30 13:01:33 +0100
commit35ca51182782193f555fbdcb06bb10766550d017 (patch)
treee790c87db174462db010ed6c8ea32e7a7506df0f /libfdisk/src/script.c
parentsfdisk: cleanup --dump error messages (diff)
downloadkernel-qcow2-util-linux-35ca51182782193f555fbdcb06bb10766550d017.tar.gz
kernel-qcow2-util-linux-35ca51182782193f555fbdcb06bb10766550d017.tar.xz
kernel-qcow2-util-linux-35ca51182782193f555fbdcb06bb10766550d017.zip
sfdisk: support empty label use-case
By default sfdisk creates partition table when a first partition is specified, otherwise the device is not modified. This force users to create at least one partition. This commit allows to create empty label without partitions if "label: <name>" header line is specified by script. The commit also modifies "New situation:" output to list label name and label identifier. Addresses: https://github.com/karelzak/util-linux/issues/374 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk/src/script.c')
-rw-r--r--libfdisk/src/script.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c
index ae7e99a14..0d1f260ea 100644
--- a/libfdisk/src/script.c
+++ b/libfdisk/src/script.c
@@ -36,7 +36,8 @@ struct fdisk_script {
size_t nlines;
struct fdisk_label *label;
- unsigned int json : 1; /* JSON output */
+ unsigned int json : 1, /* JSON output */
+ force_label : 1; /* label: <name> specified */
};
@@ -354,6 +355,22 @@ int fdisk_script_get_nlines(struct fdisk_script *dp)
}
/**
+ * fdisk_script_has_force_label:
+ * @dp: script
+ *
+ * Note that fdisk_script_set_header(dp, "label", name) does not modify
+ * force_label status. The label has to be specified by script.
+ *
+ * Returns: true if "label: <name>" has been parsed.
+ */
+int fdisk_script_has_force_label(struct fdisk_script *dp)
+{
+ assert(dp);
+ return dp->force_label;
+}
+
+
+/**
* fdisk_script_read_context:
* @dp: script
* @cxt: context
@@ -706,6 +723,7 @@ static int parse_line_header(struct fdisk_script *dp, char *s)
if (strcmp(name, "label") == 0) {
if (dp->cxt && !fdisk_get_label(dp->cxt, value))
goto done; /* unknown label name */
+ dp->force_label = 1;
} else if (strcmp(name, "unit") == 0) {
if (strcmp(value, "sectors") != 0)
goto done; /* only "sectors" supported */