Changeset 746f623 in mainline for uspace/srv/fs/fat/fat_fat.c


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

Turn fat_block_get() into a real function and make it aware of the cached last
cluster number in fat_node_t. This reduces the running time of mkfile —size 5m
by ~58% under Qemu.

File:
1 edited

Legend:

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

    r377cce8 r746f623  
    119119
    120120        return EOK;
     121}
     122
     123/** Read block from file located on a FAT file system.
     124 *
     125 * @param block         Pointer to a block pointer for storing result.
     126 * @param bs            Buffer holding the boot sector of the file system.
     127 * @param nodep         FAT node.
     128 * @param bn            Block number.
     129 * @param flags         Flags passed to libblock.
     130 *
     131 * @return              EOK on success or a negative error code.
     132 */
     133int
     134fat_block_get(block_t **block, struct fat_bs *bs, fat_node_t *nodep,
     135    aoff64_t bn, int flags)
     136{
     137        if (!nodep->size)
     138                return ELIMIT;
     139
     140        if (((((nodep->size - 1) / bs->bps) / bs->spc) == bn / bs->spc) &&
     141            (nodep->lastc_cached_valid) && (nodep->firstc != FAT_CLST_ROOT)) {
     142                /*
     143                 * This is a request to read a block within the last cluster
     144                 * when fortunately we have the last cluster number cached.
     145                 */
     146                fat_cluster_t lastc = nodep->lastc_cached_value;
     147                unsigned bps;
     148                unsigned rscnt;         /* block address of the first FAT */
     149                unsigned rde;
     150                unsigned rds;           /* root directory size */
     151                unsigned sf;
     152                unsigned ssa;           /* size of the system area */
     153
     154                bps = uint16_t_le2host(bs->bps);
     155                rscnt = uint16_t_le2host(bs->rscnt);
     156                rde = uint16_t_le2host(bs->root_ent_max);
     157                sf = uint16_t_le2host(bs->sec_per_fat);
     158
     159                rds = (sizeof(fat_dentry_t) * rde) / bps;
     160                rds += ((sizeof(fat_dentry_t) * rde) % bps != 0);
     161                ssa = rscnt + bs->fatcnt * sf + rds;
     162       
     163                return block_get(block, nodep->idx->dev_handle,
     164                    ssa + (lastc - FAT_CLST_FIRST) * bs->spc + bn % bs->spc,
     165                    flags);
     166        } else {
     167                return _fat_block_get(block, bs, nodep->idx->dev_handle,
     168                    nodep->firstc, bn, flags);
     169        }
    121170}
    122171
Note: See TracChangeset for help on using the changeset viewer.