Changes in uspace/lib/block/libblock.c [7e752b2:a6ba0c9] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/libblock.c
r7e752b2 ra6ba0c9 66 66 fibril_mutex_t lock; 67 67 size_t lblock_size; /**< Logical block size. */ 68 unsigned blocks_cluster; /**< Physical blocks per block_t */ 68 69 unsigned block_count; /**< Total number of blocks. */ 69 70 unsigned blocks_cached; /**< Number of cached blocks. */ … … 90 91 static int get_block_size(int dev_phone, size_t *bsize); 91 92 static int get_num_blocks(int dev_phone, aoff64_t *nblocks); 93 static aoff64_t ba_ltop(devcon_t *devcon, aoff64_t lba); 92 94 93 95 static devcon_t *devcon_search(devmap_handle_t devmap_handle) … … 259 261 { 260 262 block_t *b = hash_table_get_instance(item, block_t, hash_link); 261 return b-> boff== *key;263 return b->lba == *key; 262 264 } 263 265 … … 292 294 cache->mode = mode; 293 295 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; 296 301 297 302 if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 1, … … 329 334 if (b->dirty) { 330 335 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); 332 337 if (rc != EOK) 333 338 return rc; 334 339 } 335 340 336 unsigned long key = b-> boff;341 unsigned long key = b->lba; 337 342 hash_table_remove(&cache->block_hash, &key, 1); 338 343 … … 375 380 * block pointer on success. 376 381 * @param devmap_handle Device handle of the block device. 377 * @param b off Block offset.382 * @param ba Block address (logical). 378 383 * @param flags If BLOCK_FLAGS_NOREAD is specified, block_get() 379 384 * will not read the contents of the block from the … … 382 387 * @return EOK on success or a negative error code. 383 388 */ 384 int block_get(block_t **block, devmap_handle_t devmap_handle, aoff64_t b off, int flags)389 int block_get(block_t **block, devmap_handle_t devmap_handle, aoff64_t ba, int flags) 385 390 { 386 391 devcon_t *devcon; … … 388 393 block_t *b; 389 394 link_t *l; 390 unsigned long key = b off;395 unsigned long key = ba; 391 396 int rc; 392 397 … … 465 470 fibril_mutex_lock(&devcon->comm_area_lock); 466 471 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); 468 474 fibril_mutex_unlock(&devcon->comm_area_lock); 469 475 if (rc != EOK) { … … 495 501 */ 496 502 list_remove(&b->free_link); 497 temp_key = b-> boff;503 temp_key = b->lba; 498 504 hash_table_remove(&cache->block_hash, &temp_key, 1); 499 505 } … … 502 508 b->devmap_handle = devmap_handle; 503 509 b->size = cache->lblock_size; 504 b->boff = boff; 510 b->lba = ba; 511 b->pba = ba_ltop(devcon, b->lba); 505 512 hash_table_insert(&cache->block_hash, &key, &b->hash_link); 506 513 … … 519 526 */ 520 527 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); 522 529 memcpy(b->data, devcon->comm_area, cache->lblock_size); 523 530 fibril_mutex_unlock(&devcon->comm_area_lock); … … 580 587 fibril_mutex_lock(&devcon->comm_area_lock); 581 588 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); 583 590 fibril_mutex_unlock(&devcon->comm_area_lock); 584 591 block->dirty = false; … … 614 621 * Take the block out of the cache and free it. 615 622 */ 616 unsigned long key = block-> boff;623 unsigned long key = block->lba; 617 624 hash_table_remove(&cache->block_hash, &key, 1); 618 625 free(block); … … 712 719 * 713 720 * @param devmap_handle Device handle of the block device. 714 * @param ba Address of first block .721 * @param ba Address of first block (physical). 715 722 * @param cnt Number of blocks. 716 723 * @param src Buffer for storing the data. … … 740 747 * 741 748 * @param devmap_handle Device handle of the block device. 742 * @param ba Address of first block .749 * @param ba Address of first block (physical). 743 750 * @param cnt Number of blocks. 744 751 * @param src The data to be written. … … 879 886 } 880 887 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 881 895 /** @} 882 896 */
Note:
See TracChangeset
for help on using the changeset viewer.