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


Ignore:
Timestamp:
2015-08-11T16:03:59Z (9 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0bde8523
Parents:
1b23e33
Message:

Set partition type based on selected filesystem type.

File:
1 edited

Legend:

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

    r1b23e33 rf57ccb5  
    5555static int gpt_part_create(label_t *, label_part_spec_t *, label_part_t **);
    5656static int gpt_part_destroy(label_part_t *);
     57static int gpt_suggest_ptype(label_t *, label_pcnt_t, label_ptype_t *);
    5758
    5859static void gpt_unused_pte(gpt_entry_t *);
     
    8081        .part_get_info = gpt_part_get_info,
    8182        .part_create = gpt_part_create,
    82         .part_destroy = gpt_part_destroy
     83        .part_destroy = gpt_part_destroy,
     84        .suggest_ptype = gpt_suggest_ptype
    8385};
    8486
     
    547549        linfo->dcnt = dc_label;
    548550        linfo->ltype = lt_gpt;
    549         linfo->flags = 0;
     551        linfo->flags = lf_ptype_uuid; /* Partition type is in UUID format */
    550552        if (gpt_can_create_pri(label))
    551553                linfo->flags = linfo->flags | lf_can_create_pri;
     
    607609        /* GPT only has primary partitions */
    608610        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) {
    609617                rc = EINVAL;
    610618                goto error;
     
    663671}
    664672
     673static 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
    665705static void gpt_unused_pte(gpt_entry_t *pte)
    666706{
     
    677717
    678718        memset(pte, 0, sizeof(gpt_entry_t));
    679         pte->part_type[0] = 0x12;
     719        uuid_encode(&part->ptype.t.uuid, pte->part_type);
    680720        uuid_encode(&part->part_uuid, pte->part_id);
    681721        pte->start_lba = host2uint64_t_le(part->block0);
     
    713753        part->block0 = b0;
    714754        part->nblocks = b1 - b0 + 1;
     755        part->ptype.fmt = lptf_uuid;
     756        uuid_decode(pte->part_type, &part->ptype.t.uuid);
    715757        uuid_decode(pte->part_id, &part->part_uuid);
    716758
Note: See TracChangeset for help on using the changeset viewer.