Ignore:
File:
1 edited

Legend:

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

    rd8513177 r9f64c1e  
    3434 */
    3535
    36 #include <block.h>
    3736#include <byteorder.h>
    3837#include <errno.h>
     
    4039#include <stdlib.h>
    4140
     41#include "std/fat.h"
    4242#include "std/mbr.h"
    4343#include "mbr.h"
    4444
    45 static int mbr_open(service_id_t, label_t **);
     45static int mbr_open(label_bd_t *, label_t **);
    4646static int mbr_open_ext(label_t *);
    47 static int mbr_create(service_id_t, label_t **);
     47static int mbr_create(label_bd_t *, label_t **);
    4848static void mbr_close(label_t *);
    4949static int mbr_destroy(label_t *);
     
    8686};
    8787
    88 static int mbr_open(service_id_t sid, label_t **rlabel)
     88static int mbr_open(label_bd_t *bd, label_t **rlabel)
    8989{
    9090        label_t *label = NULL;
    9191        mbr_br_block_t *mbr = NULL;
     92        fat_bs_t *bs;
    9293        mbr_pte_t *eptr;
    9394        uint16_t sgn;
     
    9798        int rc;
    9899
    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);
     100        rc = bd->ops->get_bsize(bd->arg, &bsize);
     101        if (rc != EOK) {
     102                rc = EIO;
     103                goto error;
     104        }
     105
     106        rc = bd->ops->get_nblocks(bd->arg, &nblocks);
    106107        if (rc != EOK) {
    107108                rc = EIO;
     
    125126        }
    126127
    127         rc = block_read_direct(sid, mbr_ba, 1, mbr);
     128        bs = (fat_bs_t *)mbr;
     129
     130        rc = bd->ops->read(bd->arg, mbr_ba, 1, mbr);
    128131        if (rc != EOK) {
    129132                rc = EIO;
     
    146149        }
    147150
     151        /*
     152         * We can't really tell whether this is an MBR. Make sure
     153         * this is not actually the BR of a 12/16-bit FAT file system
     154         */
     155        if (bs->type[0] == 'F' && bs->type[1] == 'A' && bs->type[2] == 'T') {
     156                rc = EIO;
     157                goto error;
     158        }
     159
     160        /*
     161         * Or a 32-bit FAT file system
     162         */
     163        if (bs->fat32.type[0] == 'F' && bs->fat32.type[1] == 'A' &&
     164            bs->fat32.type[2] == 'T') {
     165                rc = EIO;
     166                goto error;
     167        }
    148168
    149169        label->ext_part = NULL;
     
    160180        label->ops = &mbr_label_ops;
    161181        label->ltype = lt_mbr;
    162         label->svc_id = sid;
     182        label->bd = *bd;
    163183        label->block_size = bsize;
    164184        label->ablock0 = mbr_ablock0;
     
    219239        while (true) {
    220240                /* Read EBR */
    221                 rc = block_read_direct(label->svc_id, ebr_b0, 1, ebr);
     241                rc = label->bd.ops->read(label->bd.arg, ebr_b0, 1, ebr);
    222242                if (rc != EOK) {
    223243                        rc = EIO;
     
    280300}
    281301
    282 static int mbr_create(service_id_t sid, label_t **rlabel)
     302static int mbr_create(label_bd_t *bd, label_t **rlabel)
    283303{
    284304        label_t *label = NULL;
     
    289309        int rc;
    290310
    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);
     311        rc = bd->ops->get_bsize(bd->arg, &bsize);
     312        if (rc != EOK) {
     313                rc = EIO;
     314                goto error;
     315        }
     316
     317        rc = bd->ops->get_nblocks(bd->arg, &nblocks);
    298318        if (rc != EOK) {
    299319                rc = EIO;
     
    321341        mbr->signature = host2uint16_t_le(mbr_br_signature);
    322342
    323         rc = block_write_direct(sid, mbr_ba, 1, mbr);
     343        rc = bd->ops->write(bd->arg, mbr_ba, 1, mbr);
    324344        if (rc != EOK) {
    325345                rc = EIO;
     
    333353        label->ltype = lt_mbr;
    334354        label->block_size = bsize;
    335         label->svc_id = sid;
     355        label->bd = *bd;
    336356        label->ablock0 = mbr_ablock0;
    337357        label->anblocks = nblocks - mbr_ablock0;
     
    387407        }
    388408
    389         rc = block_write_direct(label->svc_id, mbr_ba, 1, mbr);
     409        rc = label->bd.ops->write(label->bd.arg, mbr_ba, 1, mbr);
    390410        if (rc != EOK) {
    391411                rc = EIO;
     
    9981018                return ENOMEM;
    9991019
    1000         rc = block_read_direct(label->svc_id, mbr_ba, 1, br);
     1020        rc = label->bd.ops->read(label->bd.arg, mbr_ba, 1, br);
    10011021        if (rc != EOK) {
    10021022                rc = EIO;
     
    10061026        br->pte[index] = *pte;
    10071027
    1008         rc = block_write_direct(label->svc_id, mbr_ba, 1, br);
     1028        rc = label->bd.ops->write(label->bd.arg, mbr_ba, 1, br);
    10091029        if (rc != EOK) {
    10101030                rc = EIO;
     
    10661086        br->signature = host2uint16_t_le(mbr_br_signature);
    10671087
    1068         rc = block_write_direct(label->svc_id, ba, 1, br);
     1088        rc = label->bd.ops->write(label->bd.arg, ba, 1, br);
    10691089        if (rc != EOK) {
    10701090                rc = EIO;
     
    10911111        ba = part->block0 - part->hdr_blocks;
    10921112
    1093         rc = block_write_direct(label->svc_id, ba, 1, br);
     1113        rc = label->bd.ops->write(label->bd.arg, ba, 1, br);
    10941114        if (rc != EOK) {
    10951115                rc = EIO;
     
    11181138                return ENOMEM;
    11191139
    1120         rc = block_read_direct(label->svc_id, ba, 1, br);
     1140        rc = label->bd.ops->read(label->bd.arg, ba, 1, br);
    11211141        if (rc != EOK) {
    11221142                rc = EIO;
     
    11331153        mbr_log_part_to_ptes(part, NULL, &br->pte[mbr_ebr_pte_next]);
    11341154
    1135         rc = block_write_direct(label->svc_id, ba, 1, br);
     1155        rc = label->bd.ops->write(label->bd.arg, ba, 1, br);
    11361156        if (rc != EOK) {
    11371157                rc = EIO;
Note: See TracChangeset for help on using the changeset viewer.