Changeset f57ccb5 in mainline for uspace/lib/label
- Timestamp:
- 2015-08-11T16:03:59Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0bde8523
- Parents:
- 1b23e33
- Location:
- uspace/lib/label
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/label/include/label.h
r1b23e33 rf57ccb5 55 55 extern int label_part_destroy(label_part_t *); 56 56 extern void label_pspec_init(label_part_spec_t *); 57 extern int label_suggest_ptype(label_t *, label_pcnt_t, label_ptype_t *); 57 58 58 59 #endif -
uspace/lib/label/include/std/gpt.h
r1b23e33 rf57ccb5 77 77 } __attribute__((packed)) gpt_entry_t; 78 78 79 /** Microsoft Basic Data Partition */ 80 #define GPT_MS_BASIC_DATA "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7" 81 /** Linux Filesystem Data */ 82 #define GPT_LINUX_FS_DATA "0FC63DAF-8483-4772-8E79-3D69D8477DE4" 83 /** I could not find any definition of Minix GUID partition type. 84 * This is a randomly generated UUID */ 85 #define GPT_MINIX_FAKE "8308e350-4e2d-46c7-8e3b-24b07e8ac674" 86 79 87 #endif 80 88 -
uspace/lib/label/include/std/mbr.h
r1b23e33 rf57ccb5 57 57 }; 58 58 59 enum ptype {59 enum mbr_ptype { 60 60 /** Unused partition entry */ 61 mbr_pt_unused = 0x00,61 mbr_pt_unused = 0x00, 62 62 /** Extended partition */ 63 mbr_pt_extended = 0x05 63 mbr_pt_extended = 0x05, 64 /** Extended partition with LBA */ 65 mbr_pt_extended_lba = 0x0f, 66 /** FAT16 with LBA */ 67 mbr_pt_fat16_lba = 0x0e, 68 /** FAT32 with LBA */ 69 mbr_pt_fat32_lba = 0x0c, 70 /** IFS, HPFS, NTFS, exFAT */ 71 mbr_pt_ms_advanced = 0x07, 72 /** Minix */ 73 mbr_pt_minix = 0x81, 74 /** Linux */ 75 mbr_pt_linux = 0x83 64 76 }; 65 77 -
uspace/lib/label/include/types/liblabel.h
r1b23e33 rf57ccb5 61 61 int (*part_create)(label_t *, label_part_spec_t *, label_part_t **); 62 62 int (*part_destroy)(label_part_t *); 63 int (*suggest_ptype)(label_t *, label_pcnt_t, label_ptype_t *); 63 64 } label_ops_t; 64 65 … … 106 107 aoff64_t nblocks; 107 108 /** Partition type */ 108 uint64_t ptype;109 label_ptype_t ptype; 109 110 /** Partition UUID */ 110 111 uuid_t part_uuid; … … 124 125 label_pkind_t pkind; 125 126 /** Partition type */ 126 uint64_t ptype;127 label_ptype_t ptype; 127 128 }; 128 129 -
uspace/lib/label/src/gpt.c
r1b23e33 rf57ccb5 55 55 static int gpt_part_create(label_t *, label_part_spec_t *, label_part_t **); 56 56 static int gpt_part_destroy(label_part_t *); 57 static int gpt_suggest_ptype(label_t *, label_pcnt_t, label_ptype_t *); 57 58 58 59 static void gpt_unused_pte(gpt_entry_t *); … … 80 81 .part_get_info = gpt_part_get_info, 81 82 .part_create = gpt_part_create, 82 .part_destroy = gpt_part_destroy 83 .part_destroy = gpt_part_destroy, 84 .suggest_ptype = gpt_suggest_ptype 83 85 }; 84 86 … … 547 549 linfo->dcnt = dc_label; 548 550 linfo->ltype = lt_gpt; 549 linfo->flags = 0;551 linfo->flags = lf_ptype_uuid; /* Partition type is in UUID format */ 550 552 if (gpt_can_create_pri(label)) 551 553 linfo->flags = linfo->flags | lf_can_create_pri; … … 607 609 /* GPT only has primary partitions */ 608 610 if (pspec->pkind != lpk_primary) { 611 rc = EINVAL; 612 goto error; 613 } 614 615 /* Partition type must be in UUID format */ 616 if (pspec->ptype.fmt != lptf_uuid) { 609 617 rc = EINVAL; 610 618 goto error; … … 663 671 } 664 672 673 static int gpt_suggest_ptype(label_t *label, label_pcnt_t pcnt, 674 label_ptype_t *ptype) 675 { 676 const char *ptid; 677 int rc; 678 679 ptid = NULL; 680 681 switch (pcnt) { 682 case lpc_fat12_16: 683 case lpc_exfat: 684 case lpc_fat32: 685 ptid = GPT_MS_BASIC_DATA; 686 break; 687 case lpc_ext4: 688 ptid = GPT_LINUX_FS_DATA; 689 break; 690 case lpc_minix: 691 ptid = GPT_MINIX_FAKE; 692 break; 693 } 694 695 if (ptid == NULL) 696 return EINVAL; 697 698 ptype->fmt = lptf_uuid; 699 rc = uuid_parse(ptid, &ptype->t.uuid, NULL); 700 assert(rc == EOK); 701 702 return EOK; 703 } 704 665 705 static void gpt_unused_pte(gpt_entry_t *pte) 666 706 { … … 677 717 678 718 memset(pte, 0, sizeof(gpt_entry_t)); 679 pte->part_type[0] = 0x12;719 uuid_encode(&part->ptype.t.uuid, pte->part_type); 680 720 uuid_encode(&part->part_uuid, pte->part_id); 681 721 pte->start_lba = host2uint64_t_le(part->block0); … … 713 753 part->block0 = b0; 714 754 part->nblocks = b1 - b0 + 1; 755 part->ptype.fmt = lptf_uuid; 756 uuid_decode(pte->part_type, &part->ptype.t.uuid); 715 757 uuid_decode(pte->part_id, &part->part_uuid); 716 758 -
uspace/lib/label/src/label.c
r1b23e33 rf57ccb5 133 133 } 134 134 135 int label_suggest_ptype(label_t *label, label_pcnt_t pcnt, 136 label_ptype_t *ptype) 137 { 138 return label->ops->suggest_ptype(label, pcnt, ptype); 139 } 140 135 141 /** @} 136 142 */ -
uspace/lib/label/src/mbr.c
r1b23e33 rf57ccb5 54 54 static int mbr_part_create(label_t *, label_part_spec_t *, label_part_t **); 55 55 static int mbr_part_destroy(label_part_t *); 56 static int mbr_suggest_ptype(label_t *, label_pcnt_t, label_ptype_t *); 56 57 57 58 static void mbr_unused_pte(mbr_pte_t *); … … 77 78 .part_get_info = mbr_part_get_info, 78 79 .part_create = mbr_part_create, 79 .part_destroy = mbr_part_destroy 80 .part_destroy = mbr_part_destroy, 81 .suggest_ptype = mbr_suggest_ptype 80 82 }; 81 83 … … 485 487 486 488 log_msg(LOG_DEFAULT, LVL_NOTE, "mbr_part_get_info: index=%d ptype=%d", 487 (int)part->index, (int)part->ptype );489 (int)part->index, (int)part->ptype.t.num); 488 490 if (link_used(&part->llog)) 489 491 pinfo->pkind = lpk_logical; 490 else if (part->ptype == mbr_pt_extended)492 else if (part->ptype.t.num == mbr_pt_extended) 491 493 pinfo->pkind = lpk_extended; 492 494 else … … 503 505 int rc; 504 506 507 if (pspec->ptype.fmt != lptf_num) 508 return EINVAL; 509 505 510 part = calloc(1, sizeof(label_part_t)); 506 511 if (part == NULL) … … 521 526 break; 522 527 case lpk_extended: 523 part->ptype = mbr_pt_extended; 524 if (pspec->ptype != 0) { 528 part->ptype.fmt = lptf_num; 529 part->ptype.t.num = mbr_pt_extended; 530 if (pspec->ptype.t.num != 0) { 525 531 rc = EINVAL; 526 532 goto error; … … 705 711 } 706 712 713 static int mbr_suggest_ptype(label_t *label, label_pcnt_t pcnt, 714 label_ptype_t *ptype) 715 { 716 ptype->fmt = lptf_num; 717 ptype->t.num = 0; 718 719 switch (pcnt) { 720 case lpc_exfat: 721 ptype->t.num = mbr_pt_ms_advanced; 722 break; 723 case lpc_ext4: 724 ptype->t.num = mbr_pt_linux; 725 break; 726 case lpc_fat12_16: 727 ptype->t.num = mbr_pt_fat16_lba; 728 break; 729 case lpc_fat32: 730 ptype->t.num = mbr_pt_fat32_lba; 731 break; 732 case lpc_minix: 733 ptype->t.num = mbr_pt_minix; 734 break; 735 } 736 737 if (ptype->t.num == 0) 738 return EINVAL; 739 740 return EOK; 741 } 742 743 707 744 static void mbr_unused_pte(mbr_pte_t *pte) 708 745 { … … 716 753 if ((part->nblocks >> 32) != 0) 717 754 return EINVAL; 718 if ((part->ptype >> 8) != 0)755 if ((part->ptype.t.num >> 8) != 0) 719 756 return EINVAL; 720 757 721 758 log_msg(LOG_DEFAULT, LVL_NOTE, "mbr_part_to_pte: a0=%" PRIu64 722 759 " len=%" PRIu64 " ptype=%d", part->block0, part->nblocks, 723 (int)part->ptype );760 (int)part->ptype.t.num); 724 761 memset(pte, 0, sizeof(mbr_pte_t)); 725 pte->ptype = part->ptype ;762 pte->ptype = part->ptype.t.num; 726 763 pte->first_lba = host2uint32_t_le(part->block0); 727 764 pte->length = host2uint32_t_le(part->nblocks); … … 746 783 return ENOMEM; 747 784 748 part->ptype = pte->ptype; 785 part->ptype.fmt = lptf_num; 786 part->ptype.t.num = pte->ptype; 749 787 part->index = index; 750 788 part->block0 = block0; … … 786 824 nlparts = list_count(&label->log_parts); 787 825 788 part->ptype = pte->ptype; 826 part->ptype.fmt = lptf_num; 827 part->ptype.t.num = pte->ptype; 789 828 part->index = mbr_nprimary + 1 + nlparts; 790 829 part->block0 = block0; … … 816 855 if (pthis != NULL) { 817 856 memset(pthis, 0, sizeof(mbr_pte_t)); 818 pthis->ptype = part->ptype ;857 pthis->ptype = part->ptype.t.num; 819 858 pthis->first_lba = host2uint32_t_le(part->hdr_blocks); 820 859 pthis->length = host2uint32_t_le(part->nblocks);
Note:
See TracChangeset
for help on using the changeset viewer.