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 <string.h> | 7 #include <string.h> |
8 #include "cgptlib_internal.h" | 8 #include "cgptlib_internal.h" |
9 #include "crc32.h" | 9 #include "crc32.h" |
10 #include "gpt.h" | 10 #include "gpt.h" |
11 #include "quick_sort.h" | 11 #include "quick_sort.h" |
12 #include "utility.h" | 12 #include "utility.h" |
13 | 13 |
14 /* Macro to invalidate a GPT header/entries */ | 14 /* Macro to invalidate a GPT header/entries */ |
15 #define INVALIDATE_HEADER(valid_headers, index) \ | 15 #define INVALIDATE_HEADER(valid_headers, index) \ |
16 do { \ | 16 do { \ |
17 debug("- INVALIDATE_HEADER() at %s():%d\n", __FUNCTION__, __LINE__); \ | 17 debug("- INVALIDATE_HEADER() at %s():%d\n", __FUNCTION__, __LINE__); \ |
18 valid_headers &= ~(1<<index); \ | 18 valid_headers &= ~(1<<index); \ |
19 } while (0) | 19 } while (0) |
20 #define INVALIDATE_ENTRIES(valid_entries, index) \ | 20 #define INVALIDATE_ENTRIES(valid_entries, index) \ |
21 do { \ | 21 do { \ |
22 debug("- INVALIDATE_ENTRIES() at %s():%d\n", __FUNCTION__, __LINE__); \ | 22 debug("- INVALIDATE_ENTRIES() at %s():%d\n", __FUNCTION__, __LINE__); \ |
23 valid_entries &= ~(1<<index); \ | 23 valid_entries &= ~(1<<index); \ |
24 } while (0) | 24 } while (0) |
25 | 25 |
26 const char *GptError(int errno) { | 26 const char *GptError(int errno) { |
27 const char *error_string[] = { | 27 const char *error_string[] = { |
28 /* GPT_SUCCESS */ "Success", | 28 /* GPT_SUCCESS */ "Success", |
29 /* GPT_ERROR_NO_VALID_KERNEL */ "No valid kernel entry", | 29 /* GPT_ERROR_NO_VALID_KERNEL */ "No valid kernel entry", |
30 /* GPT_ERROR_INVALID_HEADERS */ "Invalid headers", | 30 /* GPT_ERROR_INVALID_HEADERS */ "Both primary and secondary headers are " |
31 /* GPT_ERROR_INVALID_ENTRIES */ "Invalid entries", | 31 "invalid.", |
| 32 /* GPT_ERROR_INVALID_ENTRIES */ "Both primary and secondary entries are " |
| 33 "invalid.", |
32 /* GPT_ERROR_INVALID_SECTOR_SIZE */ "Invalid sector size", | 34 /* GPT_ERROR_INVALID_SECTOR_SIZE */ "Invalid sector size", |
33 /* GPT_ERROR_INVALID_SECTOR_NUMBER */ "Invalid sector number", | 35 /* GPT_ERROR_INVALID_SECTOR_NUMBER */ "Invalid sector number", |
34 /* GPT_ERROR_INVALID_UPDATE_TYPE */ "Invalid update type", | 36 /* GPT_ERROR_INVALID_UPDATE_TYPE */ "Invalid update type", |
35 }; | 37 }; |
36 return error_string[errno]; | 38 return error_string[errno]; |
37 } | 39 } |
38 | 40 |
39 /* Checks if sector_bytes and drive_sectors are valid values. */ | 41 /* Checks if sector_bytes and drive_sectors are valid values. */ |
40 int CheckParameters(GptData *gpt) { | 42 int CheckParameters(GptData *gpt) { |
41 /* Currently, we only support 512-byte sector. In the future, we may support | 43 /* Currently, we only support 512-byte sector. In the future, we may support |
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 RepairEntries(gpt, MASK_PRIMARY); | 761 RepairEntries(gpt, MASK_PRIMARY); |
760 /* Actually two entries are dirty now. | 762 /* Actually two entries are dirty now. |
761 * Also two headers are dirty because entries_crc32 has been updated. */ | 763 * Also two headers are dirty because entries_crc32 has been updated. */ |
762 gpt->modified |= (GPT_MODIFIED_HEADER1 | GPT_MODIFIED_ENTRIES1 | | 764 gpt->modified |= (GPT_MODIFIED_HEADER1 | GPT_MODIFIED_ENTRIES1 | |
763 GPT_MODIFIED_HEADER2 | GPT_MODIFIED_ENTRIES2); | 765 GPT_MODIFIED_HEADER2 | GPT_MODIFIED_ENTRIES2); |
764 UpdateCrc(gpt); | 766 UpdateCrc(gpt); |
765 } | 767 } |
766 | 768 |
767 return GPT_SUCCESS; | 769 return GPT_SUCCESS; |
768 } | 770 } |
OLD | NEW |