Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4571 → Rev 4572

/trunk/uspace/lib/libblock/libblock.c
65,6 → 65,7
unsigned block_count; /**< Total number of blocks. */
hash_table_t block_hash;
link_t free_head;
enum cache_mode mode;
} cache_t;
 
typedef struct {
79,6 → 80,9
cache_t *cache;
} devcon_t;
 
static int write_block(devcon_t *devcon, bn_t boff, size_t block_size,
const void *src);
 
static devcon_t *devcon_search(dev_handle_t dev_handle)
{
link_t *cur;
250,7 → 254,8
.remove_callback = cache_remove_callback
};
 
int block_cache_init(dev_handle_t dev_handle, size_t size, unsigned blocks)
int block_cache_init(dev_handle_t dev_handle, size_t size, unsigned blocks,
enum cache_mode mode)
{
devcon_t *devcon = devcon_search(dev_handle);
cache_t *cache;
266,6 → 271,7
list_initialize(&cache->free_head);
cache->block_size = size;
cache->block_count = blocks;
cache->mode = mode;
 
if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 1,
&cache_ops)) {
413,6 → 419,7
{
devcon_t *devcon = devcon_search(block->dev_handle);
cache_t *cache;
int rc;
 
assert(devcon);
assert(devcon->cache);
426,6 → 433,13
* free list.
*/
list_append(&block->free_link, &cache->free_head);
if (cache->mode != CACHE_MODE_WB && block->dirty) {
rc = write_block(devcon, block->boff, block->size,
block->data);
assert(rc == EOK);
 
block->dirty = false;
}
}
fibril_mutex_unlock(&block->lock);
fibril_mutex_unlock(&cache->lock);
490,5 → 504,31
return EOK;
}
 
/** Write block to block device.
*
* @param devcon Device connection.
* @param boff Block index.
* @param block_size Block size.
* @param src Buffer containing the data to write.
*
* @return EOK on success or negative error code on failure.
*/
static int write_block(devcon_t *devcon, bn_t boff, size_t block_size,
const void *src)
{
ipcarg_t retval;
int rc;
 
assert(devcon);
memcpy(devcon->com_area, src, block_size);
rc = async_req_2_1(devcon->dev_phone, BD_WRITE_BLOCK,
boff, block_size, &retval);
if ((rc != EOK) || (retval != EOK))
return (rc != EOK ? rc : (int) retval);
 
return EOK;
}
 
/** @}
*/
/trunk/uspace/lib/libblock/libblock.h
84,6 → 84,14
void *data;
} block_t;
 
/** Caching mode */
enum cache_mode {
/** Write-Through */
CACHE_MODE_WT,
/** Write-Back */
CACHE_MODE_WB
};
 
extern int block_init(dev_handle_t, size_t);
extern void block_fini(dev_handle_t);
 
90,7 → 98,7
extern int block_bb_read(dev_handle_t, off_t, size_t);
extern void *block_bb_get(dev_handle_t);
 
extern int block_cache_init(dev_handle_t, size_t, unsigned);
extern int block_cache_init(dev_handle_t, size_t, unsigned, enum cache_mode);
 
extern block_t *block_get(dev_handle_t, bn_t, int flags);
extern void block_put(block_t *);