Changes in uspace/lib/block/libblock.c [08cba4b:c7bbf029] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/libblock.c
r08cba4b rc7bbf029 2 2 * Copyright (c) 2008 Jakub Jermar 3 3 * Copyright (c) 2008 Martin Decky 4 * Copyright (c) 2011 Martin Sucha5 4 * All rights reserved. 6 5 * … … 39 38 #include "libblock.h" 40 39 #include "../../srv/vfs/vfs.h" 41 #include <ipc/ loc.h>40 #include <ipc/devmap.h> 42 41 #include <ipc/bd.h> 43 42 #include <ipc/services.h> … … 60 59 static FIBRIL_MUTEX_INITIALIZE(dcl_lock); 61 60 /** Device connection list head. */ 62 static LIST_INITIALIZE(dcl );63 64 #define CACHE_BUCKETS_LOG2 65 #define CACHE_BUCKETS 61 static LIST_INITIALIZE(dcl_head); 62 63 #define CACHE_BUCKETS_LOG2 10 64 #define CACHE_BUCKETS (1 << CACHE_BUCKETS_LOG2) 66 65 67 66 typedef struct { 68 67 fibril_mutex_t lock; 69 size_t lblock_size; 70 unsigned blocks_cluster; 71 unsigned block_count; 72 unsigned blocks_cached; 68 size_t lblock_size; /**< Logical block size. */ 69 unsigned blocks_cluster; /**< Physical blocks per block_t */ 70 unsigned block_count; /**< Total number of blocks. */ 71 unsigned blocks_cached; /**< Number of cached blocks. */ 73 72 hash_table_t block_hash; 74 li st_t free_list;73 link_t free_head; 75 74 enum cache_mode mode; 76 75 } cache_t; … … 78 77 typedef struct { 79 78 link_t link; 80 service_id_t service_id;81 async_sess_t *sess;79 devmap_handle_t devmap_handle; 80 int dev_phone; 82 81 fibril_mutex_t comm_area_lock; 83 82 void *comm_area; … … 85 84 void *bb_buf; 86 85 aoff64_t bb_addr; 87 size_t pblock_size; 86 size_t pblock_size; /**< Physical block size. */ 88 87 cache_t *cache; 89 88 } devcon_t; 90 89 91 static int read_blocks(devcon_t *, aoff64_t, size_t); 92 static int write_blocks(devcon_t *, aoff64_t, size_t); 93 static int get_block_size(async_sess_t *, size_t *); 94 static int get_num_blocks(async_sess_t *, aoff64_t *); 95 static aoff64_t ba_ltop(devcon_t *, aoff64_t); 96 97 static devcon_t *devcon_search(service_id_t service_id) 98 { 90 static int read_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt); 91 static int write_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt); 92 static int get_block_size(int dev_phone, size_t *bsize); 93 static int get_num_blocks(int dev_phone, aoff64_t *nblocks); 94 static aoff64_t ba_ltop(devcon_t *devcon, aoff64_t lba); 95 96 static devcon_t *devcon_search(devmap_handle_t devmap_handle) 97 { 98 link_t *cur; 99 99 100 fibril_mutex_lock(&dcl_lock); 100 101 list_foreach(dcl, cur) { 101 for (cur = dcl_head.next; cur != &dcl_head; cur = cur->next) { 102 102 devcon_t *devcon = list_get_instance(cur, devcon_t, link); 103 if (devcon-> service_id == service_id) {103 if (devcon->devmap_handle == devmap_handle) { 104 104 fibril_mutex_unlock(&dcl_lock); 105 105 return devcon; 106 106 } 107 107 } 108 109 108 fibril_mutex_unlock(&dcl_lock); 110 109 return NULL; 111 110 } 112 111 113 static int devcon_add(service_id_t service_id, async_sess_t *sess, 114 size_t bsize, void *comm_area, size_t comm_size) 115 { 112 static int devcon_add(devmap_handle_t devmap_handle, int dev_phone, size_t bsize, 113 void *comm_area, size_t comm_size) 114 { 115 link_t *cur; 116 116 devcon_t *devcon; 117 117 118 118 if (comm_size < bsize) 119 119 return EINVAL; 120 120 121 121 devcon = malloc(sizeof(devcon_t)); 122 122 if (!devcon) … … 124 124 125 125 link_initialize(&devcon->link); 126 devcon-> service_id = service_id;127 devcon-> sess = sess;126 devcon->devmap_handle = devmap_handle; 127 devcon->dev_phone = dev_phone; 128 128 fibril_mutex_initialize(&devcon->comm_area_lock); 129 129 devcon->comm_area = comm_area; … … 133 133 devcon->pblock_size = bsize; 134 134 devcon->cache = NULL; 135 135 136 136 fibril_mutex_lock(&dcl_lock); 137 list_foreach(dcl, cur) {137 for (cur = dcl_head.next; cur != &dcl_head; cur = cur->next) { 138 138 devcon_t *d = list_get_instance(cur, devcon_t, link); 139 if (d-> service_id == service_id) {139 if (d->devmap_handle == devmap_handle) { 140 140 fibril_mutex_unlock(&dcl_lock); 141 141 free(devcon); … … 143 143 } 144 144 } 145 list_append(&devcon->link, &dcl );145 list_append(&devcon->link, &dcl_head); 146 146 fibril_mutex_unlock(&dcl_lock); 147 147 return EOK; … … 155 155 } 156 156 157 int block_init(exch_mgmt_t mgmt, service_id_t service_id, 158 size_t comm_size) 159 { 160 void *comm_area = mmap(NULL, comm_size, PROTO_READ | PROTO_WRITE, 157 int block_init(devmap_handle_t devmap_handle, size_t comm_size) 158 { 159 int rc; 160 int dev_phone; 161 void *comm_area; 162 size_t bsize; 163 164 comm_area = mmap(NULL, comm_size, PROTO_READ | PROTO_WRITE, 161 165 MAP_ANONYMOUS | MAP_PRIVATE, 0, 0); 162 if (!comm_area) 166 if (!comm_area) { 163 167 return ENOMEM; 164 165 async_sess_t *sess = loc_service_connect(mgmt, service_id, 166 167 if ( !sess) {168 } 169 170 dev_phone = devmap_device_connect(devmap_handle, IPC_FLAG_BLOCKING); 171 if (dev_phone < 0) { 168 172 munmap(comm_area, comm_size); 169 return ENOENT; 170 } 171 172 async_exch_t *exch = async_exchange_begin(sess); 173 int rc = async_share_out_start(exch, comm_area, 173 return dev_phone; 174 } 175 176 rc = async_share_out_start(dev_phone, comm_area, 174 177 AS_AREA_READ | AS_AREA_WRITE); 175 async_exchange_end(exch); 176 178 if (rc != EOK) { 179 munmap(comm_area, comm_size); 180 async_hangup(dev_phone); 181 return rc; 182 } 183 184 if (get_block_size(dev_phone, &bsize) != EOK) { 185 munmap(comm_area, comm_size); 186 async_hangup(dev_phone); 187 return rc; 188 } 189 190 rc = devcon_add(devmap_handle, dev_phone, bsize, comm_area, comm_size); 177 191 if (rc != EOK) { 178 192 munmap(comm_area, comm_size); 179 async_hangup( sess);193 async_hangup(dev_phone); 180 194 return rc; 181 195 } 182 183 size_t bsize; 184 rc = get_block_size(sess, &bsize); 185 186 if (rc != EOK) { 187 munmap(comm_area, comm_size); 188 async_hangup(sess); 189 return rc; 190 } 191 192 rc = devcon_add(service_id, sess, bsize, comm_area, comm_size); 193 if (rc != EOK) { 194 munmap(comm_area, comm_size); 195 async_hangup(sess); 196 return rc; 197 } 198 196 199 197 return EOK; 200 198 } 201 199 202 void block_fini( service_id_t service_id)203 { 204 devcon_t *devcon = devcon_search( service_id);200 void block_fini(devmap_handle_t devmap_handle) 201 { 202 devcon_t *devcon = devcon_search(devmap_handle); 205 203 assert(devcon); 206 204 207 205 if (devcon->cache) 208 (void) block_cache_fini( service_id);209 206 (void) block_cache_fini(devmap_handle); 207 210 208 devcon_remove(devcon); 211 209 212 210 if (devcon->bb_buf) 213 211 free(devcon->bb_buf); 214 212 215 213 munmap(devcon->comm_area, devcon->comm_size); 216 async_hangup(devcon-> sess);217 218 free(devcon); 219 } 220 221 int block_bb_read( service_id_t service_id, aoff64_t ba)214 async_hangup(devcon->dev_phone); 215 216 free(devcon); 217 } 218 219 int block_bb_read(devmap_handle_t devmap_handle, aoff64_t ba) 222 220 { 223 221 void *bb_buf; 224 222 int rc; 225 223 226 devcon_t *devcon = devcon_search( service_id);224 devcon_t *devcon = devcon_search(devmap_handle); 227 225 if (!devcon) 228 226 return ENOENT; … … 249 247 } 250 248 251 void *block_bb_get( service_id_t service_id)252 { 253 devcon_t *devcon = devcon_search( service_id);249 void *block_bb_get(devmap_handle_t devmap_handle) 250 { 251 devcon_t *devcon = devcon_search(devmap_handle); 254 252 assert(devcon); 255 253 return devcon->bb_buf; … … 258 256 static hash_index_t cache_hash(unsigned long *key) 259 257 { 260 return MERGE_LOUP32(key[0], key[1])& (CACHE_BUCKETS - 1);258 return *key & (CACHE_BUCKETS - 1); 261 259 } 262 260 … … 264 262 { 265 263 block_t *b = hash_table_get_instance(item, block_t, hash_link); 266 return b->lba == MERGE_LOUP32(key[0], key[1]);264 return b->lba == *key; 267 265 } 268 266 … … 277 275 }; 278 276 279 int block_cache_init( service_id_t service_id, size_t size, unsigned blocks,277 int block_cache_init(devmap_handle_t devmap_handle, size_t size, unsigned blocks, 280 278 enum cache_mode mode) 281 279 { 282 devcon_t *devcon = devcon_search( service_id);280 devcon_t *devcon = devcon_search(devmap_handle); 283 281 cache_t *cache; 284 282 if (!devcon) … … 291 289 292 290 fibril_mutex_initialize(&cache->lock); 293 list_initialize(&cache->free_ list);291 list_initialize(&cache->free_head); 294 292 cache->lblock_size = size; 295 293 cache->block_count = blocks; … … 305 303 cache->blocks_cluster = cache->lblock_size / devcon->pblock_size; 306 304 307 if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 2,305 if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 1, 308 306 &cache_ops)) { 309 307 free(cache); … … 315 313 } 316 314 317 int block_cache_fini( service_id_t service_id)318 { 319 devcon_t *devcon = devcon_search( service_id);315 int block_cache_fini(devmap_handle_t devmap_handle) 316 { 317 devcon_t *devcon = devcon_search(devmap_handle); 320 318 cache_t *cache; 321 319 int rc; … … 332 330 * bother with the cache and block locks because we are single-threaded. 333 331 */ 334 while (!list_empty(&cache->free_ list)) {335 block_t *b = list_get_instance( list_first(&cache->free_list),332 while (!list_empty(&cache->free_head)) { 333 block_t *b = list_get_instance(cache->free_head.next, 336 334 block_t, free_link); 337 335 … … 344 342 } 345 343 346 unsigned long key[2] = { 347 LOWER32(b->lba), 348 UPPER32(b->lba) 349 }; 350 hash_table_remove(&cache->block_hash, key, 2); 344 unsigned long key = b->lba; 345 hash_table_remove(&cache->block_hash, &key, 1); 351 346 352 347 free(b->data); … … 367 362 if (cache->blocks_cached < CACHE_LO_WATERMARK) 368 363 return true; 369 if (!list_empty(&cache->free_ list))364 if (!list_empty(&cache->free_head)) 370 365 return false; 371 366 return true; … … 387 382 * @param block Pointer to where the function will store the 388 383 * block pointer on success. 389 * @param service_id Service IDof the block device.384 * @param devmap_handle Device handle of the block device. 390 385 * @param ba Block address (logical). 391 386 * @param flags If BLOCK_FLAGS_NOREAD is specified, block_get() … … 395 390 * @return EOK on success or a negative error code. 396 391 */ 397 int block_get(block_t **block, service_id_t service_id, aoff64_t ba, int flags)392 int block_get(block_t **block, devmap_handle_t devmap_handle, aoff64_t ba, int flags) 398 393 { 399 394 devcon_t *devcon; … … 401 396 block_t *b; 402 397 link_t *l; 403 unsigned long key[2] = { 404 LOWER32(ba), 405 UPPER32(ba) 406 }; 407 398 unsigned long key = ba; 408 399 int rc; 409 400 410 devcon = devcon_search( service_id);401 devcon = devcon_search(devmap_handle); 411 402 412 403 assert(devcon); … … 420 411 421 412 fibril_mutex_lock(&cache->lock); 422 l = hash_table_find(&cache->block_hash, key);413 l = hash_table_find(&cache->block_hash, &key); 423 414 if (l) { 424 415 found: … … 458 449 * Try to recycle a block from the free list. 459 450 */ 451 unsigned long temp_key; 460 452 recycle: 461 if (list_empty(&cache->free_ list)) {453 if (list_empty(&cache->free_head)) { 462 454 fibril_mutex_unlock(&cache->lock); 463 455 rc = ENOMEM; 464 456 goto out; 465 457 } 466 l = list_first(&cache->free_list);458 l = cache->free_head.next; 467 459 b = list_get_instance(l, block_t, free_link); 468 460 … … 479 471 */ 480 472 list_remove(&b->free_link); 481 list_append(&b->free_link, &cache->free_ list);473 list_append(&b->free_link, &cache->free_head); 482 474 fibril_mutex_unlock(&cache->lock); 483 475 fibril_mutex_lock(&devcon->comm_area_lock); … … 505 497 goto retry; 506 498 } 507 l = hash_table_find(&cache->block_hash, key);499 l = hash_table_find(&cache->block_hash, &key); 508 500 if (l) { 509 501 /* … … 528 520 */ 529 521 list_remove(&b->free_link); 530 unsigned long temp_key[2] = { 531 LOWER32(b->lba), 532 UPPER32(b->lba) 533 }; 534 hash_table_remove(&cache->block_hash, temp_key, 2); 522 temp_key = b->lba; 523 hash_table_remove(&cache->block_hash, &temp_key, 1); 535 524 } 536 525 537 526 block_initialize(b); 538 b-> service_id = service_id;527 b->devmap_handle = devmap_handle; 539 528 b->size = cache->lblock_size; 540 529 b->lba = ba; 541 530 b->pba = ba_ltop(devcon, b->lba); 542 hash_table_insert(&cache->block_hash, key, &b->hash_link);531 hash_table_insert(&cache->block_hash, &key, &b->hash_link); 543 532 544 533 /* … … 586 575 int block_put(block_t *block) 587 576 { 588 devcon_t *devcon = devcon_search(block-> service_id);577 devcon_t *devcon = devcon_search(block->devmap_handle); 589 578 cache_t *cache; 590 579 unsigned blocks_cached; … … 652 641 * Take the block out of the cache and free it. 653 642 */ 654 unsigned long key[2] = { 655 LOWER32(block->lba), 656 UPPER32(block->lba) 657 }; 658 hash_table_remove(&cache->block_hash, key, 2); 643 unsigned long key = block->lba; 644 hash_table_remove(&cache->block_hash, &key, 1); 659 645 fibril_mutex_unlock(&block->lock); 660 646 free(block->data); … … 677 663 goto retry; 678 664 } 679 list_append(&block->free_link, &cache->free_ list);665 list_append(&block->free_link, &cache->free_head); 680 666 } 681 667 fibril_mutex_unlock(&block->lock); … … 687 673 /** Read sequential data from a block device. 688 674 * 689 * @param service_id Service IDof the block device.675 * @param devmap_handle Device handle of the block device. 690 676 * @param bufpos Pointer to the first unread valid offset within the 691 677 * communication buffer. … … 699 685 * @return EOK on success or a negative return code on failure. 700 686 */ 701 int block_seqread( service_id_t service_id, size_t *bufpos, size_t *buflen,687 int block_seqread(devmap_handle_t devmap_handle, size_t *bufpos, size_t *buflen, 702 688 aoff64_t *pos, void *dst, size_t size) 703 689 { … … 707 693 devcon_t *devcon; 708 694 709 devcon = devcon_search( service_id);695 devcon = devcon_search(devmap_handle); 710 696 assert(devcon); 711 697 block_size = devcon->pblock_size; … … 753 739 /** Read blocks directly from device (bypass cache). 754 740 * 755 * @param service_id Service IDof the block device.741 * @param devmap_handle Device handle of the block device. 756 742 * @param ba Address of first block (physical). 757 743 * @param cnt Number of blocks. … … 760 746 * @return EOK on success or negative error code on failure. 761 747 */ 762 int block_read_direct( service_id_t service_id, aoff64_t ba, size_t cnt, void *buf)748 int block_read_direct(devmap_handle_t devmap_handle, aoff64_t ba, size_t cnt, void *buf) 763 749 { 764 750 devcon_t *devcon; 765 751 int rc; 766 752 767 devcon = devcon_search( service_id);753 devcon = devcon_search(devmap_handle); 768 754 assert(devcon); 769 755 … … 781 767 /** Write blocks directly to device (bypass cache). 782 768 * 783 * @param service_id Service IDof the block device.769 * @param devmap_handle Device handle of the block device. 784 770 * @param ba Address of first block (physical). 785 771 * @param cnt Number of blocks. … … 788 774 * @return EOK on success or negative error code on failure. 789 775 */ 790 int block_write_direct( service_id_t service_id, aoff64_t ba, size_t cnt,776 int block_write_direct(devmap_handle_t devmap_handle, aoff64_t ba, size_t cnt, 791 777 const void *data) 792 778 { … … 794 780 int rc; 795 781 796 devcon = devcon_search( service_id);782 devcon = devcon_search(devmap_handle); 797 783 assert(devcon); 798 784 … … 809 795 /** Get device block size. 810 796 * 811 * @param service_id Service IDof the block device.797 * @param devmap_handle Device handle of the block device. 812 798 * @param bsize Output block size. 813 799 * 814 800 * @return EOK on success or negative error code on failure. 815 801 */ 816 int block_get_bsize( service_id_t service_id, size_t *bsize)802 int block_get_bsize(devmap_handle_t devmap_handle, size_t *bsize) 817 803 { 818 804 devcon_t *devcon; 819 805 820 devcon = devcon_search( service_id);821 assert(devcon); 822 823 return get_block_size(devcon-> sess, bsize);806 devcon = devcon_search(devmap_handle); 807 assert(devcon); 808 809 return get_block_size(devcon->dev_phone, bsize); 824 810 } 825 811 826 812 /** Get number of blocks on device. 827 813 * 828 * @param service_id Service IDof the block device.814 * @param devmap_handle Device handle of the block device. 829 815 * @param nblocks Output number of blocks. 830 816 * 831 817 * @return EOK on success or negative error code on failure. 832 818 */ 833 int block_get_nblocks(service_id_t service_id, aoff64_t *nblocks) 834 { 835 devcon_t *devcon = devcon_search(service_id); 836 assert(devcon); 837 838 return get_num_blocks(devcon->sess, nblocks); 839 } 840 841 /** Read bytes directly from the device (bypass cache) 842 * 843 * @param service_id Service ID of the block device. 844 * @param abs_offset Absolute offset in bytes where to start reading 845 * @param bytes Number of bytes to read 846 * @param data Buffer that receives the data 847 * 848 * @return EOK on success or negative error code on failure. 849 */ 850 int block_read_bytes_direct(service_id_t service_id, aoff64_t abs_offset, 851 size_t bytes, void *data) 852 { 853 int rc; 854 size_t phys_block_size; 855 size_t buf_size; 856 void *buffer; 857 aoff64_t first_block; 858 aoff64_t last_block; 859 size_t blocks; 860 size_t offset; 861 862 rc = block_get_bsize(service_id, &phys_block_size); 863 if (rc != EOK) { 864 return rc; 865 } 866 867 /* calculate data position and required space */ 868 first_block = abs_offset / phys_block_size; 869 offset = abs_offset % phys_block_size; 870 last_block = (abs_offset + bytes - 1) / phys_block_size; 871 blocks = last_block - first_block + 1; 872 buf_size = blocks * phys_block_size; 873 874 /* read the data into memory */ 875 buffer = malloc(buf_size); 876 if (buffer == NULL) { 877 return ENOMEM; 878 } 879 880 rc = block_read_direct(service_id, first_block, blocks, buffer); 881 if (rc != EOK) { 882 free(buffer); 883 return rc; 884 } 885 886 /* copy the data from the buffer */ 887 memcpy(data, buffer + offset, bytes); 888 free(buffer); 889 890 return EOK; 891 } 892 893 /** Get TOC from device. 894 * 895 * @param service_id Service ID of the block device. 896 * @param session Starting session. 897 * 898 * @return Allocated TOC structure. 899 * @return NULL on failure. 900 * 901 */ 902 toc_block_t *block_get_toc(service_id_t service_id, uint8_t session) 903 { 904 devcon_t *devcon = devcon_search(service_id); 905 assert(devcon); 906 907 toc_block_t *toc = NULL; 908 909 fibril_mutex_lock(&devcon->comm_area_lock); 910 911 async_exch_t *exch = async_exchange_begin(devcon->sess); 912 int rc = async_req_1_0(exch, BD_READ_TOC, session); 913 async_exchange_end(exch); 914 915 if (rc == EOK) { 916 toc = (toc_block_t *) malloc(sizeof(toc_block_t)); 917 if (toc != NULL) { 918 memset(toc, 0, sizeof(toc_block_t)); 919 memcpy(toc, devcon->comm_area, 920 min(devcon->pblock_size, sizeof(toc_block_t))); 921 } 922 } 923 924 925 fibril_mutex_unlock(&devcon->comm_area_lock); 926 927 return toc; 819 int block_get_nblocks(devmap_handle_t devmap_handle, aoff64_t *nblocks) 820 { 821 devcon_t *devcon; 822 823 devcon = devcon_search(devmap_handle); 824 assert(devcon); 825 826 return get_num_blocks(devcon->dev_phone, nblocks); 928 827 } 929 828 … … 939 838 static int read_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt) 940 839 { 941 assert(devcon);942 943 as ync_exch_t *exch = async_exchange_begin(devcon->sess);944 int rc = async_req_3_0(exch, BD_READ_BLOCKS, LOWER32(ba),840 int rc; 841 842 assert(devcon); 843 rc = async_req_3_0(devcon->dev_phone, BD_READ_BLOCKS, LOWER32(ba), 945 844 UPPER32(ba), cnt); 946 async_exchange_end(exch);947 948 845 if (rc != EOK) { 949 846 printf("Error %d reading %zu blocks starting at block %" PRIuOFF64 950 847 " from device handle %" PRIun "\n", rc, cnt, ba, 951 devcon-> service_id);848 devcon->devmap_handle); 952 849 #ifndef NDEBUG 953 850 stacktrace_print(); 954 851 #endif 955 852 } 956 957 853 return rc; 958 854 } … … 969 865 static int write_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt) 970 866 { 971 assert(devcon);972 973 as ync_exch_t *exch = async_exchange_begin(devcon->sess);974 int rc = async_req_3_0(exch, BD_WRITE_BLOCKS, LOWER32(ba),867 int rc; 868 869 assert(devcon); 870 rc = async_req_3_0(devcon->dev_phone, BD_WRITE_BLOCKS, LOWER32(ba), 975 871 UPPER32(ba), cnt); 976 async_exchange_end(exch);977 978 872 if (rc != EOK) { 979 873 printf("Error %d writing %zu blocks starting at block %" PRIuOFF64 980 " to device handle %" PRIun "\n", rc, cnt, ba, devcon-> service_id);874 " to device handle %" PRIun "\n", rc, cnt, ba, devcon->devmap_handle); 981 875 #ifndef NDEBUG 982 876 stacktrace_print(); 983 877 #endif 984 878 } 985 986 879 return rc; 987 880 } 988 881 989 882 /** Get block size used by the device. */ 990 static int get_block_size( async_sess_t *sess, size_t *bsize)883 static int get_block_size(int dev_phone, size_t *bsize) 991 884 { 992 885 sysarg_t bs; 993 994 async_exch_t *exch = async_exchange_begin(sess); 995 int rc = async_req_0_1(exch, BD_GET_BLOCK_SIZE, &bs); 996 async_exchange_end(exch); 997 886 int rc; 887 888 rc = async_req_0_1(dev_phone, BD_GET_BLOCK_SIZE, &bs); 998 889 if (rc == EOK) 999 890 *bsize = (size_t) bs; 1000 891 1001 892 return rc; 1002 893 } 1003 894 1004 895 /** Get total number of blocks on block device. */ 1005 static int get_num_blocks(async_sess_t *sess, aoff64_t *nblocks) 1006 { 1007 sysarg_t nb_l; 1008 sysarg_t nb_h; 1009 1010 async_exch_t *exch = async_exchange_begin(sess); 1011 int rc = async_req_0_2(exch, BD_GET_NUM_BLOCKS, &nb_l, &nb_h); 1012 async_exchange_end(exch); 1013 1014 if (rc == EOK) 896 static int get_num_blocks(int dev_phone, aoff64_t *nblocks) 897 { 898 sysarg_t nb_l, nb_h; 899 int rc; 900 901 rc = async_req_0_2(dev_phone, BD_GET_NUM_BLOCKS, &nb_l, &nb_h); 902 if (rc == EOK) { 1015 903 *nblocks = (aoff64_t) MERGE_LOUP32(nb_l, nb_h); 1016 904 } 905 1017 906 return rc; 1018 907 }
Note:
See TracChangeset
for help on using the changeset viewer.