diff options
author | Karel Zak | 2018-09-12 13:18:08 +0200 |
---|---|---|
committer | Karel Zak | 2018-09-12 13:26:18 +0200 |
commit | e4386c8cc0f7f2cfb09781d963b353310a3cd93a (patch) | |
tree | e91a483ea75563bc4bd3a2b9faaceefec3fafac0 /libfdisk | |
parent | sfdisk: document script GPT headers (diff) | |
download | kernel-qcow2-util-linux-e4386c8cc0f7f2cfb09781d963b353310a3cd93a.tar.gz kernel-qcow2-util-linux-e4386c8cc0f7f2cfb09781d963b353310a3cd93a.tar.xz kernel-qcow2-util-linux-e4386c8cc0f7f2cfb09781d963b353310a3cd93a.zip |
libfdisk: accept grain script header
The "grain" variable is used to calculate partitions alignment. The
default is 1MiB (or minimal I/O size). The libfdisk provides API to overwrite
this default, but this feature has been nowhere accessible for
end-user.
This patch support for "grain: <size>" in libfdisk scripts.
Addresses: https://github.com/karelzak/util-linux/issues/688
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk')
-rw-r--r-- | libfdisk/src/alignment.c | 1 | ||||
-rw-r--r-- | libfdisk/src/script.c | 24 |
2 files changed, 24 insertions, 1 deletions
diff --git a/libfdisk/src/alignment.c b/libfdisk/src/alignment.c index 891285aaa..a238c7bf0 100644 --- a/libfdisk/src/alignment.c +++ b/libfdisk/src/alignment.c @@ -338,6 +338,7 @@ int fdisk_save_user_grain(struct fdisk_context *cxt, unsigned long grain) if (!cxt || grain % 512) return -EINVAL; + DBG(CXT, ul_debugobj(cxt, "user grain size: %lu", grain)); cxt->user_grain = grain; return 0; } diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c index 1970e7b66..24c40f8ce 100644 --- a/libfdisk/src/script.c +++ b/libfdisk/src/script.c @@ -241,7 +241,6 @@ const char *fdisk_script_get_header(struct fdisk_script *dp, const char *name) return fi ? fi->data : NULL; } - /** * fdisk_script_set_header: * @dp: script instance @@ -447,6 +446,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), "%zu", fdisk_get_grain_size(cxt)); + rc = fdisk_script_set_header(dp, "grain", buf); + } + + DBG(SCRIPT, ul_debugobj(dp, "read context done [rc=%d]", rc)); return rc; } @@ -759,6 +766,7 @@ static int parse_line_header(struct fdisk_script *dp, char *s) goto done; /* only "sectors" supported */ } else if (strcmp(name, "label-id") == 0 || strcmp(name, "device") == 0 + || strcmp(name, "grain") == 0 || strcmp(name, "first-lba") == 0 || strcmp(name, "last-lba") == 0 || strcmp(name, "table-length") == 0) { @@ -1432,6 +1440,20 @@ int fdisk_apply_script_headers(struct fdisk_context *cxt, struct fdisk_script *d DBG(SCRIPT, ul_debugobj(dp, "applying script headers")); fdisk_set_script(cxt, dp); + str = fdisk_script_get_header(dp, "grain"); + if (str) { + uintmax_t sz; + + rc = parse_size(str, &sz, NULL); + if (rc == 0) + rc = fdisk_save_user_grain(cxt, sz); + if (rc) + return rc; + } + + if (fdisk_has_user_device_properties(cxt)) + fdisk_apply_user_device_properties(cxt); + /* create empty label */ name = fdisk_script_get_header(dp, "label"); if (!name) |