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


Ignore:
Timestamp:
2009-09-03T13:24:36Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
dc87ad11
Parents:
684b655
Message:

Make fat_cluster_walk() return an error code.

File:
1 edited

Legend:

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

    r684b655 re402382  
    6161 * @param dev_handle    Device handle of the device with the file.
    6262 * @param firstc        First cluster to start the walk with.
    63  * @param lastc         If non-NULL, output argument hodling the last cluster number visited.
     63 * @param lastc         If non-NULL, output argument hodling the last cluster
     64 *                      number visited.
     65 * @param numc          If non-NULL, output argument holding the number of
     66 *                      clusters seen during the walk.
    6467 * @param max_clusters  Maximum number of clusters to visit.   
    6568 *
    66  * @return              Number of clusters seen during the walk.
    67  */
    68 uint16_t
     69 * @return              EOK on success or a negative error code.
     70 */
     71int
    6972fat_cluster_walk(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t firstc,
    70     fat_cluster_t *lastc, uint16_t max_clusters)
     73    fat_cluster_t *lastc, uint16_t *numc, uint16_t max_clusters)
    7174{
    7275        block_t *b;
     
    8487                if (lastc)
    8588                        *lastc = firstc;
    86                 return 0;
     89                if (numc)
     90                        *numc = 0;
     91                return EOK;
    8792        }
    8893
     
    98103                /* read FAT1 */
    99104                rc = block_get(&b, dev_handle, rscnt + fsec, BLOCK_FLAGS_NONE);
    100                 assert(rc == EOK);
     105                if (rc != EOK)
     106                        return rc;
    101107                clst = uint16_t_le2host(((fat_cluster_t *)b->data)[fidx]);
    102108                assert(clst != FAT_CLST_BAD);
    103109                rc = block_put(b);
    104                 assert(rc == EOK);
     110                if (rc != EOK)
     111                        return rc;
    105112                clusters++;
    106113        }
     
    108115        if (lastc && clst < FAT_CLST_LAST1)
    109116                *lastc = clst;
    110 
    111         return clusters;
     117        if (numc)
     118                *numc = clusters;
     119
     120        return EOK;
    112121}
    113122
     
    134143        unsigned sf;
    135144        unsigned ssa;           /* size of the system area */
    136         unsigned clusters, max_clusters;
     145        uint16_t clusters;
     146        unsigned max_clusters;
    137147        fat_cluster_t lastc;
    138148        int rc;
     
    156166
    157167        max_clusters = bn / bs->spc;
    158         clusters = fat_cluster_walk(bs, dev_handle, firstc, &lastc,
     168        rc = fat_cluster_walk(bs, dev_handle, firstc, &lastc, &clusters,
    159169            max_clusters);
     170        if (rc != EOK)
     171                return rc;
    160172        assert(clusters == max_clusters);
    161173
     
    425437        dev_handle_t dev_handle = nodep->idx->dev_handle;
    426438        fat_cluster_t lcl;
     439        uint16_t numc;
    427440        uint8_t fatno;
    428 
    429         if (fat_cluster_walk(bs, dev_handle, nodep->firstc, &lcl,
    430             (uint16_t) -1) == 0) {
     441        int rc;
     442
     443        rc = fat_cluster_walk(bs, dev_handle, nodep->firstc, &lcl, &numc,
     444            (uint16_t) -1);
     445        assert(rc == EOK);
     446
     447        if (numc == 0) {
    431448                /* No clusters allocated to the node yet. */
    432449                nodep->firstc = mcl;
Note: See TracChangeset for help on using the changeset viewer.