Changeset 9bdfde73 in mainline


Ignore:
Timestamp:
2013-07-22T16:37:30Z (11 years ago)
Author:
Dominik Taborsky (AT DOT) <brembyseznamcz>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1a1a735, 8559fa0, 9256d093
Parents:
52f2c89
Message:

libgpt improvements

Location:
uspace/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/gpt/libgpt.c

    r52f2c89 r9bdfde73  
    5757static long long nearest_larger_int(double a);
    5858static uint8_t get_byte(const char *);
     59static int check_overlap(gpt_part_t * p1, gpt_part_t * p2);
    5960
    6061/** Allocate memory for gpt label */
     
    290291
    291292/** Write GPT and partitions to device
     293 * Note: also writes the header.
    292294 * @param label        label to write
    293295 * @param dev_handle   device to write the data to
     
    424426 * Note: for use with gpt_alloc_partition() only. You will get
    425427 * duplicates with gpt_get_partition().
     428 * Note: does not call gpt_free_partition()!
    426429 */
    427430int gpt_add_partition(gpt_label_t *label, gpt_part_t *partition)
     
    432435        }
    433436       
     437        /*FIXME:
     438         * Check dimensions and stuff! */
     439        gpt_part_foreach(label, p) {
     440                if (gpt_get_part_type(p) != GPT_PTE_UNUSED) {
     441                        if (check_overlap(partition, p))
     442                                return EINVAL;
     443                }
     444        }
     445       
    434446        memcpy(label->parts->part_array + label->parts->fill++,
    435447               partition, sizeof(gpt_part_t));
     448       
     449       
    436450       
    437451        return EOK;
     
    460474        label->parts->fill -= 1;
    461475       
    462         /* FIXME!
     476        /* FIXME! HOPEFULLY FIXED.
    463477         * We cannot reduce the array so simply. We may have some partitions
    464          * there since we allow blank spots.*/
     478         * there since we allow blank spots. */
     479        gpt_part_t * p;
    465480        if (label->parts->fill < (label->parts->arr_size / 2) - GPT_IGNORE_FILL_NUM) {
     481                for (p = gpt_get_partition_at(label, label->parts->arr_size / 2);
     482                     p < label->parts->part_array + label->parts->arr_size; ++p) {
     483                                if (gpt_get_part_type(p) != GPT_PTE_UNUSED)
     484                                        return EOK;
     485                }
     486               
    466487                if (reduce_part_array(label->parts) == ENOMEM)
    467488                        return ENOMEM;
     
    712733}
    713734
    714 
    715 
    716 
     735static int check_overlap(gpt_part_t * p1, gpt_part_t * p2)
     736{
     737        if (gpt_get_start_lba(p1) < gpt_get_start_lba(p2) && gpt_get_end_lba(p1) <= gpt_get_start_lba(p2)) {
     738                return 0;
     739        } else if (gpt_get_start_lba(p1) > gpt_get_start_lba(p2) && gpt_get_end_lba(p2) <= gpt_get_start_lba(p1)) {
     740                return 0;
     741        }
     742
     743        return 1;
     744}
     745
     746
  • uspace/lib/mbr/libmbr.h

    r52f2c89 r9bdfde73  
    204204/* Read/Write/Set MBR partitions.
    205205 * NOTE: Writing partitions writes the complete header as well. */
    206 extern int mbr_read_partitions(mbr_label_t *);
     206extern int          mbr_read_partitions(mbr_label_t *);
    207207extern int          mbr_write_partitions(mbr_label_t *, service_id_t);
    208208extern mbr_part_t * mbr_alloc_partition(void);
Note: See TracChangeset for help on using the changeset viewer.