Ignore:
File:
1 edited

Legend:

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

    rb33d140 r6a66923  
    3535
    3636#include <adt/checksum.h>
     37#include <block.h>
    3738#include <byteorder.h>
    3839#include <errno.h>
     
    4647#include "gpt.h"
    4748
    48 static int gpt_open(label_bd_t *, label_t **);
    49 static int gpt_create(label_bd_t *, label_t **);
     49static int gpt_open(service_id_t, label_t **);
     50static int gpt_create(service_id_t, label_t **);
    5051static void gpt_close(label_t *);
    5152static int gpt_destroy(label_t *);
     
    7071static int gpt_hdr_get_crc(gpt_header_t *, size_t, uint32_t *);
    7172
    72 static int gpt_pmbr_create(label_bd_t *, size_t, uint64_t);
    73 static int gpt_pmbr_destroy(label_bd_t *, size_t);
     73static int gpt_pmbr_create(service_id_t, size_t, uint64_t);
     74static int gpt_pmbr_destroy(service_id_t, size_t);
    7475
    7576const uint8_t efi_signature[8] = {
     
    9293};
    9394
    94 static int gpt_open(label_bd_t *bd, label_t **rlabel)
     95static int gpt_open(service_id_t sid, label_t **rlabel)
    9596{
    9697        label_t *label = NULL;
     
    99100        uint8_t *etable[2];
    100101        size_t bsize;
    101         aoff64_t nblocks;
    102102        uint32_t num_entries;
    103103        uint32_t esize;
     
    118118        etable[1] = NULL;
    119119
    120         rc = bd->ops->get_bsize(bd->arg, &bsize);
    121         if (rc != EOK) {
    122                 rc = EIO;
    123                 goto error;
    124         }
    125 
    126         rc = bd->ops->get_nblocks(bd->arg, &nblocks);
     120        rc = block_get_bsize(sid, &bsize);
    127121        if (rc != EOK) {
    128122                rc = EIO;
     
    147141        }
    148142
    149         rc = bd->ops->read(bd->arg, gpt_hdr_ba, 1, gpt_hdr[0]);
     143        rc = block_read_direct(sid, gpt_hdr_ba, 1, gpt_hdr[0]);
    150144        if (rc != EOK) {
    151145                rc = EIO;
     
    155149        h1ba = uint64_t_le2host(gpt_hdr[0]->alternate_lba);
    156150
    157         if (h1ba >= nblocks) {
    158                 rc = EINVAL;
    159                 goto error;
    160         }
    161 
    162         rc = bd->ops->read(bd->arg, h1ba, 1, gpt_hdr[1]);
     151        rc = block_read_direct(sid, h1ba, 1, gpt_hdr[1]);
    163152        if (rc != EOK) {
    164153                rc = EIO;
     
    288277                }
    289278
    290                 rc = bd->ops->read(bd->arg, ptba[j], pt_blocks / 2, etable[j]);
     279                rc = block_read_direct(sid, ptba[j], pt_blocks / 2, etable[j]);
    291280                if (rc != EOK) {
    292281                        rc = EIO;
     
    319308        label->ops = &gpt_label_ops;
    320309        label->ltype = lt_gpt;
    321         label->bd = *bd;
     310        label->svc_id = sid;
    322311        label->ablock0 = ba_min;
    323312        label->anblocks = ba_max - ba_min + 1;
     
    345334}
    346335
    347 static int gpt_create(label_bd_t *bd, label_t **rlabel)
     336static int gpt_create(service_id_t sid, label_t **rlabel)
    348337{
    349338        label_t *label = NULL;
     
    364353        int rc;
    365354
    366         rc = bd->ops->get_bsize(bd->arg, &bsize);
     355        rc = block_get_bsize(sid, &bsize);
    367356        if (rc != EOK) {
    368357                rc = EIO;
     
    375364        }
    376365
    377         rc = bd->ops->get_nblocks(bd->arg, &nblocks);
     366        rc = block_get_nblocks(sid, &nblocks);
    378367        if (rc != EOK) {
    379368                rc = EIO;
     
    391380        }
    392381
    393         rc = gpt_pmbr_create(bd, bsize, nblocks);
     382        rc = gpt_pmbr_create(sid, bsize, nblocks);
    394383        if (rc != EOK) {
    395384                rc = EIO;
     
    416405                }
    417406
    418                 rc = bd->ops->write(bd->arg, ptba[i], pt_blocks, etable);
     407                rc = block_write_direct(sid, ptba[i], pt_blocks, etable);
    419408                if (rc != EOK) {
    420409                        rc = EIO;
     
    451440                gpt_hdr_compute_crc(gpt_hdr, sizeof(gpt_header_t));
    452441
    453                 rc = bd->ops->write(bd->arg, hdr_ba[i], 1, gpt_hdr);
     442                rc = block_write_direct(sid, hdr_ba[i], 1, gpt_hdr);
    454443                if (rc != EOK) {
    455444                        rc = EIO;
     
    471460        label->ops = &gpt_label_ops;
    472461        label->ltype = lt_gpt;
    473         label->bd = *bd;
     462        label->svc_id = sid;
    474463        label->ablock0 = ba_min;
    475464        label->anblocks = ba_max - ba_min + 1;
     
    531520                }
    532521
    533                 rc = label->bd.ops->write(label->bd.arg, label->lt.gpt.hdr_ba[i],
     522                rc = block_write_direct(label->svc_id, label->lt.gpt.hdr_ba[i],
    534523                    1, gpt_hdr);
    535524                if (rc != EOK) {
     
    548537                }
    549538
    550                 rc = label->bd.ops->write(label->bd.arg,
     539                rc = block_write_direct(label->svc_id,
    551540                    label->lt.gpt.ptable_ba[i], label->lt.gpt.pt_blocks,
    552541                    etable);
     
    560549        }
    561550
    562         rc = gpt_pmbr_destroy(&label->bd, label->block_size);
     551        rc = gpt_pmbr_destroy(label->svc_id, label->block_size);
    563552        if (rc != EOK)
    564553                goto error;
     
    882871                nblocks = label->lt.gpt.pt_blocks;
    883872
    884                 rc = label->bd.ops->read(label->bd.arg, ba, nblocks, buf);
     873                rc = block_read_direct(label->svc_id, ba, nblocks, buf);
    885874                if (rc != EOK) {
    886875                        rc = EIO;
     
    899888                *e = *pte;
    900889
    901                 rc = label->bd.ops->write(label->bd.arg, ba, nblocks, buf);
     890                rc = block_write_direct(label->svc_id, ba, nblocks, buf);
    902891                if (rc != EOK) {
    903892                        rc = EIO;
     
    934923
    935924        for (i = 0; i < 2; i++) {
    936                 rc = label->bd.ops->read(label->bd.arg,
     925                rc = block_read_direct(label->svc_id,
    937926                    label->lt.gpt.hdr_ba[i], 1, gpt_hdr);
    938927                if (rc != EOK) {
     
    944933                gpt_hdr_compute_crc(gpt_hdr, label->lt.gpt.hdr_size);
    945934
    946                 rc = label->bd.ops->write(label->bd.arg,
     935                rc = block_write_direct(label->svc_id,
    947936                    label->lt.gpt.hdr_ba[i], 1, gpt_hdr);
    948937                if (rc != EOK) {
     
    951940                }
    952941        }
    953 
     942       
    954943        rc = EOK;
    955 
     944       
    956945exit:
    957946        free(gpt_hdr);
     
    985974
    986975/** Create GPT Protective MBR */
    987 static int gpt_pmbr_create(label_bd_t *bd, size_t bsize, uint64_t nblocks)
     976static int gpt_pmbr_create(service_id_t sid, size_t bsize, uint64_t nblocks)
    988977{
    989978        mbr_br_block_t *pmbr = NULL;
     
    1009998        pmbr->signature = host2uint16_t_le(mbr_br_signature);
    1010999
    1011         rc = bd->ops->write(bd->arg, mbr_ba, 1, pmbr);
     1000        rc = block_write_direct(sid, mbr_ba, 1, pmbr);
    10121001        if (rc != EOK) {
    10131002                rc = EIO;
     
    10231012
    10241013/** Destroy GPT Protective MBR */
    1025 static int gpt_pmbr_destroy(label_bd_t *bd, size_t bsize)
     1014static int gpt_pmbr_destroy(service_id_t sid, size_t bsize)
    10261015{
    10271016        mbr_br_block_t *pmbr = NULL;
     
    10341023        }
    10351024
    1036         rc = bd->ops->write(bd->arg, mbr_ba, 1, pmbr);
     1025        rc = block_write_direct(sid, mbr_ba, 1, pmbr);
    10371026        if (rc != EOK) {
    10381027                rc = EIO;
Note: See TracChangeset for help on using the changeset viewer.