Changeset b7a4d06 in mainline for uspace/lib


Ignore:
Timestamp:
2015-07-18T12:55:12Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c43db5f
Parents:
70815a24
Message:

Most of extended (but not logical) partition support.

Location:
uspace/lib
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/vbd.c

    r70815a24 rb7a4d06  
    264264{
    265265        async_exch_t *exch;
    266         sysarg_t index;
    267         sysarg_t b0_lo, b0_hi;
    268         sysarg_t nb_lo, nb_hi;
    269         int retval;
    270 
    271         exch = async_exchange_begin(vbd->sess);
    272         retval = async_req_1_5(exch, VBD_PART_GET_INFO, part, &index,
    273             &b0_lo, &b0_hi, &nb_lo, &nb_hi);
    274         async_exchange_end(exch);
    275 
    276         if (retval != EOK)
    277                 return EIO;
    278 
    279         pinfo->index = index;
    280         pinfo->block0 = MERGE_LOUP32(b0_lo, b0_hi);
    281         pinfo->nblocks = MERGE_LOUP32(nb_lo, nb_hi);
     266        sysarg_t retval;
     267        ipc_call_t answer;
     268
     269        exch = async_exchange_begin(vbd->sess);
     270        aid_t req = async_send_1(exch, VBD_PART_GET_INFO, part, &answer);
     271        int rc = async_data_read_start(exch, pinfo, sizeof(vbd_part_info_t));
     272        async_exchange_end(exch);
     273
     274        if (rc != EOK) {
     275                async_forget(req);
     276                return EIO;
     277        }
     278
     279        async_wait_for(req, &retval);
     280        if (retval != EOK)
     281                return EIO;
     282
    282283        return EOK;
    283284}
  • uspace/lib/c/generic/vol.c

    r70815a24 rb7a4d06  
    192192{
    193193        async_exch_t *exch;
    194         sysarg_t dcnt, ltype;
     194        sysarg_t dcnt, ltype, flags;
    195195        int retval;
    196196
    197197        exch = async_exchange_begin(vol->sess);
    198         retval = async_req_1_2(exch, VOL_DISK_INFO, sid, &dcnt, &ltype);
     198        retval = async_req_1_3(exch, VOL_DISK_INFO, sid, &dcnt, &ltype,
     199            &flags);
    199200        async_exchange_end(exch);
    200201
     
    204205        vinfo->dcnt = (label_disk_cnt_t)dcnt;
    205206        vinfo->ltype = (label_type_t)ltype;
     207        vinfo->flags = (label_flags_t)flags;
    206208        return EOK;
    207209}
  • uspace/lib/c/include/types/label.h

    r70815a24 rb7a4d06  
    5858#define LT_LIMIT (lt_gpt + 1)
    5959
     60/** Partition kind */
     61typedef enum {
     62        /** Primary partition */
     63        lpk_primary,
     64        /** Extended partition */
     65        lpk_extended,
     66        /** Logical partition */
     67        lpk_logical
     68} label_pkind_t;
     69
     70/** Label flags */
     71typedef enum {
     72        /** Label supports extended (and logical) partitions */
     73        lf_ext_supp = 0x1,
     74        /** Currently it is possible to create a primary partition */
     75        lf_can_create_pri = 0x2,
     76        /** Currently it is possible to create an extended partition */
     77        lf_can_create_ext = 0x4,
     78        /** Currrently it is possible to create a logical partition */
     79        lf_can_create_log = 0x8
     80} label_flags_t;
    6081
    6182#endif
  • uspace/lib/c/include/vbd.h

    r70815a24 rb7a4d06  
    5151        /** Label type */
    5252        label_type_t ltype;
     53        /** Label flags */
     54        label_flags_t flags;
    5355        /** First block that can be allocated */
    5456        aoff64_t ablock0;
     
    6769        /** Number of blocks */
    6870        aoff64_t nblocks;
     71        /** Partition kind */
     72        label_pkind_t pkind;
    6973        /** Partition type */
    7074        uint64_t ptype;
     
    7579        /** Partition index */
    7680        int index;
     81        /** Partition kind */
     82        label_pkind_t pkind;
    7783        /** First block */
    7884        aoff64_t block0;
  • uspace/lib/c/include/vol.h

    r70815a24 rb7a4d06  
    5353        /** Label type, if disk contents is label */
    5454        label_type_t ltype;
     55        /** Label flags */
     56        label_flags_t flags;
    5557} vol_disk_info_t;
    5658
  • uspace/lib/fdisk/include/fdisk.h

    r70815a24 rb7a4d06  
    7272extern int fdisk_ltype_format(label_type_t, char **);
    7373extern int fdisk_fstype_format(fdisk_fstype_t, char **);
     74extern int fdisk_pkind_format(label_pkind_t, char **);
    7475
    7576#endif
  • uspace/lib/fdisk/include/types/fdisk.h

    r70815a24 rb7a4d06  
    119119        /** Label type */
    120120        label_type_t ltype;
     121        /** Label flags */
     122        label_flags_t flags;
    121123} fdisk_label_info_t;
    122124
     
    131133        /** Capacity */
    132134        fdisk_cap_t capacity;
     135        /** Partition kind */
     136        label_pkind_t pkind;
    133137        /** File system type */
    134138        fdisk_fstype_t fstype;
     
    147151        /** Desired capacity */
    148152        fdisk_cap_t capacity;
     153        /** Partition kind */
     154        label_pkind_t pkind;
    149155        /** File system type */
    150156        fdisk_fstype_t fstype;
     
    153159/** Partition info */
    154160typedef struct {
     161        /** Capacity */
    155162        fdisk_cap_t capacity;
     163        /** Partition kind */
     164        label_pkind_t pkind;
    156165        /** File system type */
    157166        fdisk_fstype_t fstype;
  • uspace/lib/fdisk/src/fdisk.c

    r70815a24 rb7a4d06  
    271271        part->block0 = pinfo.block0;
    272272        part->nblocks = pinfo.nblocks;
     273        part->pkind = pinfo.pkind;
    273274
    274275        /* Insert to list by block address */
     
    442443        info->dcnt = vinfo.dcnt;
    443444        info->ltype = vinfo.ltype;
     445        info->flags = vinfo.flags;
    444446        return EOK;
    445447error:
     
    497499        info->capacity = part->capacity;
    498500        info->fstype = part->fstype;
     501        info->pkind = part->pkind;
    499502        return EOK;
    500503}
     
    671674}
    672675
     676int fdisk_pkind_format(label_pkind_t pkind, char **rstr)
     677{
     678        const char *spkind;
     679        char *s;
     680
     681        spkind = NULL;
     682        switch (pkind) {
     683        case lpk_primary:
     684                spkind = "Primary";
     685                break;
     686        case lpk_extended:
     687                spkind = "Extended";
     688                break;
     689        case lpk_logical:
     690                spkind = "Logical";
     691                break;
     692        }
     693
     694        s = str_dup(spkind);
     695        if (s == NULL)
     696                return ENOMEM;
     697
     698        *rstr = s;
     699        return EOK;
     700}
     701
    673702/** Get free partition index. */
    674703static int fdisk_part_get_free_idx(fdisk_dev_t *dev, int *rindex)
     
    765794                return EIO;
    766795
     796        memset(vpspec, 0, sizeof(vbd_part_spec_t));
    767797        vpspec->index = index;
    768798        vpspec->block0 = fblock0;
    769799        vpspec->nblocks = req_blocks;
    770         vpspec->ptype = 42;
     800        vpspec->pkind = pspec->pkind;
     801        if (pspec->pkind != lpk_extended)
     802                vpspec->ptype = 42;
     803
    771804        return EOK;
    772805}
  • uspace/lib/label/include/types/liblabel.h

    r70815a24 rb7a4d06  
    6868        /** Label type */
    6969        label_type_t ltype;
     70        /** Label flags */
     71        label_flags_t flags;
    7072        /** First block that can be allocated */
    7173        aoff64_t ablock0;
     
    7779        /** Partition index */
    7880        int index;
     81        /** Partition kind */
     82        label_pkind_t pkind;
    7983        /** Address of first block */
    8084        aoff64_t block0;
     
    8892        struct label *label;
    8993        /** Link to label_t.parts */
    90         link_t llabel;
     94        link_t lparts;
     95        /** Link to label_t.pri_parts */
     96        link_t lpri;
     97        /** Link to label_t.log_parts */
     98        link_t llog;
    9199        /** Index */
    92100        int index;
     
    109117        /** Number of blocks */
    110118        aoff64_t nblocks;
     119        /** Partition kind */
     120        label_pkind_t pkind;
    111121        /** Partition type */
    112122        uint64_t ptype;
     
    135145        /** Partitions */
    136146        list_t parts; /* of label_part_t */
     147        /** Primary partitions */
     148        list_t pri_parts; /* of label_part_t */
     149        /** Logical partitions */
     150        list_t log_parts; /* of label_part_t */
    137151        /** First block that can be allocated */
    138152        aoff64_t ablock0;
     
    141155        /** Number of primary partition entries */
    142156        int pri_entries;
     157        /** Index of extended partition or -1 if there is none */
     158        int ext_part_idx;
    143159        /** Block size */
    144160        size_t block_size;
  • uspace/lib/label/src/gpt.c

    r70815a24 rb7a4d06  
    150150
    151151        list_initialize(&label->parts);
     152        list_initialize(&label->pri_parts);
     153        list_initialize(&label->log_parts);
    152154
    153155        for (j = 0; j < 2; j++) {
     
    300302        label->pri_entries = num_entries;
    301303        label->block_size = bsize;
     304        label->ext_part_idx = -1;
    302305
    303306        label->lt.gpt.hdr_ba[0] = gpt_hdr_ba;
     
    436439
    437440        list_initialize(&label->parts);
     441        list_initialize(&label->pri_parts);
     442        list_initialize(&label->log_parts);
    438443
    439444        label->ops = &gpt_label_ops;
     
    444449        label->pri_entries = num_entries;
    445450        label->block_size = bsize;
     451        label->ext_part_idx = -1;
    446452
    447453        label->lt.gpt.hdr_ba[0] = hdr_ba[0];
     
    468474        part = gpt_part_first(label);
    469475        while (part != NULL) {
    470                 list_remove(&part->llabel);
     476                list_remove(&part->lparts);
     477                list_remove(&part->lpri);
    471478                free(part);
    472479                part = gpt_part_first(label);
     
    532539}
    533540
     541static bool gpt_can_create_pri(label_t *label)
     542{
     543        return list_count(&label->parts) < (size_t)label->pri_entries;
     544}
     545
    534546static int gpt_get_info(label_t *label, label_info_t *linfo)
    535547{
     
    537549        linfo->dcnt = dc_label;
    538550        linfo->ltype = lt_gpt;
     551        linfo->flags = 0;
     552        if (gpt_can_create_pri(label))
     553                linfo->flags = linfo->flags | lf_can_create_pri;
    539554        linfo->ablock0 = label->ablock0;
    540555        linfo->anblocks = label->anblocks;
     
    550565                return NULL;
    551566
    552         return list_get_instance(link, label_part_t, llabel);
     567        return list_get_instance(link, label_part_t, lparts);
    553568}
    554569
     
    557572        link_t *link;
    558573
    559         link = list_next(&part->llabel, &part->label->parts);
     574        link = list_next(&part->lparts, &part->label->parts);
    560575        if (link == NULL)
    561576                return NULL;
    562577
    563         return list_get_instance(link, label_part_t, llabel);
     578        return list_get_instance(link, label_part_t, lparts);
    564579}
    565580
     
    567582{
    568583        pinfo->index = part->index;
     584        pinfo->pkind = lpk_primary;
    569585        pinfo->block0 = part->block0;
    570586        pinfo->nblocks = part->nblocks;
     
    587603
    588604        if (pspec->index < 1 || pspec->index > label->pri_entries) {
     605                rc = EINVAL;
     606                goto error;
     607        }
     608
     609        /* GPT only has primary partitions */
     610        if (pspec->pkind != lpk_primary) {
    589611                rc = EINVAL;
    590612                goto error;
     
    614636        }
    615637
    616         list_append(&part->llabel, &label->parts);
     638        list_append(&part->lparts, &label->parts);
     639        list_append(&part->lpri, &label->pri_parts);
    617640
    618641        *rpart = part;
     
    636659                return EIO;
    637660
    638         list_remove(&part->llabel);
     661        list_remove(&part->lparts);
     662        list_remove(&part->lpri);
    639663        free(part);
    640664        return EOK;
     
    694718
    695719        part->label = label;
    696         list_append(&part->llabel, &label->parts);
     720        list_append(&part->lparts, &label->parts);
     721        list_append(&part->lpri, &label->pri_parts);
    697722        return EOK;
    698723}
  • uspace/lib/label/src/mbr.c

    r70815a24 rb7a4d06  
    122122
    123123        list_initialize(&label->parts);
     124        list_initialize(&label->pri_parts);
     125        list_initialize(&label->log_parts);
    124126
    125127        /* Verify boot record signature */
     
    130132        }
    131133
     134        label->ext_part_idx = -1;
    132135        for (entry = 0; entry < mbr_nprimary; entry++) {
    133136                eptr = &mbr->pte[entry];
     
    187190
    188191        list_initialize(&label->parts);
     192        list_initialize(&label->pri_parts);
     193        list_initialize(&label->log_parts);
    189194
    190195        mbr->media_id = 0;
     
    210215        label->anblocks = nblocks - mbr_ablock0;
    211216        label->pri_entries = mbr_nprimary;
     217        label->ext_part_idx = -1;
    212218
    213219        *rlabel = label;
     
    225231        part = mbr_part_first(label);
    226232        while (part != NULL) {
    227                 list_remove(&part->llabel);
     233                list_remove(&part->lparts);
     234                if (link_used(&part->lpri))
     235                        list_remove(&part->lpri);
     236                if (link_used(&part->llog))
     237                        list_remove(&part->llog);
    228238                free(part);
    229239
     
    273283        linfo->dcnt = dc_label;
    274284        linfo->ltype = lt_mbr;
     285
     286        /* We support extended partitions */
     287        linfo->flags = lf_ext_supp;
     288
     289        /** Can create primary if there is a free slot */
     290        if (list_count(&label->pri_parts) < mbr_nprimary)
     291                linfo->flags |= lf_can_create_pri;
     292        /* Can create extended if there is a free slot and no extended */
     293        if ((linfo->flags & lf_can_create_pri) != 0 && label->ext_part_idx < 0)
     294                linfo->flags |= lf_can_create_ext;
     295        /* Can create logical if there is an extended partition */
     296        if (label->ext_part_idx >= 0)
     297                linfo->flags |= lf_can_create_log;
     298
    275299        linfo->ablock0 = label->ablock0;
    276300        linfo->anblocks = label->anblocks;
     301
    277302        return EOK;
    278303}
     
    286311                return NULL;
    287312
    288         return list_get_instance(link, label_part_t, llabel);
     313        return list_get_instance(link, label_part_t, lparts);
    289314}
    290315
     
    293318        link_t *link;
    294319
    295         link = list_next(&part->llabel, &part->label->parts);
     320        link = list_next(&part->lparts, &part->label->parts);
    296321        if (link == NULL)
    297322                return NULL;
    298323
    299         return list_get_instance(link, label_part_t, llabel);
    300 }
    301 
     324        return list_get_instance(link, label_part_t, lparts);
     325}
     326
     327#include <io/log.h>
    302328static void mbr_part_get_info(label_part_t *part, label_part_info_t *pinfo)
    303329{
     
    305331        pinfo->block0 = part->block0;
    306332        pinfo->nblocks = part->nblocks;
     333
     334        log_msg(LOG_DEFAULT, LVL_NOTE, "mbr_part_get_info: index=%d ptype=%d",
     335            (int)part->index, (int)part->ptype);
     336        if (link_used(&part->llog))
     337                pinfo->pkind = lpk_logical;
     338        else if (part->ptype == mbr_pt_extended)
     339                pinfo->pkind = lpk_extended;
     340        else
     341                pinfo->pkind = lpk_primary;
    307342}
    308343
     
    318353                return ENOMEM;
    319354
    320         /* XXX Verify index, block0, nblocks */
    321 
    322         if (pspec->index < 1 || pspec->index > label->pri_entries) {
    323                 rc = EINVAL;
    324                 goto error;
    325         }
    326355
    327356        /* XXX Check if index is used */
     
    331360        part->block0 = pspec->block0;
    332361        part->nblocks = pspec->nblocks;
    333         part->ptype = pspec->ptype;
    334 
    335         rc = mbr_part_to_pte(part, &pte);
    336         if (rc != EOK) {
    337                 rc = EINVAL;
    338                 goto error;
    339         }
    340 
    341         rc = mbr_pte_update(label, &pte, pspec->index - 1);
    342         if (rc != EOK) {
    343                 rc = EIO;
    344                 goto error;
    345         }
    346 
    347         list_append(&part->llabel, &label->parts);
     362
     363        switch (pspec->pkind) {
     364        case lpk_primary:
     365                part->ptype = pspec->ptype;
     366                break;
     367        case lpk_extended:
     368                part->ptype = mbr_pt_extended;
     369                if (pspec->ptype != 0) {
     370                        rc = EINVAL;
     371                        goto error;
     372                }
     373                if (label->ext_part_idx >= 0) {
     374                        rc = EEXISTS;
     375                        goto error;
     376                }
     377                break;
     378        case lpk_logical:
     379                part->ptype = pspec->ptype;
     380                if (pspec->index != 0) {
     381                        rc = EINVAL;
     382                        goto error;
     383                }
     384                break;
     385        }
     386
     387        if (pspec->pkind != lpk_logical) {
     388                /* Primary or extended partition */
     389                /* XXX Verify index, block0, nblocks */
     390
     391                if (pspec->index < 1 || pspec->index > label->pri_entries) {
     392                        rc = EINVAL;
     393                        goto error;
     394                }
     395
     396                rc = mbr_part_to_pte(part, &pte);
     397                if (rc != EOK) {
     398                        rc = EINVAL;
     399                        goto error;
     400                }
     401
     402                rc = mbr_pte_update(label, &pte, pspec->index - 1);
     403                if (rc != EOK) {
     404                        rc = EIO;
     405                        goto error;
     406                }
     407
     408                list_append(&part->lparts, &label->parts);
     409                list_append(&part->lpri, &label->pri_parts);
     410
     411                if (pspec->pkind == lpk_extended)
     412                        label->ext_part_idx = pspec->index - 1;
     413        } else {
     414                /* Logical partition */
     415                rc = ENOTSUP;
     416                goto error;
     417        }
    348418
    349419        *rpart = part;
     
    367437                return EIO;
    368438
    369         list_remove(&part->llabel);
     439        /* If it was the extended partition, clear ext. part. index */
     440        if (part->index - 1 == part->label->ext_part_idx)
     441                part->label->ext_part_idx = -1;
     442
     443        list_remove(&part->lparts);
     444        if (link_used(&part->lpri))
     445                list_remove(&part->lpri);
     446        if (link_used(&part->llog))
     447                list_remove(&part->llog);
    370448        free(part);
    371449        return EOK;
     
    386464                return EINVAL;
    387465
     466        log_msg(LOG_DEFAULT, LVL_NOTE, "mbr_part_to_pte: a0=%" PRIu64
     467            " len=%" PRIu64 " ptype=%d", part->block0, part->nblocks,
     468            (int)part->ptype);
    388469        memset(pte, 0, sizeof(mbr_pte_t));
    389470        pte->ptype = part->ptype;
     
    403484
    404485        /* See UEFI specification 2.0 section 5.2.1 Legacy Master Boot Record */
    405         if (pte->ptype == mbr_pt_unused || pte->ptype == mbr_pt_extended ||
    406             nblocks == 0)
     486        if (pte->ptype == mbr_pt_unused || nblocks == 0)
    407487                return EOK;
    408488
     
    411491                return ENOMEM;
    412492
     493        part->ptype = pte->ptype;
    413494        part->index = index;
    414495        part->block0 = block0;
     
    422503
    423504        part->label = label;
    424         list_append(&part->llabel, &label->parts);
     505        list_append(&part->lparts, &label->parts);
     506        list_append(&part->lpri, &label->pri_parts);
     507
     508        if (pte->ptype == mbr_pt_extended)
     509                label->ext_part_idx = index - 1;
    425510        return EOK;
    426511}
Note: See TracChangeset for help on using the changeset viewer.