Changeset f092718 in mainline


Ignore:
Timestamp:
2010-11-27T17:42:19Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a6ba0c9
Parents:
45df59a
Message:

Small-to-large block size translation in block cache.

Location:
uspace
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/block/libblock.c

    r45df59a rf092718  
    6666        fibril_mutex_t lock;
    6767        size_t lblock_size;             /**< Logical block size. */
     68        unsigned blocks_cluster;        /**< Physical blocks per block_t */
    6869        unsigned block_count;           /**< Total number of blocks. */
    6970        unsigned blocks_cached;         /**< Number of cached blocks. */
     
    9091static int get_block_size(int dev_phone, size_t *bsize);
    9192static int get_num_blocks(int dev_phone, aoff64_t *nblocks);
     93static aoff64_t ba_ltop(devcon_t *devcon, aoff64_t lba);
    9294
    9395static devcon_t *devcon_search(devmap_handle_t devmap_handle)
     
    292294        cache->mode = mode;
    293295
    294         /* No block size translation a.t.m. */
    295         assert(cache->lblock_size == devcon->pblock_size);
     296        /* Allow 1:1 or small-to-large block size translation */
     297        if (cache->lblock_size % devcon->pblock_size != 0)
     298                return ENOTSUP;
     299
     300        cache->blocks_cluster = cache->lblock_size / devcon->pblock_size;
    296301
    297302        if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 1,
     
    329334                if (b->dirty) {
    330335                        memcpy(devcon->comm_area, b->data, b->size);
    331                         rc = write_blocks(devcon, b->boff, 1);
     336                        rc = write_blocks(devcon, b->pba, cache->blocks_cluster);
    332337                        if (rc != EOK)
    333338                                return rc;
     
    465470                                fibril_mutex_lock(&devcon->comm_area_lock);
    466471                                memcpy(devcon->comm_area, b->data, b->size);
    467                                 rc = write_blocks(devcon, b->boff, 1);
     472                                rc = write_blocks(devcon, b->pba,
     473                                    cache->blocks_cluster);
    468474                                fibril_mutex_unlock(&devcon->comm_area_lock);
    469475                                if (rc != EOK) {
     
    503509                b->size = cache->lblock_size;
    504510                b->boff = boff;
     511                b->pba = ba_ltop(devcon, b->boff);
    505512                hash_table_insert(&cache->block_hash, &key, &b->hash_link);
    506513
     
    519526                         */
    520527                        fibril_mutex_lock(&devcon->comm_area_lock);
    521                         rc = read_blocks(devcon, b->boff, 1);
     528                        rc = read_blocks(devcon, b->pba, cache->blocks_cluster);
    522529                        memcpy(b->data, devcon->comm_area, cache->lblock_size);
    523530                        fibril_mutex_unlock(&devcon->comm_area_lock);
     
    580587                fibril_mutex_lock(&devcon->comm_area_lock);
    581588                memcpy(devcon->comm_area, block->data, block->size);
    582                 rc = write_blocks(devcon, block->boff, 1);
     589                rc = write_blocks(devcon, block->pba, cache->blocks_cluster);
    583590                fibril_mutex_unlock(&devcon->comm_area_lock);
    584591                block->dirty = false;
     
    879886}
    880887
     888/** Convert logical block address to physical block address. */
     889static aoff64_t ba_ltop(devcon_t *devcon, aoff64_t lba)
     890{
     891        assert(devcon->cache != NULL);
     892        return lba * devcon->cache->blocks_cluster;
     893}
     894
    881895/** @}
    882896 */
  • uspace/lib/block/libblock.h

    r45df59a rf092718  
    7373        /** Handle of the device where the block resides. */
    7474        devmap_handle_t devmap_handle;
    75         /** Block offset on the block device. Counted in 'size'-byte blocks. */
     75        /** Logical block address */
    7676        aoff64_t boff;
     77        /** Physical block address */
     78        aoff64_t pba;
    7779        /** Size of the block. */
    7880        size_t size;
  • uspace/srv/fs/fat/fat_fat.c

    r45df59a rf092718  
    671671        int rc;
    672672
     673        printf("fat_sanity_check() begin\n");
     674
    673675        /* Check number of FATs. */
    674676        if (bs->fatcnt == 0)
     
    677679        /* Check total number of sectors. */
    678680
     681        printf("fat_sanity_check() totsec\n");
     682
    679683        if (bs->totsec16 == 0 && bs->totsec32 == 0)
    680684                return ENOTSUP;
     685
     686        printf("fat_sanity_check() totsec16 vs 32\n");
    681687
    682688        if (bs->totsec16 != 0 && bs->totsec32 != 0 &&
     
    684690                return ENOTSUP;
    685691
     692        printf("fat_sanity_check() media descriptor\n");
     693
    686694        /* Check media descriptor. Must be between 0xf0 and 0xff. */
    687695        if ((bs->mdesc & 0xf0) != 0xf0)
    688696                return ENOTSUP;
    689697
     698        printf("fat_sanity_check() sec_pre_fat\n");
     699
    690700        /* Check number of sectors per FAT. */
    691701        if (bs->sec_per_fat == 0)
    692702                return ENOTSUP;
     703
     704        printf("fat_sanity_check() root dir size\n");
    693705
    694706        /*
     
    705717        /* Check signature of each FAT. */
    706718
     719        printf("fat_sanity_check() FAT signatures\n");
     720
    707721        for (fat_no = 0; fat_no < bs->fatcnt; fat_no++) {
     722                printf("fat_sanity_check() read cluster 0\n");
    708723                rc = fat_get_cluster(bs, devmap_handle, fat_no, 0, &e0);
    709724                if (rc != EOK)
    710725                        return EIO;
    711726
     727                printf("fat_sanity_check() read cluster 1\n");
    712728                rc = fat_get_cluster(bs, devmap_handle, fat_no, 1, &e1);
    713729                if (rc != EOK)
    714730                        return EIO;
    715731
     732                printf("fat_sanity_check() check FAT mdesc\n");
    716733                /* Check that first byte of FAT contains the media descriptor. */
    717734                if ((e0 & 0xff) != bs->mdesc)
    718735                        return ENOTSUP;
     736
     737                printf("fat_sanity_check() e0/e1\n");
    719738
    720739                /*
     
    725744                        return ENOTSUP;
    726745        }
     746        printf("fat_sanity_check() succeeded\n");
    727747
    728748        return EOK;
Note: See TracChangeset for help on using the changeset viewer.