Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/block/libblock.c

    r7a72ce1a r867e2555  
    3939#include "libblock.h"
    4040#include "../../srv/vfs/vfs.h"
    41 #include <ipc/loc.h>
     41#include <ipc/devmap.h>
    4242#include <ipc/bd.h>
    4343#include <ipc/services.h>
     
    7878typedef struct {
    7979        link_t link;
    80         service_id_t service_id;
     80        devmap_handle_t devmap_handle;
    8181        async_sess_t *sess;
    8282        fibril_mutex_t comm_area_lock;
     
    9393static int get_block_size(async_sess_t *, size_t *);
    9494static int get_num_blocks(async_sess_t *, aoff64_t *);
    95 static int read_toc(async_sess_t *, uint8_t);
    9695static aoff64_t ba_ltop(devcon_t *, aoff64_t);
    9796
    98 static devcon_t *devcon_search(service_id_t service_id)
     97static devcon_t *devcon_search(devmap_handle_t devmap_handle)
    9998{
    10099        fibril_mutex_lock(&dcl_lock);
     
    102101        list_foreach(dcl, cur) {
    103102                devcon_t *devcon = list_get_instance(cur, devcon_t, link);
    104                 if (devcon->service_id == service_id) {
     103                if (devcon->devmap_handle == devmap_handle) {
    105104                        fibril_mutex_unlock(&dcl_lock);
    106105                        return devcon;
     
    112111}
    113112
    114 static int devcon_add(service_id_t service_id, async_sess_t *sess,
     113static int devcon_add(devmap_handle_t devmap_handle, async_sess_t *sess,
    115114    size_t bsize, void *comm_area, size_t comm_size)
    116115{
     
    125124       
    126125        link_initialize(&devcon->link);
    127         devcon->service_id = service_id;
     126        devcon->devmap_handle = devmap_handle;
    128127        devcon->sess = sess;
    129128        fibril_mutex_initialize(&devcon->comm_area_lock);
     
    138137        list_foreach(dcl, cur) {
    139138                devcon_t *d = list_get_instance(cur, devcon_t, link);
    140                 if (d->service_id == service_id) {
     139                if (d->devmap_handle == devmap_handle) {
    141140                        fibril_mutex_unlock(&dcl_lock);
    142141                        free(devcon);
     
    156155}
    157156
    158 int block_init(exch_mgmt_t mgmt, service_id_t service_id,
     157int block_init(exch_mgmt_t mgmt, devmap_handle_t devmap_handle,
    159158    size_t comm_size)
    160159{
     
    164163                return ENOMEM;
    165164       
    166         async_sess_t *sess = loc_service_connect(mgmt, service_id,
     165        async_sess_t *sess = devmap_device_connect(mgmt, devmap_handle,
    167166            IPC_FLAG_BLOCKING);
    168167        if (!sess) {
     
    191190        }
    192191       
    193         rc = devcon_add(service_id, sess, bsize, comm_area, comm_size);
     192        rc = devcon_add(devmap_handle, sess, bsize, comm_area, comm_size);
    194193        if (rc != EOK) {
    195194                munmap(comm_area, comm_size);
     
    201200}
    202201
    203 void block_fini(service_id_t service_id)
    204 {
    205         devcon_t *devcon = devcon_search(service_id);
     202void block_fini(devmap_handle_t devmap_handle)
     203{
     204        devcon_t *devcon = devcon_search(devmap_handle);
    206205        assert(devcon);
    207206       
    208207        if (devcon->cache)
    209                 (void) block_cache_fini(service_id);
     208                (void) block_cache_fini(devmap_handle);
    210209       
    211210        devcon_remove(devcon);
     
    220219}
    221220
    222 int block_bb_read(service_id_t service_id, aoff64_t ba)
     221int block_bb_read(devmap_handle_t devmap_handle, aoff64_t ba)
    223222{
    224223        void *bb_buf;
    225224        int rc;
    226225
    227         devcon_t *devcon = devcon_search(service_id);
     226        devcon_t *devcon = devcon_search(devmap_handle);
    228227        if (!devcon)
    229228                return ENOENT;
     
    250249}
    251250
    252 void *block_bb_get(service_id_t service_id)
    253 {
    254         devcon_t *devcon = devcon_search(service_id);
     251void *block_bb_get(devmap_handle_t devmap_handle)
     252{
     253        devcon_t *devcon = devcon_search(devmap_handle);
    255254        assert(devcon);
    256255        return devcon->bb_buf;
     
    278277};
    279278
    280 int block_cache_init(service_id_t service_id, size_t size, unsigned blocks,
     279int block_cache_init(devmap_handle_t devmap_handle, size_t size, unsigned blocks,
    281280    enum cache_mode mode)
    282281{
    283         devcon_t *devcon = devcon_search(service_id);
     282        devcon_t *devcon = devcon_search(devmap_handle);
    284283        cache_t *cache;
    285284        if (!devcon)
     
    316315}
    317316
    318 int block_cache_fini(service_id_t service_id)
    319 {
    320         devcon_t *devcon = devcon_search(service_id);
     317int block_cache_fini(devmap_handle_t devmap_handle)
     318{
     319        devcon_t *devcon = devcon_search(devmap_handle);
    321320        cache_t *cache;
    322321        int rc;
     
    388387 * @param block                 Pointer to where the function will store the
    389388 *                              block pointer on success.
    390  * @param service_id            Service ID of the block device.
     389 * @param devmap_handle         Device handle of the block device.
    391390 * @param ba                    Block address (logical).
    392391 * @param flags                 If BLOCK_FLAGS_NOREAD is specified, block_get()
     
    396395 * @return                      EOK on success or a negative error code.
    397396 */
    398 int block_get(block_t **block, service_id_t service_id, aoff64_t ba, int flags)
     397int block_get(block_t **block, devmap_handle_t devmap_handle, aoff64_t ba, int flags)
    399398{
    400399        devcon_t *devcon;
     
    409408        int rc;
    410409       
    411         devcon = devcon_search(service_id);
     410        devcon = devcon_search(devmap_handle);
    412411
    413412        assert(devcon);
     
    537536
    538537                block_initialize(b);
    539                 b->service_id = service_id;
     538                b->devmap_handle = devmap_handle;
    540539                b->size = cache->lblock_size;
    541540                b->lba = ba;
     
    587586int block_put(block_t *block)
    588587{
    589         devcon_t *devcon = devcon_search(block->service_id);
     588        devcon_t *devcon = devcon_search(block->devmap_handle);
    590589        cache_t *cache;
    591590        unsigned blocks_cached;
     
    688687/** Read sequential data from a block device.
    689688 *
    690  * @param service_id    Service ID of the block device.
     689 * @param devmap_handle Device handle of the block device.
    691690 * @param bufpos        Pointer to the first unread valid offset within the
    692691 *                      communication buffer.
     
    700699 * @return              EOK on success or a negative return code on failure.
    701700 */
    702 int block_seqread(service_id_t service_id, size_t *bufpos, size_t *buflen,
     701int block_seqread(devmap_handle_t devmap_handle, size_t *bufpos, size_t *buflen,
    703702    aoff64_t *pos, void *dst, size_t size)
    704703{
     
    708707        devcon_t *devcon;
    709708
    710         devcon = devcon_search(service_id);
     709        devcon = devcon_search(devmap_handle);
    711710        assert(devcon);
    712711        block_size = devcon->pblock_size;
     
    754753/** Read blocks directly from device (bypass cache).
    755754 *
    756  * @param service_id    Service ID of the block device.
     755 * @param devmap_handle Device handle of the block device.
    757756 * @param ba            Address of first block (physical).
    758757 * @param cnt           Number of blocks.
     
    761760 * @return              EOK on success or negative error code on failure.
    762761 */
    763 int block_read_direct(service_id_t service_id, aoff64_t ba, size_t cnt, void *buf)
     762int block_read_direct(devmap_handle_t devmap_handle, aoff64_t ba, size_t cnt, void *buf)
    764763{
    765764        devcon_t *devcon;
    766765        int rc;
    767766
    768         devcon = devcon_search(service_id);
     767        devcon = devcon_search(devmap_handle);
    769768        assert(devcon);
    770769       
     
    782781/** Write blocks directly to device (bypass cache).
    783782 *
    784  * @param service_id    Service ID of the block device.
     783 * @param devmap_handle Device handle of the block device.
    785784 * @param ba            Address of first block (physical).
    786785 * @param cnt           Number of blocks.
     
    789788 * @return              EOK on success or negative error code on failure.
    790789 */
    791 int block_write_direct(service_id_t service_id, aoff64_t ba, size_t cnt,
     790int block_write_direct(devmap_handle_t devmap_handle, aoff64_t ba, size_t cnt,
    792791    const void *data)
    793792{
     
    795794        int rc;
    796795
    797         devcon = devcon_search(service_id);
     796        devcon = devcon_search(devmap_handle);
    798797        assert(devcon);
    799798       
     
    810809/** Get device block size.
    811810 *
    812  * @param service_id    Service ID of the block device.
     811 * @param devmap_handle Device handle of the block device.
    813812 * @param bsize         Output block size.
    814813 *
    815814 * @return              EOK on success or negative error code on failure.
    816815 */
    817 int block_get_bsize(service_id_t service_id, size_t *bsize)
     816int block_get_bsize(devmap_handle_t devmap_handle, size_t *bsize)
    818817{
    819818        devcon_t *devcon;
    820819
    821         devcon = devcon_search(service_id);
     820        devcon = devcon_search(devmap_handle);
    822821        assert(devcon);
    823822       
     
    827826/** Get number of blocks on device.
    828827 *
    829  * @param service_id    Service ID of the block device.
     828 * @param devmap_handle Device handle of the block device.
    830829 * @param nblocks       Output number of blocks.
    831830 *
    832831 * @return              EOK on success or negative error code on failure.
    833832 */
    834 int block_get_nblocks(service_id_t service_id, aoff64_t *nblocks)
    835 {
    836         devcon_t *devcon = devcon_search(service_id);
     833int block_get_nblocks(devmap_handle_t devmap_handle, aoff64_t *nblocks)
     834{
     835        devcon_t *devcon = devcon_search(devmap_handle);
    837836        assert(devcon);
    838837       
     
    842841/** Read bytes directly from the device (bypass cache)
    843842 *
    844  * @param service_id    Service ID of the block device.
     843 * @param devmap_handle Device handle of the block device.
    845844 * @param abs_offset    Absolute offset in bytes where to start reading
    846845 * @param bytes                 Number of bytes to read
     
    849848 * @return              EOK on success or negative error code on failure.
    850849 */
    851 int block_read_bytes_direct(service_id_t service_id, aoff64_t abs_offset,
     850int block_read_bytes_direct(devmap_handle_t devmap_handle, aoff64_t abs_offset,
    852851    size_t bytes, void *data)
    853852{
     
    861860        size_t offset;
    862861       
    863         rc = block_get_bsize(service_id, &phys_block_size);
     862        rc = block_get_bsize(devmap_handle, &phys_block_size);
    864863        if (rc != EOK) {
    865864                return rc;
     
    879878        }
    880879       
    881         rc = block_read_direct(service_id, first_block, blocks, buffer);
     880        rc = block_read_direct(devmap_handle, first_block, blocks, buffer);
    882881        if (rc != EOK) {
    883882                free(buffer);
     
    890889       
    891890        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;
    918891}
    919892
     
    939912                printf("Error %d reading %zu blocks starting at block %" PRIuOFF64
    940913                    " from device handle %" PRIun "\n", rc, cnt, ba,
    941                     devcon->service_id);
     914                    devcon->devmap_handle);
    942915#ifndef NDEBUG
    943916                stacktrace_print();
     
    968941        if (rc != EOK) {
    969942                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);
    971944#ifndef NDEBUG
    972945                stacktrace_print();
     
    1008981}
    1009982
    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 
    1020983/** Convert logical block address to physical block address. */
    1021984static aoff64_t ba_ltop(devcon_t *devcon, aoff64_t lba)
Note: See TracChangeset for help on using the changeset viewer.