Changeset 45e9cc6 in mainline for uspace/lib/block/libblock.c


Ignore:
Timestamp:
2010-12-04T20:37:19Z (13 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b5ec347
Parents:
4144630 (diff), 35537a7 (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 with mainline

File:
1 edited

Legend:

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

    r4144630 r45e9cc6  
    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)
     
    259261{
    260262        block_t *b = hash_table_get_instance(item, block_t, hash_link);
    261         return b->boff == *key;
     263        return b->lba == *key;
    262264}
    263265
     
    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;
    334339                }
    335340
    336                 unsigned long key = b->boff;
     341                unsigned long key = b->lba;
    337342                hash_table_remove(&cache->block_hash, &key, 1);
    338343               
     
    375380 *                              block pointer on success.
    376381 * @param devmap_handle         Device handle of the block device.
    377  * @param boff                  Block offset.
     382 * @param ba                    Block address (logical).
    378383 * @param flags                 If BLOCK_FLAGS_NOREAD is specified, block_get()
    379384 *                              will not read the contents of the block from the
     
    382387 * @return                      EOK on success or a negative error code.
    383388 */
    384 int block_get(block_t **block, devmap_handle_t devmap_handle, aoff64_t boff, int flags)
     389int block_get(block_t **block, devmap_handle_t devmap_handle, aoff64_t ba, int flags)
    385390{
    386391        devcon_t *devcon;
     
    388393        block_t *b;
    389394        link_t *l;
    390         unsigned long key = boff;
     395        unsigned long key = ba;
    391396        int rc;
    392397       
     
    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) {
     
    495501                         */
    496502                        list_remove(&b->free_link);
    497                         temp_key = b->boff;
     503                        temp_key = b->lba;
    498504                        hash_table_remove(&cache->block_hash, &temp_key, 1);
    499505                }
     
    502508                b->devmap_handle = devmap_handle;
    503509                b->size = cache->lblock_size;
    504                 b->boff = boff;
     510                b->lba = ba;
     511                b->pba = ba_ltop(devcon, b->lba);
    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;
     
    614621                         * Take the block out of the cache and free it.
    615622                         */
    616                         unsigned long key = block->boff;
     623                        unsigned long key = block->lba;
    617624                        hash_table_remove(&cache->block_hash, &key, 1);
    618625                        free(block);
     
    712719 *
    713720 * @param devmap_handle Device handle of the block device.
    714  * @param ba            Address of first block.
     721 * @param ba            Address of first block (physical).
    715722 * @param cnt           Number of blocks.
    716723 * @param src           Buffer for storing the data.
     
    740747 *
    741748 * @param devmap_handle Device handle of the block device.
    742  * @param ba            Address of first block.
     749 * @param ba            Address of first block (physical).
    743750 * @param cnt           Number of blocks.
    744751 * @param src           The data to be written.
     
    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 */
Note: See TracChangeset for help on using the changeset viewer.