Ignore:
File:
1 edited

Legend:

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

    r15f3c3f rd70d80ed  
    4747#include <assert.h>
    4848#include <fibril_synch.h>
    49 #include <malloc.h>
    5049#include <mem.h>
    5150
     
    7170 *
    7271 * @param bs            Buffer holding the boot sector for the file.
    73  * @param service_id    Service ID of the device with the file.
     72 * @param devmap_handle Device handle of the device with the file.
    7473 * @param firstc        First cluster to start the walk with.
    7574 * @param lastc         If non-NULL, output argument hodling the last cluster
     
    8281 */
    8382int
    84 fat_cluster_walk(fat_bs_t *bs, service_id_t service_id, fat_cluster_t firstc,
     83fat_cluster_walk(fat_bs_t *bs, devmap_handle_t devmap_handle, fat_cluster_t firstc,
    8584    fat_cluster_t *lastc, uint16_t *numc, uint16_t max_clusters)
    8685{
     
    109108                fidx = clst % (BPS(bs) / sizeof(fat_cluster_t));
    110109                /* read FAT1 */
    111                 rc = block_get(&b, service_id, RSCNT(bs) + fsec,
     110                rc = block_get(&b, devmap_handle, RSCNT(bs) + fsec,
    112111                    BLOCK_FLAGS_NONE);
    113112                if (rc != EOK)
     
    160159                 * when fortunately we have the last cluster number cached.
    161160                 */
    162                 return block_get(block, nodep->idx->service_id,
     161                return block_get(block, nodep->idx->devmap_handle,
    163162                    CLBN2PBN(bs, nodep->lastc_cached_value, bn), flags);
    164163        }
     
    174173
    175174fall_through:
    176         rc = _fat_block_get(block, bs, nodep->idx->service_id, firstc,
     175        rc = _fat_block_get(block, bs, nodep->idx->devmap_handle, firstc,
    177176            &currc, relbn, flags);
    178177        if (rc != EOK)
     
    193192 * @param block         Pointer to a block pointer for storing result.
    194193 * @param bs            Buffer holding the boot sector of the file system.
    195  * @param service_id    Service ID handle of the file system.
     194 * @param devmap_handle Device handle of the file system.
    196195 * @param fcl           First cluster used by the file. Can be zero if the file
    197196 *                      is empty.
     
    205204 */
    206205int
    207 _fat_block_get(block_t **block, fat_bs_t *bs, service_id_t service_id,
     206_fat_block_get(block_t **block, fat_bs_t *bs, devmap_handle_t devmap_handle,
    208207    fat_cluster_t fcl, fat_cluster_t *clp, aoff64_t bn, int flags)
    209208{
     
    222221                /* root directory special case */
    223222                assert(bn < RDS(bs));
    224                 rc = block_get(block, service_id,
     223                rc = block_get(block, devmap_handle,
    225224                    RSCNT(bs) + FATCNT(bs) * SF(bs) + bn, flags);
    226225                return rc;
     
    228227
    229228        max_clusters = bn / SPC(bs);
    230         rc = fat_cluster_walk(bs, service_id, fcl, &c, &clusters, max_clusters);
     229        rc = fat_cluster_walk(bs, devmap_handle, fcl, &c, &clusters, max_clusters);
    231230        if (rc != EOK)
    232231                return rc;
    233232        assert(clusters == max_clusters);
    234233
    235         rc = block_get(block, service_id, CLBN2PBN(bs, c, bn), flags);
     234        rc = block_get(block, devmap_handle, CLBN2PBN(bs, c, bn), flags);
    236235
    237236        if (clp)
     
    281280        /* zero out the initial part of the new cluster chain */
    282281        for (o = boundary; o < pos; o += BPS(bs)) {
    283                 rc = _fat_block_get(&b, bs, nodep->idx->service_id, mcl,
     282                rc = _fat_block_get(&b, bs, nodep->idx->devmap_handle, mcl,
    284283                    NULL, (o - boundary) / BPS(bs), BLOCK_FLAGS_NOREAD);
    285284                if (rc != EOK)
     
    298297 *
    299298 * @param bs            Buffer holding the boot sector for the file system.
    300  * @param service_id    Service ID for the file system.
     299 * @param devmap_handle Device handle for the file system.
    301300 * @param clst          Cluster which to get.
    302301 * @param value         Output argument holding the value of the cluster.
     
    305304 */
    306305int
    307 fat_get_cluster(fat_bs_t *bs, service_id_t service_id, unsigned fatno,
     306fat_get_cluster(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned fatno,
    308307    fat_cluster_t clst, fat_cluster_t *value)
    309308{
     
    312311        int rc;
    313312
    314         rc = block_get(&b, service_id, RSCNT(bs) + SF(bs) * fatno +
     313        rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno +
    315314            (clst * sizeof(fat_cluster_t)) / BPS(bs), BLOCK_FLAGS_NONE);
    316315        if (rc != EOK)
     
    327326 *
    328327 * @param bs            Buffer holding the boot sector for the file system.
    329  * @param service_id    Device service ID for the file system.
     328 * @param devmap_handle Device handle for the file system.
    330329 * @param fatno         Number of the FAT instance where to make the change.
    331330 * @param clst          Cluster which is to be set.
     
    335334 */
    336335int
    337 fat_set_cluster(fat_bs_t *bs, service_id_t service_id, unsigned fatno,
     336fat_set_cluster(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned fatno,
    338337    fat_cluster_t clst, fat_cluster_t value)
    339338{
     
    343342
    344343        assert(fatno < FATCNT(bs));
    345         rc = block_get(&b, service_id, RSCNT(bs) + SF(bs) * fatno +
     344        rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno +
    346345            (clst * sizeof(fat_cluster_t)) / BPS(bs), BLOCK_FLAGS_NONE);
    347346        if (rc != EOK)
     
    358357 *
    359358 * @param bs            Buffer holding the boot sector of the file system.
    360  * @param service_id    Service ID of the file system.
     359 * @param devmap_handle Device handle of the file system.
    361360 * @param lifo          Chain of allocated clusters.
    362361 * @param nclsts        Number of clusters in the lifo chain.
     
    364363 * @return              EOK on success or a negative error code.
    365364 */
    366 int fat_alloc_shadow_clusters(fat_bs_t *bs, service_id_t service_id,
     365int fat_alloc_shadow_clusters(fat_bs_t *bs, devmap_handle_t devmap_handle,
    367366    fat_cluster_t *lifo, unsigned nclsts)
    368367{
     
    373372        for (fatno = FAT1 + 1; fatno < bs->fatcnt; fatno++) {
    374373                for (c = 0; c < nclsts; c++) {
    375                         rc = fat_set_cluster(bs, service_id, fatno, lifo[c],
     374                        rc = fat_set_cluster(bs, devmap_handle, fatno, lifo[c],
    376375                            c == 0 ? FAT_CLST_LAST1 : lifo[c - 1]);
    377376                        if (rc != EOK)
     
    391390 *
    392391 * @param bs            Buffer holding the boot sector of the file system.
    393  * @param service_id    Device service ID of the file system.
     392 * @param devmap_handle Device handle of the file system.
    394393 * @param nclsts        Number of clusters to allocate.
    395394 * @param mcl           Output parameter where the first cluster in the chain
     
    401400 */
    402401int
    403 fat_alloc_clusters(fat_bs_t *bs, service_id_t service_id, unsigned nclsts,
     402fat_alloc_clusters(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned nclsts,
    404403    fat_cluster_t *mcl, fat_cluster_t *lcl)
    405404{
     
    419418        fibril_mutex_lock(&fat_alloc_lock);
    420419        for (b = 0, cl = 0; b < SF(bs); b++) {
    421                 rc = block_get(&blk, service_id, RSCNT(bs) + b,
     420                rc = block_get(&blk, devmap_handle, RSCNT(bs) + b,
    422421                    BLOCK_FLAGS_NONE);
    423422                if (rc != EOK)
     
    458457                                        /* update the shadow copies of FAT */
    459458                                        rc = fat_alloc_shadow_clusters(bs,
    460                                             service_id, lifo, nclsts);
     459                                            devmap_handle, lifo, nclsts);
    461460                                        if (rc != EOK)
    462461                                                goto error;
     
    485484         */
    486485        while (found--) {
    487                 rc = fat_set_cluster(bs, service_id, FAT1, lifo[found],
     486                rc = fat_set_cluster(bs, devmap_handle, FAT1, lifo[found],
    488487                    FAT_CLST_RES0);
    489488                if (rc != EOK) {
     
    500499 *
    501500 * @param bs            Buffer hodling the boot sector of the file system.
    502  * @param service_id    Device service ID of the file system.
     501 * @param devmap_handle Device handle of the file system.
    503502 * @param firstc        First cluster in the chain which is to be freed.
    504503 *
     
    506505 */
    507506int
    508 fat_free_clusters(fat_bs_t *bs, service_id_t service_id, fat_cluster_t firstc)
     507fat_free_clusters(fat_bs_t *bs, devmap_handle_t devmap_handle, fat_cluster_t firstc)
    509508{
    510509        unsigned fatno;
     
    515514        while (firstc < FAT_CLST_LAST1) {
    516515                assert(firstc >= FAT_CLST_FIRST && firstc < FAT_CLST_BAD);
    517                 rc = fat_get_cluster(bs, service_id, FAT1, firstc, &nextc);
     516                rc = fat_get_cluster(bs, devmap_handle, FAT1, firstc, &nextc);
    518517                if (rc != EOK)
    519518                        return rc;
    520519                for (fatno = FAT1; fatno < bs->fatcnt; fatno++) {
    521                         rc = fat_set_cluster(bs, service_id, fatno, firstc,
     520                        rc = fat_set_cluster(bs, devmap_handle, fatno, firstc,
    522521                            FAT_CLST_RES0);
    523522                        if (rc != EOK)
     
    544543    fat_cluster_t lcl)
    545544{
    546         service_id_t service_id = nodep->idx->service_id;
     545        devmap_handle_t devmap_handle = nodep->idx->devmap_handle;
    547546        fat_cluster_t lastc;
    548547        uint8_t fatno;
     
    558557                        nodep->lastc_cached_valid = false;
    559558                } else {
    560                         rc = fat_cluster_walk(bs, service_id, nodep->firstc,
     559                        rc = fat_cluster_walk(bs, devmap_handle, nodep->firstc,
    561560                            &lastc, NULL, (uint16_t) -1);
    562561                        if (rc != EOK)
     
    565564
    566565                for (fatno = FAT1; fatno < bs->fatcnt; fatno++) {
    567                         rc = fat_set_cluster(bs, nodep->idx->service_id, fatno,
     566                        rc = fat_set_cluster(bs, nodep->idx->devmap_handle, fatno,
    568567                            lastc, mcl);
    569568                        if (rc != EOK)
     
    591590{
    592591        int rc;
    593         service_id_t service_id = nodep->idx->service_id;
     592        devmap_handle_t devmap_handle = nodep->idx->devmap_handle;
    594593
    595594        /*
     
    602601        if (lcl == FAT_CLST_RES0) {
    603602                /* The node will have zero size and no clusters allocated. */
    604                 rc = fat_free_clusters(bs, service_id, nodep->firstc);
     603                rc = fat_free_clusters(bs, devmap_handle, nodep->firstc);
    605604                if (rc != EOK)
    606605                        return rc;
     
    611610                unsigned fatno;
    612611
    613                 rc = fat_get_cluster(bs, service_id, FAT1, lcl, &nextc);
     612                rc = fat_get_cluster(bs, devmap_handle, FAT1, lcl, &nextc);
    614613                if (rc != EOK)
    615614                        return rc;
     
    617616                /* Terminate the cluster chain in all copies of FAT. */
    618617                for (fatno = FAT1; fatno < bs->fatcnt; fatno++) {
    619                         rc = fat_set_cluster(bs, service_id, fatno, lcl,
     618                        rc = fat_set_cluster(bs, devmap_handle, fatno, lcl,
    620619                            FAT_CLST_LAST1);
    621620                        if (rc != EOK)
     
    624623
    625624                /* Free all following clusters. */
    626                 rc = fat_free_clusters(bs, service_id, nextc);
     625                rc = fat_free_clusters(bs, devmap_handle, nextc);
    627626                if (rc != EOK)
    628627                        return rc;
     
    639638
    640639int
    641 fat_zero_cluster(struct fat_bs *bs, service_id_t service_id, fat_cluster_t c)
     640fat_zero_cluster(struct fat_bs *bs, devmap_handle_t devmap_handle, fat_cluster_t c)
    642641{
    643642        int i;
     
    646645
    647646        for (i = 0; i < SPC(bs); i++) {
    648                 rc = _fat_block_get(&b, bs, service_id, c, NULL, i,
     647                rc = _fat_block_get(&b, bs, devmap_handle, c, NULL, i,
    649648                    BLOCK_FLAGS_NOREAD);
    650649                if (rc != EOK)
     
    666665 * does not contain a fat file system.
    667666 */
    668 int fat_sanity_check(fat_bs_t *bs, service_id_t service_id)
     667int fat_sanity_check(fat_bs_t *bs, devmap_handle_t devmap_handle)
    669668{
    670669        fat_cluster_t e0, e1;
     
    707706
    708707        for (fat_no = 0; fat_no < bs->fatcnt; fat_no++) {
    709                 rc = fat_get_cluster(bs, service_id, fat_no, 0, &e0);
     708                rc = fat_get_cluster(bs, devmap_handle, fat_no, 0, &e0);
    710709                if (rc != EOK)
    711710                        return EIO;
    712711
    713                 rc = fat_get_cluster(bs, service_id, fat_no, 1, &e1);
     712                rc = fat_get_cluster(bs, devmap_handle, fat_no, 1, &e1);
    714713                if (rc != EOK)
    715714                        return EIO;
Note: See TracChangeset for help on using the changeset viewer.