diff options
| author | Karel Zak <kzak@redhat.com> | 2019-09-16 10:29:41 +0200 |
|---|---|---|
| committer | Karel Zak <kzak@redhat.com> | 2019-09-16 10:29:41 +0200 |
| commit | e56ca0681514dcf0846225cd67a72d1ab260b8a6 (patch) | |
| tree | 93bccbdb1747a47632f4694eb10b5b7bd9e11e91 /libfdisk/src/script.c | |
| parent | 9245c84dfdd1949a67d9247971e65d4ff64a6f65 (diff) | |
| download | util-linux-e56ca0681514dcf0846225cd67a72d1ab260b8a6.tar.gz | |
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 <kzak@redhat.com>
Diffstat (limited to 'libfdisk/src/script.c')
| -rw-r--r-- | libfdisk/src/script.c | 11 |
1 files changed, 8 insertions, 3 deletions
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"; |
