Changes in / [f0e1ac9:3e94678] in mainline
- Location:
- uspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/libblock.c
rf0e1ac9 r3e94678 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. … … 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 */ -
uspace/lib/block/libblock.h
rf0e1ac9 r3e94678 73 73 /** Handle of the device where the block resides. */ 74 74 devmap_handle_t devmap_handle; 75 /** Logical block address */ 76 aoff64_t lba; 77 /** Physical block address */ 78 aoff64_t pba; 75 /** Block offset on the block device. Counted in 'size'-byte blocks. */ 76 aoff64_t boff; 79 77 /** Size of the block. */ 80 78 size_t size; -
uspace/srv/bd/file_bd/file_bd.c
rf0e1ac9 r3e94678 56 56 #define NAME "file_bd" 57 57 58 #define DEFAULT_BLOCK_SIZE 512 59 60 static size_t block_size; 58 static const size_t block_size = 512; 61 59 static aoff64_t num_blocks; 62 60 static FILE *img; … … 65 63 static fibril_mutex_t dev_lock; 66 64 67 static void print_usage(void);68 65 static int file_bd_init(const char *fname); 69 66 static void file_bd_connection(ipc_callid_t iid, ipc_call_t *icall); … … 74 71 { 75 72 int rc; 76 char *image_name;77 char *device_name;78 73 79 74 printf(NAME ": File-backed block device driver\n"); 80 75 81 block_size = DEFAULT_BLOCK_SIZE; 82 83 ++argv; --argc; 84 while (*argv != NULL && (*argv)[0] == '-') { 85 /* Option */ 86 if (str_cmp(*argv, "-b") == 0) { 87 if (argc < 2) { 88 printf("Argument missing.\n"); 89 print_usage(); 90 return -1; 91 } 92 93 rc = str_size_t(argv[1], NULL, 10, true, &block_size); 94 if (rc != EOK || block_size == 0) { 95 printf("Invalid block size '%s'.\n", argv[1]); 96 print_usage(); 97 return -1; 98 } 99 ++argv; --argc; 100 } else { 101 printf("Invalid option '%s'.\n", *argv); 102 print_usage(); 103 return -1; 104 } 105 ++argv; --argc; 106 } 107 108 if (argc < 2) { 109 printf("Missing arguments.\n"); 110 print_usage(); 76 if (argc != 3) { 77 printf("Expected two arguments (image name, device name).\n"); 111 78 return -1; 112 79 } 113 80 114 image_name = argv[0]; 115 device_name = argv[1]; 116 117 if (file_bd_init(image_name) != EOK) 81 if (file_bd_init(argv[1]) != EOK) 118 82 return -1; 119 83 120 rc = devmap_device_register( device_name, &devmap_handle);84 rc = devmap_device_register(argv[2], &devmap_handle); 121 85 if (rc != EOK) { 122 86 devmap_hangup_phone(DEVMAP_DRIVER); 123 printf(NAME ": Unable to register device '%s'.\n",124 device_name);87 printf(NAME ": Unable to register device %s.\n", 88 argv[2]); 125 89 return rc; 126 90 } … … 132 96 /* Not reached */ 133 97 return 0; 134 }135 136 static void print_usage(void)137 {138 printf("Usage: " NAME " [-b <block_size>] <image_file> <device_name>\n");139 98 } 140 99
Note:
See TracChangeset
for help on using the changeset viewer.