summaryrefslogtreecommitdiff
path: root/cgpt/cgpt_show.c
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2016-04-19 16:55:36 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-04-25 15:15:32 -0700
commit39910d062dffcd16683e0626dac1e7064991c7e5 (patch)
tree0985bb84a411aaa6d46eb3d2a4f3dbbac76e8865 /cgpt/cgpt_show.c
parent5de0000ece70bf419130db9bdbaf444ffc98bf30 (diff)
downloadvboot-39910d062dffcd16683e0626dac1e7064991c7e5.tar.gz
cgptlib: Add support for IGNOREME GPT signature
This patch makes cgpt aware of a special "IGNOREME" GPT header signature string that may appear in either the primary or the secondary GPT and cause cgpt (and other cgptlib clients) to completely ignore that GPT. It will continue to function correctly for all other purposes (using the data from the non-ignored GPT), but never write any data back to the ignored GPT. BRANCH=None BUG=chrome-os-partner:52595 TEST=unit tests Change-Id: I7e53542385ae9d8d24dc25b75e91f4ff4917f66f Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/340072 Reviewed-by: Nam Nguyen <namnguyen@google.com>
Diffstat (limited to 'cgpt/cgpt_show.c')
-rw-r--r--cgpt/cgpt_show.c140
1 files changed, 76 insertions, 64 deletions
diff --git a/cgpt/cgpt_show.c b/cgpt/cgpt_show.c
index 143b5fa1..638655bd 100644
--- a/cgpt/cgpt_show.c
+++ b/cgpt/cgpt_show.c
@@ -250,79 +250,91 @@ static int GptShow(struct drive *drive, CgptShowParams *params) {
PMBRToStr(&drive->pmbr, buf, sizeof(buf)); // will exit if buf is too small
printf(GPT_FMT, 0, GPT_PMBR_SECTORS, "", buf);
- if (drive->gpt.valid_headers & MASK_PRIMARY) {
+ if (drive->gpt.ignored & MASK_PRIMARY) {
printf(GPT_FMT, (int)GPT_PMBR_SECTORS,
- (int)GPT_HEADER_SECTORS, "", "Pri GPT header");
+ (int)GPT_HEADER_SECTORS, "IGNORED", "Pri GPT header");
} else {
- printf(GPT_FMT, (int)GPT_PMBR_SECTORS,
- (int)GPT_HEADER_SECTORS, "INVALID", "Pri GPT header");
- }
-
- if (params->debug ||
- ((drive->gpt.valid_headers & MASK_PRIMARY) && params->verbose)) {
- GptHeader *header;
- char indent[64];
+ if (drive->gpt.valid_headers & MASK_PRIMARY) {
+ printf(GPT_FMT, (int)GPT_PMBR_SECTORS,
+ (int)GPT_HEADER_SECTORS, "", "Pri GPT header");
+ } else {
+ printf(GPT_FMT, (int)GPT_PMBR_SECTORS,
+ (int)GPT_HEADER_SECTORS, "INVALID", "Pri GPT header");
+ }
- require(snprintf(indent, sizeof(indent), GPT_MORE) < sizeof(indent));
- header = (GptHeader*)drive->gpt.primary_header;
- entries = (GptEntry*)drive->gpt.primary_entries;
- HeaderDetails(header, entries, indent, params->numeric);
- }
+ if (params->debug ||
+ ((drive->gpt.valid_headers & MASK_PRIMARY) && params->verbose)) {
+ GptHeader *header;
+ char indent[64];
- GptHeader* primary_header = (GptHeader*)drive->gpt.primary_header;
- printf(GPT_FMT, (int)primary_header->entries_lba,
- (int)CalculateEntriesSectors(primary_header),
- drive->gpt.valid_entries & MASK_PRIMARY ? "" : "INVALID",
- "Pri GPT table");
+ require(snprintf(indent, sizeof(indent), GPT_MORE) < sizeof(indent));
+ header = (GptHeader*)drive->gpt.primary_header;
+ entries = (GptEntry*)drive->gpt.primary_entries;
+ HeaderDetails(header, entries, indent, params->numeric);
+ }
- if (params->debug ||
- (drive->gpt.valid_entries & MASK_PRIMARY))
- EntriesDetails(drive, PRIMARY, params->numeric);
+ GptHeader* primary_header = (GptHeader*)drive->gpt.primary_header;
+ printf(GPT_FMT, (int)primary_header->entries_lba,
+ (int)CalculateEntriesSectors(primary_header),
+ drive->gpt.valid_entries & MASK_PRIMARY ? "" : "INVALID",
+ "Pri GPT table");
- /****************************** Secondary *************************/
- GptHeader* secondary_header = (GptHeader*)drive->gpt.secondary_header;
- printf(GPT_FMT, (int)secondary_header->entries_lba,
- (int)CalculateEntriesSectors(secondary_header),
- drive->gpt.valid_entries & MASK_SECONDARY ? "" : "INVALID",
- "Sec GPT table");
- /* We show secondary table details if any of following is true.
- * 1. in debug mode.
- * 2. only secondary is valid.
- * 3. secondary is not identical to promary.
- */
- if (params->debug ||
- ((drive->gpt.valid_entries & MASK_SECONDARY) &&
- (!(drive->gpt.valid_entries & MASK_PRIMARY) ||
- memcmp(drive->gpt.primary_entries, drive->gpt.secondary_entries,
- secondary_header->number_of_entries *
- secondary_header->size_of_entry)))) {
- EntriesDetails(drive, SECONDARY, params->numeric);
+ if (params->debug ||
+ (drive->gpt.valid_entries & MASK_PRIMARY))
+ EntriesDetails(drive, PRIMARY, params->numeric);
}
- if (drive->gpt.valid_headers & MASK_SECONDARY)
+ /****************************** Secondary *************************/
+ if (drive->gpt.ignored & MASK_SECONDARY) {
printf(GPT_FMT, (int)(drive->gpt.gpt_drive_sectors - GPT_HEADER_SECTORS),
- (int)GPT_HEADER_SECTORS, "", "Sec GPT header");
- else
- printf(GPT_FMT, (int)GPT_PMBR_SECTORS,
- (int)GPT_HEADER_SECTORS, "INVALID", "Sec GPT header");
- /* We show secondary header if any of following is true:
- * 1. in debug mode.
- * 2. only secondary is valid.
- * 3. secondary is not synonymous to primary.
- */
- if (params->debug ||
- ((drive->gpt.valid_headers & MASK_SECONDARY) &&
- (!(drive->gpt.valid_headers & MASK_PRIMARY) ||
- !IsSynonymous((GptHeader*)drive->gpt.primary_header,
- (GptHeader*)drive->gpt.secondary_header)) &&
- params->verbose)) {
- GptHeader *header;
- char indent[64];
-
- require(snprintf(indent, sizeof(indent), GPT_MORE) < sizeof(indent));
- header = (GptHeader*)drive->gpt.secondary_header;
- entries = (GptEntry*)drive->gpt.secondary_entries;
- HeaderDetails(header, entries, indent, params->numeric);
+ (int)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),
+ drive->gpt.valid_entries & MASK_SECONDARY ? "" : "INVALID",
+ "Sec GPT table");
+ /* We show secondary table details if any of following is true.
+ * 1. in debug mode.
+ * 2. primary table is being ignored
+ * 3. only secondary is valid.
+ * 4. secondary is not identical to promary.
+ */
+ if (params->debug || (drive->gpt.ignored & MASK_PRIMARY) ||
+ ((drive->gpt.valid_entries & MASK_SECONDARY) &&
+ (!(drive->gpt.valid_entries & MASK_PRIMARY) ||
+ memcmp(drive->gpt.primary_entries, drive->gpt.secondary_entries,
+ secondary_header->number_of_entries *
+ secondary_header->size_of_entry)))) {
+ EntriesDetails(drive, SECONDARY, params->numeric);
+ }
+
+ 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");
+ } else {
+ printf(GPT_FMT, (int)GPT_PMBR_SECTORS,
+ (int)GPT_HEADER_SECTORS, "INVALID", "Sec GPT header");
+ }
+ /* We show secondary header if any of following is true:
+ * 1. in debug mode.
+ * 2. only secondary is valid.
+ * 3. secondary is not synonymous to primary and not ignored.
+ */
+ if (params->debug ||
+ ((drive->gpt.valid_headers & MASK_SECONDARY) &&
+ (!(drive->gpt.valid_headers & MASK_PRIMARY) ||
+ !IsSynonymous((GptHeader*)drive->gpt.primary_header,
+ (GptHeader*)drive->gpt.secondary_header)) &&
+ params->verbose)) {
+ GptHeader *header;
+ char indent[64];
+
+ require(snprintf(indent, sizeof(indent), GPT_MORE) < sizeof(indent));
+ header = (GptHeader*)drive->gpt.secondary_header;
+ entries = (GptEntry*)drive->gpt.secondary_entries;
+ HeaderDetails(header, entries, indent, params->numeric);
+ }
}
}