Ignore:
File:
1 edited

Legend:

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

    r991f645 r69a60c4  
    6060#define FS_NODE(node)   ((node) ? (node)->bp : NULL)
    6161
    62 #define DPS(bs)         (BPS((bs)) / sizeof(fat_dentry_t))
    63 #define BPC(bs)         (BPS((bs)) * SPC((bs)))
    64 
    6562/** Mutex protecting the list of cached free FAT nodes. */
    6663static FIBRIL_MUTEX_INITIALIZE(ffn_mutex);
     
    7269 * Forward declarations of FAT libfs operations.
    7370 */
    74 static int fat_root_get(fs_node_t **, devmap_handle_t);
     71static int fat_root_get(fs_node_t **, dev_handle_t);
    7572static int fat_match(fs_node_t **, fs_node_t *, const char *);
    76 static int fat_node_get(fs_node_t **, devmap_handle_t, fs_index_t);
     73static int fat_node_get(fs_node_t **, dev_handle_t, fs_index_t);
    7774static int fat_node_open(fs_node_t *);
    7875static int fat_node_put(fs_node_t *);
    79 static int fat_create_node(fs_node_t **, devmap_handle_t, int);
     76static int fat_create_node(fs_node_t **, dev_handle_t, int);
    8077static int fat_destroy_node(fs_node_t *);
    8178static int fat_link(fs_node_t *, fs_node_t *, const char *);
     
    8885static bool fat_is_directory(fs_node_t *);
    8986static bool fat_is_file(fs_node_t *node);
    90 static devmap_handle_t fat_device_get(fs_node_t *node);
     87static dev_handle_t fat_device_get(fs_node_t *node);
    9188
    9289/*
     
    104101        node->refcnt = 0;
    105102        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;
    111103}
    112104
     
    116108        fat_bs_t *bs;
    117109        fat_dentry_t *d;
     110        uint16_t bps;
     111        unsigned dps;
    118112        int rc;
    119113       
    120114        assert(node->dirty);
    121115
    122         bs = block_bb_get(node->idx->devmap_handle);
     116        bs = block_bb_get(node->idx->dev_handle);
     117        bps = uint16_t_le2host(bs->bps);
     118        dps = bps / sizeof(fat_dentry_t);
    123119       
    124120        /* Read the block that contains the dentry of interest. */
    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);
     121        rc = _fat_block_get(&b, bs, node->idx->dev_handle, node->idx->pfc,
     122            (node->idx->pdi * sizeof(fat_dentry_t)) / bps, BLOCK_FLAGS_NONE);
    128123        if (rc != EOK)
    129124                return rc;
    130125
    131         d = ((fat_dentry_t *)b->data) + (node->idx->pdi % DPS(bs));
     126        d = ((fat_dentry_t *)b->data) + (node->idx->pdi % dps);
    132127
    133128        d->firstc = host2uint16_t_le(node->firstc);
     
    145140}
    146141
    147 static int fat_node_fini_by_devmap_handle(devmap_handle_t devmap_handle)
     142static int fat_node_fini_by_dev_handle(dev_handle_t dev_handle)
    148143{
    149144        link_t *lnk;
     
    170165                        goto restart;
    171166                }
    172                 if (nodep->idx->devmap_handle != devmap_handle) {
     167                if (nodep->idx->dev_handle != dev_handle) {
    173168                        fibril_mutex_unlock(&nodep->idx->lock);
    174169                        fibril_mutex_unlock(&nodep->lock);
     
    271266        fat_dentry_t *d;
    272267        fat_node_t *nodep = NULL;
     268        unsigned bps;
     269        unsigned spc;
     270        unsigned dps;
    273271        int rc;
    274272
     
    299297                return rc;
    300298
    301         bs = block_bb_get(idxp->devmap_handle);
     299        bs = block_bb_get(idxp->dev_handle);
     300        bps = uint16_t_le2host(bs->bps);
     301        spc = bs->spc;
     302        dps = bps / sizeof(fat_dentry_t);
    302303
    303304        /* Read the block that contains the dentry of interest. */
    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);
     305        rc = _fat_block_get(&b, bs, idxp->dev_handle, idxp->pfc,
     306            (idxp->pdi * sizeof(fat_dentry_t)) / bps, BLOCK_FLAGS_NONE);
    306307        if (rc != EOK) {
    307308                (void) fat_node_put(FS_NODE(nodep));
     
    309310        }
    310311
    311         d = ((fat_dentry_t *)b->data) + (idxp->pdi % DPS(bs));
     312        d = ((fat_dentry_t *)b->data) + (idxp->pdi % dps);
    312313        if (d->attr & FAT_ATTR_SUBDIR) {
    313314                /*
     
    323324                 */
    324325                uint16_t clusters;
    325                 rc = fat_clusters_get(&clusters, bs, idxp->devmap_handle,
     326                rc = fat_clusters_get(&clusters, bs, idxp->dev_handle,
    326327                    uint16_t_le2host(d->firstc));
    327328                if (rc != EOK) {
     
    329330                        return rc;
    330331                }
    331                 nodep->size = BPS(bs) * SPC(bs) * clusters;
     332                nodep->size = bps * spc * clusters;
    332333        } else {
    333334                nodep->type = FAT_FILE;
     
    356357 */
    357358
    358 int fat_root_get(fs_node_t **rfn, devmap_handle_t devmap_handle)
    359 {
    360         return fat_node_get(rfn, devmap_handle, 0);
     359int fat_root_get(fs_node_t **rfn, dev_handle_t dev_handle)
     360{
     361        return fat_node_get(rfn, dev_handle, 0);
    361362}
    362363
     
    367368        char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1];
    368369        unsigned i, j;
     370        unsigned bps;           /* bytes per sector */
     371        unsigned dps;           /* dentries per sector */
    369372        unsigned blocks;
    370373        fat_dentry_t *d;
    371         devmap_handle_t devmap_handle;
    372374        block_t *b;
    373375        int rc;
    374376
    375377        fibril_mutex_lock(&parentp->idx->lock);
    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);
     378        bs = block_bb_get(parentp->idx->dev_handle);
     379        bps = uint16_t_le2host(bs->bps);
     380        dps = bps / sizeof(fat_dentry_t);
     381        blocks = parentp->size / bps;
    381382        for (i = 0; i < blocks; i++) {
    382383                rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE);
    383                 if (rc != EOK)
     384                if (rc != EOK) {
     385                        fibril_mutex_unlock(&parentp->idx->lock);
    384386                        return rc;
    385                 for (j = 0; j < DPS(bs); j++) {
     387                }
     388                for (j = 0; j < dps; j++) {
    386389                        d = ((fat_dentry_t *)b->data) + j;
    387390                        switch (fat_classify_dentry(d)) {
     
    392395                                /* miss */
    393396                                rc = block_put(b);
     397                                fibril_mutex_unlock(&parentp->idx->lock);
    394398                                *rfn = NULL;
    395399                                return rc;
     
    402406                                /* hit */
    403407                                fat_node_t *nodep;
    404                                 fat_idx_t *idx = fat_idx_get_by_pos(devmap_handle,
    405                                     parentp->firstc, i * DPS(bs) + j);
     408                                /*
     409                                 * Assume tree hierarchy for locking.  We
     410                                 * already have the parent and now we are going
     411                                 * to lock the child.  Never lock in the oposite
     412                                 * order.
     413                                 */
     414                                fat_idx_t *idx = fat_idx_get_by_pos(
     415                                    parentp->idx->dev_handle, parentp->firstc,
     416                                    i * dps + j);
     417                                fibril_mutex_unlock(&parentp->idx->lock);
    406418                                if (!idx) {
    407419                                        /*
     
    426438                }
    427439                rc = block_put(b);
    428                 if (rc != EOK)
     440                if (rc != EOK) {
     441                        fibril_mutex_unlock(&parentp->idx->lock);
    429442                        return rc;
    430         }
    431 
     443                }
     444        }
     445
     446        fibril_mutex_unlock(&parentp->idx->lock);
    432447        *rfn = NULL;
    433448        return EOK;
     
    435450
    436451/** Instantiate a FAT in-core node. */
    437 int fat_node_get(fs_node_t **rfn, devmap_handle_t devmap_handle, fs_index_t index)
     452int fat_node_get(fs_node_t **rfn, dev_handle_t dev_handle, fs_index_t index)
    438453{
    439454        fat_node_t *nodep;
     
    441456        int rc;
    442457
    443         idxp = fat_idx_get_by_index(devmap_handle, index);
     458        idxp = fat_idx_get_by_index(dev_handle, index);
    444459        if (!idxp) {
    445460                *rfn = NULL;
     
    492507}
    493508
    494 int fat_create_node(fs_node_t **rfn, devmap_handle_t devmap_handle, int flags)
     509int fat_create_node(fs_node_t **rfn, dev_handle_t dev_handle, int flags)
    495510{
    496511        fat_idx_t *idxp;
     
    498513        fat_bs_t *bs;
    499514        fat_cluster_t mcl, lcl;
     515        uint16_t bps;
    500516        int rc;
    501517
    502         bs = block_bb_get(devmap_handle);
     518        bs = block_bb_get(dev_handle);
     519        bps = uint16_t_le2host(bs->bps);
    503520        if (flags & L_DIRECTORY) {
    504521                /* allocate a cluster */
    505                 rc = fat_alloc_clusters(bs, devmap_handle, 1, &mcl, &lcl);
     522                rc = fat_alloc_clusters(bs, dev_handle, 1, &mcl, &lcl);
    506523                if (rc != EOK)
    507524                        return rc;
    508525                /* populate the new cluster with unused dentries */
    509                 rc = fat_zero_cluster(bs, devmap_handle, mcl);
    510                 if (rc != EOK) {
    511                         (void) fat_free_clusters(bs, devmap_handle, mcl);
     526                rc = fat_zero_cluster(bs, dev_handle, mcl);
     527                if (rc != EOK) {
     528                        (void) fat_free_clusters(bs, dev_handle, mcl);
    512529                        return rc;
    513530                }
     
    516533        rc = fat_node_get_new(&nodep);
    517534        if (rc != EOK) {
    518                 (void) fat_free_clusters(bs, devmap_handle, mcl);
     535                (void) fat_free_clusters(bs, dev_handle, mcl);
    519536                return rc;
    520537        }
    521         rc = fat_idx_get_new(&idxp, devmap_handle);
    522         if (rc != EOK) {
    523                 (void) fat_free_clusters(bs, devmap_handle, mcl);       
     538        rc = fat_idx_get_new(&idxp, dev_handle);
     539        if (rc != EOK) {
     540                (void) fat_free_clusters(bs, dev_handle, mcl); 
    524541                (void) fat_node_put(FS_NODE(nodep));
    525542                return rc;
     
    529546                nodep->type = FAT_DIRECTORY;
    530547                nodep->firstc = mcl;
    531                 nodep->size = BPS(bs) * SPC(bs);
     548                nodep->size = bps * bs->spc;
    532549        } else {
    533550                nodep->type = FAT_FILE;
     
    570587        assert(!has_children);
    571588
    572         bs = block_bb_get(nodep->idx->devmap_handle);
     589        bs = block_bb_get(nodep->idx->dev_handle);
    573590        if (nodep->firstc != FAT_CLST_RES0) {
    574591                assert(nodep->size);
    575592                /* Free all clusters allocated to the node. */
    576                 rc = fat_free_clusters(bs, nodep->idx->devmap_handle,
     593                rc = fat_free_clusters(bs, nodep->idx->dev_handle,
    577594                    nodep->firstc);
    578595        }
     
    592609        block_t *b;
    593610        unsigned i, j;
     611        uint16_t bps;
     612        unsigned dps;
    594613        unsigned blocks;
    595614        fat_cluster_t mcl, lcl;
     
    620639       
    621640        fibril_mutex_lock(&parentp->idx->lock);
    622         bs = block_bb_get(parentp->idx->devmap_handle);
    623 
    624         blocks = parentp->size / BPS(bs);
     641        bs = block_bb_get(parentp->idx->dev_handle);
     642        bps = uint16_t_le2host(bs->bps);
     643        dps = bps / sizeof(fat_dentry_t);
     644
     645        blocks = parentp->size / bps;
    625646
    626647        for (i = 0; i < blocks; i++) {
     
    630651                        return rc;
    631652                }
    632                 for (j = 0; j < DPS(bs); j++) {
     653                for (j = 0; j < dps; j++) {
    633654                        d = ((fat_dentry_t *)b->data) + j;
    634655                        switch (fat_classify_dentry(d)) {
     
    659680                return ENOSPC;
    660681        }
    661         rc = fat_alloc_clusters(bs, parentp->idx->devmap_handle, 1, &mcl, &lcl);
     682        rc = fat_alloc_clusters(bs, parentp->idx->dev_handle, 1, &mcl, &lcl);
    662683        if (rc != EOK) {
    663684                fibril_mutex_unlock(&parentp->idx->lock);
    664685                return rc;
    665686        }
    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);
     687        rc = fat_zero_cluster(bs, parentp->idx->dev_handle, mcl);
     688        if (rc != EOK) {
     689                (void) fat_free_clusters(bs, parentp->idx->dev_handle, mcl);
    669690                fibril_mutex_unlock(&parentp->idx->lock);
    670691                return rc;
    671692        }
    672         rc = fat_append_clusters(bs, parentp, mcl, lcl);
    673         if (rc != EOK) {
    674                 (void) fat_free_clusters(bs, parentp->idx->devmap_handle, mcl);
     693        rc = fat_append_clusters(bs, parentp, mcl);
     694        if (rc != EOK) {
     695                (void) fat_free_clusters(bs, parentp->idx->dev_handle, mcl);
    675696                fibril_mutex_unlock(&parentp->idx->lock);
    676697                return rc;
    677698        }
    678         parentp->size += BPS(bs) * SPC(bs);
     699        parentp->size += bps * bs->spc;
    679700        parentp->dirty = true;          /* need to sync node */
    680701        rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE);
     
    750771
    751772        childp->idx->pfc = parentp->firstc;
    752         childp->idx->pdi = i * DPS(bs) + j;
     773        childp->idx->pdi = i * dps + j;
    753774        fibril_mutex_unlock(&childp->idx->lock);
    754775
     
    772793        fat_bs_t *bs;
    773794        fat_dentry_t *d;
     795        uint16_t bps;
    774796        block_t *b;
    775797        bool has_children;
     
    789811        assert(childp->lnkcnt == 1);
    790812        fibril_mutex_lock(&childp->idx->lock);
    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),
     813        bs = block_bb_get(childp->idx->dev_handle);
     814        bps = uint16_t_le2host(bs->bps);
     815
     816        rc = _fat_block_get(&b, bs, childp->idx->dev_handle, childp->idx->pfc,
     817            (childp->idx->pdi * sizeof(fat_dentry_t)) / bps,
    795818            BLOCK_FLAGS_NONE);
    796819        if (rc != EOK)
    797820                goto error;
    798821        d = (fat_dentry_t *)b->data +
    799             (childp->idx->pdi % (BPS(bs) / sizeof(fat_dentry_t)));
     822            (childp->idx->pdi % (bps / sizeof(fat_dentry_t)));
    800823        /* mark the dentry as not-currently-used */
    801824        d->name[0] = FAT_DENTRY_ERASED;
     
    829852        fat_bs_t *bs;
    830853        fat_node_t *nodep = FAT_NODE(fn);
     854        unsigned bps;
     855        unsigned dps;
    831856        unsigned blocks;
    832857        block_t *b;
     
    840865       
    841866        fibril_mutex_lock(&nodep->idx->lock);
    842         bs = block_bb_get(nodep->idx->devmap_handle);
    843 
    844         blocks = nodep->size / BPS(bs);
     867        bs = block_bb_get(nodep->idx->dev_handle);
     868        bps = uint16_t_le2host(bs->bps);
     869        dps = bps / sizeof(fat_dentry_t);
     870
     871        blocks = nodep->size / bps;
    845872
    846873        for (i = 0; i < blocks; i++) {
     
    852879                        return rc;
    853880                }
    854                 for (j = 0; j < DPS(bs); j++) {
     881                for (j = 0; j < dps; j++) {
    855882                        d = ((fat_dentry_t *)b->data) + j;
    856883                        switch (fat_classify_dentry(d)) {
     
    914941}
    915942
    916 devmap_handle_t fat_device_get(fs_node_t *node)
     943dev_handle_t fat_device_get(fs_node_t *node)
    917944{
    918945        return 0;
     
    946973void fat_mounted(ipc_callid_t rid, ipc_call_t *request)
    947974{
    948         devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
     975        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
    949976        enum cache_mode cmode;
    950977        fat_bs_t *bs;
     978        uint16_t bps;
     979        uint16_t rde;
    951980       
    952981        /* Accept the mount options */
     
    968997
    969998        /* initialize libblock */
    970         rc = block_init(devmap_handle, BS_SIZE);
     999        rc = block_init(dev_handle, BS_SIZE);
    9711000        if (rc != EOK) {
    9721001                ipc_answer_0(rid, rc);
     
    9751004
    9761005        /* prepare the boot block */
    977         rc = block_bb_read(devmap_handle, BS_BLOCK);
    978         if (rc != EOK) {
    979                 block_fini(devmap_handle);
     1006        rc = block_bb_read(dev_handle, BS_BLOCK);
     1007        if (rc != EOK) {
     1008                block_fini(dev_handle);
    9801009                ipc_answer_0(rid, rc);
    9811010                return;
     
    9831012
    9841013        /* get the buffer with the boot sector */
    985         bs = block_bb_get(devmap_handle);
    986        
    987         if (BPS(bs) != BS_SIZE) {
    988                 block_fini(devmap_handle);
     1014        bs = block_bb_get(dev_handle);
     1015       
     1016        /* Read the number of root directory entries. */
     1017        bps = uint16_t_le2host(bs->bps);
     1018        rde = uint16_t_le2host(bs->root_ent_max);
     1019
     1020        if (bps != BS_SIZE) {
     1021                block_fini(dev_handle);
    9891022                ipc_answer_0(rid, ENOTSUP);
    9901023                return;
     
    9921025
    9931026        /* Initialize the block cache */
    994         rc = block_cache_init(devmap_handle, BPS(bs), 0 /* XXX */, cmode);
    995         if (rc != EOK) {
    996                 block_fini(devmap_handle);
     1027        rc = block_cache_init(dev_handle, bps, 0 /* XXX */, cmode);
     1028        if (rc != EOK) {
     1029                block_fini(dev_handle);
    9971030                ipc_answer_0(rid, rc);
    9981031                return;
     
    10001033
    10011034        /* Do some simple sanity checks on the file system. */
    1002         rc = fat_sanity_check(bs, devmap_handle);
    1003         if (rc != EOK) {
    1004                 (void) block_cache_fini(devmap_handle);
    1005                 block_fini(devmap_handle);
     1035        rc = fat_sanity_check(bs, dev_handle);
     1036        if (rc != EOK) {
     1037                (void) block_cache_fini(dev_handle);
     1038                block_fini(dev_handle);
    10061039                ipc_answer_0(rid, rc);
    10071040                return;
    10081041        }
    10091042
    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);
     1043        rc = fat_idx_init_by_dev_handle(dev_handle);
     1044        if (rc != EOK) {
     1045                (void) block_cache_fini(dev_handle);
     1046                block_fini(dev_handle);
    10141047                ipc_answer_0(rid, rc);
    10151048                return;
     
    10191052        fs_node_t *rfn = (fs_node_t *)malloc(sizeof(fs_node_t));
    10201053        if (!rfn) {
    1021                 (void) block_cache_fini(devmap_handle);
    1022                 block_fini(devmap_handle);
    1023                 fat_idx_fini_by_devmap_handle(devmap_handle);
     1054                (void) block_cache_fini(dev_handle);
     1055                block_fini(dev_handle);
     1056                fat_idx_fini_by_dev_handle(dev_handle);
    10241057                ipc_answer_0(rid, ENOMEM);
    10251058                return;
     
    10291062        if (!rootp) {
    10301063                free(rfn);
    1031                 (void) block_cache_fini(devmap_handle);
    1032                 block_fini(devmap_handle);
    1033                 fat_idx_fini_by_devmap_handle(devmap_handle);
     1064                (void) block_cache_fini(dev_handle);
     1065                block_fini(dev_handle);
     1066                fat_idx_fini_by_dev_handle(dev_handle);
    10341067                ipc_answer_0(rid, ENOMEM);
    10351068                return;
     
    10371070        fat_node_initialize(rootp);
    10381071
    1039         fat_idx_t *ridxp = fat_idx_get_by_pos(devmap_handle, FAT_CLST_ROOTPAR, 0);
     1072        fat_idx_t *ridxp = fat_idx_get_by_pos(dev_handle, FAT_CLST_ROOTPAR, 0);
    10401073        if (!ridxp) {
    10411074                free(rfn);
    10421075                free(rootp);
    1043                 (void) block_cache_fini(devmap_handle);
    1044                 block_fini(devmap_handle);
    1045                 fat_idx_fini_by_devmap_handle(devmap_handle);
     1076                (void) block_cache_fini(dev_handle);
     1077                block_fini(dev_handle);
     1078                fat_idx_fini_by_dev_handle(dev_handle);
    10461079                ipc_answer_0(rid, ENOMEM);
    10471080                return;
     
    10541087        rootp->refcnt = 1;
    10551088        rootp->lnkcnt = 0;      /* FS root is not linked */
    1056         rootp->size = RDE(bs) * sizeof(fat_dentry_t);
     1089        rootp->size = rde * sizeof(fat_dentry_t);
    10571090        rootp->idx = ridxp;
    10581091        ridxp->nodep = rootp;
     
    10721105void fat_unmounted(ipc_callid_t rid, ipc_call_t *request)
    10731106{
    1074         devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
     1107        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
    10751108        fs_node_t *fn;
    10761109        fat_node_t *nodep;
    10771110        int rc;
    10781111
    1079         rc = fat_root_get(&fn, devmap_handle);
     1112        rc = fat_root_get(&fn, dev_handle);
    10801113        if (rc != EOK) {
    10811114                ipc_answer_0(rid, rc);
     
    11051138         * stop using libblock for this instance.
    11061139         */
    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);
     1140        (void) fat_node_fini_by_dev_handle(dev_handle);
     1141        fat_idx_fini_by_dev_handle(dev_handle);
     1142        (void) block_cache_fini(dev_handle);
     1143        block_fini(dev_handle);
    11111144
    11121145        ipc_answer_0(rid, EOK);
     
    11251158void fat_read(ipc_callid_t rid, ipc_call_t *request)
    11261159{
    1127         devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
     1160        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
    11281161        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
    11291162        aoff64_t pos =
     
    11321165        fat_node_t *nodep;
    11331166        fat_bs_t *bs;
     1167        uint16_t bps;
    11341168        size_t bytes;
    11351169        block_t *b;
    11361170        int rc;
    11371171
    1138         rc = fat_node_get(&fn, devmap_handle, index);
     1172        rc = fat_node_get(&fn, dev_handle, index);
    11391173        if (rc != EOK) {
    11401174                ipc_answer_0(rid, rc);
     
    11561190        }
    11571191
    1158         bs = block_bb_get(devmap_handle);
     1192        bs = block_bb_get(dev_handle);
     1193        bps = uint16_t_le2host(bs->bps);
    11591194
    11601195        if (nodep->type == FAT_FILE) {
     
    11691204                        (void) async_data_read_finalize(callid, NULL, 0);
    11701205                } else {
    1171                         bytes = min(len, BPS(bs) - pos % BPS(bs));
     1206                        bytes = min(len, bps - pos % bps);
    11721207                        bytes = min(bytes, nodep->size - pos);
    1173                         rc = fat_block_get(&b, bs, nodep, pos / BPS(bs),
     1208                        rc = fat_block_get(&b, bs, nodep, pos / bps,
    11741209                            BLOCK_FLAGS_NONE);
    11751210                        if (rc != EOK) {
     
    11791214                                return;
    11801215                        }
    1181                         (void) async_data_read_finalize(callid,
    1182                             b->data + pos % BPS(bs), bytes);
     1216                        (void) async_data_read_finalize(callid, b->data + pos % bps,
     1217                            bytes);
    11831218                        rc = block_put(b);
    11841219                        if (rc != EOK) {
     
    11951230
    11961231                assert(nodep->type == FAT_DIRECTORY);
    1197                 assert(nodep->size % BPS(bs) == 0);
    1198                 assert(BPS(bs) % sizeof(fat_dentry_t) == 0);
     1232                assert(nodep->size % bps == 0);
     1233                assert(bps % sizeof(fat_dentry_t) == 0);
    11991234
    12001235                /*
     
    12041239                 * the position pointer accordingly.
    12051240                 */
    1206                 bnum = (pos * sizeof(fat_dentry_t)) / BPS(bs);
    1207                 while (bnum < nodep->size / BPS(bs)) {
     1241                bnum = (pos * sizeof(fat_dentry_t)) / bps;
     1242                while (bnum < nodep->size / bps) {
    12081243                        aoff64_t o;
    12091244
     
    12121247                        if (rc != EOK)
    12131248                                goto err;
    1214                         for (o = pos % (BPS(bs) / sizeof(fat_dentry_t));
    1215                             o < BPS(bs) / sizeof(fat_dentry_t);
     1249                        for (o = pos % (bps / sizeof(fat_dentry_t));
     1250                            o < bps / sizeof(fat_dentry_t);
    12161251                            o++, pos++) {
    12171252                                d = ((fat_dentry_t *)b->data) + o;
     
    12621297void fat_write(ipc_callid_t rid, ipc_call_t *request)
    12631298{
    1264         devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
     1299        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
    12651300        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
    12661301        aoff64_t pos =
     
    12711306        size_t bytes, size;
    12721307        block_t *b;
     1308        uint16_t bps;
     1309        unsigned spc;
     1310        unsigned bpc;           /* bytes per cluster */
    12731311        aoff64_t boundary;
    12741312        int flags = BLOCK_FLAGS_NONE;
    12751313        int rc;
    12761314       
    1277         rc = fat_node_get(&fn, devmap_handle, index);
     1315        rc = fat_node_get(&fn, dev_handle, index);
    12781316        if (rc != EOK) {
    12791317                ipc_answer_0(rid, rc);
     
    12951333        }
    12961334
    1297         bs = block_bb_get(devmap_handle);
     1335        bs = block_bb_get(dev_handle);
     1336        bps = uint16_t_le2host(bs->bps);
     1337        spc = bs->spc;
     1338        bpc = bps * spc;
    12981339
    12991340        /*
     
    13041345         * value signalizing a smaller number of bytes written.
    13051346         */
    1306         bytes = min(len, BPS(bs) - pos % BPS(bs));
    1307         if (bytes == BPS(bs))
     1347        bytes = min(len, bps - pos % bps);
     1348        if (bytes == bps)
    13081349                flags |= BLOCK_FLAGS_NOREAD;
    13091350       
    1310         boundary = ROUND_UP(nodep->size, BPC(bs));
     1351        boundary = ROUND_UP(nodep->size, bpc);
    13111352        if (pos < boundary) {
    13121353                /*
     
    13231364                        return;
    13241365                }
    1325                 rc = fat_block_get(&b, bs, nodep, pos / BPS(bs), flags);
     1366                rc = fat_block_get(&b, bs, nodep, pos / bps, flags);
    13261367                if (rc != EOK) {
    13271368                        (void) fat_node_put(fn);
     
    13301371                        return;
    13311372                }
    1332                 (void) async_data_write_finalize(callid,
    1333                     b->data + pos % BPS(bs), bytes);
     1373                (void) async_data_write_finalize(callid, b->data + pos % bps,
     1374                    bytes);
    13341375                b->dirty = true;                /* need to sync block */
    13351376                rc = block_put(b);
     
    13551396                fat_cluster_t mcl, lcl;
    13561397 
    1357                 nclsts = (ROUND_UP(pos + bytes, BPC(bs)) - boundary) / BPC(bs);
     1398                nclsts = (ROUND_UP(pos + bytes, bpc) - boundary) / bpc;
    13581399                /* create an independent chain of nclsts clusters in all FATs */
    1359                 rc = fat_alloc_clusters(bs, devmap_handle, nclsts, &mcl, &lcl);
     1400                rc = fat_alloc_clusters(bs, dev_handle, nclsts, &mcl, &lcl);
    13601401                if (rc != EOK) {
    13611402                        /* could not allocate a chain of nclsts clusters */
     
    13681409                rc = fat_fill_gap(bs, nodep, mcl, pos);
    13691410                if (rc != EOK) {
    1370                         (void) fat_free_clusters(bs, devmap_handle, mcl);
     1411                        (void) fat_free_clusters(bs, dev_handle, mcl);
    13711412                        (void) fat_node_put(fn);
    13721413                        ipc_answer_0(callid, rc);
     
    13741415                        return;
    13751416                }
    1376                 rc = _fat_block_get(&b, bs, devmap_handle, lcl, NULL,
    1377                     (pos / BPS(bs)) % SPC(bs), flags);
    1378                 if (rc != EOK) {
    1379                         (void) fat_free_clusters(bs, devmap_handle, mcl);
     1417                rc = _fat_block_get(&b, bs, dev_handle, lcl, (pos / bps) % spc,
     1418                    flags);
     1419                if (rc != EOK) {
     1420                        (void) fat_free_clusters(bs, dev_handle, mcl);
    13801421                        (void) fat_node_put(fn);
    13811422                        ipc_answer_0(callid, rc);
     
    13831424                        return;
    13841425                }
    1385                 (void) async_data_write_finalize(callid,
    1386                     b->data + pos % BPS(bs), bytes);
     1426                (void) async_data_write_finalize(callid, b->data + pos % bps,
     1427                    bytes);
    13871428                b->dirty = true;                /* need to sync block */
    13881429                rc = block_put(b);
    13891430                if (rc != EOK) {
    1390                         (void) fat_free_clusters(bs, devmap_handle, mcl);
     1431                        (void) fat_free_clusters(bs, dev_handle, mcl);
    13911432                        (void) fat_node_put(fn);
    13921433                        ipc_answer_0(rid, rc);
     
    13971438                 * node's cluster chain.
    13981439                 */
    1399                 rc = fat_append_clusters(bs, nodep, mcl, lcl);
    1400                 if (rc != EOK) {
    1401                         (void) fat_free_clusters(bs, devmap_handle, mcl);
     1440                rc = fat_append_clusters(bs, nodep, mcl);
     1441                if (rc != EOK) {
     1442                        (void) fat_free_clusters(bs, dev_handle, mcl);
    14021443                        (void) fat_node_put(fn);
    14031444                        ipc_answer_0(rid, rc);
     
    14141455void fat_truncate(ipc_callid_t rid, ipc_call_t *request)
    14151456{
    1416         devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
     1457        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
    14171458        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
    14181459        aoff64_t size =
     
    14211462        fat_node_t *nodep;
    14221463        fat_bs_t *bs;
     1464        uint16_t bps;
     1465        uint8_t spc;
     1466        unsigned bpc;   /* bytes per cluster */
    14231467        int rc;
    14241468
    1425         rc = fat_node_get(&fn, devmap_handle, index);
     1469        rc = fat_node_get(&fn, dev_handle, index);
    14261470        if (rc != EOK) {
    14271471                ipc_answer_0(rid, rc);
     
    14341478        nodep = FAT_NODE(fn);
    14351479
    1436         bs = block_bb_get(devmap_handle);
     1480        bs = block_bb_get(dev_handle);
     1481        bps = uint16_t_le2host(bs->bps);
     1482        spc = bs->spc;
     1483        bpc = bps * spc;
    14371484
    14381485        if (nodep->size == size) {
     
    14441491                 */
    14451492                rc = EINVAL;
    1446         } else if (ROUND_UP(nodep->size, BPC(bs)) == ROUND_UP(size, BPC(bs))) {
     1493        } else if (ROUND_UP(nodep->size, bpc) == ROUND_UP(size, bpc)) {
    14471494                /*
    14481495                 * The node will be shrunk, but no clusters will be deallocated.
     
    14611508                } else {
    14621509                        fat_cluster_t lastc;
    1463                         rc = fat_cluster_walk(bs, devmap_handle, nodep->firstc,
    1464                             &lastc, NULL, (size - 1) / BPC(bs));
     1510                        rc = fat_cluster_walk(bs, dev_handle, nodep->firstc,
     1511                            &lastc, NULL, (size - 1) / bpc);
    14651512                        if (rc != EOK)
    14661513                                goto out;
     
    14861533void fat_destroy(ipc_callid_t rid, ipc_call_t *request)
    14871534{
    1488         devmap_handle_t devmap_handle = (devmap_handle_t)IPC_GET_ARG1(*request);
     1535        dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
    14891536        fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    14901537        fs_node_t *fn;
    14911538        int rc;
    14921539
    1493         rc = fat_node_get(&fn, devmap_handle, index);
     1540        rc = fat_node_get(&fn, dev_handle, index);
    14941541        if (rc != EOK) {
    14951542                ipc_answer_0(rid, rc);
     
    15171564void fat_sync(ipc_callid_t rid, ipc_call_t *request)
    15181565{
    1519         devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
     1566        dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
    15201567        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
    15211568       
    15221569        fs_node_t *fn;
    1523         int rc = fat_node_get(&fn, devmap_handle, index);
     1570        int rc = fat_node_get(&fn, dev_handle, index);
    15241571        if (rc != EOK) {
    15251572                ipc_answer_0(rid, rc);
Note: See TracChangeset for help on using the changeset viewer.