From: Karel Zak Date: Mon, 2 Sep 2024 12:04:18 +0000 (+0200) Subject: sfdisk: ignore last-lba from script on --force X-Git-Tag: v2.42-start~220 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4877d7f61a72e46aba3fc52f347d1cd74124dba5;p=thirdparty%2Futil-linux.git sfdisk: ignore last-lba from script on --force The last LBA depends on the disk size. It seems like a good idea to ignore it when using the --force option, in order to make it possible to apply the script on smaller disks. Addresses: https://github.com/util-linux/util-linux/issues/3186 Signed-off-by: Karel Zak --- diff --git a/disk-utils/sfdisk.8.adoc b/disk-utils/sfdisk.8.adoc index bc3ff9bb8..b2e5279d2 100644 --- a/disk-utils/sfdisk.8.adoc +++ b/disk-utils/sfdisk.8.adoc @@ -243,7 +243,7 @@ Specify the partition table identifier. It should be a hexadecimal number (with *first-lba*:: Specify the first usable sector for GPT partitions. This header is ignored if the script and device sector size differ. In this case *sfdisk* uses label specific default. *last-lba*:: -Specify the last usable sector for GPT partitions. This header is ignored if the script and device sector size differ. In this case *sfdisk* uses label specific default. +Specify the last usable sector for GPT partitions. This header is ignored if the script and device sector size differ. In this case *sfdisk* uses label specific default. The last-lba header is ignored if *--force* is specified, making the script usable on disks with different sizes. *table-length*:: Specify the maximal number of GPT partitions. *grain*:: diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c index 0575373dc..71b0191d2 100644 --- a/disk-utils/sfdisk.c +++ b/disk-utils/sfdisk.c @@ -1925,7 +1925,14 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv) ignored++; continue; } - if (!created) { /* create a new disklabel */ + if (!created) { + /* ignore "last-lba" and use default if --force specified */ + if (sf->force && fdisk_script_get_header(dp, "last-lba")) { + fdisk_info(sf->cxt, _("Ignoring last-lba script header.")); + fdisk_script_set_header(dp, "last-lba", NULL); + } + + /* create a new disklabel */ rc = fdisk_apply_script_headers(sf->cxt, dp); created = !rc; if (rc) { @@ -1933,7 +1940,6 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv) fdisk_warn(sf->cxt, _( "Failed to apply script headers, disk label not created")); } - if (rc == 0 && fdisk_get_collision(sf->cxt)) follow_wipe_mode(sf); }