diff options
author | Erdi Chen <erdi@google.com> | 2017-06-23 14:28:10 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-06-23 22:56:43 -0700 |
commit | 7662a7e3d062bea6ce3bb224c237ce9cf9e6a018 (patch) | |
tree | 6ba2164169efe78c8235af6fab47f0f39dd56fdb /cgpt | |
parent | 7bd4c0375bbc39d9d2bedeb3aa4c9b2c4c1a8575 (diff) | |
download | vboot-7662a7e3d062bea6ce3bb224c237ce9cf9e6a018.tar.gz |
cgpt: show: Print partition size with 64-bit format
Partition size on 4TB drive can overflow 32-bit integers. Running "cgpt
show /dev/sda" prints negative number for the state partition (sda1).
BRANCH=none
BUG=none
TEST=Run "cgpt show /dev/sda" with 4TB drive.
Change-Id: I56f3b43594028695745de8c5a1626d940a3b4c5b
Reviewed-on: https://chromium-review.googlesource.com/546879
Commit-Ready: Erdi Chen <erdi@google.com>
Tested-by: Erdi Chen <erdi@google.com>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Diffstat (limited to 'cgpt')
-rw-r--r-- | cgpt/cgpt_show.c | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/cgpt/cgpt_show.c b/cgpt/cgpt_show.c index 81b499c7..cd4a6136 100644 --- a/cgpt/cgpt_show.c +++ b/cgpt/cgpt_show.c @@ -44,9 +44,9 @@ static void RawDump(const uint8_t *memory, const int size, /* Output formatters */ #define TITLE_FMT "%12s%12s%8s %s\n" -#define GPT_FMT "%12d%12d%8s %s\n" +#define GPT_FMT "%12"PRId64"%12"PRId64"%8s %s\n" #define GPT_MORE "%12s%12s%8s ", "", "", "" -#define PARTITION_FMT "%12d%12d%8d %s\n" +#define PARTITION_FMT "%12"PRId64"%12"PRId64"%8d %s\n" #define PARTITION_MORE "%12s%12s%8s %s%s\n", "", "", "" void PrintSignature(const char *indent, const char *sig, size_t n, int raw) { @@ -106,8 +106,8 @@ void EntryDetails(GptEntry *entry, uint32_t index, int raw) { label, sizeof(label)); require(snprintf(contents, sizeof(contents), "Label: \"%s\"", label) < sizeof(contents)); - printf(PARTITION_FMT, (int)entry->starting_lba, - (int)(entry->ending_lba - entry->starting_lba + 1), + printf(PARTITION_FMT, (uint64_t)entry->starting_lba, + (uint64_t)(entry->ending_lba - entry->starting_lba + 1), index+1, contents); if (!raw && CGPT_OK == ResolveType(&entry->type, type)) { @@ -257,8 +257,8 @@ static int GptShow(struct drive *drive, CgptShowParams *params) { } else { GuidToStr(&entry->type, type, GUID_STRLEN); } - printf(PARTITION_FMT, (int)entry->starting_lba, - (int)(entry->ending_lba - entry->starting_lba + 1), + printf(PARTITION_FMT, (uint64_t)entry->starting_lba, + (uint64_t)(entry->ending_lba - entry->starting_lba + 1), i+1, type); } } else { // show all partitions @@ -272,18 +272,18 @@ static int GptShow(struct drive *drive, CgptShowParams *params) { printf(TITLE_FMT, "start", "size", "part", "contents"); char buf[256]; // buffer for formatted PMBR content PMBRToStr(&drive->pmbr, buf, sizeof(buf)); // will exit if buf is too small - printf(GPT_FMT, 0, GPT_PMBR_SECTORS, "", buf); + printf(GPT_FMT, (uint64_t)0, (uint64_t)GPT_PMBR_SECTORS, "", buf); if (drive->gpt.ignored & MASK_PRIMARY) { - printf(GPT_FMT, (int)GPT_PMBR_SECTORS, - (int)GPT_HEADER_SECTORS, "IGNORED", "Pri GPT header"); + printf(GPT_FMT, (uint64_t)GPT_PMBR_SECTORS, + (uint64_t)GPT_HEADER_SECTORS, "IGNORED", "Pri GPT header"); } else { if (drive->gpt.valid_headers & MASK_PRIMARY) { - printf(GPT_FMT, (int)GPT_PMBR_SECTORS, - (int)GPT_HEADER_SECTORS, "", "Pri GPT header"); + printf(GPT_FMT, (uint64_t)GPT_PMBR_SECTORS, + (uint64_t)GPT_HEADER_SECTORS, "", "Pri GPT header"); } else { - printf(GPT_FMT, (int)GPT_PMBR_SECTORS, - (int)GPT_HEADER_SECTORS, "INVALID", "Pri GPT header"); + printf(GPT_FMT, (uint64_t)GPT_PMBR_SECTORS, + (uint64_t)GPT_HEADER_SECTORS, "INVALID", "Pri GPT header"); } if (params->debug || @@ -298,8 +298,8 @@ static int GptShow(struct drive *drive, CgptShowParams *params) { } GptHeader* primary_header = (GptHeader*)drive->gpt.primary_header; - printf(GPT_FMT, (int)primary_header->entries_lba, - (int)CalculateEntriesSectors(primary_header), + printf(GPT_FMT, (uint64_t)primary_header->entries_lba, + (uint64_t)CalculateEntriesSectors(primary_header), drive->gpt.valid_entries & MASK_PRIMARY ? "" : "INVALID", "Pri GPT table"); @@ -310,12 +310,13 @@ static int GptShow(struct drive *drive, CgptShowParams *params) { /****************************** Secondary *************************/ if (drive->gpt.ignored & MASK_SECONDARY) { - printf(GPT_FMT, (int)(drive->gpt.gpt_drive_sectors - GPT_HEADER_SECTORS), - (int)GPT_HEADER_SECTORS, "IGNORED", "Sec GPT header"); + printf(GPT_FMT, + (uint64_t)(drive->gpt.gpt_drive_sectors - GPT_HEADER_SECTORS), + (uint64_t)GPT_HEADER_SECTORS, "IGNORED", "Sec GPT header"); } else { GptHeader* secondary_header = (GptHeader*)drive->gpt.secondary_header; - printf(GPT_FMT, (int)secondary_header->entries_lba, - (int)CalculateEntriesSectors(secondary_header), + printf(GPT_FMT, (uint64_t)secondary_header->entries_lba, + (uint64_t)CalculateEntriesSectors(secondary_header), drive->gpt.valid_entries & MASK_SECONDARY ? "" : "INVALID", "Sec GPT table"); /* We show secondary table details if any of following is true. @@ -334,11 +335,12 @@ static int GptShow(struct drive *drive, CgptShowParams *params) { } if (drive->gpt.valid_headers & MASK_SECONDARY) { - printf(GPT_FMT, (int)(drive->gpt.gpt_drive_sectors - GPT_HEADER_SECTORS), - (int)GPT_HEADER_SECTORS, "", "Sec GPT header"); + printf(GPT_FMT, + (uint64_t)(drive->gpt.gpt_drive_sectors - GPT_HEADER_SECTORS), + (uint64_t)GPT_HEADER_SECTORS, "", "Sec GPT header"); } else { - printf(GPT_FMT, (int)GPT_PMBR_SECTORS, - (int)GPT_HEADER_SECTORS, "INVALID", "Sec GPT header"); + printf(GPT_FMT, (uint64_t)GPT_PMBR_SECTORS, + (uint64_t)GPT_HEADER_SECTORS, "INVALID", "Sec GPT header"); } /* We show secondary header if any of following is true: * 1. in debug mode. |