Changeset 1fbe064b in mainline for uspace/lib/libblock/libblock.c


Ignore:
Timestamp:
2009-06-26T21:34:47Z (15 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
00fe6bb
Parents:
af65b72
Message:

Allow libblock to operate in write-through mode. With 'wtcache' mount option, FAT sets write-through mode on the cache.

File:
1 edited

Legend:

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

    raf65b72 r1fbe064b  
    6666        hash_table_t block_hash;
    6767        link_t free_head;
     68        enum cache_mode mode;
    6869} cache_t;
    6970
     
    8081} devcon_t;
    8182
     83static int write_block(devcon_t *devcon, bn_t boff, size_t block_size,
     84    const void *src);
     85
    8286static devcon_t *devcon_search(dev_handle_t dev_handle)
    8387{
     
    251255};
    252256
    253 int block_cache_init(dev_handle_t dev_handle, size_t size, unsigned blocks)
     257int block_cache_init(dev_handle_t dev_handle, size_t size, unsigned blocks,
     258    enum cache_mode mode)
    254259{
    255260        devcon_t *devcon = devcon_search(dev_handle);
     
    267272        cache->block_size = size;
    268273        cache->block_count = blocks;
     274        cache->mode = mode;
    269275
    270276        if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 1,
     
    414420        devcon_t *devcon = devcon_search(block->dev_handle);
    415421        cache_t *cache;
     422        int rc;
    416423
    417424        assert(devcon);
     
    427434                 */
    428435                list_append(&block->free_link, &cache->free_head);
     436                if (cache->mode != CACHE_MODE_WB && block->dirty) {
     437                        rc = write_block(devcon, block->boff, block->size,
     438                            block->data);
     439                        assert(rc == EOK);
     440
     441                        block->dirty = false;
     442                }
    429443        }
    430444        fibril_mutex_unlock(&block->lock);
     
    491505}
    492506
     507/** Write block to block device.
     508 *
     509 * @param devcon        Device connection.
     510 * @param boff          Block index.
     511 * @param block_size    Block size.
     512 * @param src           Buffer containing the data to write.
     513 *
     514 * @return              EOK on success or negative error code on failure.
     515 */
     516static int write_block(devcon_t *devcon, bn_t boff, size_t block_size,
     517    const void *src)
     518{
     519        ipcarg_t retval;
     520        int rc;
     521
     522        assert(devcon);
     523        memcpy(devcon->com_area, src, block_size);
     524       
     525        rc = async_req_2_1(devcon->dev_phone, BD_WRITE_BLOCK,
     526            boff, block_size, &retval);
     527        if ((rc != EOK) || (retval != EOK))
     528                return (rc != EOK ? rc : (int) retval);
     529
     530        return EOK;
     531}
     532
    493533/** @}
    494534 */
Note: See TracChangeset for help on using the changeset viewer.