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()
549 gpt_header *gpt_h, gpt_entry *gpt_e) in write_gpt_table() argument
551 const int pte_blk_cnt = BLOCK_CNT((gpt_h->num_partition_entries in write_gpt_table()
562 le32_to_cpu(gpt_h->num_partition_entries) * in write_gpt_table()
563 le32_to_cpu(gpt_h->sizeof_partition_entry)); in write_gpt_table()
564 gpt_h->partition_entry_array_crc32 = cpu_to_le32(calc_crc32); in write_gpt_table()
566 calc_crc32 = efi_crc32((const unsigned char *)gpt_h, in write_gpt_table()
567 le32_to_cpu(gpt_h->header_size)); in write_gpt_table()
568 gpt_h->header_crc32 = cpu_to_le32(calc_crc32); in write_gpt_table()
571 if (blk_dwrite(dev_desc, 1, 1, gpt_h) != 1) in write_gpt_table()
574 if (blk_dwrite(dev_desc, le64_to_cpu(gpt_h->partition_entry_lba), in write_gpt_table()
578 prepare_backup_gpt_header(gpt_h); in write_gpt_table()
580 if (blk_dwrite(dev_desc, (lbaint_t)le64_to_cpu(gpt_h->last_usable_lba) in write_gpt_table()
584 if (blk_dwrite(dev_desc, (lbaint_t)le64_to_cpu(gpt_h->my_lba), 1, in write_gpt_table()
585 gpt_h) != 1) in write_gpt_table()
597 gpt_header *gpt_h, gpt_entry *gpt_e, in gpt_fill_pte() argument
600 lbaint_t offset = (lbaint_t)le64_to_cpu(gpt_h->first_usable_lba); in gpt_fill_pte()
602 le64_to_cpu(gpt_h->last_usable_lba); in gpt_fill_pte()
613 size_t hdr_start = gpt_h->my_lba; in gpt_fill_pte()
616 size_t pte_start = gpt_h->partition_entry_lba; in gpt_fill_pte()
618 gpt_h->num_partition_entries * gpt_h->sizeof_partition_entry / in gpt_fill_pte()
652 gpt_e[i].ending_lba = gpt_h->last_usable_lba; in gpt_fill_pte()
763 int gpt_fill_header(struct blk_desc *dev_desc, gpt_header *gpt_h, in gpt_fill_header() argument
766 gpt_h->signature = cpu_to_le64(GPT_HEADER_SIGNATURE); in gpt_fill_header()
767 gpt_h->revision = cpu_to_le32(GPT_HEADER_REVISION_V1); in gpt_fill_header()
768 gpt_h->header_size = cpu_to_le32(sizeof(gpt_header)); in gpt_fill_header()
769 gpt_h->my_lba = cpu_to_le64(1); in gpt_fill_header()
770 gpt_h->alternate_lba = cpu_to_le64(dev_desc->lba - 1); in gpt_fill_header()
771 gpt_h->last_usable_lba = cpu_to_le64(dev_desc->lba - 34); in gpt_fill_header()
772 gpt_h->partition_entry_lba = in gpt_fill_header()
774 gpt_h->first_usable_lba = in gpt_fill_header()
775 cpu_to_le64(le64_to_cpu(gpt_h->partition_entry_lba) + 32); in gpt_fill_header()
776 gpt_h->num_partition_entries = cpu_to_le32(GPT_ENTRY_NUMBERS); in gpt_fill_header()
777 gpt_h->sizeof_partition_entry = cpu_to_le32(sizeof(gpt_entry)); in gpt_fill_header()
778 gpt_h->header_crc32 = 0; in gpt_fill_header()
779 gpt_h->partition_entry_array_crc32 = 0; in gpt_fill_header()
781 if (uuid_str_to_bin(str_guid, gpt_h->disk_guid.b, UUID_STR_FORMAT_GUID)) in gpt_fill_header()
790 gpt_header *gpt_h; in gpt_restore() local
795 gpt_h = malloc_cache_aligned(size); in gpt_restore()
796 if (gpt_h == NULL) { in gpt_restore()
800 memset(gpt_h, 0, size); in gpt_restore()
807 free(gpt_h); in gpt_restore()
813 ret = gpt_fill_header(dev_desc, gpt_h, str_disk_guid, parts_count); in gpt_restore()
818 ret = gpt_fill_pte(dev_desc, gpt_h, gpt_e, partitions, parts_count); in gpt_restore()
823 ret = write_gpt_table(dev_desc, gpt_h, gpt_e); in gpt_restore()
827 free(gpt_h); in gpt_restore()
958 gpt_header *gpt_h; in is_valid_gpt_buf() local
962 gpt_h = buf + (GPT_PRIMARY_PARTITION_TABLE_LBA * in is_valid_gpt_buf()
965 if ((le64_to_cpu(gpt_h->alternate_lba) + 1) in is_valid_gpt_buf()
967 le64_to_cpu(gpt_h->last_usable_lba) != FACTORY_UNKNOWN_LBA) { in is_valid_gpt_buf()
973 if (validate_gpt_header(gpt_h, GPT_PRIMARY_PARTITION_TABLE_LBA, in is_valid_gpt_buf()
978 gpt_e = buf + (le64_to_cpu(gpt_h->partition_entry_lba) * in is_valid_gpt_buf()
980 if (validate_gpt_entries(gpt_h, gpt_e)) in is_valid_gpt_buf()
988 gpt_header *gpt_h; in write_mbr_and_gpt_partitions() local
998 gpt_h = buf + (GPT_PRIMARY_PARTITION_TABLE_LBA * in write_mbr_and_gpt_partitions()
1002 gpt_e = buf + (le64_to_cpu(gpt_h->partition_entry_lba) * in write_mbr_and_gpt_partitions()
1004 gpt_e_blk_cnt = BLOCK_CNT((le32_to_cpu(gpt_h->num_partition_entries) * in write_mbr_and_gpt_partitions()
1005 le32_to_cpu(gpt_h->sizeof_partition_entry)), in write_mbr_and_gpt_partitions()
1020 if (blk_dwrite(dev_desc, lba, cnt, gpt_h) != cnt) { in write_mbr_and_gpt_partitions()
1026 lba = le64_to_cpu(gpt_h->partition_entry_lba); in write_mbr_and_gpt_partitions()
1034 prepare_backup_gpt_header(gpt_h); in write_mbr_and_gpt_partitions()
1037 lba = le64_to_cpu(gpt_h->partition_entry_lba); in write_mbr_and_gpt_partitions()
1045 lba = le64_to_cpu(gpt_h->my_lba); in write_mbr_and_gpt_partitions()
1047 if (blk_dwrite(dev_desc, lba, cnt, gpt_h) != cnt) { in write_mbr_and_gpt_partitions()