Ignore:
File:
1 edited

Legend:

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

    r6a66923 rb33d140  
    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;
     
    10099        uint8_t *etable[2];
    101100        size_t bsize;
     101        aoff64_t nblocks;
    102102        uint32_t num_entries;
    103103        uint32_t esize;
     
    118118        etable[1] = NULL;
    119119
    120         rc = block_get_bsize(sid, &bsize);
     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);
    121127        if (rc != EOK) {
    122128                rc = EIO;
     
    141147        }
    142148
    143         rc = block_read_direct(sid, gpt_hdr_ba, 1, gpt_hdr[0]);
     149        rc = bd->ops->read(bd->arg, gpt_hdr_ba, 1, gpt_hdr[0]);
    144150        if (rc != EOK) {
    145151                rc = EIO;
     
    149155        h1ba = uint64_t_le2host(gpt_hdr[0]->alternate_lba);
    150156
    151         rc = block_read_direct(sid, h1ba, 1, gpt_hdr[1]);
     157        if (h1ba >= nblocks) {
     158                rc = EINVAL;
     159                goto error;
     160        }
     161
     162        rc = bd->ops->read(bd->arg, h1ba, 1, gpt_hdr[1]);
    152163        if (rc != EOK) {
    153164                rc = EIO;
     
    277288                }
    278289
    279                 rc = block_read_direct(sid, ptba[j], pt_blocks / 2, etable[j]);
     290                rc = bd->ops->read(bd->arg, ptba[j], pt_blocks / 2, etable[j]);
    280291                if (rc != EOK) {
    281292                        rc = EIO;
     
    308319        label->ops = &gpt_label_ops;
    309320        label->ltype = lt_gpt;
    310         label->svc_id = sid;
     321        label->bd = *bd;
    311322        label->ablock0 = ba_min;
    312323        label->anblocks = ba_max - ba_min + 1;
     
    334345}
    335346
    336 static int gpt_create(service_id_t sid, label_t **rlabel)
     347static int gpt_create(label_bd_t *bd, label_t **rlabel)
    337348{
    338349        label_t *label = NULL;
     
    353364        int rc;
    354365
    355         rc = block_get_bsize(sid, &bsize);
     366        rc = bd->ops->get_bsize(bd->arg, &bsize);
    356367        if (rc != EOK) {
    357368                rc = EIO;
     
    364375        }
    365376
    366         rc = block_get_nblocks(sid, &nblocks);
     377        rc = bd->ops->get_nblocks(bd->arg, &nblocks);
    367378        if (rc != EOK) {
    368379                rc = EIO;
     
    380391        }
    381392
    382         rc = gpt_pmbr_create(sid, bsize, nblocks);
     393        rc = gpt_pmbr_create(bd, bsize, nblocks);
    383394        if (rc != EOK) {
    384395                rc = EIO;
     
    405416                }
    406417
    407                 rc = block_write_direct(sid, ptba[i], pt_blocks, etable);
     418                rc = bd->ops->write(bd->arg, ptba[i], pt_blocks, etable);
    408419                if (rc != EOK) {
    409420                        rc = EIO;
     
    440451                gpt_hdr_compute_crc(gpt_hdr, sizeof(gpt_header_t));
    441452
    442                 rc = block_write_direct(sid, hdr_ba[i], 1, gpt_hdr);
     453                rc = bd->ops->write(bd->arg, hdr_ba[i], 1, gpt_hdr);
    443454                if (rc != EOK) {
    444455                        rc = EIO;
     
    460471        label->ops = &gpt_label_ops;
    461472        label->ltype = lt_gpt;
    462         label->svc_id = sid;
     473        label->bd = *bd;
    463474        label->ablock0 = ba_min;
    464475        label->anblocks = ba_max - ba_min + 1;
     
    520531                }
    521532
    522                 rc = block_write_direct(label->svc_id, label->lt.gpt.hdr_ba[i],
     533                rc = label->bd.ops->write(label->bd.arg, label->lt.gpt.hdr_ba[i],
    523534                    1, gpt_hdr);
    524535                if (rc != EOK) {
     
    537548                }
    538549
    539                 rc = block_write_direct(label->svc_id,
     550                rc = label->bd.ops->write(label->bd.arg,
    540551                    label->lt.gpt.ptable_ba[i], label->lt.gpt.pt_blocks,
    541552                    etable);
     
    549560        }
    550561
    551         rc = gpt_pmbr_destroy(label->svc_id, label->block_size);
     562        rc = gpt_pmbr_destroy(&label->bd, label->block_size);
    552563        if (rc != EOK)
    553564                goto error;
     
    871882                nblocks = label->lt.gpt.pt_blocks;
    872883
    873                 rc = block_read_direct(label->svc_id, ba, nblocks, buf);
     884                rc = label->bd.ops->read(label->bd.arg, ba, nblocks, buf);
    874885                if (rc != EOK) {
    875886                        rc = EIO;
     
    888899                *e = *pte;
    889900
    890                 rc = block_write_direct(label->svc_id, ba, nblocks, buf);
     901                rc = label->bd.ops->write(label->bd.arg, ba, nblocks, buf);
    891902                if (rc != EOK) {
    892903                        rc = EIO;
     
    923934
    924935        for (i = 0; i < 2; i++) {
    925                 rc = block_read_direct(label->svc_id,
     936                rc = label->bd.ops->read(label->bd.arg,
    926937                    label->lt.gpt.hdr_ba[i], 1, gpt_hdr);
    927938                if (rc != EOK) {
     
    933944                gpt_hdr_compute_crc(gpt_hdr, label->lt.gpt.hdr_size);
    934945
    935                 rc = block_write_direct(label->svc_id,
     946                rc = label->bd.ops->write(label->bd.arg,
    936947                    label->lt.gpt.hdr_ba[i], 1, gpt_hdr);
    937948                if (rc != EOK) {
     
    940951                }
    941952        }
    942        
     953
    943954        rc = EOK;
    944        
     955
    945956exit:
    946957        free(gpt_hdr);
     
    974985
    975986/** Create GPT Protective MBR */
    976 static int gpt_pmbr_create(service_id_t sid, size_t bsize, uint64_t nblocks)
     987static int gpt_pmbr_create(label_bd_t *bd, size_t bsize, uint64_t nblocks)
    977988{
    978989        mbr_br_block_t *pmbr = NULL;
     
    9981009        pmbr->signature = host2uint16_t_le(mbr_br_signature);
    9991010
    1000         rc = block_write_direct(sid, mbr_ba, 1, pmbr);
     1011        rc = bd->ops->write(bd->arg, mbr_ba, 1, pmbr);
    10011012        if (rc != EOK) {
    10021013                rc = EIO;
     
    10121023
    10131024/** Destroy GPT Protective MBR */
    1014 static int gpt_pmbr_destroy(service_id_t sid, size_t bsize)
     1025static int gpt_pmbr_destroy(label_bd_t *bd, size_t bsize)
    10151026{
    10161027        mbr_br_block_t *pmbr = NULL;
     
    10231034        }
    10241035
    1025         rc = block_write_direct(sid, mbr_ba, 1, pmbr);
     1036        rc = bd->ops->write(bd->arg, mbr_ba, 1, pmbr);
    10261037        if (rc != EOK) {
    10271038                rc = EIO;
Note: See TracChangeset for help on using the changeset viewer.