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


Ignore:
Timestamp:
2009-09-03T14:46:17Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2f636b6
Parents:
dc87ad11
Message:

Make fat_append_clusters(), fat_chop_clusters(), fat_free_clusters(),
fat_alloc_shadow_clusters(), fat_set_cluster(), fat_fill_gap() and
fat_zero_cluster() return an error code.

File:
1 edited

Legend:

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

    rdc87ad11 rcca29e3c  
    187187 *                      this argument is ignored.
    188188 * @param pos           Position in the last node block.
    189  */
    190 void fat_fill_gap(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl, off_t pos)
     189 *
     190 * @return              EOK on success or a negative error code.
     191 */
     192int fat_fill_gap(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl, off_t pos)
    191193{
    192194        uint16_t bps;
     
    207209                    BLOCK_FLAGS_NOREAD : BLOCK_FLAGS_NONE;
    208210                rc = fat_block_get(&b, bs, nodep, o / bps, flags);
    209                 assert(rc == EOK);
     211                if (rc != EOK)
     212                        return rc;
    210213                memset(b->data + o % bps, 0, bps - o % bps);
    211214                b->dirty = true;                /* need to sync node */
    212215                rc = block_put(b);
    213                 assert(rc == EOK);
     216                if (rc != EOK)
     217                        return rc;
    214218        }
    215219       
    216220        if (o >= pos)
    217                 return;
     221                return EOK;
    218222       
    219223        /* zero out the initial part of the new cluster chain */
     
    221225                rc = _fat_block_get(&b, bs, nodep->idx->dev_handle, mcl,
    222226                    (o - boundary) / bps, BLOCK_FLAGS_NOREAD);
    223                 assert(rc == EOK);
     227                if (rc != EOK)
     228                        return rc;
    224229                memset(b->data, 0, min(bps, pos - o));
    225230                b->dirty = true;                /* need to sync node */
    226231                rc = block_put(b);
    227                 assert(rc == EOK);
    228         }
     232                if (rc != EOK)
     233                        return rc;
     234        }
     235
     236        return EOK;
    229237}
    230238
     
    269277 * @param clst          Cluster which is to be set.
    270278 * @param value         Value to set the cluster with.
    271  */
    272 void
     279 *
     280 * @return              EOK on success or a negative error code.
     281 */
     282int
    273283fat_set_cluster(fat_bs_t *bs, dev_handle_t dev_handle, unsigned fatno,
    274284    fat_cluster_t clst, fat_cluster_t value)
     
    288298        rc = block_get(&b, dev_handle, rscnt + sf * fatno +
    289299            (clst * sizeof(fat_cluster_t)) / bps, BLOCK_FLAGS_NONE);
    290         assert(rc == EOK);
     300        if (rc != EOK)
     301                return rc;
    291302        cp = (fat_cluster_t *)b->data + clst % (bps / sizeof(fat_cluster_t));
    292303        *cp = host2uint16_t_le(value);
    293304        b->dirty = true;                /* need to sync block */
    294305        rc = block_put(b);
    295         assert(rc == EOK);
     306        return rc;
    296307}
    297308
     
    302313 * @param lifo          Chain of allocated clusters.
    303314 * @param nclsts        Number of clusters in the lifo chain.
    304  */
    305 void fat_alloc_shadow_clusters(fat_bs_t *bs, dev_handle_t dev_handle,
     315 *
     316 * @return              EOK on success or a negative error code.
     317 */
     318int fat_alloc_shadow_clusters(fat_bs_t *bs, dev_handle_t dev_handle,
    306319    fat_cluster_t *lifo, unsigned nclsts)
    307320{
    308321        uint8_t fatno;
    309322        unsigned c;
     323        int rc;
    310324
    311325        for (fatno = FAT1 + 1; fatno < bs->fatcnt; fatno++) {
    312326                for (c = 0; c < nclsts; c++) {
    313                         fat_set_cluster(bs, dev_handle, fatno, lifo[c],
     327                        rc = fat_set_cluster(bs, dev_handle, fatno, lifo[c],
    314328                            c == 0 ? FAT_CLST_LAST1 : lifo[c - 1]);
     329                        if (rc != EOK)
     330                                return rc;
    315331                }
    316332        }
     333
     334        return EOK;
    317335}
    318336
     
    378396                                        assert(rc == EOK);
    379397                                        /* update the shadow copies of FAT */
    380                                         fat_alloc_shadow_clusters(bs,
     398                                        rc = fat_alloc_shadow_clusters(bs,
    381399                                            dev_handle, lifo, nclsts);
     400                                        assert(rc == EOK);
    382401                                        *mcl = lifo[found - 1];
    383402                                        *lcl = lifo[0];
     
    398417         */
    399418        while (found--) {
    400                 fat_set_cluster(bs, dev_handle, FAT1, lifo[found],
     419                rc = fat_set_cluster(bs, dev_handle, FAT1, lifo[found],
    401420                    FAT_CLST_RES0);
     421                if (rc != EOK) {
     422                        free(lifo);
     423                        return rc;
     424                }
    402425        }
    403426       
     
    411434 * @param dev_handle    Device handle of the file system.
    412435 * @param firstc        First cluster in the chain which is to be freed.
    413  */
    414 void
     436 *
     437 * @return              EOK on success or a negative return code.
     438 */
     439int
    415440fat_free_clusters(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t firstc)
    416441{
     
    423448                assert(firstc >= FAT_CLST_FIRST && firstc < FAT_CLST_BAD);
    424449                rc = fat_get_cluster(bs, dev_handle, firstc, &nextc);
    425                 assert(rc == EOK);
    426                 for (fatno = FAT1; fatno < bs->fatcnt; fatno++)
    427                         fat_set_cluster(bs, dev_handle, fatno, firstc,
     450                if (rc != EOK)
     451                        return rc;
     452                for (fatno = FAT1; fatno < bs->fatcnt; fatno++) {
     453                        rc = fat_set_cluster(bs, dev_handle, fatno, firstc,
    428454                            FAT_CLST_RES0);
     455                        if (rc != EOK)
     456                                return rc;
     457                }
     458
    429459                firstc = nextc;
    430460        }
     461
     462        return EOK;
    431463}
    432464
     
    436468 * @param nodep         Node representing the file.
    437469 * @param mcl           First cluster of the cluster chain to append.
    438  */
    439 void fat_append_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl)
     470 *
     471 * @return              EOK on success or a negative error code.
     472 */
     473int fat_append_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl)
    440474{
    441475        dev_handle_t dev_handle = nodep->idx->dev_handle;
     
    447481        rc = fat_cluster_walk(bs, dev_handle, nodep->firstc, &lcl, &numc,
    448482            (uint16_t) -1);
    449         assert(rc == EOK);
     483        if (rc != EOK)
     484                return rc;
    450485
    451486        if (numc == 0) {
     
    453488                nodep->firstc = mcl;
    454489                nodep->dirty = true;            /* need to sync node */
    455                 return;
    456         }
    457 
    458         for (fatno = FAT1; fatno < bs->fatcnt; fatno++)
    459                 fat_set_cluster(bs, nodep->idx->dev_handle, fatno, lcl, mcl);
     490                return EOK;
     491        }
     492
     493        for (fatno = FAT1; fatno < bs->fatcnt; fatno++) {
     494                rc = fat_set_cluster(bs, nodep->idx->dev_handle, fatno, lcl,
     495                    mcl);
     496                if (rc != EOK)
     497                        return rc;
     498        }
     499
     500        return EOK;
    460501}
    461502
     
    467508 *                      argument is FAT_CLST_RES0, then all clusters will
    468509 *                      be chopped off.
    469  */
    470 void fat_chop_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t lastc)
     510 *
     511 * @return              EOK on success or a negative return code.
     512 */
     513int fat_chop_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t lastc)
    471514{
    472515        int rc;
     
    475518        if (lastc == FAT_CLST_RES0) {
    476519                /* The node will have zero size and no clusters allocated. */
    477                 fat_free_clusters(bs, dev_handle, nodep->firstc);
     520                rc = fat_free_clusters(bs, dev_handle, nodep->firstc);
     521                if (rc != EOK)
     522                        return rc;
    478523                nodep->firstc = FAT_CLST_RES0;
    479524                nodep->dirty = true;            /* need to sync node */
     
    483528
    484529                rc = fat_get_cluster(bs, dev_handle, lastc, &nextc);
    485                 assert(rc == EOK);
     530                if (rc != EOK)
     531                        return rc;
    486532
    487533                /* Terminate the cluster chain in all copies of FAT. */
    488                 for (fatno = FAT1; fatno < bs->fatcnt; fatno++)
    489                         fat_set_cluster(bs, dev_handle, fatno, lastc, FAT_CLST_LAST1);
     534                for (fatno = FAT1; fatno < bs->fatcnt; fatno++) {
     535                        rc = fat_set_cluster(bs, dev_handle, fatno, lastc,
     536                            FAT_CLST_LAST1);
     537                        if (rc != EOK)
     538                                return rc;
     539                }
    490540
    491541                /* Free all following clusters. */
    492                 fat_free_clusters(bs, dev_handle, nextc);
    493         }
    494 }
    495 
    496 void
     542                rc = fat_free_clusters(bs, dev_handle, nextc);
     543                if (rc != EOK)
     544                        return rc;
     545        }
     546
     547        return EOK;
     548}
     549
     550int
    497551fat_zero_cluster(struct fat_bs *bs, dev_handle_t dev_handle, fat_cluster_t c)
    498552{
     
    507561                rc = _fat_block_get(&b, bs, dev_handle, c, i,
    508562                    BLOCK_FLAGS_NOREAD);
    509                 assert(rc == EOK);
     563                if (rc != EOK)
     564                        return rc;
    510565                memset(b->data, 0, bps);
    511566                b->dirty = true;
    512567                rc = block_put(b);
    513                 assert(rc == EOK);
    514         }
     568                if (rc != EOK)
     569                        return rc;
     570        }
     571
     572        return EOK;
    515573}
    516574
Note: See TracChangeset for help on using the changeset viewer.