Changeset 46c20c8 in mainline for uspace/srv/fs/fat/fat_ops.c


Ignore:
Timestamp:
2010-11-26T20:08:10Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
45df59a
Parents:
fb150d78 (diff), ffdd2b9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/fat/fat_ops.c

    rfb150d78 r46c20c8  
    4545#include <ipc/services.h>
    4646#include <ipc/devmap.h>
     47#include <macros.h>
    4748#include <async.h>
    4849#include <errno.h>
    49 #include <string.h>
     50#include <str.h>
    5051#include <byteorder.h>
    5152#include <adt/hash_table.h>
     
    5960#define FS_NODE(node)   ((node) ? (node)->bp : NULL)
    6061
     62#define DPS(bs)         (BPS((bs)) / sizeof(fat_dentry_t))
     63#define BPC(bs)         (BPS((bs)) * SPC((bs)))
     64
    6165/** Mutex protecting the list of cached free FAT nodes. */
    6266static FIBRIL_MUTEX_INITIALIZE(ffn_mutex);
     
    6872 * Forward declarations of FAT libfs operations.
    6973 */
    70 static int fat_root_get(fs_node_t **, dev_handle_t);
     74static int fat_root_get(fs_node_t **, devmap_handle_t);
    7175static int fat_match(fs_node_t **, fs_node_t *, const char *);
    72 static int fat_node_get(fs_node_t **, dev_handle_t, fs_index_t);
     76static int fat_node_get(fs_node_t **, devmap_handle_t, fs_index_t);
    7377static int fat_node_open(fs_node_t *);
    7478static int fat_node_put(fs_node_t *);
    75 static int fat_create_node(fs_node_t **, dev_handle_t, int);
     79static int fat_create_node(fs_node_t **, devmap_handle_t, int);
    7680static int fat_destroy_node(fs_node_t *);
    7781static int fat_link(fs_node_t *, fs_node_t *, const char *);
     
    7983static int fat_has_children(bool *, fs_node_t *);
    8084static fs_index_t fat_index_get(fs_node_t *);
    81 static size_t fat_size_get(fs_node_t *);
     85static aoff64_t fat_size_get(fs_node_t *);
    8286static unsigned fat_lnkcnt_get(fs_node_t *);
    8387static char fat_plb_get_char(unsigned);
    8488static bool fat_is_directory(fs_node_t *);
    8589static bool fat_is_file(fs_node_t *node);
    86 static dev_handle_t fat_device_get(fs_node_t *node);
     90static devmap_handle_t fat_device_get(fs_node_t *node);
    8791
    8892/*
     
    100104        node->refcnt = 0;
    101105        node->dirty = false;
     106        node->lastc_cached_valid = false;
     107        node->lastc_cached_value = FAT_CLST_LAST1;
     108        node->currc_cached_valid = false;
     109        node->currc_cached_bn = 0;
     110        node->currc_cached_value = FAT_CLST_LAST1;
    102111}
    103112
     
    107116        fat_bs_t *bs;
    108117        fat_dentry_t *d;
    109         uint16_t bps;
    110         unsigned dps;
    111118        int rc;
    112119       
    113120        assert(node->dirty);
    114121
    115         bs = block_bb_get(node->idx->dev_handle);
    116         bps = uint16_t_le2host(bs->bps);
    117         dps = bps / sizeof(fat_dentry_t);
     122        bs = block_bb_get(node->idx->devmap_handle);
    118123       
    119124        /* Read the block that contains the dentry of interest. */
    120         rc = _fat_block_get(&b, bs, node->idx->dev_handle, node->idx->pfc,
    121             (node->idx->pdi * sizeof(fat_dentry_t)) / bps, BLOCK_FLAGS_NONE);
     125        rc = _fat_block_get(&b, bs, node->idx->devmap_handle, node->idx->pfc,
     126            NULL, (node->idx->pdi * sizeof(fat_dentry_t)) / BPS(bs),
     127            BLOCK_FLAGS_NONE);
    122128        if (rc != EOK)
    123129                return rc;
    124130
    125         d = ((fat_dentry_t *)b->data) + (node->idx->pdi % dps);
     131        d = ((fat_dentry_t *)b->data) + (node->idx->pdi % DPS(bs));
    126132
    127133        d->firstc = host2uint16_t_le(node->firstc);
     
    139145}
    140146
    141 static int fat_node_fini_by_dev_handle(dev_handle_t dev_handle)
     147static int fat_node_fini_by_devmap_handle(devmap_handle_t devmap_handle)
    142148{
    143149        link_t *lnk;
     
    164170                        goto restart;
    165171                }
    166                 if (nodep->idx->dev_handle != dev_handle) {
     172                if (nodep->idx->devmap_handle != devmap_handle) {
    167173                        fibril_mutex_unlock(&nodep->idx->lock);
    168174                        fibril_mutex_unlock(&nodep->lock);
     
    265271        fat_dentry_t *d;
    266272        fat_node_t *nodep = NULL;
    267         unsigned bps;
    268         unsigned spc;
    269         unsigned dps;
    270273        int rc;
    271274
     
    296299                return rc;
    297300
    298         bs = block_bb_get(idxp->dev_handle);
    299         bps = uint16_t_le2host(bs->bps);
    300         spc = bs->spc;
    301         dps = bps / sizeof(fat_dentry_t);
     301        bs = block_bb_get(idxp->devmap_handle);
    302302
    303303        /* Read the block that contains the dentry of interest. */
    304         rc = _fat_block_get(&b, bs, idxp->dev_handle, idxp->pfc,
    305             (idxp->pdi * sizeof(fat_dentry_t)) / bps, BLOCK_FLAGS_NONE);
     304        rc = _fat_block_get(&b, bs, idxp->devmap_handle, idxp->pfc, NULL,
     305            (idxp->pdi * sizeof(fat_dentry_t)) / BPS(bs), BLOCK_FLAGS_NONE);
    306306        if (rc != EOK) {
    307307                (void) fat_node_put(FS_NODE(nodep));
     
    309309        }
    310310
    311         d = ((fat_dentry_t *)b->data) + (idxp->pdi % dps);
     311        d = ((fat_dentry_t *)b->data) + (idxp->pdi % DPS(bs));
    312312        if (d->attr & FAT_ATTR_SUBDIR) {
    313313                /*
     
    323323                 */
    324324                uint16_t clusters;
    325                 rc = fat_clusters_get(&clusters, bs, idxp->dev_handle,
     325                rc = fat_clusters_get(&clusters, bs, idxp->devmap_handle,
    326326                    uint16_t_le2host(d->firstc));
    327327                if (rc != EOK) {
     
    329329                        return rc;
    330330                }
    331                 nodep->size = bps * spc * clusters;
     331                nodep->size = BPS(bs) * SPC(bs) * clusters;
    332332        } else {
    333333                nodep->type = FAT_FILE;
     
    356356 */
    357357
    358 int fat_root_get(fs_node_t **rfn, dev_handle_t dev_handle)
    359 {
    360         return fat_node_get(rfn, dev_handle, 0);
     358int fat_root_get(fs_node_t **rfn, devmap_handle_t devmap_handle)
     359{
     360        return fat_node_get(rfn, devmap_handle, 0);
    361361}
    362362
     
    367367        char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1];
    368368        unsigned i, j;
    369         unsigned bps;           /* bytes per sector */
    370         unsigned dps;           /* dentries per sector */
    371369        unsigned blocks;
    372370        fat_dentry_t *d;
     371        devmap_handle_t devmap_handle;
    373372        block_t *b;
    374373        int rc;
    375374
    376375        fibril_mutex_lock(&parentp->idx->lock);
    377         bs = block_bb_get(parentp->idx->dev_handle);
    378         bps = uint16_t_le2host(bs->bps);
    379         dps = bps / sizeof(fat_dentry_t);
    380         blocks = parentp->size / bps;
     376        devmap_handle = parentp->idx->devmap_handle;
     377        fibril_mutex_unlock(&parentp->idx->lock);
     378
     379        bs = block_bb_get(devmap_handle);
     380        blocks = parentp->size / BPS(bs);
    381381        for (i = 0; i < blocks; i++) {
    382382                rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE);
    383                 if (rc != EOK) {
    384                         fibril_mutex_unlock(&parentp->idx->lock);
     383                if (rc != EOK)
    385384                        return rc;
    386                 }
    387                 for (j = 0; j < dps; j++) {
     385                for (j = 0; j < DPS(bs); j++) {
    388386                        d = ((fat_dentry_t *)b->data) + j;
    389387                        switch (fat_classify_dentry(d)) {
     
    394392                                /* miss */
    395393                                rc = block_put(b);
    396                                 fibril_mutex_unlock(&parentp->idx->lock);
    397394                                *rfn = NULL;
    398395                                return rc;
     
    405402                                /* hit */
    406403                                fat_node_t *nodep;
    407                                 /*
    408                                  * Assume tree hierarchy for locking.  We
    409                                  * already have the parent and now we are going
    410                                  * to lock the child.  Never lock in the oposite
    411                                  * order.
    412                                  */
    413                                 fat_idx_t *idx = fat_idx_get_by_pos(
    414                                     parentp->idx->dev_handle, parentp->firstc,
    415                                     i * dps + j);
    416                                 fibril_mutex_unlock(&parentp->idx->lock);
     404                                fat_idx_t *idx = fat_idx_get_by_pos(devmap_handle,
     405                                    parentp->firstc, i * DPS(bs) + j);
    417406                                if (!idx) {
    418407                                        /*
     
    437426                }
    438427                rc = block_put(b);
    439                 if (rc != EOK) {
    440                         fibril_mutex_unlock(&parentp->idx->lock);
     428                if (rc != EOK)
    441429                        return rc;
    442                 }
    443         }
    444 
    445         fibril_mutex_unlock(&parentp->idx->lock);
     430        }
     431
    446432        *rfn = NULL;
    447433        return EOK;
     
    449435
    450436/** Instantiate a FAT in-core node. */
    451 int fat_node_get(fs_node_t **rfn, dev_handle_t dev_handle, fs_index_t index)
     437int fat_node_get(fs_node_t **rfn, devmap_handle_t devmap_handle, fs_index_t index)
    452438{
    453439        fat_node_t *nodep;
     
    455441        int rc;
    456442
    457         idxp = fat_idx_get_by_index(dev_handle, index);
     443        idxp = fat_idx_get_by_index(devmap_handle, index);
    458444        if (!idxp) {
    459445                *rfn = NULL;
     
    506492}
    507493
    508 int fat_create_node(fs_node_t **rfn, dev_handle_t dev_handle, int flags)
     494int fat_create_node(fs_node_t **rfn, devmap_handle_t devmap_handle, int flags)
    509495{
    510496        fat_idx_t *idxp;
     
    512498        fat_bs_t *bs;
    513499        fat_cluster_t mcl, lcl;
    514         uint16_t bps;
    515500        int rc;
    516501
    517         bs = block_bb_get(dev_handle);
    518         bps = uint16_t_le2host(bs->bps);
     502        bs = block_bb_get(devmap_handle);
    519503        if (flags & L_DIRECTORY) {
    520504                /* allocate a cluster */
    521                 rc = fat_alloc_clusters(bs, dev_handle, 1, &mcl, &lcl);
     505                rc = fat_alloc_clusters(bs, devmap_handle, 1, &mcl, &lcl);
    522506                if (rc != EOK)
    523507                        return rc;
    524508                /* populate the new cluster with unused dentries */
    525                 rc = fat_zero_cluster(bs, dev_handle, mcl);
     509                rc = fat_zero_cluster(bs, devmap_handle, mcl);
    526510                if (rc != EOK) {
    527                         (void) fat_free_clusters(bs, dev_handle, mcl);
     511                        (void) fat_free_clusters(bs, devmap_handle, mcl);
    528512                        return rc;
    529513                }
     
    532516        rc = fat_node_get_new(&nodep);
    533517        if (rc != EOK) {
    534                 (void) fat_free_clusters(bs, dev_handle, mcl);
     518                (void) fat_free_clusters(bs, devmap_handle, mcl);
    535519                return rc;
    536520        }
    537         rc = fat_idx_get_new(&idxp, dev_handle);
    538         if (rc != EOK) {
    539                 (void) fat_free_clusters(bs, dev_handle, mcl); 
     521        rc = fat_idx_get_new(&idxp, devmap_handle);
     522        if (rc != EOK) {
     523                (void) fat_free_clusters(bs, devmap_handle, mcl);       
    540524                (void) fat_node_put(FS_NODE(nodep));
    541525                return rc;
     
    545529                nodep->type = FAT_DIRECTORY;
    546530                nodep->firstc = mcl;
    547                 nodep->size = bps * bs->spc;
     531                nodep->size = BPS(bs) * SPC(bs);
    548532        } else {
    549533                nodep->type = FAT_FILE;
     
    586570        assert(!has_children);
    587571
    588         bs = block_bb_get(nodep->idx->dev_handle);
     572        bs = block_bb_get(nodep->idx->devmap_handle);
    589573        if (nodep->firstc != FAT_CLST_RES0) {
    590574                assert(nodep->size);
    591575                /* Free all clusters allocated to the node. */
    592                 rc = fat_free_clusters(bs, nodep->idx->dev_handle,
     576                rc = fat_free_clusters(bs, nodep->idx->devmap_handle,
    593577                    nodep->firstc);
    594578        }
     
    608592        block_t *b;
    609593        unsigned i, j;
    610         uint16_t bps;
    611         unsigned dps;
    612594        unsigned blocks;
    613595        fat_cluster_t mcl, lcl;
     
    638620       
    639621        fibril_mutex_lock(&parentp->idx->lock);
    640         bs = block_bb_get(parentp->idx->dev_handle);
    641         bps = uint16_t_le2host(bs->bps);
    642         dps = bps / sizeof(fat_dentry_t);
    643 
    644         blocks = parentp->size / bps;
     622        bs = block_bb_get(parentp->idx->devmap_handle);
     623
     624        blocks = parentp->size / BPS(bs);
    645625
    646626        for (i = 0; i < blocks; i++) {
     
    650630                        return rc;
    651631                }
    652                 for (j = 0; j < dps; j++) {
     632                for (j = 0; j < DPS(bs); j++) {
    653633                        d = ((fat_dentry_t *)b->data) + j;
    654634                        switch (fat_classify_dentry(d)) {
     
    679659                return ENOSPC;
    680660        }
    681         rc = fat_alloc_clusters(bs, parentp->idx->dev_handle, 1, &mcl, &lcl);
     661        rc = fat_alloc_clusters(bs, parentp->idx->devmap_handle, 1, &mcl, &lcl);
    682662        if (rc != EOK) {
    683663                fibril_mutex_unlock(&parentp->idx->lock);
    684664                return rc;
    685665        }
    686         rc = fat_zero_cluster(bs, parentp->idx->dev_handle, mcl);
    687         if (rc != EOK) {
    688                 (void) fat_free_clusters(bs, parentp->idx->dev_handle, mcl);
     666        rc = fat_zero_cluster(bs, parentp->idx->devmap_handle, mcl);
     667        if (rc != EOK) {
     668                (void) fat_free_clusters(bs, parentp->idx->devmap_handle, mcl);
    689669                fibril_mutex_unlock(&parentp->idx->lock);
    690670                return rc;
    691671        }
    692         rc = fat_append_clusters(bs, parentp, mcl);
    693         if (rc != EOK) {
    694                 (void) fat_free_clusters(bs, parentp->idx->dev_handle, mcl);
     672        rc = fat_append_clusters(bs, parentp, mcl, lcl);
     673        if (rc != EOK) {
     674                (void) fat_free_clusters(bs, parentp->idx->devmap_handle, mcl);
    695675                fibril_mutex_unlock(&parentp->idx->lock);
    696676                return rc;
    697677        }
    698         parentp->size += bps * bs->spc;
     678        parentp->size += BPS(bs) * SPC(bs);
    699679        parentp->dirty = true;          /* need to sync node */
    700680        rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE);
     
    722702        fibril_mutex_lock(&childp->idx->lock);
    723703       
    724         /*
    725          * If possible, create the Sub-directory Identifier Entry and the
    726          * Sub-directory Parent Pointer Entry (i.e. "." and ".."). These entries
    727          * are not mandatory according to Standard ECMA-107 and HelenOS VFS does
    728          * not use them anyway, so this is rather a sign of our good will.
    729          */
    730         rc = fat_block_get(&b, bs, childp, 0, BLOCK_FLAGS_NONE);
    731         if (rc != EOK) {
     704        if (childp->type == FAT_DIRECTORY) {
    732705                /*
    733                  * Rather than returning an error, simply skip the creation of
    734                  * these two entries.
     706                 * If possible, create the Sub-directory Identifier Entry and
     707                 * the Sub-directory Parent Pointer Entry (i.e. "." and "..").
     708                 * These entries are not mandatory according to Standard
     709                 * ECMA-107 and HelenOS VFS does not use them anyway, so this is
     710                 * rather a sign of our good will.
    735711                 */
    736                 goto skip_dots;
    737         }
    738         d = (fat_dentry_t *)b->data;
    739         if (fat_classify_dentry(d) == FAT_DENTRY_LAST ||
    740             str_cmp(d->name, FAT_NAME_DOT) == 0) {
    741                 memset(d, 0, sizeof(fat_dentry_t));
    742                 str_cpy(d->name, 8, FAT_NAME_DOT);
    743                 str_cpy(d->ext, 3, FAT_EXT_PAD);
    744                 d->attr = FAT_ATTR_SUBDIR;
    745                 d->firstc = host2uint16_t_le(childp->firstc);
    746                 /* TODO: initialize also the date/time members. */
    747         }
    748         d++;
    749         if (fat_classify_dentry(d) == FAT_DENTRY_LAST ||
    750             str_cmp(d->name, FAT_NAME_DOT_DOT) == 0) {
    751                 memset(d, 0, sizeof(fat_dentry_t));
    752                 str_cpy(d->name, 8, FAT_NAME_DOT_DOT);
    753                 str_cpy(d->ext, 3, FAT_EXT_PAD);
    754                 d->attr = FAT_ATTR_SUBDIR;
    755                 d->firstc = (parentp->firstc == FAT_CLST_ROOT) ?
    756                     host2uint16_t_le(FAT_CLST_RES0) :
    757                     host2uint16_t_le(parentp->firstc);
    758                 /* TODO: initialize also the date/time members. */
    759         }
    760         b->dirty = true;                /* need to sync block */
    761         /*
    762          * Ignore the return value as we would have fallen through on error
    763          * anyway.
    764          */
    765         (void) block_put(b);
     712                rc = fat_block_get(&b, bs, childp, 0, BLOCK_FLAGS_NONE);
     713                if (rc != EOK) {
     714                        /*
     715                         * Rather than returning an error, simply skip the
     716                         * creation of these two entries.
     717                         */
     718                        goto skip_dots;
     719                }
     720                d = (fat_dentry_t *) b->data;
     721                if ((fat_classify_dentry(d) == FAT_DENTRY_LAST) ||
     722                    (str_cmp((char *) d->name, FAT_NAME_DOT)) == 0) {
     723                        memset(d, 0, sizeof(fat_dentry_t));
     724                        str_cpy((char *) d->name, 8, FAT_NAME_DOT);
     725                        str_cpy((char *) d->ext, 3, FAT_EXT_PAD);
     726                        d->attr = FAT_ATTR_SUBDIR;
     727                        d->firstc = host2uint16_t_le(childp->firstc);
     728                        /* TODO: initialize also the date/time members. */
     729                }
     730                d++;
     731                if ((fat_classify_dentry(d) == FAT_DENTRY_LAST) ||
     732                    (str_cmp((char *) d->name, FAT_NAME_DOT_DOT) == 0)) {
     733                        memset(d, 0, sizeof(fat_dentry_t));
     734                        str_cpy((char *) d->name, 8, FAT_NAME_DOT_DOT);
     735                        str_cpy((char *) d->ext, 3, FAT_EXT_PAD);
     736                        d->attr = FAT_ATTR_SUBDIR;
     737                        d->firstc = (parentp->firstc == FAT_CLST_ROOT) ?
     738                            host2uint16_t_le(FAT_CLST_RES0) :
     739                            host2uint16_t_le(parentp->firstc);
     740                        /* TODO: initialize also the date/time members. */
     741                }
     742                b->dirty = true;                /* need to sync block */
     743                /*
     744                 * Ignore the return value as we would have fallen through on error
     745                 * anyway.
     746                 */
     747                (void) block_put(b);
     748        }
    766749skip_dots:
    767750
    768751        childp->idx->pfc = parentp->firstc;
    769         childp->idx->pdi = i * dps + j;
     752        childp->idx->pdi = i * DPS(bs) + j;
    770753        fibril_mutex_unlock(&childp->idx->lock);
    771754
     
    789772        fat_bs_t *bs;
    790773        fat_dentry_t *d;
    791         uint16_t bps;
    792774        block_t *b;
    793775        bool has_children;
     
    807789        assert(childp->lnkcnt == 1);
    808790        fibril_mutex_lock(&childp->idx->lock);
    809         bs = block_bb_get(childp->idx->dev_handle);
    810         bps = uint16_t_le2host(bs->bps);
    811 
    812         rc = _fat_block_get(&b, bs, childp->idx->dev_handle, childp->idx->pfc,
    813             (childp->idx->pdi * sizeof(fat_dentry_t)) / bps,
     791        bs = block_bb_get(childp->idx->devmap_handle);
     792
     793        rc = _fat_block_get(&b, bs, childp->idx->devmap_handle, childp->idx->pfc,
     794            NULL, (childp->idx->pdi * sizeof(fat_dentry_t)) / BPS(bs),
    814795            BLOCK_FLAGS_NONE);
    815796        if (rc != EOK)
    816797                goto error;
    817798        d = (fat_dentry_t *)b->data +
    818             (childp->idx->pdi % (bps / sizeof(fat_dentry_t)));
     799            (childp->idx->pdi % (BPS(bs) / sizeof(fat_dentry_t)));
    819800        /* mark the dentry as not-currently-used */
    820801        d->name[0] = FAT_DENTRY_ERASED;
     
    848829        fat_bs_t *bs;
    849830        fat_node_t *nodep = FAT_NODE(fn);
    850         unsigned bps;
    851         unsigned dps;
    852831        unsigned blocks;
    853832        block_t *b;
     
    861840       
    862841        fibril_mutex_lock(&nodep->idx->lock);
    863         bs = block_bb_get(nodep->idx->dev_handle);
    864         bps = uint16_t_le2host(bs->bps);
    865         dps = bps / sizeof(fat_dentry_t);
    866 
    867         blocks = nodep->size / bps;
     842        bs = block_bb_get(nodep->idx->devmap_handle);
     843
     844        blocks = nodep->size / BPS(bs);
    868845
    869846        for (i = 0; i < blocks; i++) {
     
    875852                        return rc;
    876853                }
    877                 for (j = 0; j < dps; j++) {
     854                for (j = 0; j < DPS(bs); j++) {
    878855                        d = ((fat_dentry_t *)b->data) + j;
    879856                        switch (fat_classify_dentry(d)) {
     
    912889}
    913890
    914 size_t fat_size_get(fs_node_t *fn)
     891aoff64_t fat_size_get(fs_node_t *fn)
    915892{
    916893        return FAT_NODE(fn)->size;
     
    937914}
    938915
    939 dev_handle_t fat_device_get(fs_node_t *node)
     916devmap_handle_t fat_device_get(fs_node_t *node)
    940917{
    941918        return 0;
     
    969946void fat_mounted(ipc_callid_t rid, ipc_call_t *request)
    970947{
    971         dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     948        devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
    972949        enum cache_mode cmode;
    973950        fat_bs_t *bs;
    974         uint16_t bps;
    975         uint16_t rde;
    976951       
    977952        /* Accept the mount options */
     
    993968
    994969        /* initialize libblock */
    995         rc = block_init(dev_handle, BS_SIZE);
     970        rc = block_init(devmap_handle, BS_SIZE);
    996971        if (rc != EOK) {
    997972                ipc_answer_0(rid, rc);
     
    1000975
    1001976        /* prepare the boot block */
    1002         rc = block_bb_read(dev_handle, BS_BLOCK);
    1003         if (rc != EOK) {
    1004                 block_fini(dev_handle);
     977        rc = block_bb_read(devmap_handle, BS_BLOCK);
     978        if (rc != EOK) {
     979                block_fini(devmap_handle);
    1005980                ipc_answer_0(rid, rc);
    1006981                return;
     
    1008983
    1009984        /* get the buffer with the boot sector */
    1010         bs = block_bb_get(dev_handle);
    1011        
    1012         /* Read the number of root directory entries. */
    1013         bps = uint16_t_le2host(bs->bps);
    1014         rde = uint16_t_le2host(bs->root_ent_max);
    1015 
    1016         if (bps != BS_SIZE) {
    1017                 block_fini(dev_handle);
     985        bs = block_bb_get(devmap_handle);
     986       
     987        if (BPS(bs) != BS_SIZE) {
     988                block_fini(devmap_handle);
    1018989                ipc_answer_0(rid, ENOTSUP);
    1019990                return;
     
    1021992
    1022993        /* Initialize the block cache */
    1023         rc = block_cache_init(dev_handle, bps, 0 /* XXX */, cmode);
    1024         if (rc != EOK) {
    1025                 block_fini(dev_handle);
     994        rc = block_cache_init(devmap_handle, BPS(bs), 0 /* XXX */, cmode);
     995        if (rc != EOK) {
     996                block_fini(devmap_handle);
    1026997                ipc_answer_0(rid, rc);
    1027998                return;
     
    10291000
    10301001        /* Do some simple sanity checks on the file system. */
    1031         rc = fat_sanity_check(bs, dev_handle);
    1032         if (rc != EOK) {
    1033                 (void) block_cache_fini(dev_handle);
    1034                 block_fini(dev_handle);
     1002        rc = fat_sanity_check(bs, devmap_handle);
     1003        if (rc != EOK) {
     1004                (void) block_cache_fini(devmap_handle);
     1005                block_fini(devmap_handle);
    10351006                ipc_answer_0(rid, rc);
    10361007                return;
    10371008        }
    10381009
    1039         rc = fat_idx_init_by_dev_handle(dev_handle);
    1040         if (rc != EOK) {
    1041                 (void) block_cache_fini(dev_handle);
    1042                 block_fini(dev_handle);
     1010        rc = fat_idx_init_by_devmap_handle(devmap_handle);
     1011        if (rc != EOK) {
     1012                (void) block_cache_fini(devmap_handle);
     1013                block_fini(devmap_handle);
    10431014                ipc_answer_0(rid, rc);
    10441015                return;
     
    10481019        fs_node_t *rfn = (fs_node_t *)malloc(sizeof(fs_node_t));
    10491020        if (!rfn) {
    1050                 (void) block_cache_fini(dev_handle);
    1051                 block_fini(dev_handle);
    1052                 fat_idx_fini_by_dev_handle(dev_handle);
     1021                (void) block_cache_fini(devmap_handle);
     1022                block_fini(devmap_handle);
     1023                fat_idx_fini_by_devmap_handle(devmap_handle);
    10531024                ipc_answer_0(rid, ENOMEM);
    10541025                return;
     
    10581029        if (!rootp) {
    10591030                free(rfn);
    1060                 (void) block_cache_fini(dev_handle);
    1061                 block_fini(dev_handle);
    1062                 fat_idx_fini_by_dev_handle(dev_handle);
     1031                (void) block_cache_fini(devmap_handle);
     1032                block_fini(devmap_handle);
     1033                fat_idx_fini_by_devmap_handle(devmap_handle);
    10631034                ipc_answer_0(rid, ENOMEM);
    10641035                return;
     
    10661037        fat_node_initialize(rootp);
    10671038
    1068         fat_idx_t *ridxp = fat_idx_get_by_pos(dev_handle, FAT_CLST_ROOTPAR, 0);
     1039        fat_idx_t *ridxp = fat_idx_get_by_pos(devmap_handle, FAT_CLST_ROOTPAR, 0);
    10691040        if (!ridxp) {
    10701041                free(rfn);
    10711042                free(rootp);
    1072                 (void) block_cache_fini(dev_handle);
    1073                 block_fini(dev_handle);
    1074                 fat_idx_fini_by_dev_handle(dev_handle);
     1043                (void) block_cache_fini(devmap_handle);
     1044                block_fini(devmap_handle);
     1045                fat_idx_fini_by_devmap_handle(devmap_handle);
    10751046                ipc_answer_0(rid, ENOMEM);
    10761047                return;
     
    10831054        rootp->refcnt = 1;
    10841055        rootp->lnkcnt = 0;      /* FS root is not linked */
    1085         rootp->size = rde * sizeof(fat_dentry_t);
     1056        rootp->size = RDE(bs) * sizeof(fat_dentry_t);
    10861057        rootp->idx = ridxp;
    10871058        ridxp->nodep = rootp;
     
    11011072void fat_unmounted(ipc_callid_t rid, ipc_call_t *request)
    11021073{
    1103         dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     1074        devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
    11041075        fs_node_t *fn;
    11051076        fat_node_t *nodep;
    11061077        int rc;
    11071078
    1108         rc = fat_root_get(&fn, dev_handle);
     1079        rc = fat_root_get(&fn, devmap_handle);
    11091080        if (rc != EOK) {
    11101081                ipc_answer_0(rid, rc);
     
    11341105         * stop using libblock for this instance.
    11351106         */
    1136         (void) fat_node_fini_by_dev_handle(dev_handle);
    1137         fat_idx_fini_by_dev_handle(dev_handle);
    1138         (void) block_cache_fini(dev_handle);
    1139         block_fini(dev_handle);
     1107        (void) fat_node_fini_by_devmap_handle(devmap_handle);
     1108        fat_idx_fini_by_devmap_handle(devmap_handle);
     1109        (void) block_cache_fini(devmap_handle);
     1110        block_fini(devmap_handle);
    11401111
    11411112        ipc_answer_0(rid, EOK);
     
    11541125void fat_read(ipc_callid_t rid, ipc_call_t *request)
    11551126{
    1156         dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
    1157         fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    1158         off_t pos = (off_t)IPC_GET_ARG3(*request);
     1127        devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
     1128        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
     1129        aoff64_t pos =
     1130            (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request));
    11591131        fs_node_t *fn;
    11601132        fat_node_t *nodep;
    11611133        fat_bs_t *bs;
    1162         uint16_t bps;
    11631134        size_t bytes;
    11641135        block_t *b;
    11651136        int rc;
    11661137
    1167         rc = fat_node_get(&fn, dev_handle, index);
     1138        rc = fat_node_get(&fn, devmap_handle, index);
    11681139        if (rc != EOK) {
    11691140                ipc_answer_0(rid, rc);
     
    11851156        }
    11861157
    1187         bs = block_bb_get(dev_handle);
    1188         bps = uint16_t_le2host(bs->bps);
     1158        bs = block_bb_get(devmap_handle);
    11891159
    11901160        if (nodep->type == FAT_FILE) {
     
    11991169                        (void) async_data_read_finalize(callid, NULL, 0);
    12001170                } else {
    1201                         bytes = min(len, bps - pos % bps);
     1171                        bytes = min(len, BPS(bs) - pos % BPS(bs));
    12021172                        bytes = min(bytes, nodep->size - pos);
    1203                         rc = fat_block_get(&b, bs, nodep, pos / bps,
     1173                        rc = fat_block_get(&b, bs, nodep, pos / BPS(bs),
    12041174                            BLOCK_FLAGS_NONE);
    12051175                        if (rc != EOK) {
     
    12091179                                return;
    12101180                        }
    1211                         (void) async_data_read_finalize(callid, b->data + pos % bps,
    1212                             bytes);
     1181                        (void) async_data_read_finalize(callid,
     1182                            b->data + pos % BPS(bs), bytes);
    12131183                        rc = block_put(b);
    12141184                        if (rc != EOK) {
     
    12201190        } else {
    12211191                unsigned bnum;
    1222                 off_t spos = pos;
     1192                aoff64_t spos = pos;
    12231193                char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1];
    12241194                fat_dentry_t *d;
    12251195
    12261196                assert(nodep->type == FAT_DIRECTORY);
    1227                 assert(nodep->size % bps == 0);
    1228                 assert(bps % sizeof(fat_dentry_t) == 0);
     1197                assert(nodep->size % BPS(bs) == 0);
     1198                assert(BPS(bs) % sizeof(fat_dentry_t) == 0);
    12291199
    12301200                /*
     
    12341204                 * the position pointer accordingly.
    12351205                 */
    1236                 bnum = (pos * sizeof(fat_dentry_t)) / bps;
    1237                 while (bnum < nodep->size / bps) {
    1238                         off_t o;
     1206                bnum = (pos * sizeof(fat_dentry_t)) / BPS(bs);
     1207                while (bnum < nodep->size / BPS(bs)) {
     1208                        aoff64_t o;
    12391209
    12401210                        rc = fat_block_get(&b, bs, nodep, bnum,
     
    12421212                        if (rc != EOK)
    12431213                                goto err;
    1244                         for (o = pos % (bps / sizeof(fat_dentry_t));
    1245                             o < bps / sizeof(fat_dentry_t);
     1214                        for (o = pos % (BPS(bs) / sizeof(fat_dentry_t));
     1215                            o < BPS(bs) / sizeof(fat_dentry_t);
    12461216                            o++, pos++) {
    12471217                                d = ((fat_dentry_t *)b->data) + o;
     
    12921262void fat_write(ipc_callid_t rid, ipc_call_t *request)
    12931263{
    1294         dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
    1295         fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    1296         off_t pos = (off_t)IPC_GET_ARG3(*request);
     1264        devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
     1265        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
     1266        aoff64_t pos =
     1267            (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request));
    12971268        fs_node_t *fn;
    12981269        fat_node_t *nodep;
     
    13001271        size_t bytes, size;
    13011272        block_t *b;
    1302         uint16_t bps;
    1303         unsigned spc;
    1304         unsigned bpc;           /* bytes per cluster */
    1305         off_t boundary;
     1273        aoff64_t boundary;
    13061274        int flags = BLOCK_FLAGS_NONE;
    13071275        int rc;
    13081276       
    1309         rc = fat_node_get(&fn, dev_handle, index);
     1277        rc = fat_node_get(&fn, devmap_handle, index);
    13101278        if (rc != EOK) {
    13111279                ipc_answer_0(rid, rc);
     
    13271295        }
    13281296
    1329         bs = block_bb_get(dev_handle);
    1330         bps = uint16_t_le2host(bs->bps);
    1331         spc = bs->spc;
    1332         bpc = bps * spc;
     1297        bs = block_bb_get(devmap_handle);
    13331298
    13341299        /*
     
    13391304         * value signalizing a smaller number of bytes written.
    13401305         */
    1341         bytes = min(len, bps - pos % bps);
    1342         if (bytes == bps)
     1306        bytes = min(len, BPS(bs) - pos % BPS(bs));
     1307        if (bytes == BPS(bs))
    13431308                flags |= BLOCK_FLAGS_NOREAD;
    13441309       
    1345         boundary = ROUND_UP(nodep->size, bpc);
     1310        boundary = ROUND_UP(nodep->size, BPC(bs));
    13461311        if (pos < boundary) {
    13471312                /*
     
    13581323                        return;
    13591324                }
    1360                 rc = fat_block_get(&b, bs, nodep, pos / bps, flags);
     1325                rc = fat_block_get(&b, bs, nodep, pos / BPS(bs), flags);
    13611326                if (rc != EOK) {
    13621327                        (void) fat_node_put(fn);
     
    13651330                        return;
    13661331                }
    1367                 (void) async_data_write_finalize(callid, b->data + pos % bps,
    1368                     bytes);
     1332                (void) async_data_write_finalize(callid,
     1333                    b->data + pos % BPS(bs), bytes);
    13691334                b->dirty = true;                /* need to sync block */
    13701335                rc = block_put(b);
     
    13901355                fat_cluster_t mcl, lcl;
    13911356 
    1392                 nclsts = (ROUND_UP(pos + bytes, bpc) - boundary) / bpc;
     1357                nclsts = (ROUND_UP(pos + bytes, BPC(bs)) - boundary) / BPC(bs);
    13931358                /* create an independent chain of nclsts clusters in all FATs */
    1394                 rc = fat_alloc_clusters(bs, dev_handle, nclsts, &mcl, &lcl);
     1359                rc = fat_alloc_clusters(bs, devmap_handle, nclsts, &mcl, &lcl);
    13951360                if (rc != EOK) {
    13961361                        /* could not allocate a chain of nclsts clusters */
     
    14031368                rc = fat_fill_gap(bs, nodep, mcl, pos);
    14041369                if (rc != EOK) {
    1405                         (void) fat_free_clusters(bs, dev_handle, mcl);
     1370                        (void) fat_free_clusters(bs, devmap_handle, mcl);
    14061371                        (void) fat_node_put(fn);
    14071372                        ipc_answer_0(callid, rc);
     
    14091374                        return;
    14101375                }
    1411                 rc = _fat_block_get(&b, bs, dev_handle, lcl, (pos / bps) % spc,
    1412                     flags);
     1376                rc = _fat_block_get(&b, bs, devmap_handle, lcl, NULL,
     1377                    (pos / BPS(bs)) % SPC(bs), flags);
    14131378                if (rc != EOK) {
    1414                         (void) fat_free_clusters(bs, dev_handle, mcl);
     1379                        (void) fat_free_clusters(bs, devmap_handle, mcl);
    14151380                        (void) fat_node_put(fn);
    14161381                        ipc_answer_0(callid, rc);
     
    14181383                        return;
    14191384                }
    1420                 (void) async_data_write_finalize(callid, b->data + pos % bps,
    1421                     bytes);
     1385                (void) async_data_write_finalize(callid,
     1386                    b->data + pos % BPS(bs), bytes);
    14221387                b->dirty = true;                /* need to sync block */
    14231388                rc = block_put(b);
    14241389                if (rc != EOK) {
    1425                         (void) fat_free_clusters(bs, dev_handle, mcl);
     1390                        (void) fat_free_clusters(bs, devmap_handle, mcl);
    14261391                        (void) fat_node_put(fn);
    14271392                        ipc_answer_0(rid, rc);
     
    14321397                 * node's cluster chain.
    14331398                 */
    1434                 rc = fat_append_clusters(bs, nodep, mcl);
     1399                rc = fat_append_clusters(bs, nodep, mcl, lcl);
    14351400                if (rc != EOK) {
    1436                         (void) fat_free_clusters(bs, dev_handle, mcl);
     1401                        (void) fat_free_clusters(bs, devmap_handle, mcl);
    14371402                        (void) fat_node_put(fn);
    14381403                        ipc_answer_0(rid, rc);
     
    14491414void fat_truncate(ipc_callid_t rid, ipc_call_t *request)
    14501415{
    1451         dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
    1452         fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    1453         size_t size = (off_t)IPC_GET_ARG3(*request);
     1416        devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
     1417        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
     1418        aoff64_t size =
     1419            (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request));
    14541420        fs_node_t *fn;
    14551421        fat_node_t *nodep;
    14561422        fat_bs_t *bs;
    1457         uint16_t bps;
    1458         uint8_t spc;
    1459         unsigned bpc;   /* bytes per cluster */
    14601423        int rc;
    14611424
    1462         rc = fat_node_get(&fn, dev_handle, index);
     1425        rc = fat_node_get(&fn, devmap_handle, index);
    14631426        if (rc != EOK) {
    14641427                ipc_answer_0(rid, rc);
     
    14711434        nodep = FAT_NODE(fn);
    14721435
    1473         bs = block_bb_get(dev_handle);
    1474         bps = uint16_t_le2host(bs->bps);
    1475         spc = bs->spc;
    1476         bpc = bps * spc;
     1436        bs = block_bb_get(devmap_handle);
    14771437
    14781438        if (nodep->size == size) {
     
    14841444                 */
    14851445                rc = EINVAL;
    1486         } else if (ROUND_UP(nodep->size, bpc) == ROUND_UP(size, bpc)) {
     1446        } else if (ROUND_UP(nodep->size, BPC(bs)) == ROUND_UP(size, BPC(bs))) {
    14871447                /*
    14881448                 * The node will be shrunk, but no clusters will be deallocated.
     
    15011461                } else {
    15021462                        fat_cluster_t lastc;
    1503                         rc = fat_cluster_walk(bs, dev_handle, nodep->firstc,
    1504                             &lastc, NULL, (size - 1) / bpc);
     1463                        rc = fat_cluster_walk(bs, devmap_handle, nodep->firstc,
     1464                            &lastc, NULL, (size - 1) / BPC(bs));
    15051465                        if (rc != EOK)
    15061466                                goto out;
     
    15261486void fat_destroy(ipc_callid_t rid, ipc_call_t *request)
    15271487{
    1528         dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
     1488        devmap_handle_t devmap_handle = (devmap_handle_t)IPC_GET_ARG1(*request);
    15291489        fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    15301490        fs_node_t *fn;
    15311491        int rc;
    15321492
    1533         rc = fat_node_get(&fn, dev_handle, index);
     1493        rc = fat_node_get(&fn, devmap_handle, index);
    15341494        if (rc != EOK) {
    15351495                ipc_answer_0(rid, rc);
     
    15571517void fat_sync(ipc_callid_t rid, ipc_call_t *request)
    15581518{
    1559         /* Dummy implementation */
    1560         ipc_answer_0(rid, EOK);
     1519        devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
     1520        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
     1521       
     1522        fs_node_t *fn;
     1523        int rc = fat_node_get(&fn, devmap_handle, index);
     1524        if (rc != EOK) {
     1525                ipc_answer_0(rid, rc);
     1526                return;
     1527        }
     1528        if (!fn) {
     1529                ipc_answer_0(rid, ENOENT);
     1530                return;
     1531        }
     1532       
     1533        fat_node_t *nodep = FAT_NODE(fn);
     1534       
     1535        nodep->dirty = true;
     1536        rc = fat_node_sync(nodep);
     1537       
     1538        fat_node_put(fn);
     1539        ipc_answer_0(rid, rc);
    15611540}
    15621541
Note: See TracChangeset for help on using the changeset viewer.