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 * Utility for ChromeOS-specific GPT partitions, Please see corresponding .c | 5 * Utility for ChromeOS-specific GPT partitions, Please see corresponding .c |
6 * files for more details. | 6 * files for more details. |
7 */ | 7 */ |
8 | 8 |
9 #include "cgpt.h" | 9 #include "cgpt.h" |
10 | 10 |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 | 550 |
551 /* A null-terminator shows up before the UTF8 sequence ends. */ | 551 /* A null-terminator shows up before the UTF8 sequence ends. */ |
552 if (expected_units != decoded_units) { | 552 if (expected_units != decoded_units) { |
553 retval = CGPT_FAILED; | 553 retval = CGPT_FAILED; |
554 } | 554 } |
555 | 555 |
556 utf16[s16idx++] = 0; | 556 utf16[s16idx++] = 0; |
557 return retval; | 557 return retval; |
558 } | 558 } |
559 | 559 |
560 struct { | 560 /* global types to compare against */ |
561 Guid type; | 561 const Guid guid_chromeos_kernel = GPT_ENT_TYPE_CHROMEOS_KERNEL; |
| 562 const Guid guid_chromeos_rootfs = GPT_ENT_TYPE_CHROMEOS_ROOTFS; |
| 563 const Guid guid_linux_data = GPT_ENT_TYPE_LINUX_DATA; |
| 564 const Guid guid_chromeos_reserved = GPT_ENT_TYPE_CHROMEOS_RESERVED; |
| 565 const Guid guid_efi = GPT_ENT_TYPE_EFI; |
| 566 const Guid guid_unused = GPT_ENT_TYPE_UNUSED; |
| 567 |
| 568 static struct { |
| 569 const Guid *type; |
562 char *name; | 570 char *name; |
563 char *description; | 571 char *description; |
564 } supported_types[] = { | 572 } supported_types[] = { |
565 {GPT_ENT_TYPE_CHROMEOS_KERNEL, "kernel", "ChromeOS kernel"}, | 573 {&guid_chromeos_kernel, "kernel", "ChromeOS kernel"}, |
566 {GPT_ENT_TYPE_CHROMEOS_ROOTFS, "rootfs", "ChromeOS rootfs"}, | 574 {&guid_chromeos_rootfs, "rootfs", "ChromeOS rootfs"}, |
567 {GPT_ENT_TYPE_LINUX_DATA, "data", "Linux data"}, | 575 {&guid_linux_data, "data", "Linux data"}, |
568 {GPT_ENT_TYPE_CHROMEOS_RESERVED, "reserved", "ChromeOS reserved"}, | 576 {&guid_chromeos_reserved, "reserved", "ChromeOS reserved"}, |
569 {GPT_ENT_TYPE_EFI, "efi", "EFI System Partition"}, | 577 {&guid_efi, "efi", "EFI System Partition"}, |
570 {GPT_ENT_TYPE_UNUSED, "unused", "Unused (nonexistent) partition"}, | 578 {&guid_unused, "unused", "Unused (nonexistent) partition"}, |
571 }; | 579 }; |
572 | 580 |
573 /* Resolves human-readable GPT type. | 581 /* Resolves human-readable GPT type. |
574 * Returns CGPT_OK if found. | 582 * Returns CGPT_OK if found. |
575 * Returns CGPT_FAILED if no known type found. */ | 583 * Returns CGPT_FAILED if no known type found. */ |
576 int ResolveType(const Guid *type, char *buf) { | 584 int ResolveType(const Guid *type, char *buf) { |
577 int i; | 585 int i; |
578 for (i = 0; i < ARRAY_COUNT(supported_types); ++i) { | 586 for (i = 0; i < ARRAY_COUNT(supported_types); ++i) { |
579 if (!memcmp(type, &supported_types[i].type, sizeof(Guid))) { | 587 if (!memcmp(type, supported_types[i].type, sizeof(Guid))) { |
580 strcpy(buf, supported_types[i].description); | 588 strcpy(buf, supported_types[i].description); |
581 return CGPT_OK; | 589 return CGPT_OK; |
582 } | 590 } |
583 } | 591 } |
584 return CGPT_FAILED; | 592 return CGPT_FAILED; |
585 } | 593 } |
586 | 594 |
587 int SupportedType(const char *name, Guid *type) { | 595 int SupportedType(const char *name, Guid *type) { |
588 int i; | 596 int i; |
589 for (i = 0; i < ARRAY_COUNT(supported_types); ++i) { | 597 for (i = 0; i < ARRAY_COUNT(supported_types); ++i) { |
590 if (!strcmp(name, supported_types[i].name)) { | 598 if (!strcmp(name, supported_types[i].name)) { |
591 memcpy(type, &supported_types[i].type, sizeof(Guid)); | 599 memcpy(type, supported_types[i].type, sizeof(Guid)); |
592 return CGPT_OK; | 600 return CGPT_OK; |
593 } | 601 } |
594 } | 602 } |
595 return CGPT_FAILED; | 603 return CGPT_FAILED; |
596 } | 604 } |
597 | 605 |
598 void PrintTypes(void) { | 606 void PrintTypes(void) { |
599 int i; | 607 int i; |
600 printf("The partition type may also be given as one of these aliases:\n\n"); | 608 printf("The partition type may also be given as one of these aliases:\n\n"); |
601 for (i = 0; i < ARRAY_COUNT(supported_types); ++i) { | 609 for (i = 0; i < ARRAY_COUNT(supported_types); ++i) { |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 memcpy(primary_header, secondary_header, sizeof(GptHeader)); | 843 memcpy(primary_header, secondary_header, sizeof(GptHeader)); |
836 primary_header->my_lba = GPT_PMBR_SECTOR; /* the second sector on drive */ | 844 primary_header->my_lba = GPT_PMBR_SECTOR; /* the second sector on drive */ |
837 primary_header->alternate_lba = secondary_header->my_lba; | 845 primary_header->alternate_lba = secondary_header->my_lba; |
838 primary_header->entries_lba = primary_header->my_lba + GPT_HEADER_SECTOR; | 846 primary_header->entries_lba = primary_header->my_lba + GPT_HEADER_SECTOR; |
839 return GPT_MODIFIED_HEADER1; | 847 return GPT_MODIFIED_HEADER1; |
840 } | 848 } |
841 | 849 |
842 return 0; | 850 return 0; |
843 } | 851 } |
844 | 852 |
| 853 int GuidEqual(const Guid *guid1, const Guid *guid2) { |
| 854 return (0 == memcmp(guid1, guid2, sizeof(Guid))); |
| 855 } |
845 | 856 |
846 int IsZero(const Guid *gp) { | 857 int IsZero(const Guid *gp) { |
847 return (0 == memcmp(gp, &guid_unused, sizeof(Guid))); | 858 return GuidEqual(gp, &guid_unused); |
848 } | 859 } |
849 | 860 |
850 void PMBRToStr(struct pmbr *pmbr, char *str, unsigned int buflen) { | 861 void PMBRToStr(struct pmbr *pmbr, char *str, unsigned int buflen) { |
851 char buf[GUID_STRLEN]; | 862 char buf[GUID_STRLEN]; |
852 if (IsZero(&pmbr->boot_guid)) { | 863 if (IsZero(&pmbr->boot_guid)) { |
853 require(snprintf(str, buflen, "PMBR") < buflen); | 864 require(snprintf(str, buflen, "PMBR") < buflen); |
854 } else { | 865 } else { |
855 GuidToStr(&pmbr->boot_guid, buf, sizeof(buf)); | 866 GuidToStr(&pmbr->boot_guid, buf, sizeof(buf)); |
856 require(snprintf(str, buflen, "PMBR (Boot GUID: %s)", buf) < buflen); | 867 require(snprintf(str, buflen, "PMBR (Boot GUID: %s)", buf) < buflen); |
857 } | 868 } |
858 } | 869 } |
OLD | NEW |