diff options
author | Karel Zak | 2016-05-18 14:29:50 +0200 |
---|---|---|
committer | Karel Zak | 2016-05-18 14:29:50 +0200 |
commit | 747600537c67a25cc27a235a24980b234b6ac29e (patch) | |
tree | 8ff56a53953a4518b6068bc436414f1542d2e6e1 /libfdisk/src/script.c | |
parent | libfdisk: make table-length usage more robust (diff) | |
download | kernel-qcow2-util-linux-747600537c67a25cc27a235a24980b234b6ac29e.tar.gz kernel-qcow2-util-linux-747600537c67a25cc27a235a24980b234b6ac29e.tar.xz kernel-qcow2-util-linux-747600537c67a25cc27a235a24980b234b6ac29e.zip |
libfdisk: use table-length in dump for non-standard PT
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, 15 insertions, 8 deletions
diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c index 75e1b52de..956d4f52e 100644 --- a/libfdisk/src/script.c +++ b/libfdisk/src/script.c @@ -403,24 +403,31 @@ int fdisk_script_read_context(struct fdisk_script *dp, struct fdisk_context *cxt struct fdisk_labelitem item; char buf[64]; + /* first-lba */ rc = fdisk_get_disklabel_item(cxt, GPT_LABELITEM_FIRSTLBA, &item); - if (rc == 0) { + if (!rc) { snprintf(buf, sizeof(buf), "%"PRIu64, item.data.num64); rc = fdisk_script_set_header(dp, "first-lba", buf); } - if (rc < 0) - goto done; - rc = fdisk_get_disklabel_item(cxt, GPT_LABELITEM_LASTLBA, &item); - if (rc == 0) { + /* last-lba */ + if (!rc) + rc = fdisk_get_disklabel_item(cxt, GPT_LABELITEM_LASTLBA, &item); + if (!rc) { snprintf(buf, sizeof(buf), "%"PRIu64, item.data.num64); rc = fdisk_script_set_header(dp, "last-lba", buf); } - if (rc < 0) - goto done; + + /* table-length */ + if (!rc) { + size_t n = fdisk_get_npartitions(cxt); + if (n != FDISK_GPT_NPARTITIONS_DEFAULT) { + snprintf(buf, sizeof(buf), "%zu", n); + rc = fdisk_script_set_header(dp, "table-length", buf); + } + } } -done: DBG(SCRIPT, ul_debugobj(dp, "read context done [rc=%d]", rc)); return rc; } |