Changes in uspace/lib/block/libblock.c [7a72ce1a:867e2555] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/libblock.c
r7a72ce1a r867e2555 39 39 #include "libblock.h" 40 40 #include "../../srv/vfs/vfs.h" 41 #include <ipc/ loc.h>41 #include <ipc/devmap.h> 42 42 #include <ipc/bd.h> 43 43 #include <ipc/services.h> … … 78 78 typedef struct { 79 79 link_t link; 80 service_id_t service_id;80 devmap_handle_t devmap_handle; 81 81 async_sess_t *sess; 82 82 fibril_mutex_t comm_area_lock; … … 93 93 static int get_block_size(async_sess_t *, size_t *); 94 94 static int get_num_blocks(async_sess_t *, aoff64_t *); 95 static int read_toc(async_sess_t *, uint8_t);96 95 static aoff64_t ba_ltop(devcon_t *, aoff64_t); 97 96 98 static devcon_t *devcon_search( service_id_t service_id)97 static devcon_t *devcon_search(devmap_handle_t devmap_handle) 99 98 { 100 99 fibril_mutex_lock(&dcl_lock); … … 102 101 list_foreach(dcl, cur) { 103 102 devcon_t *devcon = list_get_instance(cur, devcon_t, link); 104 if (devcon-> service_id == service_id) {103 if (devcon->devmap_handle == devmap_handle) { 105 104 fibril_mutex_unlock(&dcl_lock); 106 105 return devcon; … … 112 111 } 113 112 114 static int devcon_add( service_id_t service_id, async_sess_t *sess,113 static int devcon_add(devmap_handle_t devmap_handle, async_sess_t *sess, 115 114 size_t bsize, void *comm_area, size_t comm_size) 116 115 { … … 125 124 126 125 link_initialize(&devcon->link); 127 devcon-> service_id = service_id;126 devcon->devmap_handle = devmap_handle; 128 127 devcon->sess = sess; 129 128 fibril_mutex_initialize(&devcon->comm_area_lock); … … 138 137 list_foreach(dcl, cur) { 139 138 devcon_t *d = list_get_instance(cur, devcon_t, link); 140 if (d-> service_id == service_id) {139 if (d->devmap_handle == devmap_handle) { 141 140 fibril_mutex_unlock(&dcl_lock); 142 141 free(devcon); … … 156 155 } 157 156 158 int block_init(exch_mgmt_t mgmt, service_id_t service_id,157 int block_init(exch_mgmt_t mgmt, devmap_handle_t devmap_handle, 159 158 size_t comm_size) 160 159 { … … 164 163 return ENOMEM; 165 164 166 async_sess_t *sess = loc_service_connect(mgmt, service_id,165 async_sess_t *sess = devmap_device_connect(mgmt, devmap_handle, 167 166 IPC_FLAG_BLOCKING); 168 167 if (!sess) { … … 191 190 } 192 191 193 rc = devcon_add( service_id, sess, bsize, comm_area, comm_size);192 rc = devcon_add(devmap_handle, sess, bsize, comm_area, comm_size); 194 193 if (rc != EOK) { 195 194 munmap(comm_area, comm_size); … … 201 200 } 202 201 203 void block_fini( service_id_t service_id)204 { 205 devcon_t *devcon = devcon_search( service_id);202 void block_fini(devmap_handle_t devmap_handle) 203 { 204 devcon_t *devcon = devcon_search(devmap_handle); 206 205 assert(devcon); 207 206 208 207 if (devcon->cache) 209 (void) block_cache_fini( service_id);208 (void) block_cache_fini(devmap_handle); 210 209 211 210 devcon_remove(devcon); … … 220 219 } 221 220 222 int block_bb_read( service_id_t service_id, aoff64_t ba)221 int block_bb_read(devmap_handle_t devmap_handle, aoff64_t ba) 223 222 { 224 223 void *bb_buf; 225 224 int rc; 226 225 227 devcon_t *devcon = devcon_search( service_id);226 devcon_t *devcon = devcon_search(devmap_handle); 228 227 if (!devcon) 229 228 return ENOENT; … … 250 249 } 251 250 252 void *block_bb_get( service_id_t service_id)253 { 254 devcon_t *devcon = devcon_search( service_id);251 void *block_bb_get(devmap_handle_t devmap_handle) 252 { 253 devcon_t *devcon = devcon_search(devmap_handle); 255 254 assert(devcon); 256 255 return devcon->bb_buf; … … 278 277 }; 279 278 280 int block_cache_init( service_id_t service_id, size_t size, unsigned blocks,279 int block_cache_init(devmap_handle_t devmap_handle, size_t size, unsigned blocks, 281 280 enum cache_mode mode) 282 281 { 283 devcon_t *devcon = devcon_search( service_id);282 devcon_t *devcon = devcon_search(devmap_handle); 284 283 cache_t *cache; 285 284 if (!devcon) … … 316 315 } 317 316 318 int block_cache_fini( service_id_t service_id)319 { 320 devcon_t *devcon = devcon_search( service_id);317 int block_cache_fini(devmap_handle_t devmap_handle) 318 { 319 devcon_t *devcon = devcon_search(devmap_handle); 321 320 cache_t *cache; 322 321 int rc; … … 388 387 * @param block Pointer to where the function will store the 389 388 * block pointer on success. 390 * @param service_id Service IDof the block device.389 * @param devmap_handle Device handle of the block device. 391 390 * @param ba Block address (logical). 392 391 * @param flags If BLOCK_FLAGS_NOREAD is specified, block_get() … … 396 395 * @return EOK on success or a negative error code. 397 396 */ 398 int block_get(block_t **block, service_id_t service_id, aoff64_t ba, int flags)397 int block_get(block_t **block, devmap_handle_t devmap_handle, aoff64_t ba, int flags) 399 398 { 400 399 devcon_t *devcon; … … 409 408 int rc; 410 409 411 devcon = devcon_search( service_id);410 devcon = devcon_search(devmap_handle); 412 411 413 412 assert(devcon); … … 537 536 538 537 block_initialize(b); 539 b-> service_id = service_id;538 b->devmap_handle = devmap_handle; 540 539 b->size = cache->lblock_size; 541 540 b->lba = ba; … … 587 586 int block_put(block_t *block) 588 587 { 589 devcon_t *devcon = devcon_search(block-> service_id);588 devcon_t *devcon = devcon_search(block->devmap_handle); 590 589 cache_t *cache; 591 590 unsigned blocks_cached; … … 688 687 /** Read sequential data from a block device. 689 688 * 690 * @param service_id Service IDof the block device.689 * @param devmap_handle Device handle of the block device. 691 690 * @param bufpos Pointer to the first unread valid offset within the 692 691 * communication buffer. … … 700 699 * @return EOK on success or a negative return code on failure. 701 700 */ 702 int block_seqread( service_id_t service_id, size_t *bufpos, size_t *buflen,701 int block_seqread(devmap_handle_t devmap_handle, size_t *bufpos, size_t *buflen, 703 702 aoff64_t *pos, void *dst, size_t size) 704 703 { … … 708 707 devcon_t *devcon; 709 708 710 devcon = devcon_search( service_id);709 devcon = devcon_search(devmap_handle); 711 710 assert(devcon); 712 711 block_size = devcon->pblock_size; … … 754 753 /** Read blocks directly from device (bypass cache). 755 754 * 756 * @param service_id Service IDof the block device.755 * @param devmap_handle Device handle of the block device. 757 756 * @param ba Address of first block (physical). 758 757 * @param cnt Number of blocks. … … 761 760 * @return EOK on success or negative error code on failure. 762 761 */ 763 int block_read_direct( service_id_t service_id, aoff64_t ba, size_t cnt, void *buf)762 int block_read_direct(devmap_handle_t devmap_handle, aoff64_t ba, size_t cnt, void *buf) 764 763 { 765 764 devcon_t *devcon; 766 765 int rc; 767 766 768 devcon = devcon_search( service_id);767 devcon = devcon_search(devmap_handle); 769 768 assert(devcon); 770 769 … … 782 781 /** Write blocks directly to device (bypass cache). 783 782 * 784 * @param service_id Service IDof the block device.783 * @param devmap_handle Device handle of the block device. 785 784 * @param ba Address of first block (physical). 786 785 * @param cnt Number of blocks. … … 789 788 * @return EOK on success or negative error code on failure. 790 789 */ 791 int block_write_direct( service_id_t service_id, aoff64_t ba, size_t cnt,790 int block_write_direct(devmap_handle_t devmap_handle, aoff64_t ba, size_t cnt, 792 791 const void *data) 793 792 { … … 795 794 int rc; 796 795 797 devcon = devcon_search( service_id);796 devcon = devcon_search(devmap_handle); 798 797 assert(devcon); 799 798 … … 810 809 /** Get device block size. 811 810 * 812 * @param service_id Service IDof the block device.811 * @param devmap_handle Device handle of the block device. 813 812 * @param bsize Output block size. 814 813 * 815 814 * @return EOK on success or negative error code on failure. 816 815 */ 817 int block_get_bsize( service_id_t service_id, size_t *bsize)816 int block_get_bsize(devmap_handle_t devmap_handle, size_t *bsize) 818 817 { 819 818 devcon_t *devcon; 820 819 821 devcon = devcon_search( service_id);820 devcon = devcon_search(devmap_handle); 822 821 assert(devcon); 823 822 … … 827 826 /** Get number of blocks on device. 828 827 * 829 * @param service_id Service IDof the block device.828 * @param devmap_handle Device handle of the block device. 830 829 * @param nblocks Output number of blocks. 831 830 * 832 831 * @return EOK on success or negative error code on failure. 833 832 */ 834 int block_get_nblocks( service_id_t service_id, aoff64_t *nblocks)835 { 836 devcon_t *devcon = devcon_search( service_id);833 int block_get_nblocks(devmap_handle_t devmap_handle, aoff64_t *nblocks) 834 { 835 devcon_t *devcon = devcon_search(devmap_handle); 837 836 assert(devcon); 838 837 … … 842 841 /** Read bytes directly from the device (bypass cache) 843 842 * 844 * @param service_id Service IDof the block device.843 * @param devmap_handle Device handle of the block device. 845 844 * @param abs_offset Absolute offset in bytes where to start reading 846 845 * @param bytes Number of bytes to read … … 849 848 * @return EOK on success or negative error code on failure. 850 849 */ 851 int block_read_bytes_direct( service_id_t service_id, aoff64_t abs_offset,850 int block_read_bytes_direct(devmap_handle_t devmap_handle, aoff64_t abs_offset, 852 851 size_t bytes, void *data) 853 852 { … … 861 860 size_t offset; 862 861 863 rc = block_get_bsize( service_id, &phys_block_size);862 rc = block_get_bsize(devmap_handle, &phys_block_size); 864 863 if (rc != EOK) { 865 864 return rc; … … 879 878 } 880 879 881 rc = block_read_direct( service_id, first_block, blocks, buffer);880 rc = block_read_direct(devmap_handle, first_block, blocks, buffer); 882 881 if (rc != EOK) { 883 882 free(buffer); … … 890 889 891 890 return EOK; 892 }893 894 /** Get TOC from device.895 *896 * @param service_id Service ID of the block device.897 * @param session Starting session.898 * @param data Buffer to read TOC into.899 *900 * @return EOK on success.901 * @return Error code on failure.902 *903 */904 int block_get_toc(service_id_t service_id, uint8_t session, void *data)905 {906 devcon_t *devcon = devcon_search(service_id);907 assert(devcon);908 909 fibril_mutex_lock(&devcon->comm_area_lock);910 911 int rc = read_toc(devcon->sess, session);912 if (rc == EOK)913 memcpy(data, devcon->comm_area, devcon->pblock_size);914 915 fibril_mutex_unlock(&devcon->comm_area_lock);916 917 return rc;918 891 } 919 892 … … 939 912 printf("Error %d reading %zu blocks starting at block %" PRIuOFF64 940 913 " from device handle %" PRIun "\n", rc, cnt, ba, 941 devcon-> service_id);914 devcon->devmap_handle); 942 915 #ifndef NDEBUG 943 916 stacktrace_print(); … … 968 941 if (rc != EOK) { 969 942 printf("Error %d writing %zu blocks starting at block %" PRIuOFF64 970 " to device handle %" PRIun "\n", rc, cnt, ba, devcon-> service_id);943 " to device handle %" PRIun "\n", rc, cnt, ba, devcon->devmap_handle); 971 944 #ifndef NDEBUG 972 945 stacktrace_print(); … … 1008 981 } 1009 982 1010 /** Get TOC from block device. */1011 static int read_toc(async_sess_t *sess, uint8_t session)1012 {1013 async_exch_t *exch = async_exchange_begin(sess);1014 int rc = async_req_1_0(exch, BD_READ_TOC, session);1015 async_exchange_end(exch);1016 1017 return rc;1018 }1019 1020 983 /** Convert logical block address to physical block address. */ 1021 984 static aoff64_t ba_ltop(devcon_t *devcon, aoff64_t lba)
Note:
See TracChangeset
for help on using the changeset viewer.