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