| OLD | NEW |
| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 return !Memcmp(&zero, (const uint8_t*)(&e->type), sizeof(zero)); | 108 return !Memcmp(&zero, (const uint8_t*)(&e->type), sizeof(zero)); |
| 109 } | 109 } |
| 110 | 110 |
| 111 /* Returns non-zero if the entry is a Chrome OS kernel partition, else 0. */ | 111 /* Returns non-zero if the entry is a Chrome OS kernel partition, else 0. */ |
| 112 int IsKernelEntry(const GptEntry* e) { | 112 int IsKernelEntry(const GptEntry* e) { |
| 113 static Guid chromeos_kernel = GPT_ENT_TYPE_CHROMEOS_KERNEL; | 113 static Guid chromeos_kernel = GPT_ENT_TYPE_CHROMEOS_KERNEL; |
| 114 return !Memcmp(&e->type, &chromeos_kernel, sizeof(Guid)); | 114 return !Memcmp(&e->type, &chromeos_kernel, sizeof(Guid)); |
| 115 } | 115 } |
| 116 | 116 |
| 117 | 117 |
| 118 int CheckEntries(GptEntry* entries, GptHeader* h, uint64_t drive_sectors) { | 118 int CheckEntries(GptEntry* entries, GptHeader* h) { |
| 119 | 119 |
| 120 GptEntry* entry; | 120 GptEntry* entry; |
| 121 uint32_t crc32; | 121 uint32_t crc32; |
| 122 uint32_t i; | 122 uint32_t i; |
| 123 | 123 |
| 124 /* Check CRC before examining entries. */ | 124 /* Check CRC before examining entries. */ |
| 125 crc32 = Crc32((const uint8_t *)entries, | 125 crc32 = Crc32((const uint8_t *)entries, |
| 126 h->size_of_entry * h->number_of_entries); | 126 h->size_of_entry * h->number_of_entries); |
| 127 if (crc32 != h->entries_crc32) | 127 if (crc32 != h->entries_crc32) |
| 128 return 1; | 128 return 1; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 } | 220 } |
| 221 | 221 |
| 222 if (!gpt->valid_headers) | 222 if (!gpt->valid_headers) |
| 223 return GPT_ERROR_INVALID_HEADERS; | 223 return GPT_ERROR_INVALID_HEADERS; |
| 224 | 224 |
| 225 /* Checks if entries are valid. | 225 /* Checks if entries are valid. |
| 226 * | 226 * |
| 227 * Note that we use the same header in both checks. This way we'll | 227 * Note that we use the same header in both checks. This way we'll |
| 228 * catch the case where (header1,entries1) and (header2,entries2) | 228 * catch the case where (header1,entries1) and (header2,entries2) |
| 229 * are both valid, but (entries1 != entries2). */ | 229 * are both valid, but (entries1 != entries2). */ |
| 230 if (0 == CheckEntries(entries1, goodhdr, gpt->drive_sectors)) | 230 if (0 == CheckEntries(entries1, goodhdr)) |
| 231 gpt->valid_entries |= MASK_PRIMARY; | 231 gpt->valid_entries |= MASK_PRIMARY; |
| 232 if (0 == CheckEntries(entries2, goodhdr, gpt->drive_sectors)) | 232 if (0 == CheckEntries(entries2, goodhdr)) |
| 233 gpt->valid_entries |= MASK_SECONDARY; | 233 gpt->valid_entries |= MASK_SECONDARY; |
| 234 | 234 |
| 235 /* If both headers are good but neither entries were good, check the | 235 /* If both headers are good but neither entries were good, check the |
| 236 * entries with the secondary header. */ | 236 * entries with the secondary header. */ |
| 237 if (MASK_BOTH == gpt->valid_headers && !gpt->valid_entries) { | 237 if (MASK_BOTH == gpt->valid_headers && !gpt->valid_entries) { |
| 238 if (0 == CheckEntries(entries1, header2, gpt->drive_sectors)) | 238 if (0 == CheckEntries(entries1, header2)) |
| 239 gpt->valid_entries |= MASK_PRIMARY; | 239 gpt->valid_entries |= MASK_PRIMARY; |
| 240 if (0 == CheckEntries(entries2, header2, gpt->drive_sectors)) | 240 if (0 == CheckEntries(entries2, header2)) |
| 241 gpt->valid_entries |= MASK_SECONDARY; | 241 gpt->valid_entries |= MASK_SECONDARY; |
| 242 if (gpt->valid_entries) { | 242 if (gpt->valid_entries) { |
| 243 /* Sure enough, header2 had a good CRC for one of the entries. Mark | 243 /* Sure enough, header2 had a good CRC for one of the entries. Mark |
| 244 * header1 invalid, so we'll update its entries CRC. */ | 244 * header1 invalid, so we'll update its entries CRC. */ |
| 245 gpt->valid_headers &= ~MASK_PRIMARY; | 245 gpt->valid_headers &= ~MASK_PRIMARY; |
| 246 goodhdr = header2; | 246 goodhdr = header2; |
| 247 } | 247 } |
| 248 } | 248 } |
| 249 | 249 |
| 250 if (!gpt->valid_entries) | 250 if (!gpt->valid_entries) |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 e->attrs.fields.gpt_att |= (priority << CGPT_ATTRIBUTE_PRIORITY_OFFSET) & | 339 e->attrs.fields.gpt_att |= (priority << CGPT_ATTRIBUTE_PRIORITY_OFFSET) & |
| 340 CGPT_ATTRIBUTE_PRIORITY_MASK; | 340 CGPT_ATTRIBUTE_PRIORITY_MASK; |
| 341 } | 341 } |
| 342 | 342 |
| 343 | 343 |
| 344 void SetEntryTries(GptEntry* e, int tries) { | 344 void SetEntryTries(GptEntry* e, int tries) { |
| 345 e->attrs.fields.gpt_att &= ~CGPT_ATTRIBUTE_TRIES_MASK; | 345 e->attrs.fields.gpt_att &= ~CGPT_ATTRIBUTE_TRIES_MASK; |
| 346 e->attrs.fields.gpt_att |= (tries << CGPT_ATTRIBUTE_TRIES_OFFSET) & | 346 e->attrs.fields.gpt_att |= (tries << CGPT_ATTRIBUTE_TRIES_OFFSET) & |
| 347 CGPT_ATTRIBUTE_TRIES_MASK; | 347 CGPT_ATTRIBUTE_TRIES_MASK; |
| 348 } | 348 } |
| OLD | NEW |