Lines Matching refs:gpt_h
76 static int validate_gpt_header(gpt_header *gpt_h, lbaint_t lba, in validate_gpt_header() argument
83 if (le64_to_cpu(gpt_h->signature) != GPT_HEADER_SIGNATURE) { in validate_gpt_header()
84 if (le64_to_cpu(gpt_h->signature) != 0) in validate_gpt_header()
87 le64_to_cpu(gpt_h->signature), in validate_gpt_header()
93 memcpy(&crc32_backup, &gpt_h->header_crc32, sizeof(crc32_backup)); in validate_gpt_header()
94 memset(&gpt_h->header_crc32, 0, sizeof(gpt_h->header_crc32)); in validate_gpt_header()
96 calc_crc32 = efi_crc32((const unsigned char *)gpt_h, in validate_gpt_header()
97 le32_to_cpu(gpt_h->header_size)); in validate_gpt_header()
99 memcpy(&gpt_h->header_crc32, &crc32_backup, sizeof(crc32_backup)); in validate_gpt_header()
111 if (le64_to_cpu(gpt_h->my_lba) != lba) { in validate_gpt_header()
113 le64_to_cpu(gpt_h->my_lba), in validate_gpt_header()
122 if (le64_to_cpu(gpt_h->first_usable_lba) > lastlba) { in validate_gpt_header()
124 le64_to_cpu(gpt_h->first_usable_lba), lastlba); in validate_gpt_header()
127 if (le64_to_cpu(gpt_h->last_usable_lba) > lastlba) { in validate_gpt_header()
128 if (le64_to_cpu(gpt_h->last_usable_lba) == FACTORY_UNKNOWN_LBA) { in validate_gpt_header()
131 gpt_h->last_usable_lba = lastlba - 34; in validate_gpt_header()
139 le64_to_cpu(gpt_h->last_usable_lba), lastlba); in validate_gpt_header()
144 LBAF "\n", le64_to_cpu(gpt_h->first_usable_lba), in validate_gpt_header()
145 le64_to_cpu(gpt_h->last_usable_lba), lastlba); in validate_gpt_header()
150 static int validate_gpt_entries(gpt_header *gpt_h, gpt_entry *gpt_e) in validate_gpt_entries() argument
156 le32_to_cpu(gpt_h->num_partition_entries) * in validate_gpt_entries()
157 le32_to_cpu(gpt_h->sizeof_partition_entry)); in validate_gpt_entries()
159 if (calc_crc32 != le32_to_cpu(gpt_h->partition_entry_array_crc32)) { in validate_gpt_entries()
162 le32_to_cpu(gpt_h->partition_entry_array_crc32), in validate_gpt_entries()
170 static void prepare_backup_gpt_header(gpt_header *gpt_h) in prepare_backup_gpt_header() argument
176 val = le64_to_cpu(gpt_h->my_lba); in prepare_backup_gpt_header()
177 gpt_h->my_lba = gpt_h->alternate_lba; in prepare_backup_gpt_header()
178 gpt_h->alternate_lba = cpu_to_le64(val); in prepare_backup_gpt_header()
179 gpt_h->partition_entry_lba = in prepare_backup_gpt_header()
180 cpu_to_le64(le64_to_cpu(gpt_h->last_usable_lba) + 1); in prepare_backup_gpt_header()
181 gpt_h->header_crc32 = 0; in prepare_backup_gpt_header()
183 calc_crc32 = efi_crc32((const unsigned char *)gpt_h, in prepare_backup_gpt_header()
184 le32_to_cpu(gpt_h->header_size)); in prepare_backup_gpt_header()
185 gpt_h->header_crc32 = cpu_to_le32(calc_crc32); in prepare_backup_gpt_header()
601 gpt_header *gpt_h, gpt_entry *gpt_e) in write_gpt_table() argument
603 const int pte_blk_cnt = BLOCK_CNT((gpt_h->num_partition_entries in write_gpt_table()
616 le32_to_cpu(gpt_h->num_partition_entries) * in write_gpt_table()
617 le32_to_cpu(gpt_h->sizeof_partition_entry)); in write_gpt_table()
618 gpt_h->partition_entry_array_crc32 = cpu_to_le32(calc_crc32); in write_gpt_table()
620 calc_crc32 = efi_crc32((const unsigned char *)gpt_h, in write_gpt_table()
621 le32_to_cpu(gpt_h->header_size)); in write_gpt_table()
622 gpt_h->header_crc32 = cpu_to_le32(calc_crc32); in write_gpt_table()
625 if (blk_dwrite(dev_desc, 1 * sector, sector, gpt_h) != sector) in write_gpt_table()
628 if (blk_dwrite(dev_desc, le64_to_cpu(gpt_h->partition_entry_lba * sector), in write_gpt_table()
632 prepare_backup_gpt_header(gpt_h); in write_gpt_table()
634 if (blk_dwrite(dev_desc, (lbaint_t)(le64_to_cpu(gpt_h->last_usable_lba) in write_gpt_table()
638 if (blk_dwrite(dev_desc, (lbaint_t)le64_to_cpu(gpt_h->my_lba) * sector, 1, in write_gpt_table()
639 gpt_h) != 1) in write_gpt_table()
651 gpt_header *gpt_h, gpt_entry *gpt_e, in gpt_fill_pte() argument
654 lbaint_t offset = (lbaint_t)le64_to_cpu(gpt_h->first_usable_lba); in gpt_fill_pte()
656 le64_to_cpu(gpt_h->last_usable_lba); in gpt_fill_pte()
667 size_t hdr_start = gpt_h->my_lba; in gpt_fill_pte()
670 size_t pte_start = gpt_h->partition_entry_lba; in gpt_fill_pte()
672 gpt_h->num_partition_entries * gpt_h->sizeof_partition_entry / in gpt_fill_pte()
706 gpt_e[i].ending_lba = gpt_h->last_usable_lba; in gpt_fill_pte()
816 int gpt_fill_header(struct blk_desc *dev_desc, gpt_header *gpt_h, in gpt_fill_header() argument
819 gpt_h->signature = cpu_to_le64(GPT_HEADER_SIGNATURE); in gpt_fill_header()
820 gpt_h->revision = cpu_to_le32(GPT_HEADER_REVISION_V1); in gpt_fill_header()
821 gpt_h->header_size = cpu_to_le32(sizeof(gpt_header)); in gpt_fill_header()
822 gpt_h->my_lba = cpu_to_le64(1); in gpt_fill_header()
823 gpt_h->alternate_lba = cpu_to_le64(dev_desc->rawlba - 1); in gpt_fill_header()
824 gpt_h->partition_entry_lba = in gpt_fill_header()
827 gpt_h->last_usable_lba = cpu_to_le64(dev_desc->rawlba - 6); in gpt_fill_header()
828 gpt_h->first_usable_lba = in gpt_fill_header()
829 cpu_to_le64(le64_to_cpu(gpt_h->partition_entry_lba) + 4); in gpt_fill_header()
831 gpt_h->last_usable_lba = cpu_to_le64(dev_desc->rawlba - 34); in gpt_fill_header()
832 gpt_h->first_usable_lba = in gpt_fill_header()
833 cpu_to_le64(le64_to_cpu(gpt_h->partition_entry_lba) + 32); in gpt_fill_header()
835 gpt_h->num_partition_entries = cpu_to_le32(GPT_ENTRY_NUMBERS); in gpt_fill_header()
836 gpt_h->sizeof_partition_entry = cpu_to_le32(sizeof(gpt_entry)); in gpt_fill_header()
837 gpt_h->header_crc32 = 0; in gpt_fill_header()
838 gpt_h->partition_entry_array_crc32 = 0; in gpt_fill_header()
840 if (uuid_str_to_bin(str_guid, gpt_h->disk_guid.b, UUID_STR_FORMAT_GUID)) in gpt_fill_header()
849 gpt_header *gpt_h; in gpt_restore() local
854 gpt_h = malloc_cache_aligned(size); in gpt_restore()
855 if (gpt_h == NULL) { in gpt_restore()
859 memset(gpt_h, 0, size); in gpt_restore()
865 free(gpt_h); in gpt_restore()
871 ret = gpt_fill_header(dev_desc, gpt_h, str_disk_guid, parts_count); in gpt_restore()
876 ret = gpt_fill_pte(dev_desc, gpt_h, gpt_e, partitions, parts_count); in gpt_restore()
881 ret = write_gpt_table(dev_desc, gpt_h, gpt_e); in gpt_restore()
885 free(gpt_h); in gpt_restore()
1016 gpt_header *gpt_h; in is_valid_gpt_buf() local
1020 gpt_h = buf + (GPT_PRIMARY_PARTITION_TABLE_LBA * in is_valid_gpt_buf()
1023 if ((le64_to_cpu(gpt_h->alternate_lba) + 1) in is_valid_gpt_buf()
1025 le64_to_cpu(gpt_h->last_usable_lba) != FACTORY_UNKNOWN_LBA) { in is_valid_gpt_buf()
1031 if (validate_gpt_header(gpt_h, GPT_PRIMARY_PARTITION_TABLE_LBA, in is_valid_gpt_buf()
1036 gpt_e = buf + (le64_to_cpu(gpt_h->partition_entry_lba) * in is_valid_gpt_buf()
1038 if (validate_gpt_entries(gpt_h, gpt_e)) in is_valid_gpt_buf()
1046 gpt_header *gpt_h; in write_mbr_and_gpt_partitions() local
1061 gpt_h = buf + (GPT_PRIMARY_PARTITION_TABLE_LBA * in write_mbr_and_gpt_partitions()
1065 gpt_e = buf + (le64_to_cpu(gpt_h->partition_entry_lba) * in write_mbr_and_gpt_partitions()
1067 gpt_e_blk_cnt = BLOCK_CNT((le32_to_cpu(gpt_h->num_partition_entries) * in write_mbr_and_gpt_partitions()
1068 le32_to_cpu(gpt_h->sizeof_partition_entry)), in write_mbr_and_gpt_partitions()
1083 if (blk_dwrite(dev_desc, lba, cnt, gpt_h) != cnt) { in write_mbr_and_gpt_partitions()
1089 lba = le64_to_cpu(gpt_h->partition_entry_lba); in write_mbr_and_gpt_partitions()
1097 prepare_backup_gpt_header(gpt_h); in write_mbr_and_gpt_partitions()
1100 lba = le64_to_cpu(gpt_h->partition_entry_lba); in write_mbr_and_gpt_partitions()
1108 lba = le64_to_cpu(gpt_h->my_lba); in write_mbr_and_gpt_partitions()
1110 if (blk_dwrite(dev_desc, lba, cnt, gpt_h) != cnt) { in write_mbr_and_gpt_partitions()