Changeset 377cce8 in mainline for uspace/srv/fs/fat/fat_fat.c


Ignore:
Timestamp:
2010-07-25T21:08:47Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
746f623
Parents:
c621f4aa
Message:

Start to cache the FAT node's last cluster in fat_node_t and change
fat_append/chop_clusters() to make use of the cached value.

File:
1 edited

Legend:

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

    rc621f4aa r377cce8  
    511511 * @param nodep         Node representing the file.
    512512 * @param mcl           First cluster of the cluster chain to append.
     513 * @param lcl           Last cluster of the cluster chain to append.
    513514 *
    514515 * @return              EOK on success or a negative error code.
    515516 */
    516 int fat_append_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl)
     517int
     518fat_append_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl,
     519    fat_cluster_t lcl)
    517520{
    518521        dev_handle_t dev_handle = nodep->idx->dev_handle;
    519         fat_cluster_t lcl;
     522        fat_cluster_t lastc;
    520523        uint16_t numc;
    521524        uint8_t fatno;
    522525        int rc;
    523526
    524         rc = fat_cluster_walk(bs, dev_handle, nodep->firstc, &lcl, &numc,
    525             (uint16_t) -1);
    526         if (rc != EOK)
    527                 return rc;
    528 
    529         if (numc == 0) {
    530                 /* No clusters allocated to the node yet. */
    531                 nodep->firstc = mcl;
    532                 nodep->dirty = true;            /* need to sync node */
    533                 return EOK;
     527        if (nodep->lastc_cached_valid) {
     528                lastc = nodep->lastc_cached_value;
     529                nodep->lastc_cached_valid = false;
     530        } else {
     531                rc = fat_cluster_walk(bs, dev_handle, nodep->firstc, &lastc,
     532                    &numc, (uint16_t) -1);
     533                if (rc != EOK)
     534                        return rc;
     535
     536                if (numc == 0) {
     537                        /* No clusters allocated to the node yet. */
     538                        nodep->firstc = mcl;
     539                        nodep->dirty = true;    /* need to sync node */
     540                        return EOK;
     541                }
    534542        }
    535543
    536544        for (fatno = FAT1; fatno < bs->fatcnt; fatno++) {
    537                 rc = fat_set_cluster(bs, nodep->idx->dev_handle, fatno, lcl,
     545                rc = fat_set_cluster(bs, nodep->idx->dev_handle, fatno, lastc,
    538546                    mcl);
    539547                if (rc != EOK)
    540548                        return rc;
    541549        }
     550
     551        nodep->lastc_cached_valid = true;
     552        nodep->lastc_cached_value = lcl;
    542553
    543554        return EOK;
     
    548559 * @param bs            Buffer holding the boot sector of the file system.
    549560 * @param nodep         FAT node where the chopping will take place.
    550  * @param lastc         Last cluster which will remain in the node. If this
     561 * @param lcl           Last cluster which will remain in the node. If this
    551562 *                      argument is FAT_CLST_RES0, then all clusters will
    552563 *                      be chopped off.
     
    554565 * @return              EOK on success or a negative return code.
    555566 */
    556 int fat_chop_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t lastc)
    557 {
    558         int rc;
    559 
     567int fat_chop_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t lcl)
     568{
     569        int rc;
    560570        dev_handle_t dev_handle = nodep->idx->dev_handle;
    561         if (lastc == FAT_CLST_RES0) {
     571
     572        nodep->lastc_cached_valid = false;
     573        if (lcl == FAT_CLST_RES0) {
    562574                /* The node will have zero size and no clusters allocated. */
    563575                rc = fat_free_clusters(bs, dev_handle, nodep->firstc);
     
    570582                unsigned fatno;
    571583
    572                 rc = fat_get_cluster(bs, dev_handle, FAT1, lastc, &nextc);
     584                rc = fat_get_cluster(bs, dev_handle, FAT1, lcl, &nextc);
    573585                if (rc != EOK)
    574586                        return rc;
     
    576588                /* Terminate the cluster chain in all copies of FAT. */
    577589                for (fatno = FAT1; fatno < bs->fatcnt; fatno++) {
    578                         rc = fat_set_cluster(bs, dev_handle, fatno, lastc,
     590                        rc = fat_set_cluster(bs, dev_handle, fatno, lcl,
    579591                            FAT_CLST_LAST1);
    580592                        if (rc != EOK)
     
    587599                        return rc;
    588600        }
     601
     602        nodep->lastc_cached_valid = true;
     603        nodep->lastc_cached_value = lcl;
    589604
    590605        return EOK;
Note: See TracChangeset for help on using the changeset viewer.