Changeset 15f3c3f in mainline for uspace/lib/block/libblock.c
- Timestamp:
- 2011-06-22T22:00:52Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 86ffa27f
- Parents:
- ef09a7a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/libblock.c
ref09a7a r15f3c3f 39 39 #include "libblock.h" 40 40 #include "../../srv/vfs/vfs.h" 41 #include <ipc/ devmap.h>41 #include <ipc/loc.h> 42 42 #include <ipc/bd.h> 43 43 #include <ipc/services.h> … … 78 78 typedef struct { 79 79 link_t link; 80 devmap_handle_t devmap_handle;80 service_id_t service_id; 81 81 async_sess_t *sess; 82 82 fibril_mutex_t comm_area_lock; … … 95 95 static aoff64_t ba_ltop(devcon_t *, aoff64_t); 96 96 97 static devcon_t *devcon_search( devmap_handle_t devmap_handle)97 static devcon_t *devcon_search(service_id_t service_id) 98 98 { 99 99 fibril_mutex_lock(&dcl_lock); … … 101 101 list_foreach(dcl, cur) { 102 102 devcon_t *devcon = list_get_instance(cur, devcon_t, link); 103 if (devcon-> devmap_handle == devmap_handle) {103 if (devcon->service_id == service_id) { 104 104 fibril_mutex_unlock(&dcl_lock); 105 105 return devcon; … … 111 111 } 112 112 113 static int devcon_add( devmap_handle_t devmap_handle, async_sess_t *sess,113 static int devcon_add(service_id_t service_id, async_sess_t *sess, 114 114 size_t bsize, void *comm_area, size_t comm_size) 115 115 { … … 124 124 125 125 link_initialize(&devcon->link); 126 devcon-> devmap_handle = devmap_handle;126 devcon->service_id = service_id; 127 127 devcon->sess = sess; 128 128 fibril_mutex_initialize(&devcon->comm_area_lock); … … 137 137 list_foreach(dcl, cur) { 138 138 devcon_t *d = list_get_instance(cur, devcon_t, link); 139 if (d-> devmap_handle == devmap_handle) {139 if (d->service_id == service_id) { 140 140 fibril_mutex_unlock(&dcl_lock); 141 141 free(devcon); … … 155 155 } 156 156 157 int block_init(exch_mgmt_t mgmt, devmap_handle_t devmap_handle,157 int block_init(exch_mgmt_t mgmt, service_id_t service_id, 158 158 size_t comm_size) 159 159 { … … 163 163 return ENOMEM; 164 164 165 async_sess_t *sess = devmap_device_connect(mgmt, devmap_handle,165 async_sess_t *sess = loc_service_connect(mgmt, service_id, 166 166 IPC_FLAG_BLOCKING); 167 167 if (!sess) { … … 190 190 } 191 191 192 rc = devcon_add( devmap_handle, sess, bsize, comm_area, comm_size);192 rc = devcon_add(service_id, sess, bsize, comm_area, comm_size); 193 193 if (rc != EOK) { 194 194 munmap(comm_area, comm_size); … … 200 200 } 201 201 202 void block_fini( devmap_handle_t devmap_handle)203 { 204 devcon_t *devcon = devcon_search( devmap_handle);202 void block_fini(service_id_t service_id) 203 { 204 devcon_t *devcon = devcon_search(service_id); 205 205 assert(devcon); 206 206 207 207 if (devcon->cache) 208 (void) block_cache_fini( devmap_handle);208 (void) block_cache_fini(service_id); 209 209 210 210 devcon_remove(devcon); … … 219 219 } 220 220 221 int block_bb_read( devmap_handle_t devmap_handle, aoff64_t ba)221 int block_bb_read(service_id_t service_id, aoff64_t ba) 222 222 { 223 223 void *bb_buf; 224 224 int rc; 225 225 226 devcon_t *devcon = devcon_search( devmap_handle);226 devcon_t *devcon = devcon_search(service_id); 227 227 if (!devcon) 228 228 return ENOENT; … … 249 249 } 250 250 251 void *block_bb_get( devmap_handle_t devmap_handle)252 { 253 devcon_t *devcon = devcon_search( devmap_handle);251 void *block_bb_get(service_id_t service_id) 252 { 253 devcon_t *devcon = devcon_search(service_id); 254 254 assert(devcon); 255 255 return devcon->bb_buf; … … 277 277 }; 278 278 279 int block_cache_init( devmap_handle_t devmap_handle, size_t size, unsigned blocks,279 int block_cache_init(service_id_t service_id, size_t size, unsigned blocks, 280 280 enum cache_mode mode) 281 281 { 282 devcon_t *devcon = devcon_search( devmap_handle);282 devcon_t *devcon = devcon_search(service_id); 283 283 cache_t *cache; 284 284 if (!devcon) … … 315 315 } 316 316 317 int block_cache_fini( devmap_handle_t devmap_handle)318 { 319 devcon_t *devcon = devcon_search( devmap_handle);317 int block_cache_fini(service_id_t service_id) 318 { 319 devcon_t *devcon = devcon_search(service_id); 320 320 cache_t *cache; 321 321 int rc; … … 384 384 * @param block Pointer to where the function will store the 385 385 * block pointer on success. 386 * @param devmap_handle Device handleof the block device.386 * @param service_id Service ID of the block device. 387 387 * @param ba Block address (logical). 388 388 * @param flags If BLOCK_FLAGS_NOREAD is specified, block_get() … … 392 392 * @return EOK on success or a negative error code. 393 393 */ 394 int block_get(block_t **block, devmap_handle_t devmap_handle, aoff64_t ba, int flags)394 int block_get(block_t **block, service_id_t service_id, aoff64_t ba, int flags) 395 395 { 396 396 devcon_t *devcon; … … 401 401 int rc; 402 402 403 devcon = devcon_search( devmap_handle);403 devcon = devcon_search(service_id); 404 404 405 405 assert(devcon); … … 527 527 528 528 block_initialize(b); 529 b-> devmap_handle = devmap_handle;529 b->service_id = service_id; 530 530 b->size = cache->lblock_size; 531 531 b->lba = ba; … … 577 577 int block_put(block_t *block) 578 578 { 579 devcon_t *devcon = devcon_search(block-> devmap_handle);579 devcon_t *devcon = devcon_search(block->service_id); 580 580 cache_t *cache; 581 581 unsigned blocks_cached; … … 675 675 /** Read sequential data from a block device. 676 676 * 677 * @param devmap_handle Device handleof the block device.677 * @param service_id Service ID of the block device. 678 678 * @param bufpos Pointer to the first unread valid offset within the 679 679 * communication buffer. … … 687 687 * @return EOK on success or a negative return code on failure. 688 688 */ 689 int block_seqread( devmap_handle_t devmap_handle, size_t *bufpos, size_t *buflen,689 int block_seqread(service_id_t service_id, size_t *bufpos, size_t *buflen, 690 690 aoff64_t *pos, void *dst, size_t size) 691 691 { … … 695 695 devcon_t *devcon; 696 696 697 devcon = devcon_search( devmap_handle);697 devcon = devcon_search(service_id); 698 698 assert(devcon); 699 699 block_size = devcon->pblock_size; … … 741 741 /** Read blocks directly from device (bypass cache). 742 742 * 743 * @param devmap_handle Device handleof the block device.743 * @param service_id Service ID of the block device. 744 744 * @param ba Address of first block (physical). 745 745 * @param cnt Number of blocks. … … 748 748 * @return EOK on success or negative error code on failure. 749 749 */ 750 int block_read_direct( devmap_handle_t devmap_handle, aoff64_t ba, size_t cnt, void *buf)750 int block_read_direct(service_id_t service_id, aoff64_t ba, size_t cnt, void *buf) 751 751 { 752 752 devcon_t *devcon; 753 753 int rc; 754 754 755 devcon = devcon_search( devmap_handle);755 devcon = devcon_search(service_id); 756 756 assert(devcon); 757 757 … … 769 769 /** Write blocks directly to device (bypass cache). 770 770 * 771 * @param devmap_handle Device handleof the block device.771 * @param service_id Service ID of the block device. 772 772 * @param ba Address of first block (physical). 773 773 * @param cnt Number of blocks. … … 776 776 * @return EOK on success or negative error code on failure. 777 777 */ 778 int block_write_direct( devmap_handle_t devmap_handle, aoff64_t ba, size_t cnt,778 int block_write_direct(service_id_t service_id, aoff64_t ba, size_t cnt, 779 779 const void *data) 780 780 { … … 782 782 int rc; 783 783 784 devcon = devcon_search( devmap_handle);784 devcon = devcon_search(service_id); 785 785 assert(devcon); 786 786 … … 797 797 /** Get device block size. 798 798 * 799 * @param devmap_handle Device handleof the block device.799 * @param service_id Service ID of the block device. 800 800 * @param bsize Output block size. 801 801 * 802 802 * @return EOK on success or negative error code on failure. 803 803 */ 804 int block_get_bsize( devmap_handle_t devmap_handle, size_t *bsize)804 int block_get_bsize(service_id_t service_id, size_t *bsize) 805 805 { 806 806 devcon_t *devcon; 807 807 808 devcon = devcon_search( devmap_handle);808 devcon = devcon_search(service_id); 809 809 assert(devcon); 810 810 … … 814 814 /** Get number of blocks on device. 815 815 * 816 * @param devmap_handle Device handleof the block device.816 * @param service_id Service ID of the block device. 817 817 * @param nblocks Output number of blocks. 818 818 * 819 819 * @return EOK on success or negative error code on failure. 820 820 */ 821 int block_get_nblocks( devmap_handle_t devmap_handle, aoff64_t *nblocks)822 { 823 devcon_t *devcon = devcon_search( devmap_handle);821 int block_get_nblocks(service_id_t service_id, aoff64_t *nblocks) 822 { 823 devcon_t *devcon = devcon_search(service_id); 824 824 assert(devcon); 825 825 … … 829 829 /** Read bytes directly from the device (bypass cache) 830 830 * 831 * @param devmap_handle Device handleof the block device.831 * @param service_id Service ID of the block device. 832 832 * @param abs_offset Absolute offset in bytes where to start reading 833 833 * @param bytes Number of bytes to read … … 836 836 * @return EOK on success or negative error code on failure. 837 837 */ 838 int block_read_bytes_direct( devmap_handle_t devmap_handle, aoff64_t abs_offset,838 int block_read_bytes_direct(service_id_t service_id, aoff64_t abs_offset, 839 839 size_t bytes, void *data) 840 840 { … … 848 848 size_t offset; 849 849 850 rc = block_get_bsize( devmap_handle, &phys_block_size);850 rc = block_get_bsize(service_id, &phys_block_size); 851 851 if (rc != EOK) { 852 852 return rc; … … 866 866 } 867 867 868 rc = block_read_direct( devmap_handle, first_block, blocks, buffer);868 rc = block_read_direct(service_id, first_block, blocks, buffer); 869 869 if (rc != EOK) { 870 870 free(buffer); … … 900 900 printf("Error %d reading %zu blocks starting at block %" PRIuOFF64 901 901 " from device handle %" PRIun "\n", rc, cnt, ba, 902 devcon-> devmap_handle);902 devcon->service_id); 903 903 #ifndef NDEBUG 904 904 stacktrace_print(); … … 929 929 if (rc != EOK) { 930 930 printf("Error %d writing %zu blocks starting at block %" PRIuOFF64 931 " to device handle %" PRIun "\n", rc, cnt, ba, devcon-> devmap_handle);931 " to device handle %" PRIun "\n", rc, cnt, ba, devcon->service_id); 932 932 #ifndef NDEBUG 933 933 stacktrace_print();
Note:
See TracChangeset
for help on using the changeset viewer.