| 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 <string.h> | 6 #include <string.h> |
| 7 | 7 |
| 8 #include "cgptlib.h" | 8 #include "cgptlib.h" |
| 9 #include "cgptlib_internal.h" | 9 #include "cgptlib_internal.h" |
| 10 #include "cgptlib_test.h" | 10 #include "cgptlib_test.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 gpt->valid_headers = MASK_BOTH; | 129 gpt->valid_headers = MASK_BOTH; |
| 130 gpt->valid_entries = MASK_BOTH; | 130 gpt->valid_entries = MASK_BOTH; |
| 131 gpt->modified = 0; | 131 gpt->modified = 0; |
| 132 | 132 |
| 133 /* build primary */ | 133 /* build primary */ |
| 134 header = (GptHeader*)gpt->primary_header; | 134 header = (GptHeader*)gpt->primary_header; |
| 135 entries = (GptEntry*)gpt->primary_entries; | 135 entries = (GptEntry*)gpt->primary_entries; |
| 136 Memcpy(header->signature, GPT_HEADER_SIGNATURE, | 136 Memcpy(header->signature, GPT_HEADER_SIGNATURE, |
| 137 sizeof(GPT_HEADER_SIGNATURE)); | 137 sizeof(GPT_HEADER_SIGNATURE)); |
| 138 header->revision = GPT_HEADER_REVISION; | 138 header->revision = GPT_HEADER_REVISION; |
| 139 header->size = sizeof(GptHeader) - sizeof(header->padding); | 139 header->size = sizeof(GptHeader); |
| 140 header->reserved = 0; | 140 header->reserved_zero = 0; |
| 141 header->my_lba = 1; | 141 header->my_lba = 1; |
| 142 header->alternate_lba = DEFAULT_DRIVE_SECTORS - 1; | 142 header->alternate_lba = DEFAULT_DRIVE_SECTORS - 1; |
| 143 header->first_usable_lba = 34; | 143 header->first_usable_lba = 34; |
| 144 header->last_usable_lba = DEFAULT_DRIVE_SECTORS - 1 - 32 - 1; /* 433 */ | 144 header->last_usable_lba = DEFAULT_DRIVE_SECTORS - 1 - 32 - 1; /* 433 */ |
| 145 header->entries_lba = 2; | 145 header->entries_lba = 2; |
| 146 header->number_of_entries = 128; /* 512B / 128B * 32sectors = 128 entries */ | 146 header->number_of_entries = 128; /* 512B / 128B * 32sectors = 128 entries */ |
| 147 header->size_of_entry = 128; /* bytes */ | 147 header->size_of_entry = 128; /* bytes */ |
| 148 Memcpy(&entries[0].type, &chromeos_kernel, sizeof(chromeos_kernel)); | 148 Memcpy(&entries[0].type, &chromeos_kernel, sizeof(chromeos_kernel)); |
| 149 entries[0].starting_lba = 34; | 149 entries[0].starting_lba = 34; |
| 150 entries[0].ending_lba = 133; | 150 entries[0].ending_lba = 133; |
| 151 Memcpy(&entries[1].type, &chromeos_rootfs, sizeof(chromeos_rootfs)); | 151 Memcpy(&entries[1].type, &chromeos_rootfs, sizeof(chromeos_rootfs)); |
| 152 entries[1].starting_lba = 134; | 152 entries[1].starting_lba = 134; |
| 153 entries[1].ending_lba = 232; | 153 entries[1].ending_lba = 232; |
| 154 Memcpy(&entries[2].type, &chromeos_rootfs, sizeof(chromeos_rootfs)); | 154 Memcpy(&entries[2].type, &chromeos_rootfs, sizeof(chromeos_rootfs)); |
| 155 entries[2].starting_lba = 234; | 155 entries[2].starting_lba = 234; |
| 156 entries[2].ending_lba = 331; | 156 entries[2].ending_lba = 331; |
| 157 Memcpy(&entries[3].type, &chromeos_kernel, sizeof(chromeos_kernel)); | 157 Memcpy(&entries[3].type, &chromeos_kernel, sizeof(chromeos_kernel)); |
| 158 entries[3].starting_lba = 334; | 158 entries[3].starting_lba = 334; |
| 159 entries[3].ending_lba = 430; | 159 entries[3].ending_lba = 430; |
| 160 Memset(header->padding, 0, sizeof(header->padding)); | |
| 161 | 160 |
| 162 /* build secondary */ | 161 /* build secondary */ |
| 163 header2 = (GptHeader*)gpt->secondary_header; | 162 header2 = (GptHeader*)gpt->secondary_header; |
| 164 entries2 = (GptEntry*)gpt->secondary_entries; | 163 entries2 = (GptEntry*)gpt->secondary_entries; |
| 165 Memcpy(header2, header, sizeof(GptHeader)); | 164 Memcpy(header2, header, sizeof(GptHeader)); |
| 166 Memcpy(entries2, entries, PARTITION_ENTRIES_SIZE); | 165 Memcpy(entries2, entries, PARTITION_ENTRIES_SIZE); |
| 167 header2->my_lba = DEFAULT_DRIVE_SECTORS - 1; /* 466 */ | 166 header2->my_lba = DEFAULT_DRIVE_SECTORS - 1; /* 466 */ |
| 168 header2->alternate_lba = 1; | 167 header2->alternate_lba = 1; |
| 169 header2->entries_lba = DEFAULT_DRIVE_SECTORS - 1 - 32; /* 434 */ | 168 header2->entries_lba = DEFAULT_DRIVE_SECTORS - 1 - 32; /* 434 */ |
| 170 | 169 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 347 |
| 349 | 348 |
| 350 /* Tests if reserved fields are checked. | 349 /* Tests if reserved fields are checked. |
| 351 * We'll try non-zero values to test. */ | 350 * We'll try non-zero values to test. */ |
| 352 static int ReservedFieldsTest() { | 351 static int ReservedFieldsTest() { |
| 353 GptData* gpt = GetEmptyGptData(); | 352 GptData* gpt = GetEmptyGptData(); |
| 354 GptHeader* h1 = (GptHeader*)gpt->primary_header; | 353 GptHeader* h1 = (GptHeader*)gpt->primary_header; |
| 355 GptHeader* h2 = (GptHeader*)gpt->secondary_header; | 354 GptHeader* h2 = (GptHeader*)gpt->secondary_header; |
| 356 | 355 |
| 357 BuildTestGptData(gpt); | 356 BuildTestGptData(gpt); |
| 358 h1->reserved ^= 0x12345678; /* whatever random */ | 357 h1->reserved_zero ^= 0x12345678; /* whatever random */ |
| 359 h2->reserved ^= 0x12345678; /* whatever random */ | 358 h2->reserved_zero ^= 0x12345678; /* whatever random */ |
| 360 RefreshCrc32(gpt); | 359 RefreshCrc32(gpt); |
| 361 EXPECT(1 == CheckHeader(h1, 0, gpt->drive_sectors)); | 360 EXPECT(1 == CheckHeader(h1, 0, gpt->drive_sectors)); |
| 362 EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors)); | 361 EXPECT(1 == CheckHeader(h2, 1, gpt->drive_sectors)); |
| 363 | 362 |
| 364 #ifdef PADDING_CHECKED | 363 #ifdef PADDING_CHECKED |
| 365 /* TODO: padding check is currently disabled */ | 364 /* TODO: padding check is currently disabled */ |
| 366 BuildTestGptData(gpt); | 365 BuildTestGptData(gpt); |
| 367 h1->padding[12] ^= 0x34; /* whatever random */ | 366 h1->padding[12] ^= 0x34; /* whatever random */ |
| 368 h2->padding[56] ^= 0x78; /* whatever random */ | 367 h2->padding[56] ^= 0x78; /* whatever random */ |
| 369 RefreshCrc32(gpt); | 368 RefreshCrc32(gpt); |
| (...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 printf(COL_RED "The following %d test cases are failed:\n" COL_STOP, | 1131 printf(COL_RED "The following %d test cases are failed:\n" COL_STOP, |
| 1133 error_count); | 1132 error_count); |
| 1134 for (i = 0; i < sizeof(test_cases)/sizeof(test_cases[0]); ++i) { | 1133 for (i = 0; i < sizeof(test_cases)/sizeof(test_cases[0]); ++i) { |
| 1135 if (test_cases[i].retval) | 1134 if (test_cases[i].retval) |
| 1136 printf(" %s()\n", test_cases[i].name); | 1135 printf(" %s()\n", test_cases[i].name); |
| 1137 } | 1136 } |
| 1138 } | 1137 } |
| 1139 | 1138 |
| 1140 return (error_count) ? 1 : 0; | 1139 return (error_count) ? 1 : 0; |
| 1141 } | 1140 } |
| OLD | NEW |