From: Karel Zak Date: Mon, 16 Sep 2019 08:29:41 +0000 (+0200) Subject: libfdisk: add sector-size to dump X-Git-Tag: v2.35-rc1~212 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e56ca0681514dcf0846225cd67a72d1ab260b8a6;p=thirdparty%2Futil-linux.git libfdisk: add sector-size to dump We do not use sector-size from dumps to create partition tables, because it's always necessary to use real device specific settings. The new sector-size value is usable when you use the dump as a description of the device or disk image. Addresses: https://github.com/karelzak/util-linux/issues/869 Signed-off-by: Karel Zak --- diff --git a/disk-utils/sfdisk.8 b/disk-utils/sfdisk.8 index 9dee0cace8..d1e429381f 100644 --- a/disk-utils/sfdisk.8 +++ b/disk-utils/sfdisk.8 @@ -337,6 +337,11 @@ Specify the maximal number of GPT partitions. Specify minimal size in bytes used to calculate partitions alignment. The default is 1MiB and it's strongly recommended to use the default. Do not modify this variable if you're not sure. +.TP +.B sector-size +Specify sector size. This header is informative only and it is not used when +sfdisk creates a new partition table, in this case the real device specific +value is always used and sector size from the dump is ignored. .RE .sp Note that it is only possible to use header lines before the first partition diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c index a28983dbad..50899664fe 100644 --- a/libfdisk/src/script.c +++ b/libfdisk/src/script.c @@ -445,6 +445,7 @@ int fdisk_script_read_context(struct fdisk_script *dp, struct fdisk_context *cxt struct fdisk_label *lb; int rc; char *p = NULL; + char buf[64]; if (!dp || (!cxt && !dp->cxt)) return -EINVAL; @@ -478,7 +479,6 @@ int fdisk_script_read_context(struct fdisk_script *dp, struct fdisk_context *cxt if (!rc && fdisk_is_label(cxt, GPT)) { struct fdisk_labelitem item = FDISK_LABELITEM_INIT; - char buf[64]; /* first-lba */ rc = fdisk_get_disklabel_item(cxt, GPT_LABELITEM_FIRSTLBA, &item); @@ -506,12 +506,14 @@ int fdisk_script_read_context(struct fdisk_script *dp, struct fdisk_context *cxt } if (!rc && fdisk_get_grain_size(cxt) != 2048 * 512) { - char buf[64]; - snprintf(buf, sizeof(buf), "%lu", fdisk_get_grain_size(cxt)); rc = fdisk_script_set_header(dp, "grain", buf); } + if (!rc) { + snprintf(buf, sizeof(buf), "%lu", fdisk_get_sector_size(cxt)); + rc = fdisk_script_set_header(dp, "sector-size", buf); + } DBG(SCRIPT, ul_debugobj(dp, "read context done [rc=%d]", rc)); return rc; @@ -580,6 +582,9 @@ static int write_file_json(struct fdisk_script *dp, FILE *f) } else if (strcmp(name, "last-lba") == 0) { name = "lastlba"; num = 1; + } else if (strcmp(name, "sector-size") == 0) { + name = "sectorsize"; + num = 1; } else if (strcmp(name, "label-id") == 0) name = "id";