Lines Matching refs:dev_desc
50 static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba,
52 static gpt_entry *alloc_read_gpt_entries(struct blk_desc *dev_desc,
189 int get_disk_guid(struct blk_desc * dev_desc, char *guid) in get_disk_guid() argument
191 ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz); in get_disk_guid()
196 if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, in get_disk_guid()
199 if (is_gpt_valid(dev_desc, dev_desc->lba - 1, in get_disk_guid()
216 void part_print_efi(struct blk_desc *dev_desc) in part_print_efi() argument
218 ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz); in part_print_efi()
225 if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, in part_print_efi()
228 if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), in part_print_efi()
273 int part_get_info_efi(struct blk_desc *dev_desc, int part, in part_get_info_efi() argument
276 ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz); in part_get_info_efi()
286 if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, in part_get_info_efi()
289 if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), in part_get_info_efi()
313 info->blksz = dev_desc->blksz; in part_get_info_efi()
336 static int part_test_efi(struct blk_desc *dev_desc) in part_test_efi() argument
338 ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, dev_desc->blksz); in part_test_efi()
341 if ((blk_dread(dev_desc, 0, 1, (ulong *)legacymbr) != 1) in part_test_efi()
354 static int set_protective_mbr(struct blk_desc *dev_desc) in set_protective_mbr() argument
357 ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, p_mbr, 1, dev_desc->blksz); in set_protective_mbr()
364 if (blk_dread(dev_desc, 0, 1, p_mbr) != 1) { in set_protective_mbr()
365 pr_err("** Can't read from device %d **\n", dev_desc->devnum); in set_protective_mbr()
377 p_mbr->partition_record[0].nr_sects = (u32) dev_desc->lba - 1; in set_protective_mbr()
380 if (blk_dwrite(dev_desc, 0, 1, p_mbr) != 1) { in set_protective_mbr()
382 dev_desc->devnum); in set_protective_mbr()
389 int write_gpt_table(struct blk_desc *dev_desc, in write_gpt_table() argument
393 * sizeof(gpt_entry)), dev_desc); in write_gpt_table()
396 debug("max lba: %x\n", (u32) dev_desc->lba); in write_gpt_table()
398 if (set_protective_mbr(dev_desc) < 0) in write_gpt_table()
412 if (blk_dwrite(dev_desc, 1, 1, gpt_h) != 1) in write_gpt_table()
415 if (blk_dwrite(dev_desc, le64_to_cpu(gpt_h->partition_entry_lba), in write_gpt_table()
421 if (blk_dwrite(dev_desc, (lbaint_t)le64_to_cpu(gpt_h->last_usable_lba) in write_gpt_table()
425 if (blk_dwrite(dev_desc, (lbaint_t)le64_to_cpu(gpt_h->my_lba), 1, in write_gpt_table()
433 printf("** Can't write to device %d **\n", dev_desc->devnum); in write_gpt_table()
437 int gpt_fill_pte(struct blk_desc *dev_desc, in gpt_fill_pte() argument
460 dev_desc->blksz; in gpt_fill_pte()
557 static uint32_t partition_entries_offset(struct blk_desc *dev_desc) in partition_entries_offset() argument
573 PAD_TO_BLOCKSIZE(CONFIG_EFI_PARTITION_ENTRIES_OFF, dev_desc); in partition_entries_offset()
574 offset_blks = offset_bytes / dev_desc->blksz; in partition_entries_offset()
587 offset_bytes = PAD_TO_BLOCKSIZE(config_offset, dev_desc); in partition_entries_offset()
588 offset_blks = offset_bytes / dev_desc->blksz; in partition_entries_offset()
604 int gpt_fill_header(struct blk_desc *dev_desc, gpt_header *gpt_h, in gpt_fill_header() argument
611 gpt_h->alternate_lba = cpu_to_le64(dev_desc->lba - 1); in gpt_fill_header()
612 gpt_h->last_usable_lba = cpu_to_le64(dev_desc->lba - 34); in gpt_fill_header()
614 cpu_to_le64(partition_entries_offset(dev_desc)); in gpt_fill_header()
628 int gpt_restore(struct blk_desc *dev_desc, char *str_disk_guid, in gpt_restore() argument
635 size = PAD_TO_BLOCKSIZE(sizeof(gpt_header), dev_desc); in gpt_restore()
644 dev_desc); in gpt_restore()
654 ret = gpt_fill_header(dev_desc, gpt_h, str_disk_guid, parts_count); in gpt_restore()
659 ret = gpt_fill_pte(dev_desc, gpt_h, gpt_e, partitions, parts_count); in gpt_restore()
664 ret = write_gpt_table(dev_desc, gpt_h, gpt_e); in gpt_restore()
686 int gpt_verify_headers(struct blk_desc *dev_desc, gpt_header *gpt_head, in gpt_verify_headers() argument
693 if (is_gpt_valid(dev_desc, in gpt_verify_headers()
700 if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), in gpt_verify_headers()
710 int gpt_verify_partitions(struct blk_desc *dev_desc, in gpt_verify_partitions() argument
719 ret = gpt_verify_headers(dev_desc, gpt_head, gpt_pte); in gpt_verify_partitions()
788 int is_valid_gpt_buf(struct blk_desc *dev_desc, void *buf) in is_valid_gpt_buf() argument
795 dev_desc->blksz); in is_valid_gpt_buf()
797 dev_desc->lba)) in is_valid_gpt_buf()
802 dev_desc->blksz); in is_valid_gpt_buf()
809 int write_mbr_and_gpt_partitions(struct blk_desc *dev_desc, void *buf) in write_mbr_and_gpt_partitions() argument
817 if (is_valid_gpt_buf(dev_desc, buf)) in write_mbr_and_gpt_partitions()
822 dev_desc->blksz); in write_mbr_and_gpt_partitions()
826 dev_desc->blksz); in write_mbr_and_gpt_partitions()
829 dev_desc); in write_mbr_and_gpt_partitions()
834 if (blk_dwrite(dev_desc, lba, cnt, buf) != cnt) { in write_mbr_and_gpt_partitions()
843 if (blk_dwrite(dev_desc, lba, cnt, gpt_h) != cnt) { in write_mbr_and_gpt_partitions()
851 if (blk_dwrite(dev_desc, lba, cnt, gpt_e) != cnt) { in write_mbr_and_gpt_partitions()
862 if (blk_dwrite(dev_desc, lba, cnt, gpt_e) != cnt) { in write_mbr_and_gpt_partitions()
870 if (blk_dwrite(dev_desc, lba, cnt, gpt_h) != cnt) { in write_mbr_and_gpt_partitions()
931 static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba, in is_gpt_valid() argument
935 if (!dev_desc || !pgpt_head) { in is_gpt_valid()
940 ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, mbr, 1, dev_desc->blksz); in is_gpt_valid()
943 if (blk_dread(dev_desc, 0, 1, (ulong *)mbr) != 1) { in is_gpt_valid()
949 if (blk_dread(dev_desc, (lbaint_t)lba, 1, pgpt_head) != 1) { in is_gpt_valid()
954 if (validate_gpt_header(pgpt_head, (lbaint_t)lba, dev_desc->lba)) in is_gpt_valid()
957 if (dev_desc->sig_type == SIG_TYPE_NONE) { in is_gpt_valid()
960 dev_desc->sig_type = SIG_TYPE_GUID; in is_gpt_valid()
961 memcpy(&dev_desc->guid_sig, &pgpt_head->disk_guid, in is_gpt_valid()
964 dev_desc->sig_type = SIG_TYPE_MBR; in is_gpt_valid()
965 dev_desc->mbr_sig = mbr->unique_mbr_signature; in is_gpt_valid()
970 *pgpt_pte = alloc_read_gpt_entries(dev_desc, pgpt_head); in is_gpt_valid()
994 static gpt_entry *alloc_read_gpt_entries(struct blk_desc *dev_desc, in alloc_read_gpt_entries() argument
1001 if (!dev_desc || !pgpt_head) { in alloc_read_gpt_entries()
1017 PAD_TO_BLOCKSIZE(count, dev_desc)); in alloc_read_gpt_entries()
1028 blk_cnt = BLOCK_CNT(count, dev_desc); in alloc_read_gpt_entries()
1029 if (blk_dread(dev_desc, blk, (lbaint_t)blk_cnt, pte) != blk_cnt) { in alloc_read_gpt_entries()