Ignore:
File:
1 edited

Legend:

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

    ra6ba0c9 r991f645  
    6666        fibril_mutex_t lock;
    6767        size_t lblock_size;             /**< Logical block size. */
    68         unsigned blocks_cluster;        /**< Physical blocks per block_t */
    6968        unsigned block_count;           /**< Total number of blocks. */
    7069        unsigned blocks_cached;         /**< Number of cached blocks. */
     
    9190static int get_block_size(int dev_phone, size_t *bsize);
    9291static int get_num_blocks(int dev_phone, aoff64_t *nblocks);
    93 static aoff64_t ba_ltop(devcon_t *devcon, aoff64_t lba);
    9492
    9593static devcon_t *devcon_search(devmap_handle_t devmap_handle)
     
    261259{
    262260        block_t *b = hash_table_get_instance(item, block_t, hash_link);
    263         return b->lba == *key;
     261        return b->boff == *key;
    264262}
    265263
     
    294292        cache->mode = mode;
    295293
    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;
     294        /* No block size translation a.t.m. */
     295        assert(cache->lblock_size == devcon->pblock_size);
    301296
    302297        if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 1,
     
    334329                if (b->dirty) {
    335330                        memcpy(devcon->comm_area, b->data, b->size);
    336                         rc = write_blocks(devcon, b->pba, cache->blocks_cluster);
     331                        rc = write_blocks(devcon, b->boff, 1);
    337332                        if (rc != EOK)
    338333                                return rc;
    339334                }
    340335
    341                 unsigned long key = b->lba;
     336                unsigned long key = b->boff;
    342337                hash_table_remove(&cache->block_hash, &key, 1);
    343338               
     
    380375 *                              block pointer on success.
    381376 * @param devmap_handle         Device handle of the block device.
    382  * @param ba                    Block address (logical).
     377 * @param boff                  Block offset.
    383378 * @param flags                 If BLOCK_FLAGS_NOREAD is specified, block_get()
    384379 *                              will not read the contents of the block from the
     
    387382 * @return                      EOK on success or a negative error code.
    388383 */
    389 int block_get(block_t **block, devmap_handle_t devmap_handle, aoff64_t ba, int flags)
     384int block_get(block_t **block, devmap_handle_t devmap_handle, aoff64_t boff, int flags)
    390385{
    391386        devcon_t *devcon;
     
    393388        block_t *b;
    394389        link_t *l;
    395         unsigned long key = ba;
     390        unsigned long key = boff;
    396391        int rc;
    397392       
     
    470465                                fibril_mutex_lock(&devcon->comm_area_lock);
    471466                                memcpy(devcon->comm_area, b->data, b->size);
    472                                 rc = write_blocks(devcon, b->pba,
    473                                     cache->blocks_cluster);
     467                                rc = write_blocks(devcon, b->boff, 1);
    474468                                fibril_mutex_unlock(&devcon->comm_area_lock);
    475469                                if (rc != EOK) {
     
    501495                         */
    502496                        list_remove(&b->free_link);
    503                         temp_key = b->lba;
     497                        temp_key = b->boff;
    504498                        hash_table_remove(&cache->block_hash, &temp_key, 1);
    505499                }
     
    508502                b->devmap_handle = devmap_handle;
    509503                b->size = cache->lblock_size;
    510                 b->lba = ba;
    511                 b->pba = ba_ltop(devcon, b->lba);
     504                b->boff = boff;
    512505                hash_table_insert(&cache->block_hash, &key, &b->hash_link);
    513506
     
    526519                         */
    527520                        fibril_mutex_lock(&devcon->comm_area_lock);
    528                         rc = read_blocks(devcon, b->pba, cache->blocks_cluster);
     521                        rc = read_blocks(devcon, b->boff, 1);
    529522                        memcpy(b->data, devcon->comm_area, cache->lblock_size);
    530523                        fibril_mutex_unlock(&devcon->comm_area_lock);
     
    587580                fibril_mutex_lock(&devcon->comm_area_lock);
    588581                memcpy(devcon->comm_area, block->data, block->size);
    589                 rc = write_blocks(devcon, block->pba, cache->blocks_cluster);
     582                rc = write_blocks(devcon, block->boff, 1);
    590583                fibril_mutex_unlock(&devcon->comm_area_lock);
    591584                block->dirty = false;
     
    621614                         * Take the block out of the cache and free it.
    622615                         */
    623                         unsigned long key = block->lba;
     616                        unsigned long key = block->boff;
    624617                        hash_table_remove(&cache->block_hash, &key, 1);
    625618                        free(block);
     
    719712 *
    720713 * @param devmap_handle Device handle of the block device.
    721  * @param ba            Address of first block (physical).
     714 * @param ba            Address of first block.
    722715 * @param cnt           Number of blocks.
    723716 * @param src           Buffer for storing the data.
     
    747740 *
    748741 * @param devmap_handle Device handle of the block device.
    749  * @param ba            Address of first block (physical).
     742 * @param ba            Address of first block.
    750743 * @param cnt           Number of blocks.
    751744 * @param src           The data to be written.
     
    823816            UPPER32(ba), cnt);
    824817        if (rc != EOK) {
    825                 printf("Error %d reading %zu blocks starting at block %" PRIuOFF64
    826                     " from device handle %" PRIun "\n", rc, cnt, ba,
     818                printf("Error %d reading %d blocks starting at block %" PRIuOFF64
     819                    " from device handle %d\n", rc, cnt, ba,
    827820                    devcon->devmap_handle);
    828821#ifndef NDEBUG
     
    850843            UPPER32(ba), cnt);
    851844        if (rc != EOK) {
    852                 printf("Error %d writing %zu blocks starting at block %" PRIuOFF64
    853                     " to device handle %" PRIun "\n", rc, cnt, ba, devcon->devmap_handle);
     845                printf("Error %d writing %d blocks starting at block %" PRIuOFF64
     846                    " to device handle %d\n", rc, cnt, ba, devcon->devmap_handle);
    854847#ifndef NDEBUG
    855848                stacktrace_print();
     
    886879}
    887880
    888 /** Convert logical block address to physical block address. */
    889 static 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 
    895881/** @}
    896882 */
Note: See TracChangeset for help on using the changeset viewer.