Changeset d8513177 in mainline for uspace/lib/label/src/gpt.c


Ignore:
Timestamp:
2015-11-03T21:31:53Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
eed70f1
Parents:
ff381a7
Message:

Initialize EBR for empty partition chain when creating extended partition. Fix logical partition size. When creating partition in liblabel, check index and block range are within bounds and free.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/label/src/gpt.c

    rff381a7 rd8513177  
    5757static int gpt_suggest_ptype(label_t *, label_pcnt_t, label_ptype_t *);
    5858
     59static int gpt_check_free_idx(label_t *, int);
     60static int gpt_check_free_range(label_t *, uint64_t, uint64_t);
     61
    5962static void gpt_unused_pte(gpt_entry_t *);
    6063static int gpt_part_to_pte(label_part_t *, gpt_entry_t *);
     
    608611        }
    609612
    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) {
    613623                rc = EINVAL;
    614624                goto error;
     
    711721}
    712722
     723/** Verify that the specified index is valid and free. */
     724static 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. */
     742static 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
     747static 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
    713767static void gpt_unused_pte(gpt_entry_t *pte)
    714768{
Note: See TracChangeset for help on using the changeset viewer.