Changeset f0e1ac9 in mainline
- Timestamp:
- 2010-11-27T17:13:30Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 41a7f62
- Parents:
- 3e94678 (diff), d70d80ed (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/libblock.c
r3e94678 rf0e1ac9 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 */ -
uspace/lib/block/libblock.h
r3e94678 rf0e1ac9 73 73 /** Handle of the device where the block resides. */ 74 74 devmap_handle_t devmap_handle; 75 /** Block offset on the block device. Counted in 'size'-byte blocks. */ 76 aoff64_t boff; 75 /** Logical block address */ 76 aoff64_t lba; 77 /** Physical block address */ 78 aoff64_t pba; 77 79 /** Size of the block. */ 78 80 size_t size; -
uspace/srv/bd/file_bd/file_bd.c
r3e94678 rf0e1ac9 56 56 #define NAME "file_bd" 57 57 58 static const size_t block_size = 512; 58 #define DEFAULT_BLOCK_SIZE 512 59 60 static size_t block_size; 59 61 static aoff64_t num_blocks; 60 62 static FILE *img; … … 63 65 static fibril_mutex_t dev_lock; 64 66 67 static void print_usage(void); 65 68 static int file_bd_init(const char *fname); 66 69 static void file_bd_connection(ipc_callid_t iid, ipc_call_t *icall); … … 71 74 { 72 75 int rc; 76 char *image_name; 77 char *device_name; 73 78 74 79 printf(NAME ": File-backed block device driver\n"); 75 80 76 if (argc != 3) { 77 printf("Expected two arguments (image name, device name).\n"); 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(); 78 111 return -1; 79 112 } 80 113 81 if (file_bd_init(argv[1]) != EOK) 114 image_name = argv[0]; 115 device_name = argv[1]; 116 117 if (file_bd_init(image_name) != EOK) 82 118 return -1; 83 119 84 rc = devmap_device_register( argv[2], &devmap_handle);120 rc = devmap_device_register(device_name, &devmap_handle); 85 121 if (rc != EOK) { 86 122 devmap_hangup_phone(DEVMAP_DRIVER); 87 printf(NAME ": Unable to register device %s.\n",88 argv[2]);123 printf(NAME ": Unable to register device '%s'.\n", 124 device_name); 89 125 return rc; 90 126 } … … 96 132 /* Not reached */ 97 133 return 0; 134 } 135 136 static void print_usage(void) 137 { 138 printf("Usage: " NAME " [-b <block_size>] <image_file> <device_name>\n"); 98 139 } 99 140
Note:
See TracChangeset
for help on using the changeset viewer.