Changeset 7a23d60 in mainline


Ignore:
Timestamp:
2010-07-26T20:10:21Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6da81e0
Parents:
ed6cf34b
Message:

Use convenience macros for accessing FAT boot sector in fat_ops.c as well.

Location:
uspace/srv/fs/fat
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/fat/fat.h

    red6cf34b r7a23d60  
    4848
    4949#define min(a, b)               ((a) < (b) ? (a) : (b))
     50
     51/*
     52 * Convenience macros for accessing some frequently used boot sector members.
     53 */
     54#define BPS(bs)         uint16_t_le2host((bs)->bps)
     55#define SPC(bs)         (bs)->spc
     56#define RSCNT(bs)       uint16_t_le2host((bs)->rscnt)
     57#define FATCNT(bs)      (bs)->fatcnt
     58#define SF(bs)          uint16_t_le2host((bs)->sec_per_fat)
     59#define RDE(bs)         uint16_t_le2host((bs)->root_ent_max)
     60#define TS(bs)          (uint16_t_le2host((bs)->totsec16) != 0 ? \
     61                        uint16_t_le2host((bs)->totsec16) : \
     62                        uint32_t_le2host(bs->totsec32))
    5063
    5164#define BS_BLOCK                0
  • uspace/srv/fs/fat/fat_fat.c

    red6cf34b r7a23d60  
    5050
    5151/*
    52  * Convenience macros for accessing some frequently used boot sector members.
    53  */
    54 #define BPS(bs)         uint16_t_le2host((bs)->bps)
    55 #define SPC(bs)         (bs)->spc
    56 #define RSCNT(bs)       uint16_t_le2host((bs)->rscnt)
    57 #define FATCNT(bs)      (bs)->fatcnt
    58 #define SF(bs)          uint16_t_le2host((bs)->sec_per_fat)
    59 #define RDE(bs)         uint16_t_le2host((bs)->root_ent_max)
    60 #define TS(bs)          (uint16_t_le2host((bs)->totsec16) != 0 ? \
    61                         uint16_t_le2host((bs)->totsec16) : \
    62                         uint32_t_le2host(bs->totsec32))
    63 
    64 /*
    6552 * Convenience macros for computing some frequently used values from the
    6653 * primitive boot sector members.
     
    7259#define CLBN2PBN(bs, cl, bn) \
    7360        (SSA((bs)) + ((cl) - FAT_CLST_FIRST) * SPC((bs)) + (bn) % SPC((bs)))
    74 
    7561
    7662/**
  • uspace/srv/fs/fat/fat_ops.c

    red6cf34b r7a23d60  
    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);
     
    110113        fat_bs_t *bs;
    111114        fat_dentry_t *d;
    112         uint16_t bps;
    113         unsigned dps;
    114115        int rc;
    115116       
     
    117118
    118119        bs = block_bb_get(node->idx->dev_handle);
    119         bps = uint16_t_le2host(bs->bps);
    120         dps = bps / sizeof(fat_dentry_t);
    121120       
    122121        /* Read the block that contains the dentry of interest. */
    123122        rc = _fat_block_get(&b, bs, node->idx->dev_handle, node->idx->pfc,
    124             (node->idx->pdi * sizeof(fat_dentry_t)) / bps, BLOCK_FLAGS_NONE);
     123            (node->idx->pdi * sizeof(fat_dentry_t)) / BPS(bs),
     124            BLOCK_FLAGS_NONE);
    125125        if (rc != EOK)
    126126                return rc;
    127127
    128         d = ((fat_dentry_t *)b->data) + (node->idx->pdi % dps);
     128        d = ((fat_dentry_t *)b->data) + (node->idx->pdi % DPS(bs));
    129129
    130130        d->firstc = host2uint16_t_le(node->firstc);
     
    268268        fat_dentry_t *d;
    269269        fat_node_t *nodep = NULL;
    270         unsigned bps;
    271         unsigned spc;
    272         unsigned dps;
    273270        int rc;
    274271
     
    300297
    301298        bs = block_bb_get(idxp->dev_handle);
    302         bps = uint16_t_le2host(bs->bps);
    303         spc = bs->spc;
    304         dps = bps / sizeof(fat_dentry_t);
    305299
    306300        /* Read the block that contains the dentry of interest. */
    307301        rc = _fat_block_get(&b, bs, idxp->dev_handle, idxp->pfc,
    308             (idxp->pdi * sizeof(fat_dentry_t)) / bps, BLOCK_FLAGS_NONE);
     302            (idxp->pdi * sizeof(fat_dentry_t)) / BPS(bs), BLOCK_FLAGS_NONE);
    309303        if (rc != EOK) {
    310304                (void) fat_node_put(FS_NODE(nodep));
     
    312306        }
    313307
    314         d = ((fat_dentry_t *)b->data) + (idxp->pdi % dps);
     308        d = ((fat_dentry_t *)b->data) + (idxp->pdi % DPS(bs));
    315309        if (d->attr & FAT_ATTR_SUBDIR) {
    316310                /*
     
    332326                        return rc;
    333327                }
    334                 nodep->size = bps * spc * clusters;
     328                nodep->size = BPS(bs) * SPC(bs) * clusters;
    335329        } else {
    336330                nodep->type = FAT_FILE;
     
    370364        char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1];
    371365        unsigned i, j;
    372         unsigned bps;           /* bytes per sector */
    373         unsigned dps;           /* dentries per sector */
    374366        unsigned blocks;
    375367        fat_dentry_t *d;
     
    379371        fibril_mutex_lock(&parentp->idx->lock);
    380372        bs = block_bb_get(parentp->idx->dev_handle);
    381         bps = uint16_t_le2host(bs->bps);
    382         dps = bps / sizeof(fat_dentry_t);
    383         blocks = parentp->size / bps;
     373        blocks = parentp->size / BPS(bs);
    384374        for (i = 0; i < blocks; i++) {
    385375                rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE);
     
    388378                        return rc;
    389379                }
    390                 for (j = 0; j < dps; j++) {
     380                for (j = 0; j < DPS(bs); j++) {
    391381                        d = ((fat_dentry_t *)b->data) + j;
    392382                        switch (fat_classify_dentry(d)) {
     
    416406                                fat_idx_t *idx = fat_idx_get_by_pos(
    417407                                    parentp->idx->dev_handle, parentp->firstc,
    418                                     i * dps + j);
     408                                    i * DPS(bs) + j);
    419409                                fibril_mutex_unlock(&parentp->idx->lock);
    420410                                if (!idx) {
     
    515505        fat_bs_t *bs;
    516506        fat_cluster_t mcl, lcl;
    517         uint16_t bps;
    518507        int rc;
    519508
    520509        bs = block_bb_get(dev_handle);
    521         bps = uint16_t_le2host(bs->bps);
    522510        if (flags & L_DIRECTORY) {
    523511                /* allocate a cluster */
     
    548536                nodep->type = FAT_DIRECTORY;
    549537                nodep->firstc = mcl;
    550                 nodep->size = bps * bs->spc;
     538                nodep->size = BPS(bs) * SPC(bs);
    551539        } else {
    552540                nodep->type = FAT_FILE;
     
    611599        block_t *b;
    612600        unsigned i, j;
    613         uint16_t bps;
    614         unsigned dps;
    615601        unsigned blocks;
    616602        fat_cluster_t mcl, lcl;
     
    642628        fibril_mutex_lock(&parentp->idx->lock);
    643629        bs = block_bb_get(parentp->idx->dev_handle);
    644         bps = uint16_t_le2host(bs->bps);
    645         dps = bps / sizeof(fat_dentry_t);
    646 
    647         blocks = parentp->size / bps;
     630
     631        blocks = parentp->size / BPS(bs);
    648632
    649633        for (i = 0; i < blocks; i++) {
     
    653637                        return rc;
    654638                }
    655                 for (j = 0; j < dps; j++) {
     639                for (j = 0; j < DPS(bs); j++) {
    656640                        d = ((fat_dentry_t *)b->data) + j;
    657641                        switch (fat_classify_dentry(d)) {
     
    699683                return rc;
    700684        }
    701         parentp->size += bps * bs->spc;
     685        parentp->size += BPS(bs) * SPC(bs);
    702686        parentp->dirty = true;          /* need to sync node */
    703687        rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE);
     
    773757
    774758        childp->idx->pfc = parentp->firstc;
    775         childp->idx->pdi = i * dps + j;
     759        childp->idx->pdi = i * DPS(bs) + j;
    776760        fibril_mutex_unlock(&childp->idx->lock);
    777761
     
    795779        fat_bs_t *bs;
    796780        fat_dentry_t *d;
    797         uint16_t bps;
    798781        block_t *b;
    799782        bool has_children;
     
    814797        fibril_mutex_lock(&childp->idx->lock);
    815798        bs = block_bb_get(childp->idx->dev_handle);
    816         bps = uint16_t_le2host(bs->bps);
    817799
    818800        rc = _fat_block_get(&b, bs, childp->idx->dev_handle, childp->idx->pfc,
    819             (childp->idx->pdi * sizeof(fat_dentry_t)) / bps,
     801            (childp->idx->pdi * sizeof(fat_dentry_t)) / BPS(bs),
    820802            BLOCK_FLAGS_NONE);
    821803        if (rc != EOK)
    822804                goto error;
    823805        d = (fat_dentry_t *)b->data +
    824             (childp->idx->pdi % (bps / sizeof(fat_dentry_t)));
     806            (childp->idx->pdi % (BPS(bs) / sizeof(fat_dentry_t)));
    825807        /* mark the dentry as not-currently-used */
    826808        d->name[0] = FAT_DENTRY_ERASED;
     
    854836        fat_bs_t *bs;
    855837        fat_node_t *nodep = FAT_NODE(fn);
    856         unsigned bps;
    857         unsigned dps;
    858838        unsigned blocks;
    859839        block_t *b;
     
    868848        fibril_mutex_lock(&nodep->idx->lock);
    869849        bs = block_bb_get(nodep->idx->dev_handle);
    870         bps = uint16_t_le2host(bs->bps);
    871         dps = bps / sizeof(fat_dentry_t);
    872 
    873         blocks = nodep->size / bps;
     850
     851        blocks = nodep->size / BPS(bs);
    874852
    875853        for (i = 0; i < blocks; i++) {
     
    881859                        return rc;
    882860                }
    883                 for (j = 0; j < dps; j++) {
     861                for (j = 0; j < DPS(bs); j++) {
    884862                        d = ((fat_dentry_t *)b->data) + j;
    885863                        switch (fat_classify_dentry(d)) {
     
    978956        enum cache_mode cmode;
    979957        fat_bs_t *bs;
    980         uint16_t bps;
    981         uint16_t rde;
    982958       
    983959        /* Accept the mount options */
     
    1016992        bs = block_bb_get(dev_handle);
    1017993       
    1018         /* Read the number of root directory entries. */
    1019         bps = uint16_t_le2host(bs->bps);
    1020         rde = uint16_t_le2host(bs->root_ent_max);
    1021 
    1022         if (bps != BS_SIZE) {
     994        if (BPS(bs) != BS_SIZE) {
    1023995                block_fini(dev_handle);
    1024996                ipc_answer_0(rid, ENOTSUP);
     
    1027999
    10281000        /* Initialize the block cache */
    1029         rc = block_cache_init(dev_handle, bps, 0 /* XXX */, cmode);
     1001        rc = block_cache_init(dev_handle, BPS(bs), 0 /* XXX */, cmode);
    10301002        if (rc != EOK) {
    10311003                block_fini(dev_handle);
     
    10891061        rootp->refcnt = 1;
    10901062        rootp->lnkcnt = 0;      /* FS root is not linked */
    1091         rootp->size = rde * sizeof(fat_dentry_t);
     1063        rootp->size = RDE(bs) * sizeof(fat_dentry_t);
    10921064        rootp->idx = ridxp;
    10931065        ridxp->nodep = rootp;
     
    11671139        fat_node_t *nodep;
    11681140        fat_bs_t *bs;
    1169         uint16_t bps;
    11701141        size_t bytes;
    11711142        block_t *b;
     
    11931164
    11941165        bs = block_bb_get(dev_handle);
    1195         bps = uint16_t_le2host(bs->bps);
    11961166
    11971167        if (nodep->type == FAT_FILE) {
     
    12061176                        (void) async_data_read_finalize(callid, NULL, 0);
    12071177                } else {
    1208                         bytes = min(len, bps - pos % bps);
     1178                        bytes = min(len, BPS(bs) - pos % BPS(bs));
    12091179                        bytes = min(bytes, nodep->size - pos);
    1210                         rc = fat_block_get(&b, bs, nodep, pos / bps,
     1180                        rc = fat_block_get(&b, bs, nodep, pos / BPS(bs),
    12111181                            BLOCK_FLAGS_NONE);
    12121182                        if (rc != EOK) {
     
    12161186                                return;
    12171187                        }
    1218                         (void) async_data_read_finalize(callid, b->data + pos % bps,
    1219                             bytes);
     1188                        (void) async_data_read_finalize(callid,
     1189                            b->data + pos % BPS(bs), bytes);
    12201190                        rc = block_put(b);
    12211191                        if (rc != EOK) {
     
    12321202
    12331203                assert(nodep->type == FAT_DIRECTORY);
    1234                 assert(nodep->size % bps == 0);
    1235                 assert(bps % sizeof(fat_dentry_t) == 0);
     1204                assert(nodep->size % BPS(bs) == 0);
     1205                assert(BPS(bs) % sizeof(fat_dentry_t) == 0);
    12361206
    12371207                /*
     
    12411211                 * the position pointer accordingly.
    12421212                 */
    1243                 bnum = (pos * sizeof(fat_dentry_t)) / bps;
    1244                 while (bnum < nodep->size / bps) {
     1213                bnum = (pos * sizeof(fat_dentry_t)) / BPS(bs);
     1214                while (bnum < nodep->size / BPS(bs)) {
    12451215                        aoff64_t o;
    12461216
     
    12491219                        if (rc != EOK)
    12501220                                goto err;
    1251                         for (o = pos % (bps / sizeof(fat_dentry_t));
    1252                             o < bps / sizeof(fat_dentry_t);
     1221                        for (o = pos % (BPS(bs) / sizeof(fat_dentry_t));
     1222                            o < BPS(bs) / sizeof(fat_dentry_t);
    12531223                            o++, pos++) {
    12541224                                d = ((fat_dentry_t *)b->data) + o;
     
    13081278        size_t bytes, size;
    13091279        block_t *b;
    1310         uint16_t bps;
    1311         unsigned spc;
    1312         unsigned bpc;           /* bytes per cluster */
    13131280        aoff64_t boundary;
    13141281        int flags = BLOCK_FLAGS_NONE;
     
    13361303
    13371304        bs = block_bb_get(dev_handle);
    1338         bps = uint16_t_le2host(bs->bps);
    1339         spc = bs->spc;
    1340         bpc = bps * spc;
    13411305
    13421306        /*
     
    13471311         * value signalizing a smaller number of bytes written.
    13481312         */
    1349         bytes = min(len, bps - pos % bps);
    1350         if (bytes == bps)
     1313        bytes = min(len, BPS(bs) - pos % BPS(bs));
     1314        if (bytes == BPS(bs))
    13511315                flags |= BLOCK_FLAGS_NOREAD;
    13521316       
    1353         boundary = ROUND_UP(nodep->size, bpc);
     1317        boundary = ROUND_UP(nodep->size, BPC(bs));
    13541318        if (pos < boundary) {
    13551319                /*
     
    13661330                        return;
    13671331                }
    1368                 rc = fat_block_get(&b, bs, nodep, pos / bps, flags);
     1332                rc = fat_block_get(&b, bs, nodep, pos / BPS(bs), flags);
    13691333                if (rc != EOK) {
    13701334                        (void) fat_node_put(fn);
     
    13731337                        return;
    13741338                }
    1375                 (void) async_data_write_finalize(callid, b->data + pos % bps,
    1376                     bytes);
     1339                (void) async_data_write_finalize(callid,
     1340                    b->data + pos % BPS(bs), bytes);
    13771341                b->dirty = true;                /* need to sync block */
    13781342                rc = block_put(b);
     
    13981362                fat_cluster_t mcl, lcl;
    13991363 
    1400                 nclsts = (ROUND_UP(pos + bytes, bpc) - boundary) / bpc;
     1364                nclsts = (ROUND_UP(pos + bytes, BPC(bs)) - boundary) / BPC(bs);
    14011365                /* create an independent chain of nclsts clusters in all FATs */
    14021366                rc = fat_alloc_clusters(bs, dev_handle, nclsts, &mcl, &lcl);
     
    14171381                        return;
    14181382                }
    1419                 rc = _fat_block_get(&b, bs, dev_handle, lcl, (pos / bps) % spc,
    1420                     flags);
     1383                rc = _fat_block_get(&b, bs, dev_handle, lcl,
     1384                    (pos / BPS(bs)) % SPC(bs), flags);
    14211385                if (rc != EOK) {
    14221386                        (void) fat_free_clusters(bs, dev_handle, mcl);
     
    14261390                        return;
    14271391                }
    1428                 (void) async_data_write_finalize(callid, b->data + pos % bps,
    1429                     bytes);
     1392                (void) async_data_write_finalize(callid,
     1393                    b->data + pos % BPS(bs), bytes);
    14301394                b->dirty = true;                /* need to sync block */
    14311395                rc = block_put(b);
     
    14641428        fat_node_t *nodep;
    14651429        fat_bs_t *bs;
    1466         uint16_t bps;
    1467         uint8_t spc;
    1468         unsigned bpc;   /* bytes per cluster */
    14691430        int rc;
    14701431
     
    14811442
    14821443        bs = block_bb_get(dev_handle);
    1483         bps = uint16_t_le2host(bs->bps);
    1484         spc = bs->spc;
    1485         bpc = bps * spc;
    14861444
    14871445        if (nodep->size == size) {
     
    14931451                 */
    14941452                rc = EINVAL;
    1495         } else if (ROUND_UP(nodep->size, bpc) == ROUND_UP(size, bpc)) {
     1453        } else if (ROUND_UP(nodep->size, BPC(bs)) == ROUND_UP(size, BPC(bs))) {
    14961454                /*
    14971455                 * The node will be shrunk, but no clusters will be deallocated.
     
    15111469                        fat_cluster_t lastc;
    15121470                        rc = fat_cluster_walk(bs, dev_handle, nodep->firstc,
    1513                             &lastc, NULL, (size - 1) / bpc);
     1471                            &lastc, NULL, (size - 1) / BPC(bs));
    15141472                        if (rc != EOK)
    15151473                                goto out;
Note: See TracChangeset for help on using the changeset viewer.