From: Karel Zak Date: Wed, 18 May 2016 12:29:50 +0000 (+0200) Subject: libfdisk: use table-length in dump for non-standard PT X-Git-Tag: v2.29-rc1~242 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=747600537c67a25cc27a235a24980b234b6ac29e;p=thirdparty%2Futil-linux.git libfdisk: use table-length in dump for non-standard PT Signed-off-by: Karel Zak --- diff --git a/libfdisk/src/fdiskP.h b/libfdisk/src/fdiskP.h index e20723e61e..82561297d4 100644 --- a/libfdisk/src/fdiskP.h +++ b/libfdisk/src/fdiskP.h @@ -58,6 +58,7 @@ struct fdisk_test { extern int fdisk_run_test(struct fdisk_test *tests, int argc, char *argv[]); #endif +#define FDISK_GPT_NPARTITIONS_DEFAULT 128 /* * Generic iterator diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c index eaa9f4803b..3028a392f8 100644 --- a/libfdisk/src/gpt.c +++ b/libfdisk/src/gpt.c @@ -50,7 +50,7 @@ #define EFI_PMBR_OSTYPE 0xEE #define MSDOS_MBR_SIGNATURE 0xAA55 #define GPT_PART_NAME_LEN (72 / sizeof(uint16_t)) -#define GPT_NPARTITIONS 128 +#define GPT_NPARTITIONS FDISK_GPT_NPARTITIONS_DEFAULT /* Globally unique identifier */ struct gpt_guid { diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c index 75e1b52deb..956d4f52e6 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; }