Ignore:
File:
1 edited

Legend:

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

    r69a60c4 r991f645  
    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
    6265/** Mutex protecting the list of cached free FAT nodes. */
    6366static FIBRIL_MUTEX_INITIALIZE(ffn_mutex);
     
    6972 * Forward declarations of FAT libfs operations.
    7073 */
    71 static int fat_root_get(fs_node_t **, dev_handle_t);
     74static int fat_root_get(fs_node_t **, devmap_handle_t);
    7275static int fat_match(fs_node_t **, fs_node_t *, const char *);
    73 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);
    7477static int fat_node_open(fs_node_t *);
    7578static int fat_node_put(fs_node_t *);
    76 static int fat_create_node(fs_node_t **, dev_handle_t, int);
     79static int fat_create_node(fs_node_t **, devmap_handle_t, int);
    7780static int fat_destroy_node(fs_node_t *);
    7881static int fat_link(fs_node_t *, fs_node_t *, const char *);
     
    8588static bool fat_is_directory(fs_node_t *);
    8689static bool fat_is_file(fs_node_t *node);
    87 static dev_handle_t fat_device_get(fs_node_t *node);
     90static devmap_handle_t fat_device_get(fs_node_t *node);
    8891
    8992/*
     
    101104        node->refcnt = 0;
    102105        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;
    103111}
    104112
     
    108116        fat_bs_t *bs;
    109117        fat_dentry_t *d;
    110         uint16_t bps;
    111         unsigned dps;
    112118        int rc;
    113119       
    114120        assert(node->dirty);
    115121
    116         bs = block_bb_get(node->idx->dev_handle);
    117         bps = uint16_t_le2host(bs->bps);
    118         dps = bps / sizeof(fat_dentry_t);
     122        bs = block_bb_get(node->idx->devmap_handle);
    119123       
    120124        /* Read the block that contains the dentry of interest. */
    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);
     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);
    123128        if (rc != EOK)
    124129                return rc;
    125130
    126         d = ((fat_dentry_t *)b->data) + (node->idx->pdi % dps);
     131        d = ((fat_dentry_t *)b->data) + (node->idx->pdi % DPS(bs));
    127132
    128133        d->firstc = host2uint16_t_le(node->firstc);
     
    140145}
    141146
    142 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)
    143148{
    144149        link_t *lnk;
     
    165170                        goto restart;
    166171                }
    167                 if (nodep->idx->dev_handle != dev_handle) {
     172                if (nodep->idx->devmap_handle != devmap_handle) {
    168173                        fibril_mutex_unlock(&nodep->idx->lock);
    169174                        fibril_mutex_unlock(&nodep->lock);
     
    266271        fat_dentry_t *d;
    267272        fat_node_t *nodep = NULL;
    268         unsigned bps;
    269         unsigned spc;
    270         unsigned dps;
    271273        int rc;
    272274
     
    297299                return rc;
    298300
    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);
     301        bs = block_bb_get(idxp->devmap_handle);
    303302
    304303        /* Read the block that contains the dentry of interest. */
    305         rc = _fat_block_get(&b, bs, idxp->dev_handle, idxp->pfc,
    306             (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);
    307306        if (rc != EOK) {
    308307                (void) fat_node_put(FS_NODE(nodep));
     
    310309        }
    311310
    312         d = ((fat_dentry_t *)b->data) + (idxp->pdi % dps);
     311        d = ((fat_dentry_t *)b->data) + (idxp->pdi % DPS(bs));
    313312        if (d->attr & FAT_ATTR_SUBDIR) {
    314313                /*
     
    324323                 */
    325324                uint16_t clusters;
    326                 rc = fat_clusters_get(&clusters, bs, idxp->dev_handle,
     325                rc = fat_clusters_get(&clusters, bs, idxp->devmap_handle,
    327326                    uint16_t_le2host(d->firstc));
    328327                if (rc != EOK) {
     
    330329                        return rc;
    331330                }
    332                 nodep->size = bps * spc * clusters;
     331                nodep->size = BPS(bs) * SPC(bs) * clusters;
    333332        } else {
    334333                nodep->type = FAT_FILE;
     
    357356 */
    358357
    359 int fat_root_get(fs_node_t **rfn, dev_handle_t dev_handle)
    360 {
    361         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);
    362361}
    363362
     
    368367        char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1];
    369368        unsigned i, j;
    370         unsigned bps;           /* bytes per sector */
    371         unsigned dps;           /* dentries per sector */
    372369        unsigned blocks;
    373370        fat_dentry_t *d;
     371        devmap_handle_t devmap_handle;
    374372        block_t *b;
    375373        int rc;
    376374
    377375        fibril_mutex_lock(&parentp->idx->lock);
    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;
     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);
    382381        for (i = 0; i < blocks; i++) {
    383382                rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE);
    384                 if (rc != EOK) {
    385                         fibril_mutex_unlock(&parentp->idx->lock);
     383                if (rc != EOK)
    386384                        return rc;
    387                 }
    388                 for (j = 0; j < dps; j++) {
     385                for (j = 0; j < DPS(bs); j++) {
    389386                        d = ((fat_dentry_t *)b->data) + j;
    390387                        switch (fat_classify_dentry(d)) {
     
    395392                                /* miss */
    396393                                rc = block_put(b);
    397                                 fibril_mutex_unlock(&parentp->idx->lock);
    398394                                *rfn = NULL;
    399395                                return rc;
     
    406402                                /* hit */
    407403                                fat_node_t *nodep;
    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);
     404                                fat_idx_t *idx = fat_idx_get_by_pos(devmap_handle,
     405                                    parentp->firstc, i * DPS(bs) + j);
    418406                                if (!idx) {
    419407                                        /*
     
    438426                }
    439427                rc = block_put(b);
    440                 if (rc != EOK) {
    441                         fibril_mutex_unlock(&parentp->idx->lock);
     428                if (rc != EOK)
    442429                        return rc;
    443                 }
    444         }
    445 
    446         fibril_mutex_unlock(&parentp->idx->lock);
     430        }
     431
    447432        *rfn = NULL;
    448433        return EOK;
     
    450435
    451436/** Instantiate a FAT in-core node. */
    452 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)
    453438{
    454439        fat_node_t *nodep;
     
    456441        int rc;
    457442
    458         idxp = fat_idx_get_by_index(dev_handle, index);
     443        idxp = fat_idx_get_by_index(devmap_handle, index);
    459444        if (!idxp) {
    460445                *rfn = NULL;
     
    507492}
    508493
    509 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)
    510495{
    511496        fat_idx_t *idxp;
     
    513498        fat_bs_t *bs;
    514499        fat_cluster_t mcl, lcl;
    515         uint16_t bps;
    516500        int rc;
    517501
    518         bs = block_bb_get(dev_handle);
    519         bps = uint16_t_le2host(bs->bps);
     502        bs = block_bb_get(devmap_handle);
    520503        if (flags & L_DIRECTORY) {
    521504                /* allocate a cluster */
    522                 rc = fat_alloc_clusters(bs, dev_handle, 1, &mcl, &lcl);
     505                rc = fat_alloc_clusters(bs, devmap_handle, 1, &mcl, &lcl);
    523506                if (rc != EOK)
    524507                        return rc;
    525508                /* populate the new cluster with unused dentries */
    526                 rc = fat_zero_cluster(bs, dev_handle, mcl);
     509                rc = fat_zero_cluster(bs, devmap_handle, mcl);
    527510                if (rc != EOK) {
    528                         (void) fat_free_clusters(bs, dev_handle, mcl);
     511                        (void) fat_free_clusters(bs, devmap_handle, mcl);
    529512                        return rc;
    530513                }
     
    533516        rc = fat_node_get_new(&nodep);
    534517        if (rc != EOK) {
    535                 (void) fat_free_clusters(bs, dev_handle, mcl);
     518                (void) fat_free_clusters(bs, devmap_handle, mcl);
    536519                return rc;
    537520        }
    538         rc = fat_idx_get_new(&idxp, dev_handle);
    539         if (rc != EOK) {
    540                 (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);       
    541524                (void) fat_node_put(FS_NODE(nodep));
    542525                return rc;
     
    546529                nodep->type = FAT_DIRECTORY;
    547530                nodep->firstc = mcl;
    548                 nodep->size = bps * bs->spc;
     531                nodep->size = BPS(bs) * SPC(bs);
    549532        } else {
    550533                nodep->type = FAT_FILE;
     
    587570        assert(!has_children);
    588571
    589         bs = block_bb_get(nodep->idx->dev_handle);
     572        bs = block_bb_get(nodep->idx->devmap_handle);
    590573        if (nodep->firstc != FAT_CLST_RES0) {
    591574                assert(nodep->size);
    592575                /* Free all clusters allocated to the node. */
    593                 rc = fat_free_clusters(bs, nodep->idx->dev_handle,
     576                rc = fat_free_clusters(bs, nodep->idx->devmap_handle,
    594577                    nodep->firstc);
    595578        }
     
    609592        block_t *b;
    610593        unsigned i, j;
    611         uint16_t bps;
    612         unsigned dps;
    613594        unsigned blocks;
    614595        fat_cluster_t mcl, lcl;
     
    639620       
    640621        fibril_mutex_lock(&parentp->idx->lock);
    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;
     622        bs = block_bb_get(parentp->idx->devmap_handle);
     623
     624        blocks = parentp->size / BPS(bs);
    646625
    647626        for (i = 0; i < blocks; i++) {
     
    651630                        return rc;
    652631                }
    653                 for (j = 0; j < dps; j++) {
     632                for (j = 0; j < DPS(bs); j++) {
    654633                        d = ((fat_dentry_t *)b->data) + j;
    655634                        switch (fat_classify_dentry(d)) {
     
    680659                return ENOSPC;
    681660        }
    682         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);
    683662        if (rc != EOK) {
    684663                fibril_mutex_unlock(&parentp->idx->lock);
    685664                return rc;
    686665        }
    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);
     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);
    690669                fibril_mutex_unlock(&parentp->idx->lock);
    691670                return rc;
    692671        }
    693         rc = fat_append_clusters(bs, parentp, mcl);
    694         if (rc != EOK) {
    695                 (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);
    696675                fibril_mutex_unlock(&parentp->idx->lock);
    697676                return rc;
    698677        }
    699         parentp->size += bps * bs->spc;
     678        parentp->size += BPS(bs) * SPC(bs);
    700679        parentp->dirty = true;          /* need to sync node */
    701680        rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE);
     
    771750
    772751        childp->idx->pfc = parentp->firstc;
    773         childp->idx->pdi = i * dps + j;
     752        childp->idx->pdi = i * DPS(bs) + j;
    774753        fibril_mutex_unlock(&childp->idx->lock);
    775754
     
    793772        fat_bs_t *bs;
    794773        fat_dentry_t *d;
    795         uint16_t bps;
    796774        block_t *b;
    797775        bool has_children;
     
    811789        assert(childp->lnkcnt == 1);
    812790        fibril_mutex_lock(&childp->idx->lock);
    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,
     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),
    818795            BLOCK_FLAGS_NONE);
    819796        if (rc != EOK)
    820797                goto error;
    821798        d = (fat_dentry_t *)b->data +
    822             (childp->idx->pdi % (bps / sizeof(fat_dentry_t)));
     799            (childp->idx->pdi % (BPS(bs) / sizeof(fat_dentry_t)));
    823800        /* mark the dentry as not-currently-used */
    824801        d->name[0] = FAT_DENTRY_ERASED;
     
    852829        fat_bs_t *bs;
    853830        fat_node_t *nodep = FAT_NODE(fn);
    854         unsigned bps;
    855         unsigned dps;
    856831        unsigned blocks;
    857832        block_t *b;
     
    865840       
    866841        fibril_mutex_lock(&nodep->idx->lock);
    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;
     842        bs = block_bb_get(nodep->idx->devmap_handle);
     843
     844        blocks = nodep->size / BPS(bs);
    872845
    873846        for (i = 0; i < blocks; i++) {
     
    879852                        return rc;
    880853                }
    881                 for (j = 0; j < dps; j++) {
     854                for (j = 0; j < DPS(bs); j++) {
    882855                        d = ((fat_dentry_t *)b->data) + j;
    883856                        switch (fat_classify_dentry(d)) {
     
    941914}
    942915
    943 dev_handle_t fat_device_get(fs_node_t *node)
     916devmap_handle_t fat_device_get(fs_node_t *node)
    944917{
    945918        return 0;
     
    973946void fat_mounted(ipc_callid_t rid, ipc_call_t *request)
    974947{
    975         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);
    976949        enum cache_mode cmode;
    977950        fat_bs_t *bs;
    978         uint16_t bps;
    979         uint16_t rde;
    980951       
    981952        /* Accept the mount options */
     
    997968
    998969        /* initialize libblock */
    999         rc = block_init(dev_handle, BS_SIZE);
     970        rc = block_init(devmap_handle, BS_SIZE);
    1000971        if (rc != EOK) {
    1001972                ipc_answer_0(rid, rc);
     
    1004975
    1005976        /* prepare the boot block */
    1006         rc = block_bb_read(dev_handle, BS_BLOCK);
    1007         if (rc != EOK) {
    1008                 block_fini(dev_handle);
     977        rc = block_bb_read(devmap_handle, BS_BLOCK);
     978        if (rc != EOK) {
     979                block_fini(devmap_handle);
    1009980                ipc_answer_0(rid, rc);
    1010981                return;
     
    1012983
    1013984        /* get the buffer with the boot sector */
    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);
     985        bs = block_bb_get(devmap_handle);
     986       
     987        if (BPS(bs) != BS_SIZE) {
     988                block_fini(devmap_handle);
    1022989                ipc_answer_0(rid, ENOTSUP);
    1023990                return;
     
    1025992
    1026993        /* Initialize the block cache */
    1027         rc = block_cache_init(dev_handle, bps, 0 /* XXX */, cmode);
    1028         if (rc != EOK) {
    1029                 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);
    1030997                ipc_answer_0(rid, rc);
    1031998                return;
     
    10331000
    10341001        /* Do some simple sanity checks on the file system. */
    1035         rc = fat_sanity_check(bs, dev_handle);
    1036         if (rc != EOK) {
    1037                 (void) block_cache_fini(dev_handle);
    1038                 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);
    10391006                ipc_answer_0(rid, rc);
    10401007                return;
    10411008        }
    10421009
    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);
     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);
    10471014                ipc_answer_0(rid, rc);
    10481015                return;
     
    10521019        fs_node_t *rfn = (fs_node_t *)malloc(sizeof(fs_node_t));
    10531020        if (!rfn) {
    1054                 (void) block_cache_fini(dev_handle);
    1055                 block_fini(dev_handle);
    1056                 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);
    10571024                ipc_answer_0(rid, ENOMEM);
    10581025                return;
     
    10621029        if (!rootp) {
    10631030                free(rfn);
    1064                 (void) block_cache_fini(dev_handle);
    1065                 block_fini(dev_handle);
    1066                 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);
    10671034                ipc_answer_0(rid, ENOMEM);
    10681035                return;
     
    10701037        fat_node_initialize(rootp);
    10711038
    1072         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);
    10731040        if (!ridxp) {
    10741041                free(rfn);
    10751042                free(rootp);
    1076                 (void) block_cache_fini(dev_handle);
    1077                 block_fini(dev_handle);
    1078                 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);
    10791046                ipc_answer_0(rid, ENOMEM);
    10801047                return;
     
    10871054        rootp->refcnt = 1;
    10881055        rootp->lnkcnt = 0;      /* FS root is not linked */
    1089         rootp->size = rde * sizeof(fat_dentry_t);
     1056        rootp->size = RDE(bs) * sizeof(fat_dentry_t);
    10901057        rootp->idx = ridxp;
    10911058        ridxp->nodep = rootp;
     
    11051072void fat_unmounted(ipc_callid_t rid, ipc_call_t *request)
    11061073{
    1107         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);
    11081075        fs_node_t *fn;
    11091076        fat_node_t *nodep;
    11101077        int rc;
    11111078
    1112         rc = fat_root_get(&fn, dev_handle);
     1079        rc = fat_root_get(&fn, devmap_handle);
    11131080        if (rc != EOK) {
    11141081                ipc_answer_0(rid, rc);
     
    11381105         * stop using libblock for this instance.
    11391106         */
    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);
     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);
    11441111
    11451112        ipc_answer_0(rid, EOK);
     
    11581125void fat_read(ipc_callid_t rid, ipc_call_t *request)
    11591126{
    1160         dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     1127        devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
    11611128        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
    11621129        aoff64_t pos =
     
    11651132        fat_node_t *nodep;
    11661133        fat_bs_t *bs;
    1167         uint16_t bps;
    11681134        size_t bytes;
    11691135        block_t *b;
    11701136        int rc;
    11711137
    1172         rc = fat_node_get(&fn, dev_handle, index);
     1138        rc = fat_node_get(&fn, devmap_handle, index);
    11731139        if (rc != EOK) {
    11741140                ipc_answer_0(rid, rc);
     
    11901156        }
    11911157
    1192         bs = block_bb_get(dev_handle);
    1193         bps = uint16_t_le2host(bs->bps);
     1158        bs = block_bb_get(devmap_handle);
    11941159
    11951160        if (nodep->type == FAT_FILE) {
     
    12041169                        (void) async_data_read_finalize(callid, NULL, 0);
    12051170                } else {
    1206                         bytes = min(len, bps - pos % bps);
     1171                        bytes = min(len, BPS(bs) - pos % BPS(bs));
    12071172                        bytes = min(bytes, nodep->size - pos);
    1208                         rc = fat_block_get(&b, bs, nodep, pos / bps,
     1173                        rc = fat_block_get(&b, bs, nodep, pos / BPS(bs),
    12091174                            BLOCK_FLAGS_NONE);
    12101175                        if (rc != EOK) {
     
    12141179                                return;
    12151180                        }
    1216                         (void) async_data_read_finalize(callid, b->data + pos % bps,
    1217                             bytes);
     1181                        (void) async_data_read_finalize(callid,
     1182                            b->data + pos % BPS(bs), bytes);
    12181183                        rc = block_put(b);
    12191184                        if (rc != EOK) {
     
    12301195
    12311196                assert(nodep->type == FAT_DIRECTORY);
    1232                 assert(nodep->size % bps == 0);
    1233                 assert(bps % sizeof(fat_dentry_t) == 0);
     1197                assert(nodep->size % BPS(bs) == 0);
     1198                assert(BPS(bs) % sizeof(fat_dentry_t) == 0);
    12341199
    12351200                /*
     
    12391204                 * the position pointer accordingly.
    12401205                 */
    1241                 bnum = (pos * sizeof(fat_dentry_t)) / bps;
    1242                 while (bnum < nodep->size / bps) {
     1206                bnum = (pos * sizeof(fat_dentry_t)) / BPS(bs);
     1207                while (bnum < nodep->size / BPS(bs)) {
    12431208                        aoff64_t o;
    12441209
     
    12471212                        if (rc != EOK)
    12481213                                goto err;
    1249                         for (o = pos % (bps / sizeof(fat_dentry_t));
    1250                             o < bps / sizeof(fat_dentry_t);
     1214                        for (o = pos % (BPS(bs) / sizeof(fat_dentry_t));
     1215                            o < BPS(bs) / sizeof(fat_dentry_t);
    12511216                            o++, pos++) {
    12521217                                d = ((fat_dentry_t *)b->data) + o;
     
    12971262void fat_write(ipc_callid_t rid, ipc_call_t *request)
    12981263{
    1299         dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     1264        devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
    13001265        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
    13011266        aoff64_t pos =
     
    13061271        size_t bytes, size;
    13071272        block_t *b;
    1308         uint16_t bps;
    1309         unsigned spc;
    1310         unsigned bpc;           /* bytes per cluster */
    13111273        aoff64_t boundary;
    13121274        int flags = BLOCK_FLAGS_NONE;
    13131275        int rc;
    13141276       
    1315         rc = fat_node_get(&fn, dev_handle, index);
     1277        rc = fat_node_get(&fn, devmap_handle, index);
    13161278        if (rc != EOK) {
    13171279                ipc_answer_0(rid, rc);
     
    13331295        }
    13341296
    1335         bs = block_bb_get(dev_handle);
    1336         bps = uint16_t_le2host(bs->bps);
    1337         spc = bs->spc;
    1338         bpc = bps * spc;
     1297        bs = block_bb_get(devmap_handle);
    13391298
    13401299        /*
     
    13451304         * value signalizing a smaller number of bytes written.
    13461305         */
    1347         bytes = min(len, bps - pos % bps);
    1348         if (bytes == bps)
     1306        bytes = min(len, BPS(bs) - pos % BPS(bs));
     1307        if (bytes == BPS(bs))
    13491308                flags |= BLOCK_FLAGS_NOREAD;
    13501309       
    1351         boundary = ROUND_UP(nodep->size, bpc);
     1310        boundary = ROUND_UP(nodep->size, BPC(bs));
    13521311        if (pos < boundary) {
    13531312                /*
     
    13641323                        return;
    13651324                }
    1366                 rc = fat_block_get(&b, bs, nodep, pos / bps, flags);
     1325                rc = fat_block_get(&b, bs, nodep, pos / BPS(bs), flags);
    13671326                if (rc != EOK) {
    13681327                        (void) fat_node_put(fn);
     
    13711330                        return;
    13721331                }
    1373                 (void) async_data_write_finalize(callid, b->data + pos % bps,
    1374                     bytes);
     1332                (void) async_data_write_finalize(callid,
     1333                    b->data + pos % BPS(bs), bytes);
    13751334                b->dirty = true;                /* need to sync block */
    13761335                rc = block_put(b);
     
    13961355                fat_cluster_t mcl, lcl;
    13971356 
    1398                 nclsts = (ROUND_UP(pos + bytes, bpc) - boundary) / bpc;
     1357                nclsts = (ROUND_UP(pos + bytes, BPC(bs)) - boundary) / BPC(bs);
    13991358                /* create an independent chain of nclsts clusters in all FATs */
    1400                 rc = fat_alloc_clusters(bs, dev_handle, nclsts, &mcl, &lcl);
     1359                rc = fat_alloc_clusters(bs, devmap_handle, nclsts, &mcl, &lcl);
    14011360                if (rc != EOK) {
    14021361                        /* could not allocate a chain of nclsts clusters */
     
    14091368                rc = fat_fill_gap(bs, nodep, mcl, pos);
    14101369                if (rc != EOK) {
    1411                         (void) fat_free_clusters(bs, dev_handle, mcl);
     1370                        (void) fat_free_clusters(bs, devmap_handle, mcl);
    14121371                        (void) fat_node_put(fn);
    14131372                        ipc_answer_0(callid, rc);
     
    14151374                        return;
    14161375                }
    1417                 rc = _fat_block_get(&b, bs, dev_handle, lcl, (pos / bps) % spc,
    1418                     flags);
     1376                rc = _fat_block_get(&b, bs, devmap_handle, lcl, NULL,
     1377                    (pos / BPS(bs)) % SPC(bs), flags);
    14191378                if (rc != EOK) {
    1420                         (void) fat_free_clusters(bs, dev_handle, mcl);
     1379                        (void) fat_free_clusters(bs, devmap_handle, mcl);
    14211380                        (void) fat_node_put(fn);
    14221381                        ipc_answer_0(callid, rc);
     
    14241383                        return;
    14251384                }
    1426                 (void) async_data_write_finalize(callid, b->data + pos % bps,
    1427                     bytes);
     1385                (void) async_data_write_finalize(callid,
     1386                    b->data + pos % BPS(bs), bytes);
    14281387                b->dirty = true;                /* need to sync block */
    14291388                rc = block_put(b);
    14301389                if (rc != EOK) {
    1431                         (void) fat_free_clusters(bs, dev_handle, mcl);
     1390                        (void) fat_free_clusters(bs, devmap_handle, mcl);
    14321391                        (void) fat_node_put(fn);
    14331392                        ipc_answer_0(rid, rc);
     
    14381397                 * node's cluster chain.
    14391398                 */
    1440                 rc = fat_append_clusters(bs, nodep, mcl);
     1399                rc = fat_append_clusters(bs, nodep, mcl, lcl);
    14411400                if (rc != EOK) {
    1442                         (void) fat_free_clusters(bs, dev_handle, mcl);
     1401                        (void) fat_free_clusters(bs, devmap_handle, mcl);
    14431402                        (void) fat_node_put(fn);
    14441403                        ipc_answer_0(rid, rc);
     
    14551414void fat_truncate(ipc_callid_t rid, ipc_call_t *request)
    14561415{
    1457         dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     1416        devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
    14581417        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
    14591418        aoff64_t size =
     
    14621421        fat_node_t *nodep;
    14631422        fat_bs_t *bs;
    1464         uint16_t bps;
    1465         uint8_t spc;
    1466         unsigned bpc;   /* bytes per cluster */
    14671423        int rc;
    14681424
    1469         rc = fat_node_get(&fn, dev_handle, index);
     1425        rc = fat_node_get(&fn, devmap_handle, index);
    14701426        if (rc != EOK) {
    14711427                ipc_answer_0(rid, rc);
     
    14781434        nodep = FAT_NODE(fn);
    14791435
    1480         bs = block_bb_get(dev_handle);
    1481         bps = uint16_t_le2host(bs->bps);
    1482         spc = bs->spc;
    1483         bpc = bps * spc;
     1436        bs = block_bb_get(devmap_handle);
    14841437
    14851438        if (nodep->size == size) {
     
    14911444                 */
    14921445                rc = EINVAL;
    1493         } 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))) {
    14941447                /*
    14951448                 * The node will be shrunk, but no clusters will be deallocated.
     
    15081461                } else {
    15091462                        fat_cluster_t lastc;
    1510                         rc = fat_cluster_walk(bs, dev_handle, nodep->firstc,
    1511                             &lastc, NULL, (size - 1) / bpc);
     1463                        rc = fat_cluster_walk(bs, devmap_handle, nodep->firstc,
     1464                            &lastc, NULL, (size - 1) / BPC(bs));
    15121465                        if (rc != EOK)
    15131466                                goto out;
     
    15331486void fat_destroy(ipc_callid_t rid, ipc_call_t *request)
    15341487{
    1535         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);
    15361489        fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
    15371490        fs_node_t *fn;
    15381491        int rc;
    15391492
    1540         rc = fat_node_get(&fn, dev_handle, index);
     1493        rc = fat_node_get(&fn, devmap_handle, index);
    15411494        if (rc != EOK) {
    15421495                ipc_answer_0(rid, rc);
     
    15641517void fat_sync(ipc_callid_t rid, ipc_call_t *request)
    15651518{
    1566         dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     1519        devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
    15671520        fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
    15681521       
    15691522        fs_node_t *fn;
    1570         int rc = fat_node_get(&fn, dev_handle, index);
     1523        int rc = fat_node_get(&fn, devmap_handle, index);
    15711524        if (rc != EOK) {
    15721525                ipc_answer_0(rid, rc);
Note: See TracChangeset for help on using the changeset viewer.