Changeset f57ccb5 in mainline for uspace/lib/label/src/mbr.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/mbr.c

    r1b23e33 rf57ccb5  
    5454static int mbr_part_create(label_t *, label_part_spec_t *, label_part_t **);
    5555static int mbr_part_destroy(label_part_t *);
     56static int mbr_suggest_ptype(label_t *, label_pcnt_t, label_ptype_t *);
    5657
    5758static void mbr_unused_pte(mbr_pte_t *);
     
    7778        .part_get_info = mbr_part_get_info,
    7879        .part_create = mbr_part_create,
    79         .part_destroy = mbr_part_destroy
     80        .part_destroy = mbr_part_destroy,
     81        .suggest_ptype = mbr_suggest_ptype
    8082};
    8183
     
    485487
    486488        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);
    488490        if (link_used(&part->llog))
    489491                pinfo->pkind = lpk_logical;
    490         else if (part->ptype == mbr_pt_extended)
     492        else if (part->ptype.t.num == mbr_pt_extended)
    491493                pinfo->pkind = lpk_extended;
    492494        else
     
    503505        int rc;
    504506
     507        if (pspec->ptype.fmt != lptf_num)
     508                return EINVAL;
     509
    505510        part = calloc(1, sizeof(label_part_t));
    506511        if (part == NULL)
     
    521526                break;
    522527        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) {
    525531                        rc = EINVAL;
    526532                        goto error;
     
    705711}
    706712
     713static 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
    707744static void mbr_unused_pte(mbr_pte_t *pte)
    708745{
     
    716753        if ((part->nblocks >> 32) != 0)
    717754                return EINVAL;
    718         if ((part->ptype >> 8) != 0)
     755        if ((part->ptype.t.num >> 8) != 0)
    719756                return EINVAL;
    720757
    721758        log_msg(LOG_DEFAULT, LVL_NOTE, "mbr_part_to_pte: a0=%" PRIu64
    722759            " len=%" PRIu64 " ptype=%d", part->block0, part->nblocks,
    723             (int)part->ptype);
     760            (int)part->ptype.t.num);
    724761        memset(pte, 0, sizeof(mbr_pte_t));
    725         pte->ptype = part->ptype;
     762        pte->ptype = part->ptype.t.num;
    726763        pte->first_lba = host2uint32_t_le(part->block0);
    727764        pte->length = host2uint32_t_le(part->nblocks);
     
    746783                return ENOMEM;
    747784
    748         part->ptype = pte->ptype;
     785        part->ptype.fmt = lptf_num;
     786        part->ptype.t.num = pte->ptype;
    749787        part->index = index;
    750788        part->block0 = block0;
     
    786824        nlparts = list_count(&label->log_parts);
    787825
    788         part->ptype = pte->ptype;
     826        part->ptype.fmt = lptf_num;
     827        part->ptype.t.num = pte->ptype;
    789828        part->index = mbr_nprimary + 1 + nlparts;
    790829        part->block0 = block0;
     
    816855        if (pthis != NULL) {
    817856                memset(pthis, 0, sizeof(mbr_pte_t));
    818                 pthis->ptype = part->ptype;
     857                pthis->ptype = part->ptype.t.num;
    819858                pthis->first_lba = host2uint32_t_le(part->hdr_blocks);
    820859                pthis->length = host2uint32_t_le(part->nblocks);
Note: See TracChangeset for help on using the changeset viewer.