Add labels to MTD partitions.

Add labels to MTD partitions and clean up some of the show code, adding more
info on the MTD prints and eliminating duplicated code.

BRANCH=none
TEST=make runtests & manual cgpt add -l "label"; cgpt show to verify labels
BUG=none

Change-Id: I59736128f394c2aca937a3a0bb5fc5d42b0149a9
Reviewed-on: https://gerrit.chromium.org/gerrit/63367
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Commit-Queue: Albert Chaulk <achaulk@chromium.org>
Tested-by: Albert Chaulk <achaulk@chromium.org>
This commit is contained in:
Albert Chaulk
2013-07-25 11:32:57 -07:00
committed by ChromeBot
parent 05f5944a40
commit 32fd6dead1
3 changed files with 55 additions and 39 deletions

View File

@@ -113,6 +113,9 @@ static int MtdSetEntryAttributes(struct drive *drive,
} }
if (params->set_type) if (params->set_type)
MtdSetEntryType(entry, LookupMtdTypeForGuid(&params->type_guid)); MtdSetEntryType(entry, LookupMtdTypeForGuid(&params->type_guid));
if (params->label) {
strncpy(entry->label, params->label, sizeof(entry->label));
}
return 0; return 0;
} }

View File

@@ -111,28 +111,46 @@ static void HeaderDetails(GptHeader *header, GptEntry *entries,
void MtdEntryDetails(MtdDiskPartition *entry, uint32_t index, int raw) { void MtdEntryDetails(MtdDiskPartition *entry, uint32_t index, int raw) {
const Guid *guid = LookupGuidForMtdType(MtdGetEntryType(entry)); const Guid *guid = LookupGuidForMtdType(MtdGetEntryType(entry));
char buf[256]; // scratch buffer for formatting output char type[256];
char contents[256];
char name[sizeof(entry->label) + 1];
uint64_t start, size; uint64_t start, size;
if (guid) { if (guid) {
ResolveType(guid, buf); ResolveType(guid, type);
} else { } else {
snprintf(buf, sizeof(buf), "MTD partition type %d", MtdGetEntryType(entry)); snprintf(type, sizeof(type), "MTD partition type %d",
MtdGetEntryType(entry));
} }
MtdGetPartitionSizeInSectors(entry, &start, NULL, &size); MtdGetPartitionSizeInSectors(entry, &start, NULL, &size);
if (!raw) { // Provide a NUL if we are at maximum size.
printf(PARTITION_FMT, (int)start, (int)size, index+1, buf); name[sizeof(name)-1] = '\0';
memcpy(name, entry->label, sizeof(entry->label));
require(snprintf(contents, sizeof(contents),
"Label: \"%s\"", name) < sizeof(contents));
printf(PARTITION_FMT, (int)start, (int)size, index+1, contents);
printf(PARTITION_MORE, "Type: ", type);
if (raw && MtdGetEntryType(entry) == MTD_PARTITION_TYPE_CHROMEOS_KERNEL) {
int tries = MtdGetEntryTries(entry);
int successful = MtdGetEntrySuccessful(entry);
int priority = MtdGetEntryPriority(entry);
require(snprintf(contents, sizeof(contents),
"priority=%d tries=%d successful=%d",
priority, tries, successful) < sizeof(contents));
printf(PARTITION_MORE, "Attr: ", contents);
} else { } else {
printf(PARTITION_FMT, (int)start, (int)size, index+1, buf); require(snprintf(contents, sizeof(contents),
"[%x]", entry->flags) < sizeof(contents));
printf(PARTITION_MORE, "Attr: ", contents);
} }
} }
void EntryDetails(GptEntry *entry, uint32_t index, int raw) { void EntryDetails(GptEntry *entry, uint32_t index, int raw) {
char contents[256]; // scratch buffer for formatting output char contents[256]; // scratch buffer for formatting output
uint8_t label[GPT_PARTNAME_LEN]; uint8_t label[GPT_PARTNAME_LEN];
if (!raw) {
char type[GUID_STRLEN], unique[GUID_STRLEN]; char type[GUID_STRLEN], unique[GUID_STRLEN];
UTF16ToUTF8(entry->name, sizeof(entry->name) / sizeof(entry->name[0]), UTF16ToUTF8(entry->name, sizeof(entry->name) / sizeof(entry->name[0]),
@@ -142,7 +160,8 @@ void EntryDetails(GptEntry *entry, uint32_t index, int raw) {
printf(PARTITION_FMT, (int)entry->starting_lba, printf(PARTITION_FMT, (int)entry->starting_lba,
(int)(entry->ending_lba - entry->starting_lba + 1), (int)(entry->ending_lba - entry->starting_lba + 1),
index+1, contents); index+1, contents);
if (CGPT_OK == ResolveType(&entry->type, type)) {
if (!raw && CGPT_OK == ResolveType(&entry->type, type)) {
printf(PARTITION_MORE, "Type: ", type); printf(PARTITION_MORE, "Type: ", type);
} else { } else {
GuidToStr(&entry->type, type, GUID_STRLEN); GuidToStr(&entry->type, type, GUID_STRLEN);
@@ -150,6 +169,8 @@ void EntryDetails(GptEntry *entry, uint32_t index, int raw) {
} }
GuidToStr(&entry->unique, unique, GUID_STRLEN); GuidToStr(&entry->unique, unique, GUID_STRLEN);
printf(PARTITION_MORE, "UUID: ", unique); printf(PARTITION_MORE, "UUID: ", unique);
if (!raw) {
if (GuidEqual(&guid_chromeos_kernel, &entry->type)) { if (GuidEqual(&guid_chromeos_kernel, &entry->type)) {
int tries = (entry->attrs.fields.gpt_att & int tries = (entry->attrs.fields.gpt_att &
CGPT_ATTRIBUTE_TRIES_MASK) >> CGPT_ATTRIBUTE_TRIES_MASK) >>
@@ -166,19 +187,6 @@ void EntryDetails(GptEntry *entry, uint32_t index, int raw) {
printf(PARTITION_MORE, "Attr: ", contents); printf(PARTITION_MORE, "Attr: ", contents);
} }
} else { } else {
char type[GUID_STRLEN], unique[GUID_STRLEN];
UTF16ToUTF8(entry->name, sizeof(entry->name) / sizeof(entry->name[0]),
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),
index+1, contents);
GuidToStr(&entry->type, type, GUID_STRLEN);
printf(PARTITION_MORE, "Type: ", type);
GuidToStr(&entry->unique, unique, GUID_STRLEN);
printf(PARTITION_MORE, "UUID: ", unique);
require(snprintf(contents, sizeof(contents), require(snprintf(contents, sizeof(contents),
"[%x]", entry->attrs.fields.gpt_att) < sizeof(contents)); "[%x]", entry->attrs.fields.gpt_att) < sizeof(contents));
printf(PARTITION_MORE, "Attr: ", contents); printf(PARTITION_MORE, "Attr: ", contents);
@@ -321,7 +329,7 @@ int MtdShow(struct drive *drive, CgptShowParams *params) {
require(snprintf(indent, sizeof(indent), GPT_MORE) < sizeof(indent)); require(snprintf(indent, sizeof(indent), GPT_MORE) < sizeof(indent));
MtdHeaderDetails(&drive->mtd.primary, indent, 0); MtdHeaderDetails(&drive->mtd.primary, indent, 0);
} }
printf(TITLE_FMT, "start", "size", "part", "contents");
MtdEntriesDetails(drive, PRIMARY, params->numeric); MtdEntriesDetails(drive, PRIMARY, params->numeric);
} }

View File

@@ -66,6 +66,11 @@ typedef struct {
uint64_t starting_offset; uint64_t starting_offset;
uint64_t ending_offset; uint64_t ending_offset;
uint32_t flags; uint32_t flags;
/* 28 characters is a balance between GPT parity and size constraints, at
* current sizes this table occupies 10% of the FTS data store.
*/
char label[28];
} __attribute__((packed)) MtdDiskPartition; } __attribute__((packed)) MtdDiskPartition;
typedef struct { typedef struct {
@@ -81,9 +86,9 @@ typedef struct {
MtdDiskPartition partitions[MTD_MAX_PARTITIONS]; MtdDiskPartition partitions[MTD_MAX_PARTITIONS];
} __attribute__((packed)) MtdDiskLayout; } __attribute__((packed)) MtdDiskLayout;
#define MTD_DRIVE_V1_SIZE (32 + 16*20) #define MTD_DRIVE_V1_SIZE (32 + 16*48)
#define MTDENTRY_EXPECTED_SIZE (20) #define MTDENTRY_EXPECTED_SIZE (48)
#define MTDLAYOUT_EXPECTED_SIZE (32 + 16 * MTDENTRY_EXPECTED_SIZE) #define MTDLAYOUT_EXPECTED_SIZE (32 + 16 * MTDENTRY_EXPECTED_SIZE)