summaryrefslogtreecommitdiffstats
path: root/libfdisk
diff options
context:
space:
mode:
authorKarel Zak2016-05-18 14:15:02 +0200
committerKarel Zak2016-05-18 14:15:02 +0200
commita67054f9be6998cd111ab81e4ca8931128569f56 (patch)
treec0c6596e792a39646dc4f9a40a2c531abb731e04 /libfdisk
parentsfdisk: Add support for altering GPT size (diff)
downloadkernel-qcow2-util-linux-a67054f9be6998cd111ab81e4ca8931128569f56.tar.gz
kernel-qcow2-util-linux-a67054f9be6998cd111ab81e4ca8931128569f56.tar.xz
kernel-qcow2-util-linux-a67054f9be6998cd111ab81e4ca8931128569f56.zip
libfdisk: make table-length usage more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk')
-rw-r--r--libfdisk/src/gpt.c2
-rw-r--r--libfdisk/src/script.c11
2 files changed, 10 insertions, 3 deletions
diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c
index ff435e3ea..eaa9f4803 100644
--- a/libfdisk/src/gpt.c
+++ b/libfdisk/src/gpt.c
@@ -2503,6 +2503,8 @@ int fdisk_gpt_set_npartitions(struct fdisk_context *cxt, unsigned long new)
gpt = self_label(cxt);
old = le32_to_cpu(gpt->pheader->npartition_entries);
+ if (old == new)
+ return 0; /* do nothing, say nothing */
/* calculate the size (bytes) of the entries array */
new_size = new * le32_to_cpu(gpt->pheader->sizeof_partition_entry);
diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c
index fd05bf703..75e1b52de 100644
--- a/libfdisk/src/script.c
+++ b/libfdisk/src/script.c
@@ -1346,10 +1346,15 @@ int fdisk_apply_script_headers(struct fdisk_context *cxt, struct fdisk_script *d
return rc;
str = fdisk_script_get_header(dp, "table-length");
- if (str)
- return fdisk_gpt_set_npartitions(cxt, strtoul(str, NULL, 0));
+ if (str) {
+ uintmax_t sz;
- return 0;
+ rc = parse_size(str, &sz, NULL);
+ if (rc == 0)
+ rc = fdisk_gpt_set_npartitions(cxt, sz);
+ }
+
+ return rc;
}
/**