aboutsummaryrefslogtreecommitdiffstats
path: root/disk-utils/sfdisk.c
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2021-08-19 12:10:02 +0200
committerKarel Zak <kzak@redhat.com>2021-08-19 12:10:02 +0200
commit0c7e7cc4eccb6303c4723587d536d9e45fa8e5f3 (patch)
tree5f6b6ef0f8194de0b0664bd714973ffd91dae8c1 /disk-utils/sfdisk.c
parentd73690420693677ab07e331f20a80805a327773d (diff)
downloadutil-linux-0c7e7cc4eccb6303c4723587d536d9e45fa8e5f3.tar.gz
sfdisk: write empty label also when only ignored partition specified
sfdisk writes empty disk label only when "label:" header specified. Unfortunately, this feature is ignored when all specified partitions are ignored echo -e "label: dos\n0,0,0\n" | sfdisk /dev/sdc Fixes: https://github.com/karelzak/util-linux/issues/1413 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/sfdisk.c')
-rw-r--r--disk-utils/sfdisk.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c
index 526d090071..b08c945c06 100644
--- a/disk-utils/sfdisk.c
+++ b/disk-utils/sfdisk.c
@@ -1714,7 +1714,7 @@ static void refresh_prompt_buffer(struct sfdisk *sf, const char *devname,
*/
static int command_fdisk(struct sfdisk *sf, int argc, char **argv)
{
- int rc = 0, partno = sf->partno, created = 0, unused = 0;
+ int rc = 0, partno = sf->partno, created = 0, unused = 0, ignored = 0;
struct fdisk_script *dp;
struct fdisk_table *tb = NULL;
const char *devname = NULL, *label;
@@ -1897,6 +1897,7 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv)
if (ignore_partition(pa)) {
fdisk_info(sf->cxt, _("Ignoring partition."));
next_partno++;
+ ignored++;
continue;
}
if (!created) { /* create a new disklabel */
@@ -1960,7 +1961,7 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv)
/* create empty disk label if label, but no partition specified */
if ((rc == SFDISK_DONE_EOF || rc == SFDISK_DONE_WRITE) && created == 0
&& fdisk_script_has_force_label(dp) == 1
- && fdisk_table_get_nents(tb) == 0
+ && fdisk_table_get_nents(tb) == (size_t) ignored
&& fdisk_script_get_header(dp, "label")) {
int xrc = fdisk_apply_script_headers(sf->cxt, dp);