Changeset deacc58d in mainline


Ignore:
Timestamp:
2017-06-20T17:34:02Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
80da8f70
Parents:
63e27ef
Message:

Break liblabel dependency on libblock.

Location:
uspace
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/label/Makefile

    r63e27ef rdeacc58d  
    2828
    2929USPACE_PREFIX = ../..
    30 EXTRA_CFLAGS = -Iinclude -I$(LIBBLOCK_PREFIX)
     30EXTRA_CFLAGS = -Iinclude
    3131
    3232LIBRARY = liblabel
  • uspace/lib/label/include/label.h

    r63e27ef rdeacc58d  
    3737#define LIBLABEL_LABEL_H_
    3838
    39 #include <loc.h>
    4039#include <types/label.h>
    4140#include <types/liblabel.h>
    4241
    43 extern int label_open(service_id_t, label_t **);
    44 extern int label_create(service_id_t, label_type_t, label_t **);
     42extern int label_open(label_bd_t *, label_t **);
     43extern int label_create(label_bd_t *, label_type_t, label_t **);
    4544extern void label_close(label_t *);
    4645extern int label_destroy(label_t *);
  • uspace/lib/label/include/types/liblabel.h

    r63e27ef rdeacc58d  
    4040#include <types/label.h>
    4141#include <offset.h>
     42#include <stddef.h>
    4243#include <vol.h>
    4344#include <uuid.h>
     
    4849typedef struct label_part_info label_part_info_t;
    4950typedef struct label_part_spec label_part_spec_t;
     51typedef struct label_bd label_bd_t;
     52typedef struct label_bd_ops label_bd_ops_t;
    5053
    5154/** Ops for individual label type */
    5255typedef struct {
    53         int (*open)(service_id_t, label_t **);
    54         int (*create)(service_id_t, label_t **);
     56        int (*open)(label_bd_t *, label_t **);
     57        int (*create)(label_bd_t *, label_t **);
    5558        void (*close)(label_t *);
    5659        int (*destroy)(label_t *);
     
    138141} label_mbr_t;
    139142
     143/** Block device operations */
     144struct label_bd_ops {
     145        /** Get block size */
     146        int (*get_bsize)(void *, size_t *);
     147        /** Get number of blocks */
     148        int (*get_nblocks)(void *, aoff64_t *);
     149        /** Read blocks */
     150        int (*read)(void *, aoff64_t, size_t, void *);
     151        /** Write blocks */
     152        int (*write)(void *, aoff64_t, size_t, const void *);
     153};
     154
     155/** Block device */
     156struct label_bd {
     157        /** Ops structure */
     158        label_bd_ops_t *ops;
     159        /** Argument */
     160        void *arg;
     161};
     162
    140163/** Label instance */
    141164struct label {
     
    144167        /** Label type */
    145168        label_type_t ltype;
    146         /** Block device service ID */
    147         service_id_t svc_id;
     169        /** Block device */
     170        label_bd_t bd;
    148171        /** Partitions */
    149172        list_t parts; /* of label_part_t */
  • uspace/lib/label/src/dummy.c

    r63e27ef rdeacc58d  
    3434 */
    3535
    36 #include <block.h>
    3736#include <errno.h>
    3837#include <mem.h>
     
    4140#include "dummy.h"
    4241
    43 static int dummy_open(service_id_t, label_t **);
    44 static int dummy_create(service_id_t, label_t **);
     42static int dummy_open(label_bd_t *, label_t **);
     43static int dummy_create(label_bd_t *, label_t **);
    4544static void dummy_close(label_t *);
    4645static int dummy_destroy(label_t *);
     
    6766};
    6867
    69 static int dummy_open(service_id_t sid, label_t **rlabel)
     68static int dummy_open(label_bd_t *bd, label_t **rlabel)
    7069{
    7170        label_t *label = NULL;
     
    7675        int rc;
    7776
    78         rc = block_get_bsize(sid, &bsize);
     77        rc = bd->ops->get_bsize(bd->arg, &bsize);
    7978        if (rc != EOK) {
    8079                rc = EIO;
     
    8281        }
    8382
    84         rc = block_get_nblocks(sid, &nblocks);
     83        rc = bd->ops->get_nblocks(bd->arg, &nblocks);
    8584        if (rc != EOK) {
    8685                rc = EIO;
     
    101100        label->ops = &dummy_label_ops;
    102101        label->ltype = lt_none;
    103         label->svc_id = sid;
     102        label->bd = *bd;
    104103        label->ablock0 = ba_min;
    105104        label->anblocks = ba_max - ba_min + 1;
     
    129128}
    130129
    131 static int dummy_create(service_id_t sid, label_t **rlabel)
     130static int dummy_create(label_bd_t *bd, label_t **rlabel)
    132131{
    133132        return ENOTSUP;
  • uspace/lib/label/src/gpt.c

    r63e27ef rdeacc58d  
    3535
    3636#include <adt/checksum.h>
    37 #include <block.h>
    3837#include <byteorder.h>
    3938#include <errno.h>
     
    4746#include "gpt.h"
    4847
    49 static int gpt_open(service_id_t, label_t **);
    50 static int gpt_create(service_id_t, label_t **);
     48static int gpt_open(label_bd_t *, label_t **);
     49static int gpt_create(label_bd_t *, label_t **);
    5150static void gpt_close(label_t *);
    5251static int gpt_destroy(label_t *);
     
    7170static int gpt_hdr_get_crc(gpt_header_t *, size_t, uint32_t *);
    7271
    73 static int gpt_pmbr_create(service_id_t, size_t, uint64_t);
    74 static int gpt_pmbr_destroy(service_id_t, size_t);
     72static int gpt_pmbr_create(label_bd_t *, size_t, uint64_t);
     73static int gpt_pmbr_destroy(label_bd_t *, size_t);
    7574
    7675const uint8_t efi_signature[8] = {
     
    9392};
    9493
    95 static int gpt_open(service_id_t sid, label_t **rlabel)
     94static int gpt_open(label_bd_t *bd, label_t **rlabel)
    9695{
    9796        label_t *label = NULL;
     
    118117        etable[1] = NULL;
    119118
    120         rc = block_get_bsize(sid, &bsize);
     119        rc = bd->ops->get_bsize(bd->arg, &bsize);
    121120        if (rc != EOK) {
    122121                rc = EIO;
     
    141140        }
    142141
    143         rc = block_read_direct(sid, gpt_hdr_ba, 1, gpt_hdr[0]);
     142        rc = bd->ops->read(bd->arg, gpt_hdr_ba, 1, gpt_hdr[0]);
    144143        if (rc != EOK) {
    145144                rc = EIO;
     
    149148        h1ba = uint64_t_le2host(gpt_hdr[0]->alternate_lba);
    150149
    151         rc = block_read_direct(sid, h1ba, 1, gpt_hdr[1]);
     150        rc = bd->ops->read(bd->arg, h1ba, 1, gpt_hdr[1]);
    152151        if (rc != EOK) {
    153152                rc = EIO;
     
    277276                }
    278277
    279                 rc = block_read_direct(sid, ptba[j], pt_blocks / 2, etable[j]);
     278                rc = bd->ops->read(bd->arg, ptba[j], pt_blocks / 2, etable[j]);
    280279                if (rc != EOK) {
    281280                        rc = EIO;
     
    308307        label->ops = &gpt_label_ops;
    309308        label->ltype = lt_gpt;
    310         label->svc_id = sid;
     309        label->bd = *bd;
    311310        label->ablock0 = ba_min;
    312311        label->anblocks = ba_max - ba_min + 1;
     
    334333}
    335334
    336 static int gpt_create(service_id_t sid, label_t **rlabel)
     335static int gpt_create(label_bd_t *bd, label_t **rlabel)
    337336{
    338337        label_t *label = NULL;
     
    353352        int rc;
    354353
    355         rc = block_get_bsize(sid, &bsize);
     354        rc = bd->ops->get_bsize(bd->arg, &bsize);
    356355        if (rc != EOK) {
    357356                rc = EIO;
     
    364363        }
    365364
    366         rc = block_get_nblocks(sid, &nblocks);
     365        rc = bd->ops->get_nblocks(bd->arg, &nblocks);
    367366        if (rc != EOK) {
    368367                rc = EIO;
     
    380379        }
    381380
    382         rc = gpt_pmbr_create(sid, bsize, nblocks);
     381        rc = gpt_pmbr_create(bd, bsize, nblocks);
    383382        if (rc != EOK) {
    384383                rc = EIO;
     
    405404                }
    406405
    407                 rc = block_write_direct(sid, ptba[i], pt_blocks, etable);
     406                rc = bd->ops->write(bd->arg, ptba[i], pt_blocks, etable);
    408407                if (rc != EOK) {
    409408                        rc = EIO;
     
    440439                gpt_hdr_compute_crc(gpt_hdr, sizeof(gpt_header_t));
    441440
    442                 rc = block_write_direct(sid, hdr_ba[i], 1, gpt_hdr);
     441                rc = bd->ops->write(bd->arg, hdr_ba[i], 1, gpt_hdr);
    443442                if (rc != EOK) {
    444443                        rc = EIO;
     
    460459        label->ops = &gpt_label_ops;
    461460        label->ltype = lt_gpt;
    462         label->svc_id = sid;
     461        label->bd = *bd;
    463462        label->ablock0 = ba_min;
    464463        label->anblocks = ba_max - ba_min + 1;
     
    520519                }
    521520
    522                 rc = block_write_direct(label->svc_id, label->lt.gpt.hdr_ba[i],
     521                rc = label->bd.ops->write(label->bd.arg, label->lt.gpt.hdr_ba[i],
    523522                    1, gpt_hdr);
    524523                if (rc != EOK) {
     
    537536                }
    538537
    539                 rc = block_write_direct(label->svc_id,
     538                rc = label->bd.ops->write(label->bd.arg,
    540539                    label->lt.gpt.ptable_ba[i], label->lt.gpt.pt_blocks,
    541540                    etable);
     
    549548        }
    550549
    551         rc = gpt_pmbr_destroy(label->svc_id, label->block_size);
     550        rc = gpt_pmbr_destroy(&label->bd, label->block_size);
    552551        if (rc != EOK)
    553552                goto error;
     
    871870                nblocks = label->lt.gpt.pt_blocks;
    872871
    873                 rc = block_read_direct(label->svc_id, ba, nblocks, buf);
     872                rc = label->bd.ops->read(label->bd.arg, ba, nblocks, buf);
    874873                if (rc != EOK) {
    875874                        rc = EIO;
     
    888887                *e = *pte;
    889888
    890                 rc = block_write_direct(label->svc_id, ba, nblocks, buf);
     889                rc = label->bd.ops->write(label->bd.arg, ba, nblocks, buf);
    891890                if (rc != EOK) {
    892891                        rc = EIO;
     
    923922
    924923        for (i = 0; i < 2; i++) {
    925                 rc = block_read_direct(label->svc_id,
     924                rc = label->bd.ops->read(label->bd.arg,
    926925                    label->lt.gpt.hdr_ba[i], 1, gpt_hdr);
    927926                if (rc != EOK) {
     
    933932                gpt_hdr_compute_crc(gpt_hdr, label->lt.gpt.hdr_size);
    934933
    935                 rc = block_write_direct(label->svc_id,
     934                rc = label->bd.ops->write(label->bd.arg,
    936935                    label->lt.gpt.hdr_ba[i], 1, gpt_hdr);
    937936                if (rc != EOK) {
     
    940939                }
    941940        }
    942        
     941
    943942        rc = EOK;
    944        
     943
    945944exit:
    946945        free(gpt_hdr);
     
    974973
    975974/** Create GPT Protective MBR */
    976 static int gpt_pmbr_create(service_id_t sid, size_t bsize, uint64_t nblocks)
     975static int gpt_pmbr_create(label_bd_t *bd, size_t bsize, uint64_t nblocks)
    977976{
    978977        mbr_br_block_t *pmbr = NULL;
     
    998997        pmbr->signature = host2uint16_t_le(mbr_br_signature);
    999998
    1000         rc = block_write_direct(sid, mbr_ba, 1, pmbr);
     999        rc = bd->ops->write(bd->arg, mbr_ba, 1, pmbr);
    10011000        if (rc != EOK) {
    10021001                rc = EIO;
     
    10121011
    10131012/** Destroy GPT Protective MBR */
    1014 static int gpt_pmbr_destroy(service_id_t sid, size_t bsize)
     1013static int gpt_pmbr_destroy(label_bd_t *bd, size_t bsize)
    10151014{
    10161015        mbr_br_block_t *pmbr = NULL;
     
    10231022        }
    10241023
    1025         rc = block_write_direct(sid, mbr_ba, 1, pmbr);
     1024        rc = bd->ops->write(bd->arg, mbr_ba, 1, pmbr);
    10261025        if (rc != EOK) {
    10271026                rc = EIO;
  • uspace/lib/label/src/label.c

    r63e27ef rdeacc58d  
    5151};
    5252
    53 int label_open(service_id_t sid, label_t **rlabel)
     53int label_open(label_bd_t *bd, label_t **rlabel)
    5454{
    5555        label_ops_t **ops;
     
    5858        ops = &probe_list[0];
    5959        while (ops[0] != NULL) {
    60                 rc = ops[0]->open(sid, rlabel);
     60                rc = ops[0]->open(bd, rlabel);
    6161                if (rc == EOK)
    6262                        return EOK;
     
    6767}
    6868
    69 int label_create(service_id_t sid, label_type_t ltype, label_t **rlabel)
     69int label_create(label_bd_t *bd, label_type_t ltype, label_t **rlabel)
    7070{
    7171        label_ops_t *ops = NULL;
     
    8585                return ENOTSUP;
    8686
    87         return ops->create(sid, rlabel);
     87        return ops->create(bd, rlabel);
    8888}
    8989
  • uspace/lib/label/src/mbr.c

    r63e27ef rdeacc58d  
    3434 */
    3535
    36 #include <block.h>
    3736#include <byteorder.h>
    3837#include <errno.h>
     
    4342#include "mbr.h"
    4443
    45 static int mbr_open(service_id_t, label_t **);
     44static int mbr_open(label_bd_t *, label_t **);
    4645static int mbr_open_ext(label_t *);
    47 static int mbr_create(service_id_t, label_t **);
     46static int mbr_create(label_bd_t *, label_t **);
    4847static void mbr_close(label_t *);
    4948static int mbr_destroy(label_t *);
     
    8685};
    8786
    88 static int mbr_open(service_id_t sid, label_t **rlabel)
     87static int mbr_open(label_bd_t *bd, label_t **rlabel)
    8988{
    9089        label_t *label = NULL;
     
    9796        int rc;
    9897
    99         rc = block_get_bsize(sid, &bsize);
    100         if (rc != EOK) {
    101                 rc = EIO;
    102                 goto error;
    103         }
    104 
    105         rc = block_get_nblocks(sid, &nblocks);
     98        rc = bd->ops->get_bsize(bd->arg, &bsize);
     99        if (rc != EOK) {
     100                rc = EIO;
     101                goto error;
     102        }
     103
     104        rc = bd->ops->get_nblocks(bd->arg, &nblocks);
    106105        if (rc != EOK) {
    107106                rc = EIO;
     
    125124        }
    126125
    127         rc = block_read_direct(sid, mbr_ba, 1, mbr);
     126        rc = bd->ops->read(bd->arg, mbr_ba, 1, mbr);
    128127        if (rc != EOK) {
    129128                rc = EIO;
     
    160159        label->ops = &mbr_label_ops;
    161160        label->ltype = lt_mbr;
    162         label->svc_id = sid;
     161        label->bd = *bd;
    163162        label->block_size = bsize;
    164163        label->ablock0 = mbr_ablock0;
     
    219218        while (true) {
    220219                /* Read EBR */
    221                 rc = block_read_direct(label->svc_id, ebr_b0, 1, ebr);
     220                rc = label->bd.ops->read(label->bd.arg, ebr_b0, 1, ebr);
    222221                if (rc != EOK) {
    223222                        rc = EIO;
     
    280279}
    281280
    282 static int mbr_create(service_id_t sid, label_t **rlabel)
     281static int mbr_create(label_bd_t *bd, label_t **rlabel)
    283282{
    284283        label_t *label = NULL;
     
    289288        int rc;
    290289
    291         rc = block_get_bsize(sid, &bsize);
    292         if (rc != EOK) {
    293                 rc = EIO;
    294                 goto error;
    295         }
    296 
    297         rc = block_get_nblocks(sid, &nblocks);
     290        rc = bd->ops->get_bsize(bd->arg, &bsize);
     291        if (rc != EOK) {
     292                rc = EIO;
     293                goto error;
     294        }
     295
     296        rc = bd->ops->get_nblocks(bd->arg, &nblocks);
    298297        if (rc != EOK) {
    299298                rc = EIO;
     
    321320        mbr->signature = host2uint16_t_le(mbr_br_signature);
    322321
    323         rc = block_write_direct(sid, mbr_ba, 1, mbr);
     322        rc = bd->ops->write(bd->arg, mbr_ba, 1, mbr);
    324323        if (rc != EOK) {
    325324                rc = EIO;
     
    333332        label->ltype = lt_mbr;
    334333        label->block_size = bsize;
    335         label->svc_id = sid;
     334        label->bd = *bd;
    336335        label->ablock0 = mbr_ablock0;
    337336        label->anblocks = nblocks - mbr_ablock0;
     
    387386        }
    388387
    389         rc = block_write_direct(label->svc_id, mbr_ba, 1, mbr);
     388        rc = label->bd.ops->write(label->bd.arg, mbr_ba, 1, mbr);
    390389        if (rc != EOK) {
    391390                rc = EIO;
     
    998997                return ENOMEM;
    999998
    1000         rc = block_read_direct(label->svc_id, mbr_ba, 1, br);
     999        rc = label->bd.ops->read(label->bd.arg, mbr_ba, 1, br);
    10011000        if (rc != EOK) {
    10021001                rc = EIO;
     
    10061005        br->pte[index] = *pte;
    10071006
    1008         rc = block_write_direct(label->svc_id, mbr_ba, 1, br);
     1007        rc = label->bd.ops->write(label->bd.arg, mbr_ba, 1, br);
    10091008        if (rc != EOK) {
    10101009                rc = EIO;
     
    10661065        br->signature = host2uint16_t_le(mbr_br_signature);
    10671066
    1068         rc = block_write_direct(label->svc_id, ba, 1, br);
     1067        rc = label->bd.ops->write(label->bd.arg, ba, 1, br);
    10691068        if (rc != EOK) {
    10701069                rc = EIO;
     
    10911090        ba = part->block0 - part->hdr_blocks;
    10921091
    1093         rc = block_write_direct(label->svc_id, ba, 1, br);
     1092        rc = label->bd.ops->write(label->bd.arg, ba, 1, br);
    10941093        if (rc != EOK) {
    10951094                rc = EIO;
     
    11181117                return ENOMEM;
    11191118
    1120         rc = block_read_direct(label->svc_id, ba, 1, br);
     1119        rc = label->bd.ops->read(label->bd.arg, ba, 1, br);
    11211120        if (rc != EOK) {
    11221121                rc = EIO;
     
    11331132        mbr_log_part_to_ptes(part, NULL, &br->pte[mbr_ebr_pte_next]);
    11341133
    1135         rc = block_write_direct(label->svc_id, ba, 1, br);
     1134        rc = label->bd.ops->write(label->bd.arg, ba, 1, br);
    11361135        if (rc != EOK) {
    11371136                rc = EIO;
  • uspace/srv/bd/vbd/disk.c

    r63e27ef rdeacc58d  
    7575static vbd_part_id_t vbds_part_id = 1;
    7676
     77static int vbds_label_get_bsize(void *, size_t *);
     78static int vbds_label_get_nblocks(void *, aoff64_t *);
     79static int vbds_label_read(void *, aoff64_t, size_t, void *);
     80static int vbds_label_write(void *, aoff64_t, size_t, const void *);
     81
     82/** Block device operations provided by VBD */
    7783static bd_ops_t vbds_bd_ops = {
    7884        .open = vbds_bd_open,
     
    8389        .get_block_size = vbds_bd_get_block_size,
    8490        .get_num_blocks = vbds_bd_get_num_blocks
     91};
     92
     93/** Provide disk access to liblabel */
     94static label_bd_ops_t vbds_label_bd_ops = {
     95        .get_bsize = vbds_label_get_bsize,
     96        .get_nblocks = vbds_label_get_nblocks,
     97        .read = vbds_label_read,
     98        .write = vbds_label_write
    8599};
    86100
     
    450464{
    451465        label_t *label = NULL;
     466        label_bd_t lbd;
    452467        vbds_disk_t *disk = NULL;
    453468        bool block_inited = false;
     
    467482                return ENOMEM;
    468483
     484        /* Must be set before calling label_open */
     485        disk->svc_id = sid;
     486
    469487        rc = loc_service_get_name(sid, &disk->svc_name);
    470488        if (rc != EOK) {
     
    501519        block_inited = true;
    502520
    503         rc = label_open(sid, &label);
     521        lbd.ops = &vbds_label_bd_ops;
     522        lbd.arg = (void *) disk;
     523
     524        rc = label_open(&lbd, &label);
    504525        if (rc != EOK) {
    505526                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed to open label in disk %s.",
     
    509530        }
    510531
    511         disk->svc_id = sid;
    512532        disk->label = label;
    513533        disk->block_size = block_size;
     
    648668{
    649669        label_t *label;
     670        label_bd_t lbd;
    650671        label_info_t linfo;
    651672        vbds_disk_t *disk;
     
    683704        log_msg(LOG_DEFAULT, LVL_DEBUG, "vbds_label_create(%zu) - label_create", sid);
    684705
    685         rc = label_create(sid, ltype, &label);
     706        lbd.ops = &vbds_label_bd_ops;
     707        lbd.arg = (void *) disk;
     708
     709        rc = label_create(&lbd, ltype, &label);
    686710        if (rc != EOK)
    687711                goto error;
     
    695719        log_msg(LOG_DEFAULT, LVL_DEBUG, "vbds_label_create(%zu) - failure", sid);
    696720        if (disk->label == NULL) {
    697                 rc2 = label_open(sid, &label);
     721                lbd.ops = &vbds_label_bd_ops;
     722                lbd.arg = (void *) disk;
     723
     724                rc2 = label_open(&lbd, &label);
    698725                if (rc2 != EOK) {
    699726                        log_msg(LOG_DEFAULT, LVL_ERROR, "Failed to open label in disk %s.",
     
    713740        vbds_disk_t *disk;
    714741        label_t *label;
     742        label_bd_t lbd;
    715743        int rc;
    716744
     
    735763        disk->label = NULL;
    736764
    737         rc = label_open(disk->svc_id, &label);
     765        lbd.ops = &vbds_label_bd_ops;
     766        lbd.arg = (void *) disk;
     767
     768        rc = label_open(&lbd, &label);
    738769        if (rc != EOK) {
    739770                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed to open label in disk %s.",
     
    11791210}
    11801211
     1212/** Get block size wrapper for liblabel */
     1213static int vbds_label_get_bsize(void *arg, size_t *bsize)
     1214{
     1215        vbds_disk_t *disk = (vbds_disk_t *)arg;
     1216        return block_get_bsize(disk->svc_id, bsize);
     1217}
     1218
     1219/** Get number of blocks wrapper for liblabel */
     1220static int vbds_label_get_nblocks(void *arg, aoff64_t *nblocks)
     1221{
     1222        vbds_disk_t *disk = (vbds_disk_t *)arg;
     1223        return block_get_nblocks(disk->svc_id, nblocks);
     1224}
     1225
     1226/** Read blocks wrapper for liblabel */
     1227static int vbds_label_read(void *arg, aoff64_t ba, size_t cnt, void *buf)
     1228{
     1229        vbds_disk_t *disk = (vbds_disk_t *)arg;
     1230        return block_read_direct(disk->svc_id, ba, cnt, buf);
     1231}
     1232
     1233/** Write blocks wrapper for liblabel */
     1234static int vbds_label_write(void *arg, aoff64_t ba, size_t cnt, const void *data)
     1235{
     1236        vbds_disk_t *disk = (vbds_disk_t *)arg;
     1237        return block_write_direct(disk->svc_id, ba, cnt, data);
     1238}
     1239
    11811240/** @}
    11821241 */
Note: See TracChangeset for help on using the changeset viewer.