Changeset d8513177 in mainline for uspace/lib/label/src/gpt.c
- Timestamp:
- 2015-11-03T21:31:53Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- eed70f1
- Parents:
- ff381a7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/label/src/gpt.c
rff381a7 rd8513177 57 57 static int gpt_suggest_ptype(label_t *, label_pcnt_t, label_ptype_t *); 58 58 59 static int gpt_check_free_idx(label_t *, int); 60 static int gpt_check_free_range(label_t *, uint64_t, uint64_t); 61 59 62 static void gpt_unused_pte(gpt_entry_t *); 60 63 static int gpt_part_to_pte(label_part_t *, gpt_entry_t *); … … 608 611 } 609 612 610 /* XXX Verify index, block0, nblocks */ 611 612 if (pspec->index < 1 || pspec->index > label->pri_entries) { 613 /* Verify index is within bounds and free */ 614 rc = gpt_check_free_idx(label, pspec->index); 615 if (rc != EOK) { 616 rc = EINVAL; 617 goto error; 618 } 619 620 /* Verify range is within bounds and free */ 621 rc = gpt_check_free_range(label, pspec->block0, pspec->nblocks); 622 if (rc != EOK) { 613 623 rc = EINVAL; 614 624 goto error; … … 711 721 } 712 722 723 /** Verify that the specified index is valid and free. */ 724 static int gpt_check_free_idx(label_t *label, int index) 725 { 726 label_part_t *part; 727 728 if (index < 1 || index > label->pri_entries) 729 return EINVAL; 730 731 part = gpt_part_first(label); 732 while (part != NULL) { 733 if (part->index == index) 734 return EEXIST; 735 part = gpt_part_next(part); 736 } 737 738 return EOK; 739 } 740 741 /** Determine if two block address ranges overlap. */ 742 static bool gpt_overlap(uint64_t a0, uint64_t an, uint64_t b0, uint64_t bn) 743 { 744 return !(a0 + an <= b0 || b0 + bn <= a0); 745 } 746 747 static int gpt_check_free_range(label_t *label, uint64_t block0, 748 uint64_t nblocks) 749 { 750 label_part_t *part; 751 752 if (block0 < label->ablock0) 753 return EINVAL; 754 if (block0 + nblocks > label->ablock0 + label->anblocks) 755 return EINVAL; 756 757 part = gpt_part_first(label); 758 while (part != NULL) { 759 if (gpt_overlap(block0, nblocks, part->block0, part->nblocks)) 760 return EEXIST; 761 part = gpt_part_next(part); 762 } 763 764 return EOK; 765 } 766 713 767 static void gpt_unused_pte(gpt_entry_t *pte) 714 768 {
Note:
See TracChangeset
for help on using the changeset viewer.