Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Side by Side Diff: firmware/lib/cgptlib/cgptlib.c

Issue 2799019: Modify the size of the attributes field to comply with msc limitations. (Closed) Base URL: ssh://git@chromiumos-git/vboot_reference.git
Patch Set: Fix the attribute field to allow compilation in the BIOS environment. Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cgpt/cmd_show.c ('k') | firmware/lib/cgptlib/cgptlib_internal.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 */ 4 */
5 5
6 #include "cgptlib.h" 6 #include "cgptlib.h"
7 #include "cgptlib_internal.h" 7 #include "cgptlib_internal.h"
8 #include "crc32.h" 8 #include "crc32.h"
9 #include "gpt.h" 9 #include "gpt.h"
10 #include "utility.h" 10 #include "utility.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 *start_sector = e->starting_lba; 86 *start_sector = e->starting_lba;
87 *size = e->ending_lba - e->starting_lba + 1; 87 *size = e->ending_lba - e->starting_lba + 1;
88 return GPT_SUCCESS; 88 return GPT_SUCCESS;
89 } 89 }
90 90
91 91
92 int GptUpdateKernelEntry(GptData* gpt, uint32_t update_type) { 92 int GptUpdateKernelEntry(GptData* gpt, uint32_t update_type) {
93 GptHeader* header = (GptHeader*)gpt->primary_header; 93 GptHeader* header = (GptHeader*)gpt->primary_header;
94 GptEntry* entries = (GptEntry*)gpt->primary_entries; 94 GptEntry* entries = (GptEntry*)gpt->primary_entries;
95 GptEntry* e = entries + gpt->current_kernel; 95 GptEntry* e = entries + gpt->current_kernel;
96 uint64_t previous_attr = e->attributes; 96 uint16_t previous_attr = e->attrs.fields.gpt_att;
97 97
98 if (gpt->current_kernel == CGPT_KERNEL_ENTRY_NOT_FOUND) 98 if (gpt->current_kernel == CGPT_KERNEL_ENTRY_NOT_FOUND)
99 return GPT_ERROR_INVALID_UPDATE_TYPE; 99 return GPT_ERROR_INVALID_UPDATE_TYPE;
100 if (!IsKernelEntry(e)) 100 if (!IsKernelEntry(e))
101 return GPT_ERROR_INVALID_UPDATE_TYPE; 101 return GPT_ERROR_INVALID_UPDATE_TYPE;
102 102
103 switch (update_type) { 103 switch (update_type) {
104 case GPT_UPDATE_ENTRY_TRY: { 104 case GPT_UPDATE_ENTRY_TRY: {
105 /* Used up a try */ 105 /* Used up a try */
106 int tries; 106 int tries;
107 if (GetEntrySuccessful(e)) 107 if (GetEntrySuccessful(e))
108 return GPT_SUCCESS; /* Successfully booted this partition, so 108 return GPT_SUCCESS; /* Successfully booted this partition, so
109 * tries field is ignored. */ 109 * tries field is ignored. */
110 tries = GetEntryTries(e); 110 tries = GetEntryTries(e);
111 if (tries > 1) { 111 if (tries > 1) {
112 /* Still have tries left */ 112 /* Still have tries left */
113 SetEntryTries(e, tries - 1); 113 SetEntryTries(e, tries - 1);
114 break; 114 break;
115 } 115 }
116 /* Out of tries, so drop through and mark partition bad. */ 116 /* Out of tries, so drop through and mark partition bad. */
117 } 117 }
118 case GPT_UPDATE_ENTRY_BAD: { 118 case GPT_UPDATE_ENTRY_BAD: {
119 /* Giving up on this partition entirely. */ 119 /* Giving up on this partition entirely. */
120 e->attributes &= ~(CGPT_ATTRIBUTE_SUCCESSFUL_MASK | 120 e->attrs.fields.gpt_att = previous_attr & ~(
121 CGPT_ATTRIBUTE_TRIES_MASK | 121 CGPT_ATTRIBUTE_SUCCESSFUL_MASK |
122 CGPT_ATTRIBUTE_PRIORITY_MASK); 122 CGPT_ATTRIBUTE_TRIES_MASK |
123 CGPT_ATTRIBUTE_PRIORITY_MASK);
123 break; 124 break;
124 } 125 }
125 default: 126 default:
126 return GPT_ERROR_INVALID_UPDATE_TYPE; 127 return GPT_ERROR_INVALID_UPDATE_TYPE;
127 } 128 }
128 129
129 /* If no change to attributes, we're done */ 130 /* If no change to attributes, we're done */
130 if (e->attributes == previous_attr) 131 if (e->attrs.fields.gpt_att == previous_attr)
131 return GPT_SUCCESS; 132 return GPT_SUCCESS;
132 133
133 /* Update the CRCs */ 134 /* Update the CRCs */
134 header->entries_crc32 = Crc32((const uint8_t *)entries, 135 header->entries_crc32 = Crc32((const uint8_t *)entries,
135 header->size_of_entry * 136 header->size_of_entry *
136 header->number_of_entries); 137 header->number_of_entries);
137 header->header_crc32 = HeaderCrc(header); 138 header->header_crc32 = HeaderCrc(header);
138 gpt->modified |= GPT_MODIFIED_HEADER1 | GPT_MODIFIED_ENTRIES1; 139 gpt->modified |= GPT_MODIFIED_HEADER1 | GPT_MODIFIED_ENTRIES1;
139 140
140 /* Use the repair function to update the other copy of the GPT. 141 /* Use the repair function to update the other copy of the GPT.
141 * This is a tad inefficient, but is much faster than the disk I/O 142 * This is a tad inefficient, but is much faster than the disk I/O
142 * to update the GPT on disk so it doesn't matter. */ 143 * to update the GPT on disk so it doesn't matter. */
143 gpt->valid_headers = MASK_PRIMARY; 144 gpt->valid_headers = MASK_PRIMARY;
144 gpt->valid_entries = MASK_PRIMARY; 145 gpt->valid_entries = MASK_PRIMARY;
145 GptRepair(gpt); 146 GptRepair(gpt);
146 147
147 return GPT_SUCCESS; 148 return GPT_SUCCESS;
148 } 149 }
OLDNEW
« no previous file with comments | « cgpt/cmd_show.c ('k') | firmware/lib/cgptlib/cgptlib_internal.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698