Ignore:
File:
1 edited

Legend:

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

    rd70d80ed r15f3c3f  
    4747#include <assert.h>
    4848#include <fibril_synch.h>
     49#include <malloc.h>
    4950#include <mem.h>
    5051
     
    7071 *
    7172 * @param bs            Buffer holding the boot sector for the file.
    72  * @param devmap_handle Device handle of the device with the file.
     73 * @param service_id    Service ID of the device with the file.
    7374 * @param firstc        First cluster to start the walk with.
    7475 * @param lastc         If non-NULL, output argument hodling the last cluster
     
    8182 */
    8283int
    83 fat_cluster_walk(fat_bs_t *bs, devmap_handle_t devmap_handle, fat_cluster_t firstc,
     84fat_cluster_walk(fat_bs_t *bs, service_id_t service_id, fat_cluster_t firstc,
    8485    fat_cluster_t *lastc, uint16_t *numc, uint16_t max_clusters)
    8586{
     
    108109                fidx = clst % (BPS(bs) / sizeof(fat_cluster_t));
    109110                /* read FAT1 */
    110                 rc = block_get(&b, devmap_handle, RSCNT(bs) + fsec,
     111                rc = block_get(&b, service_id, RSCNT(bs) + fsec,
    111112                    BLOCK_FLAGS_NONE);
    112113                if (rc != EOK)
     
    159160                 * when fortunately we have the last cluster number cached.
    160161                 */
    161                 return block_get(block, nodep->idx->devmap_handle,
     162                return block_get(block, nodep->idx->service_id,
    162163                    CLBN2PBN(bs, nodep->lastc_cached_value, bn), flags);
    163164        }
     
    173174
    174175fall_through:
    175         rc = _fat_block_get(block, bs, nodep->idx->devmap_handle, firstc,
     176        rc = _fat_block_get(block, bs, nodep->idx->service_id, firstc,
    176177            &currc, relbn, flags);
    177178        if (rc != EOK)
     
    192193 * @param block         Pointer to a block pointer for storing result.
    193194 * @param bs            Buffer holding the boot sector of the file system.
    194  * @param devmap_handle Device handle of the file system.
     195 * @param service_id    Service ID handle of the file system.
    195196 * @param fcl           First cluster used by the file. Can be zero if the file
    196197 *                      is empty.
     
    204205 */
    205206int
    206 _fat_block_get(block_t **block, fat_bs_t *bs, devmap_handle_t devmap_handle,
     207_fat_block_get(block_t **block, fat_bs_t *bs, service_id_t service_id,
    207208    fat_cluster_t fcl, fat_cluster_t *clp, aoff64_t bn, int flags)
    208209{
     
    221222                /* root directory special case */
    222223                assert(bn < RDS(bs));
    223                 rc = block_get(block, devmap_handle,
     224                rc = block_get(block, service_id,
    224225                    RSCNT(bs) + FATCNT(bs) * SF(bs) + bn, flags);
    225226                return rc;
     
    227228
    228229        max_clusters = bn / SPC(bs);
    229         rc = fat_cluster_walk(bs, devmap_handle, fcl, &c, &clusters, max_clusters);
     230        rc = fat_cluster_walk(bs, service_id, fcl, &c, &clusters, max_clusters);
    230231        if (rc != EOK)
    231232                return rc;
    232233        assert(clusters == max_clusters);
    233234
    234         rc = block_get(block, devmap_handle, CLBN2PBN(bs, c, bn), flags);
     235        rc = block_get(block, service_id, CLBN2PBN(bs, c, bn), flags);
    235236
    236237        if (clp)
     
    280281        /* zero out the initial part of the new cluster chain */
    281282        for (o = boundary; o < pos; o += BPS(bs)) {
    282                 rc = _fat_block_get(&b, bs, nodep->idx->devmap_handle, mcl,
     283                rc = _fat_block_get(&b, bs, nodep->idx->service_id, mcl,
    283284                    NULL, (o - boundary) / BPS(bs), BLOCK_FLAGS_NOREAD);
    284285                if (rc != EOK)
     
    297298 *
    298299 * @param bs            Buffer holding the boot sector for the file system.
    299  * @param devmap_handle Device handle for the file system.
     300 * @param service_id    Service ID for the file system.
    300301 * @param clst          Cluster which to get.
    301302 * @param value         Output argument holding the value of the cluster.
     
    304305 */
    305306int
    306 fat_get_cluster(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned fatno,
     307fat_get_cluster(fat_bs_t *bs, service_id_t service_id, unsigned fatno,
    307308    fat_cluster_t clst, fat_cluster_t *value)
    308309{
     
    311312        int rc;
    312313
    313         rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno +
     314        rc = block_get(&b, service_id, RSCNT(bs) + SF(bs) * fatno +
    314315            (clst * sizeof(fat_cluster_t)) / BPS(bs), BLOCK_FLAGS_NONE);
    315316        if (rc != EOK)
     
    326327 *
    327328 * @param bs            Buffer holding the boot sector for the file system.
    328  * @param devmap_handle Device handle for the file system.
     329 * @param service_id    Device service ID for the file system.
    329330 * @param fatno         Number of the FAT instance where to make the change.
    330331 * @param clst          Cluster which is to be set.
     
    334335 */
    335336int
    336 fat_set_cluster(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned fatno,
     337fat_set_cluster(fat_bs_t *bs, service_id_t service_id, unsigned fatno,
    337338    fat_cluster_t clst, fat_cluster_t value)
    338339{
     
    342343
    343344        assert(fatno < FATCNT(bs));
    344         rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno +
     345        rc = block_get(&b, service_id, RSCNT(bs) + SF(bs) * fatno +
    345346            (clst * sizeof(fat_cluster_t)) / BPS(bs), BLOCK_FLAGS_NONE);
    346347        if (rc != EOK)
     
    357358 *
    358359 * @param bs            Buffer holding the boot sector of the file system.
    359  * @param devmap_handle Device handle of the file system.
     360 * @param service_id    Service ID of the file system.
    360361 * @param lifo          Chain of allocated clusters.
    361362 * @param nclsts        Number of clusters in the lifo chain.
     
    363364 * @return              EOK on success or a negative error code.
    364365 */
    365 int fat_alloc_shadow_clusters(fat_bs_t *bs, devmap_handle_t devmap_handle,
     366int fat_alloc_shadow_clusters(fat_bs_t *bs, service_id_t service_id,
    366367    fat_cluster_t *lifo, unsigned nclsts)
    367368{
     
    372373        for (fatno = FAT1 + 1; fatno < bs->fatcnt; fatno++) {
    373374                for (c = 0; c < nclsts; c++) {
    374                         rc = fat_set_cluster(bs, devmap_handle, fatno, lifo[c],
     375                        rc = fat_set_cluster(bs, service_id, fatno, lifo[c],
    375376                            c == 0 ? FAT_CLST_LAST1 : lifo[c - 1]);
    376377                        if (rc != EOK)
     
    390391 *
    391392 * @param bs            Buffer holding the boot sector of the file system.
    392  * @param devmap_handle Device handle of the file system.
     393 * @param service_id    Device service ID of the file system.
    393394 * @param nclsts        Number of clusters to allocate.
    394395 * @param mcl           Output parameter where the first cluster in the chain
     
    400401 */
    401402int
    402 fat_alloc_clusters(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned nclsts,
     403fat_alloc_clusters(fat_bs_t *bs, service_id_t service_id, unsigned nclsts,
    403404    fat_cluster_t *mcl, fat_cluster_t *lcl)
    404405{
     
    418419        fibril_mutex_lock(&fat_alloc_lock);
    419420        for (b = 0, cl = 0; b < SF(bs); b++) {
    420                 rc = block_get(&blk, devmap_handle, RSCNT(bs) + b,
     421                rc = block_get(&blk, service_id, RSCNT(bs) + b,
    421422                    BLOCK_FLAGS_NONE);
    422423                if (rc != EOK)
     
    457458                                        /* update the shadow copies of FAT */
    458459                                        rc = fat_alloc_shadow_clusters(bs,
    459                                             devmap_handle, lifo, nclsts);
     460                                            service_id, lifo, nclsts);
    460461                                        if (rc != EOK)
    461462                                                goto error;
     
    484485         */
    485486        while (found--) {
    486                 rc = fat_set_cluster(bs, devmap_handle, FAT1, lifo[found],
     487                rc = fat_set_cluster(bs, service_id, FAT1, lifo[found],
    487488                    FAT_CLST_RES0);
    488489                if (rc != EOK) {
     
    499500 *
    500501 * @param bs            Buffer hodling the boot sector of the file system.
    501  * @param devmap_handle Device handle of the file system.
     502 * @param service_id    Device service ID of the file system.
    502503 * @param firstc        First cluster in the chain which is to be freed.
    503504 *
     
    505506 */
    506507int
    507 fat_free_clusters(fat_bs_t *bs, devmap_handle_t devmap_handle, fat_cluster_t firstc)
     508fat_free_clusters(fat_bs_t *bs, service_id_t service_id, fat_cluster_t firstc)
    508509{
    509510        unsigned fatno;
     
    514515        while (firstc < FAT_CLST_LAST1) {
    515516                assert(firstc >= FAT_CLST_FIRST && firstc < FAT_CLST_BAD);
    516                 rc = fat_get_cluster(bs, devmap_handle, FAT1, firstc, &nextc);
     517                rc = fat_get_cluster(bs, service_id, FAT1, firstc, &nextc);
    517518                if (rc != EOK)
    518519                        return rc;
    519520                for (fatno = FAT1; fatno < bs->fatcnt; fatno++) {
    520                         rc = fat_set_cluster(bs, devmap_handle, fatno, firstc,
     521                        rc = fat_set_cluster(bs, service_id, fatno, firstc,
    521522                            FAT_CLST_RES0);
    522523                        if (rc != EOK)
     
    543544    fat_cluster_t lcl)
    544545{
    545         devmap_handle_t devmap_handle = nodep->idx->devmap_handle;
     546        service_id_t service_id = nodep->idx->service_id;
    546547        fat_cluster_t lastc;
    547548        uint8_t fatno;
     
    557558                        nodep->lastc_cached_valid = false;
    558559                } else {
    559                         rc = fat_cluster_walk(bs, devmap_handle, nodep->firstc,
     560                        rc = fat_cluster_walk(bs, service_id, nodep->firstc,
    560561                            &lastc, NULL, (uint16_t) -1);
    561562                        if (rc != EOK)
     
    564565
    565566                for (fatno = FAT1; fatno < bs->fatcnt; fatno++) {
    566                         rc = fat_set_cluster(bs, nodep->idx->devmap_handle, fatno,
     567                        rc = fat_set_cluster(bs, nodep->idx->service_id, fatno,
    567568                            lastc, mcl);
    568569                        if (rc != EOK)
     
    590591{
    591592        int rc;
    592         devmap_handle_t devmap_handle = nodep->idx->devmap_handle;
     593        service_id_t service_id = nodep->idx->service_id;
    593594
    594595        /*
     
    601602        if (lcl == FAT_CLST_RES0) {
    602603                /* The node will have zero size and no clusters allocated. */
    603                 rc = fat_free_clusters(bs, devmap_handle, nodep->firstc);
     604                rc = fat_free_clusters(bs, service_id, nodep->firstc);
    604605                if (rc != EOK)
    605606                        return rc;
     
    610611                unsigned fatno;
    611612
    612                 rc = fat_get_cluster(bs, devmap_handle, FAT1, lcl, &nextc);
     613                rc = fat_get_cluster(bs, service_id, FAT1, lcl, &nextc);
    613614                if (rc != EOK)
    614615                        return rc;
     
    616617                /* Terminate the cluster chain in all copies of FAT. */
    617618                for (fatno = FAT1; fatno < bs->fatcnt; fatno++) {
    618                         rc = fat_set_cluster(bs, devmap_handle, fatno, lcl,
     619                        rc = fat_set_cluster(bs, service_id, fatno, lcl,
    619620                            FAT_CLST_LAST1);
    620621                        if (rc != EOK)
     
    623624
    624625                /* Free all following clusters. */
    625                 rc = fat_free_clusters(bs, devmap_handle, nextc);
     626                rc = fat_free_clusters(bs, service_id, nextc);
    626627                if (rc != EOK)
    627628                        return rc;
     
    638639
    639640int
    640 fat_zero_cluster(struct fat_bs *bs, devmap_handle_t devmap_handle, fat_cluster_t c)
     641fat_zero_cluster(struct fat_bs *bs, service_id_t service_id, fat_cluster_t c)
    641642{
    642643        int i;
     
    645646
    646647        for (i = 0; i < SPC(bs); i++) {
    647                 rc = _fat_block_get(&b, bs, devmap_handle, c, NULL, i,
     648                rc = _fat_block_get(&b, bs, service_id, c, NULL, i,
    648649                    BLOCK_FLAGS_NOREAD);
    649650                if (rc != EOK)
     
    665666 * does not contain a fat file system.
    666667 */
    667 int fat_sanity_check(fat_bs_t *bs, devmap_handle_t devmap_handle)
     668int fat_sanity_check(fat_bs_t *bs, service_id_t service_id)
    668669{
    669670        fat_cluster_t e0, e1;
     
    706707
    707708        for (fat_no = 0; fat_no < bs->fatcnt; fat_no++) {
    708                 rc = fat_get_cluster(bs, devmap_handle, fat_no, 0, &e0);
     709                rc = fat_get_cluster(bs, service_id, fat_no, 0, &e0);
    709710                if (rc != EOK)
    710711                        return EIO;
    711712
    712                 rc = fat_get_cluster(bs, devmap_handle, fat_no, 1, &e1);
     713                rc = fat_get_cluster(bs, service_id, fat_no, 1, &e1);
    713714                if (rc != EOK)
    714715                        return EIO;
Note: See TracChangeset for help on using the changeset viewer.