diff options
author | Karel Zak | 2015-03-02 13:58:23 +0100 |
---|---|---|
committer | Karel Zak | 2015-03-02 13:58:23 +0100 |
commit | b7c67e6414a68caaef133e978b3110d599f3d147 (patch) | |
tree | ceaafb05e947de09c4a7e38457e9f002d1ff6c5d /libfdisk/src/script.c | |
parent | docs: fstab(5) grammar / English fixes, and some other updates (diff) | |
download | kernel-qcow2-util-linux-b7c67e6414a68caaef133e978b3110d599f3d147.tar.gz kernel-qcow2-util-linux-b7c67e6414a68caaef133e978b3110d599f3d147.tar.xz kernel-qcow2-util-linux-b7c67e6414a68caaef133e978b3110d599f3d147.zip |
libfdisk: add {first,last}-lba header to sfdisk scritps
The current sfdisk does not allow to create partition that
starts before the default libfdisk First LBA (~1MiB). It
means that
# sfdisk --dump /dev/sda > foo
# sfdisk /dev/sdb < foo
does not work on systems where 1st partition does not start at offset
2048.
This patch add new headers to scripts to inform libfdisk about different
First/Last LBA ranges. For example:
label: gpt
first-lba: 34
allows to override the library default.
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk/src/script.c')
-rw-r--r-- | libfdisk/src/script.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c index 5a89790d7..eb4e31d20 100644 --- a/libfdisk/src/script.c +++ b/libfdisk/src/script.c @@ -238,17 +238,22 @@ int fdisk_script_set_header(struct fdisk_script *dp, if (!dp || !name) return -EINVAL; + fi = script_get_header(dp, name); if (!fi && !data) return 0; /* want to remove header that does not exist, success */ if (!data) { + DBG(SCRIPT, ul_debugobj(dp, "freeing header %s", name)); + /* no data, remove the header */ fdisk_script_free_header(dp, fi); return 0; } if (!fi) { + DBG(SCRIPT, ul_debugobj(dp, "setting new header %s='%s'", name, data)); + /* new header */ fi = calloc(1, sizeof(*fi)); if (!fi) @@ -265,6 +270,8 @@ int fdisk_script_set_header(struct fdisk_script *dp, /* update existing */ char *x = strdup(data); + DBG(SCRIPT, ul_debugobj(dp, "update '%s' header '%s' -> '%s'", name, fi->data, data)); + if (!x) return -ENOMEM; free(fi->data); @@ -366,7 +373,17 @@ int fdisk_script_read_context(struct fdisk_script *dp, struct fdisk_context *cxt if (!rc) rc = fdisk_script_set_header(dp, "unit", "sectors"); - /* TODO: label specific headers (e.g. uuid for GPT) */ + if (!rc && fdisk_is_label(cxt, GPT)) { + char buf[64]; + + snprintf(buf, sizeof(buf), "%ju", cxt->first_lba); + rc = fdisk_script_set_header(dp, "first-lba", buf); + + if (!rc) { + snprintf(buf, sizeof(buf), "%ju", cxt->last_lba); + rc = fdisk_script_set_header(dp, "last-lba", buf); + } + } DBG(SCRIPT, ul_debugobj(dp, "read context done [rc=%d]", rc)); return rc; @@ -493,7 +510,9 @@ static int parse_header_line(struct fdisk_script *dp, char *s) if (strcmp(value, "sectors") != 0) goto done; /* only "sectors" supported */ } else if (strcmp(name, "label-id") == 0 - || strcmp(name, "device") == 0) { + || strcmp(name, "device") == 0 + || strcmp(name, "first-lba") == 0 + || strcmp(name, "last-lba") == 0) { ; /* whatever is posssible */ } else goto done; /* unknown header */ |