Changeset 1fbe064b in mainline for uspace/lib/libblock/libblock.c
- Timestamp:
- 2009-06-26T21:34:47Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 00fe6bb
- Parents:
- af65b72
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libblock/libblock.c
raf65b72 r1fbe064b 66 66 hash_table_t block_hash; 67 67 link_t free_head; 68 enum cache_mode mode; 68 69 } cache_t; 69 70 … … 80 81 } devcon_t; 81 82 83 static int write_block(devcon_t *devcon, bn_t boff, size_t block_size, 84 const void *src); 85 82 86 static devcon_t *devcon_search(dev_handle_t dev_handle) 83 87 { … … 251 255 }; 252 256 253 int block_cache_init(dev_handle_t dev_handle, size_t size, unsigned blocks) 257 int block_cache_init(dev_handle_t dev_handle, size_t size, unsigned blocks, 258 enum cache_mode mode) 254 259 { 255 260 devcon_t *devcon = devcon_search(dev_handle); … … 267 272 cache->block_size = size; 268 273 cache->block_count = blocks; 274 cache->mode = mode; 269 275 270 276 if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 1, … … 414 420 devcon_t *devcon = devcon_search(block->dev_handle); 415 421 cache_t *cache; 422 int rc; 416 423 417 424 assert(devcon); … … 427 434 */ 428 435 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 } 429 443 } 430 444 fibril_mutex_unlock(&block->lock); … … 491 505 } 492 506 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 */ 516 static 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 493 533 /** @} 494 534 */
Note:
See TracChangeset
for help on using the changeset viewer.