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


Ignore:
Timestamp:
2017-06-20T17:34:02Z (8 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.