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


Ignore:
Timestamp:
2011-08-17T18:04:50Z (13 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0cf27ee
Parents:
e898296d (diff), e6165be (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge libposix.

File:
1 edited

Legend:

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

    re898296d r3e01316f  
    7171 *
    7272 * @param bs            Buffer holding the boot sector for the file.
    73  * @param devmap_handle Device handle of the device with the file.
     73 * @param service_id    Service ID of the device with the file.
    7474 * @param firstc        First cluster to start the walk with.
    7575 * @param lastc         If non-NULL, output argument hodling the last cluster
     
    8282 */
    8383int
    84 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,
    8585    fat_cluster_t *lastc, uint16_t *numc, uint16_t max_clusters)
    8686{
     
    109109                fidx = clst % (BPS(bs) / sizeof(fat_cluster_t));
    110110                /* read FAT1 */
    111                 rc = block_get(&b, devmap_handle, RSCNT(bs) + fsec,
     111                rc = block_get(&b, service_id, RSCNT(bs) + fsec,
    112112                    BLOCK_FLAGS_NONE);
    113113                if (rc != EOK)
     
    160160                 * when fortunately we have the last cluster number cached.
    161161                 */
    162                 return block_get(block, nodep->idx->devmap_handle,
     162                return block_get(block, nodep->idx->service_id,
    163163                    CLBN2PBN(bs, nodep->lastc_cached_value, bn), flags);
    164164        }
     
    174174
    175175fall_through:
    176         rc = _fat_block_get(block, bs, nodep->idx->devmap_handle, firstc,
     176        rc = _fat_block_get(block, bs, nodep->idx->service_id, firstc,
    177177            &currc, relbn, flags);
    178178        if (rc != EOK)
     
    193193 * @param block         Pointer to a block pointer for storing result.
    194194 * @param bs            Buffer holding the boot sector of the file system.
    195  * @param devmap_handle Device handle of the file system.
     195 * @param service_id    Service ID handle of the file system.
    196196 * @param fcl           First cluster used by the file. Can be zero if the file
    197197 *                      is empty.
     
    205205 */
    206206int
    207 _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,
    208208    fat_cluster_t fcl, fat_cluster_t *clp, aoff64_t bn, int flags)
    209209{
     
    222222                /* root directory special case */
    223223                assert(bn < RDS(bs));
    224                 rc = block_get(block, devmap_handle,
     224                rc = block_get(block, service_id,
    225225                    RSCNT(bs) + FATCNT(bs) * SF(bs) + bn, flags);
    226226                return rc;
     
    228228
    229229        max_clusters = bn / SPC(bs);
    230         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);
    231231        if (rc != EOK)
    232232                return rc;
    233233        assert(clusters == max_clusters);
    234234
    235         rc = block_get(block, devmap_handle, CLBN2PBN(bs, c, bn), flags);
     235        rc = block_get(block, service_id, CLBN2PBN(bs, c, bn), flags);
    236236
    237237        if (clp)
     
    281281        /* zero out the initial part of the new cluster chain */
    282282        for (o = boundary; o < pos; o += BPS(bs)) {
    283                 rc = _fat_block_get(&b, bs, nodep->idx->devmap_handle, mcl,
     283                rc = _fat_block_get(&b, bs, nodep->idx->service_id, mcl,
    284284                    NULL, (o - boundary) / BPS(bs), BLOCK_FLAGS_NOREAD);
    285285                if (rc != EOK)
     
    298298 *
    299299 * @param bs            Buffer holding the boot sector for the file system.
    300  * @param devmap_handle Device handle for the file system.
     300 * @param service_id    Service ID for the file system.
    301301 * @param clst          Cluster which to get.
    302302 * @param value         Output argument holding the value of the cluster.
     
    305305 */
    306306int
    307 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,
    308308    fat_cluster_t clst, fat_cluster_t *value)
    309309{
     
    312312        int rc;
    313313
    314         rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno +
     314        rc = block_get(&b, service_id, RSCNT(bs) + SF(bs) * fatno +
    315315            (clst * sizeof(fat_cluster_t)) / BPS(bs), BLOCK_FLAGS_NONE);
    316316        if (rc != EOK)
     
    327327 *
    328328 * @param bs            Buffer holding the boot sector for the file system.
    329  * @param devmap_handle Device handle for the file system.
     329 * @param service_id    Device service ID for the file system.
    330330 * @param fatno         Number of the FAT instance where to make the change.
    331331 * @param clst          Cluster which is to be set.
     
    335335 */
    336336int
    337 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,
    338338    fat_cluster_t clst, fat_cluster_t value)
    339339{
     
    343343
    344344        assert(fatno < FATCNT(bs));
    345         rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno +
     345        rc = block_get(&b, service_id, RSCNT(bs) + SF(bs) * fatno +
    346346            (clst * sizeof(fat_cluster_t)) / BPS(bs), BLOCK_FLAGS_NONE);
    347347        if (rc != EOK)
     
    358358 *
    359359 * @param bs            Buffer holding the boot sector of the file system.
    360  * @param devmap_handle Device handle of the file system.
     360 * @param service_id    Service ID of the file system.
    361361 * @param lifo          Chain of allocated clusters.
    362362 * @param nclsts        Number of clusters in the lifo chain.
     
    364364 * @return              EOK on success or a negative error code.
    365365 */
    366 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,
    367367    fat_cluster_t *lifo, unsigned nclsts)
    368368{
     
    373373        for (fatno = FAT1 + 1; fatno < bs->fatcnt; fatno++) {
    374374                for (c = 0; c < nclsts; c++) {
    375                         rc = fat_set_cluster(bs, devmap_handle, fatno, lifo[c],
     375                        rc = fat_set_cluster(bs, service_id, fatno, lifo[c],
    376376                            c == 0 ? FAT_CLST_LAST1 : lifo[c - 1]);
    377377                        if (rc != EOK)
     
    391391 *
    392392 * @param bs            Buffer holding the boot sector of the file system.
    393  * @param devmap_handle Device handle of the file system.
     393 * @param service_id    Device service ID of the file system.
    394394 * @param nclsts        Number of clusters to allocate.
    395395 * @param mcl           Output parameter where the first cluster in the chain
     
    401401 */
    402402int
    403 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,
    404404    fat_cluster_t *mcl, fat_cluster_t *lcl)
    405405{
     
    419419        fibril_mutex_lock(&fat_alloc_lock);
    420420        for (b = 0, cl = 0; b < SF(bs); b++) {
    421                 rc = block_get(&blk, devmap_handle, RSCNT(bs) + b,
     421                rc = block_get(&blk, service_id, RSCNT(bs) + b,
    422422                    BLOCK_FLAGS_NONE);
    423423                if (rc != EOK)
     
    458458                                        /* update the shadow copies of FAT */
    459459                                        rc = fat_alloc_shadow_clusters(bs,
    460                                             devmap_handle, lifo, nclsts);
     460                                            service_id, lifo, nclsts);
    461461                                        if (rc != EOK)
    462462                                                goto error;
     
    485485         */
    486486        while (found--) {
    487                 rc = fat_set_cluster(bs, devmap_handle, FAT1, lifo[found],
     487                rc = fat_set_cluster(bs, service_id, FAT1, lifo[found],
    488488                    FAT_CLST_RES0);
    489489                if (rc != EOK) {
     
    500500 *
    501501 * @param bs            Buffer hodling the boot sector of the file system.
    502  * @param devmap_handle Device handle of the file system.
     502 * @param service_id    Device service ID of the file system.
    503503 * @param firstc        First cluster in the chain which is to be freed.
    504504 *
     
    506506 */
    507507int
    508 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)
    509509{
    510510        unsigned fatno;
     
    515515        while (firstc < FAT_CLST_LAST1) {
    516516                assert(firstc >= FAT_CLST_FIRST && firstc < FAT_CLST_BAD);
    517                 rc = fat_get_cluster(bs, devmap_handle, FAT1, firstc, &nextc);
     517                rc = fat_get_cluster(bs, service_id, FAT1, firstc, &nextc);
    518518                if (rc != EOK)
    519519                        return rc;
    520520                for (fatno = FAT1; fatno < bs->fatcnt; fatno++) {
    521                         rc = fat_set_cluster(bs, devmap_handle, fatno, firstc,
     521                        rc = fat_set_cluster(bs, service_id, fatno, firstc,
    522522                            FAT_CLST_RES0);
    523523                        if (rc != EOK)
     
    544544    fat_cluster_t lcl)
    545545{
    546         devmap_handle_t devmap_handle = nodep->idx->devmap_handle;
     546        service_id_t service_id = nodep->idx->service_id;
    547547        fat_cluster_t lastc;
    548548        uint8_t fatno;
     
    558558                        nodep->lastc_cached_valid = false;
    559559                } else {
    560                         rc = fat_cluster_walk(bs, devmap_handle, nodep->firstc,
     560                        rc = fat_cluster_walk(bs, service_id, nodep->firstc,
    561561                            &lastc, NULL, (uint16_t) -1);
    562562                        if (rc != EOK)
     
    565565
    566566                for (fatno = FAT1; fatno < bs->fatcnt; fatno++) {
    567                         rc = fat_set_cluster(bs, nodep->idx->devmap_handle, fatno,
     567                        rc = fat_set_cluster(bs, nodep->idx->service_id, fatno,
    568568                            lastc, mcl);
    569569                        if (rc != EOK)
     
    591591{
    592592        int rc;
    593         devmap_handle_t devmap_handle = nodep->idx->devmap_handle;
     593        service_id_t service_id = nodep->idx->service_id;
    594594
    595595        /*
     
    602602        if (lcl == FAT_CLST_RES0) {
    603603                /* The node will have zero size and no clusters allocated. */
    604                 rc = fat_free_clusters(bs, devmap_handle, nodep->firstc);
     604                rc = fat_free_clusters(bs, service_id, nodep->firstc);
    605605                if (rc != EOK)
    606606                        return rc;
     
    611611                unsigned fatno;
    612612
    613                 rc = fat_get_cluster(bs, devmap_handle, FAT1, lcl, &nextc);
     613                rc = fat_get_cluster(bs, service_id, FAT1, lcl, &nextc);
    614614                if (rc != EOK)
    615615                        return rc;
     
    617617                /* Terminate the cluster chain in all copies of FAT. */
    618618                for (fatno = FAT1; fatno < bs->fatcnt; fatno++) {
    619                         rc = fat_set_cluster(bs, devmap_handle, fatno, lcl,
     619                        rc = fat_set_cluster(bs, service_id, fatno, lcl,
    620620                            FAT_CLST_LAST1);
    621621                        if (rc != EOK)
     
    624624
    625625                /* Free all following clusters. */
    626                 rc = fat_free_clusters(bs, devmap_handle, nextc);
     626                rc = fat_free_clusters(bs, service_id, nextc);
    627627                if (rc != EOK)
    628628                        return rc;
     
    639639
    640640int
    641 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)
    642642{
    643643        int i;
     
    646646
    647647        for (i = 0; i < SPC(bs); i++) {
    648                 rc = _fat_block_get(&b, bs, devmap_handle, c, NULL, i,
     648                rc = _fat_block_get(&b, bs, service_id, c, NULL, i,
    649649                    BLOCK_FLAGS_NOREAD);
    650650                if (rc != EOK)
     
    666666 * does not contain a fat file system.
    667667 */
    668 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)
    669669{
    670670        fat_cluster_t e0, e1;
     
    707707
    708708        for (fat_no = 0; fat_no < bs->fatcnt; fat_no++) {
    709                 rc = fat_get_cluster(bs, devmap_handle, fat_no, 0, &e0);
     709                rc = fat_get_cluster(bs, service_id, fat_no, 0, &e0);
    710710                if (rc != EOK)
    711711                        return EIO;
    712712
    713                 rc = fat_get_cluster(bs, devmap_handle, fat_no, 1, &e1);
     713                rc = fat_get_cluster(bs, service_id, fat_no, 1, &e1);
    714714                if (rc != EOK)
    715715                        return EIO;
Note: See TracChangeset for help on using the changeset viewer.