summaryrefslogtreecommitdiff
path: root/cgpt/cgpt_common.c
diff options
context:
space:
mode:
authorAlbert Chaulk <achaulk@chromium.org>2013-03-26 13:43:02 -0700
committerChromeBot <chrome-bot@google.com>2013-05-06 15:48:41 -0700
commitfa6b35c1ffa33833b3250a6515869ccd4cb59121 (patch)
tree2de52d0da32d597818fe74015703056d80fdb770 /cgpt/cgpt_common.c
parent5c9e4532b9bc45cff22f37d3556da679809a60a7 (diff)
downloadvboot-fa6b35c1ffa33833b3250a6515869ccd4cb59121.tar.gz
Refactor CgptAdd and CgptPrioitize to remove gpt-specific code
- Refactor cgpt_prioitize.c to completely remove gpt-specific code. - Refactor cgpt_add.c to isolate gpt-dependence to one helper function and the backup/restore logic - Change several common apis to take a struct drive* rather than a GptData*, this provides a path to cleanly implement mtd versions BUG=chromium:221745 TEST=no functional changes, existing tests cover this BRANCH=none Change-Id: I27ed166aae390aa5dc83062f62939e45122edc76 Original-Change-Id: I1b0a73509efbf22411c4ae5cf044feede0a49a33 Reviewed-on: https://gerrit.chromium.org/gerrit/46548 Tested-by: Albert Chaulk <achaulk@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: Albert Chaulk <achaulk@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/49788
Diffstat (limited to 'cgpt/cgpt_common.c')
-rw-r--r--cgpt/cgpt_common.c97
1 files changed, 58 insertions, 39 deletions
diff --git a/cgpt/cgpt_common.c b/cgpt/cgpt_common.c
index dec26d12..b4f71f76 100644
--- a/cgpt/cgpt_common.c
+++ b/cgpt/cgpt_common.c
@@ -621,33 +621,29 @@ void PrintTypes(void) {
printf("\n");
}
-uint32_t GetNumberOfEntries(const GptData *gpt) {
- GptHeader *header = 0;
+GptHeader* GetGptHeader(const GptData *gpt) {
if (gpt->valid_headers & MASK_PRIMARY)
- header = (GptHeader*)gpt->primary_header;
+ return (GptHeader*)gpt->primary_header;
else if (gpt->valid_headers & MASK_SECONDARY)
- header = (GptHeader*)gpt->secondary_header;
+ return (GptHeader*)gpt->secondary_header;
else
return 0;
- return header->number_of_entries;
}
-static uint32_t GetSizeOfEntries(const GptData *gpt) {
- GptHeader *header = 0;
- if (gpt->valid_headers & MASK_PRIMARY)
- header = (GptHeader*)gpt->primary_header;
- else if (gpt->valid_headers & MASK_SECONDARY)
- header = (GptHeader*)gpt->secondary_header;
- else
+uint32_t GetNumberOfEntries(const struct drive *drive) {
+ GptHeader *header = GetGptHeader(&drive->gpt);
+ if (!header)
return 0;
- return header->size_of_entry;
+ return header->number_of_entries;
}
+
GptEntry *GetEntry(GptData *gpt, int secondary, uint32_t entry_index) {
+ GptHeader *header = GetGptHeader(gpt);
uint8_t *entries;
- uint32_t stride = GetSizeOfEntries(gpt);
+ uint32_t stride = header->size_of_entry;
require(stride);
- require(entry_index < GetNumberOfEntries(gpt));
+ require(entry_index < header->number_of_entries);
if (secondary == PRIMARY) {
entries = gpt->primary_entries;
@@ -666,52 +662,75 @@ GptEntry *GetEntry(GptData *gpt, int secondary, uint32_t entry_index) {
return (GptEntry*)(&entries[stride * entry_index]);
}
-void SetPriority(GptData *gpt, int secondary, uint32_t entry_index,
+void SetPriority(struct drive *drive, int secondary, uint32_t entry_index,
int priority) {
GptEntry *entry;
- entry = GetEntry(gpt, secondary, entry_index);
+ entry = GetEntry(&drive->gpt, secondary, entry_index);
require(priority >= 0 && priority <= CGPT_ATTRIBUTE_MAX_PRIORITY);
- entry->attrs.fields.gpt_att &= ~CGPT_ATTRIBUTE_PRIORITY_MASK;
- entry->attrs.fields.gpt_att |= priority << CGPT_ATTRIBUTE_PRIORITY_OFFSET;
+ SetEntryPriority(entry, priority);
}
-int GetPriority(GptData *gpt, int secondary, uint32_t entry_index) {
+int GetPriority(struct drive *drive, int secondary, uint32_t entry_index) {
GptEntry *entry;
- entry = GetEntry(gpt, secondary, entry_index);
- return (entry->attrs.fields.gpt_att & CGPT_ATTRIBUTE_PRIORITY_MASK) >>
- CGPT_ATTRIBUTE_PRIORITY_OFFSET;
+ entry = GetEntry(&drive->gpt, secondary, entry_index);
+ return GetEntryPriority(entry);
}
-void SetTries(GptData *gpt, int secondary, uint32_t entry_index, int tries) {
+void SetTries(struct drive *drive, int secondary, uint32_t entry_index,
+ int tries) {
GptEntry *entry;
- entry = GetEntry(gpt, secondary, entry_index);
+ entry = GetEntry(&drive->gpt, secondary, entry_index);
require(tries >= 0 && tries <= CGPT_ATTRIBUTE_MAX_TRIES);
- entry->attrs.fields.gpt_att &= ~CGPT_ATTRIBUTE_TRIES_MASK;
- entry->attrs.fields.gpt_att |= tries << CGPT_ATTRIBUTE_TRIES_OFFSET;
+ SetEntryTries(entry, tries);
}
-int GetTries(GptData *gpt, int secondary, uint32_t entry_index) {
+int GetTries(struct drive *drive, int secondary, uint32_t entry_index) {
GptEntry *entry;
- entry = GetEntry(gpt, secondary, entry_index);
- return (entry->attrs.fields.gpt_att & CGPT_ATTRIBUTE_TRIES_MASK) >>
- CGPT_ATTRIBUTE_TRIES_OFFSET;
+ entry = GetEntry(&drive->gpt, secondary, entry_index);
+ return GetEntryTries(entry);
}
-void SetSuccessful(GptData *gpt, int secondary, uint32_t entry_index,
+void SetSuccessful(struct drive *drive, int secondary, uint32_t entry_index,
int success) {
GptEntry *entry;
- entry = GetEntry(gpt, secondary, entry_index);
+ entry = GetEntry(&drive->gpt, secondary, entry_index);
require(success >= 0 && success <= CGPT_ATTRIBUTE_MAX_SUCCESSFUL);
- entry->attrs.fields.gpt_att &= ~CGPT_ATTRIBUTE_SUCCESSFUL_MASK;
- entry->attrs.fields.gpt_att |= success << CGPT_ATTRIBUTE_SUCCESSFUL_OFFSET;
+ SetEntrySuccessful(entry, success);
+}
+
+int GetSuccessful(struct drive *drive, int secondary, uint32_t entry_index) {
+ GptEntry *entry;
+ entry = GetEntry(&drive->gpt, secondary, entry_index);
+ return GetEntrySuccessful(entry);
+}
+
+void SetRaw(struct drive *drive, int secondary, uint32_t entry_index,
+ uint32_t raw) {
+ GptEntry *entry;
+ entry = GetEntry(&drive->gpt, secondary, entry_index);
+ entry->attrs.fields.gpt_att = (uint16_t)raw;
+}
+
+void UpdateAllEntries(struct drive *drive) {
+ RepairEntries(&drive->gpt, MASK_PRIMARY);
+ RepairHeader(&drive->gpt, MASK_PRIMARY);
+
+ drive->gpt.modified |= (GPT_MODIFIED_HEADER1 | GPT_MODIFIED_ENTRIES1 |
+ GPT_MODIFIED_HEADER2 | GPT_MODIFIED_ENTRIES2);
+ UpdateCrc(&drive->gpt);
+}
+
+int IsUnused(struct drive *drive, int secondary, uint32_t index) {
+ GptEntry *entry;
+ entry = GetEntry(&drive->gpt, secondary, index);
+ return GuidIsZero(&entry->type);
}
-int GetSuccessful(GptData *gpt, int secondary, uint32_t entry_index) {
+int IsKernel(struct drive *drive, int secondary, uint32_t index) {
GptEntry *entry;
- entry = GetEntry(gpt, secondary, entry_index);
- return (entry->attrs.fields.gpt_att & CGPT_ATTRIBUTE_SUCCESSFUL_MASK) >>
- CGPT_ATTRIBUTE_SUCCESSFUL_OFFSET;
+ entry = GetEntry(&drive->gpt, secondary, index);
+ return GuidEqual(&entry->type, &guid_chromeos_kernel);
}