Ignore:
File:
1 edited

Legend:

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

    r867e2555 r7a72ce1a  
    3939#include "libblock.h"
    4040#include "../../srv/vfs/vfs.h"
    41 #include <ipc/devmap.h>
     41#include <ipc/loc.h>
    4242#include <ipc/bd.h>
    4343#include <ipc/services.h>
     
    7878typedef struct {
    7979        link_t link;
    80         devmap_handle_t devmap_handle;
     80        service_id_t service_id;
    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 *);
     95static int read_toc(async_sess_t *, uint8_t);
    9596static aoff64_t ba_ltop(devcon_t *, aoff64_t);
    9697
    97 static devcon_t *devcon_search(devmap_handle_t devmap_handle)
     98static devcon_t *devcon_search(service_id_t service_id)
    9899{
    99100        fibril_mutex_lock(&dcl_lock);
     
    101102        list_foreach(dcl, cur) {
    102103                devcon_t *devcon = list_get_instance(cur, devcon_t, link);
    103                 if (devcon->devmap_handle == devmap_handle) {
     104                if (devcon->service_id == service_id) {
    104105                        fibril_mutex_unlock(&dcl_lock);
    105106                        return devcon;
     
    111112}
    112113
    113 static int devcon_add(devmap_handle_t devmap_handle, async_sess_t *sess,
     114static int devcon_add(service_id_t service_id, async_sess_t *sess,
    114115    size_t bsize, void *comm_area, size_t comm_size)
    115116{
     
    124125       
    125126        link_initialize(&devcon->link);
    126         devcon->devmap_handle = devmap_handle;
     127        devcon->service_id = service_id;
    127128        devcon->sess = sess;
    128129        fibril_mutex_initialize(&devcon->comm_area_lock);
     
    137138        list_foreach(dcl, cur) {
    138139                devcon_t *d = list_get_instance(cur, devcon_t, link);
    139                 if (d->devmap_handle == devmap_handle) {
     140                if (d->service_id == service_id) {
    140141                        fibril_mutex_unlock(&dcl_lock);
    141142                        free(devcon);
     
    155156}
    156157
    157 int block_init(exch_mgmt_t mgmt, devmap_handle_t devmap_handle,
     158int block_init(exch_mgmt_t mgmt, service_id_t service_id,
    158159    size_t comm_size)
    159160{
     
    163164                return ENOMEM;
    164165       
    165         async_sess_t *sess = devmap_device_connect(mgmt, devmap_handle,
     166        async_sess_t *sess = loc_service_connect(mgmt, service_id,
    166167            IPC_FLAG_BLOCKING);
    167168        if (!sess) {
     
    190191        }
    191192       
    192         rc = devcon_add(devmap_handle, sess, bsize, comm_area, comm_size);
     193        rc = devcon_add(service_id, sess, bsize, comm_area, comm_size);
    193194        if (rc != EOK) {
    194195                munmap(comm_area, comm_size);
     
    200201}
    201202
    202 void block_fini(devmap_handle_t devmap_handle)
    203 {
    204         devcon_t *devcon = devcon_search(devmap_handle);
     203void block_fini(service_id_t service_id)
     204{
     205        devcon_t *devcon = devcon_search(service_id);
    205206        assert(devcon);
    206207       
    207208        if (devcon->cache)
    208                 (void) block_cache_fini(devmap_handle);
     209                (void) block_cache_fini(service_id);
    209210       
    210211        devcon_remove(devcon);
     
    219220}
    220221
    221 int block_bb_read(devmap_handle_t devmap_handle, aoff64_t ba)
     222int block_bb_read(service_id_t service_id, aoff64_t ba)
    222223{
    223224        void *bb_buf;
    224225        int rc;
    225226
    226         devcon_t *devcon = devcon_search(devmap_handle);
     227        devcon_t *devcon = devcon_search(service_id);
    227228        if (!devcon)
    228229                return ENOENT;
     
    249250}
    250251
    251 void *block_bb_get(devmap_handle_t devmap_handle)
    252 {
    253         devcon_t *devcon = devcon_search(devmap_handle);
     252void *block_bb_get(service_id_t service_id)
     253{
     254        devcon_t *devcon = devcon_search(service_id);
    254255        assert(devcon);
    255256        return devcon->bb_buf;
     
    277278};
    278279
    279 int block_cache_init(devmap_handle_t devmap_handle, size_t size, unsigned blocks,
     280int block_cache_init(service_id_t service_id, size_t size, unsigned blocks,
    280281    enum cache_mode mode)
    281282{
    282         devcon_t *devcon = devcon_search(devmap_handle);
     283        devcon_t *devcon = devcon_search(service_id);
    283284        cache_t *cache;
    284285        if (!devcon)
     
    315316}
    316317
    317 int block_cache_fini(devmap_handle_t devmap_handle)
    318 {
    319         devcon_t *devcon = devcon_search(devmap_handle);
     318int block_cache_fini(service_id_t service_id)
     319{
     320        devcon_t *devcon = devcon_search(service_id);
    320321        cache_t *cache;
    321322        int rc;
     
    387388 * @param block                 Pointer to where the function will store the
    388389 *                              block pointer on success.
    389  * @param devmap_handle         Device handle of the block device.
     390 * @param service_id            Service ID of the block device.
    390391 * @param ba                    Block address (logical).
    391392 * @param flags                 If BLOCK_FLAGS_NOREAD is specified, block_get()
     
    395396 * @return                      EOK on success or a negative error code.
    396397 */
    397 int block_get(block_t **block, devmap_handle_t devmap_handle, aoff64_t ba, int flags)
     398int block_get(block_t **block, service_id_t service_id, aoff64_t ba, int flags)
    398399{
    399400        devcon_t *devcon;
     
    408409        int rc;
    409410       
    410         devcon = devcon_search(devmap_handle);
     411        devcon = devcon_search(service_id);
    411412
    412413        assert(devcon);
     
    536537
    537538                block_initialize(b);
    538                 b->devmap_handle = devmap_handle;
     539                b->service_id = service_id;
    539540                b->size = cache->lblock_size;
    540541                b->lba = ba;
     
    586587int block_put(block_t *block)
    587588{
    588         devcon_t *devcon = devcon_search(block->devmap_handle);
     589        devcon_t *devcon = devcon_search(block->service_id);
    589590        cache_t *cache;
    590591        unsigned blocks_cached;
     
    687688/** Read sequential data from a block device.
    688689 *
    689  * @param devmap_handle Device handle of the block device.
     690 * @param service_id    Service ID of the block device.
    690691 * @param bufpos        Pointer to the first unread valid offset within the
    691692 *                      communication buffer.
     
    699700 * @return              EOK on success or a negative return code on failure.
    700701 */
    701 int block_seqread(devmap_handle_t devmap_handle, size_t *bufpos, size_t *buflen,
     702int block_seqread(service_id_t service_id, size_t *bufpos, size_t *buflen,
    702703    aoff64_t *pos, void *dst, size_t size)
    703704{
     
    707708        devcon_t *devcon;
    708709
    709         devcon = devcon_search(devmap_handle);
     710        devcon = devcon_search(service_id);
    710711        assert(devcon);
    711712        block_size = devcon->pblock_size;
     
    753754/** Read blocks directly from device (bypass cache).
    754755 *
    755  * @param devmap_handle Device handle of the block device.
     756 * @param service_id    Service ID of the block device.
    756757 * @param ba            Address of first block (physical).
    757758 * @param cnt           Number of blocks.
     
    760761 * @return              EOK on success or negative error code on failure.
    761762 */
    762 int block_read_direct(devmap_handle_t devmap_handle, aoff64_t ba, size_t cnt, void *buf)
     763int block_read_direct(service_id_t service_id, aoff64_t ba, size_t cnt, void *buf)
    763764{
    764765        devcon_t *devcon;
    765766        int rc;
    766767
    767         devcon = devcon_search(devmap_handle);
     768        devcon = devcon_search(service_id);
    768769        assert(devcon);
    769770       
     
    781782/** Write blocks directly to device (bypass cache).
    782783 *
    783  * @param devmap_handle Device handle of the block device.
     784 * @param service_id    Service ID of the block device.
    784785 * @param ba            Address of first block (physical).
    785786 * @param cnt           Number of blocks.
     
    788789 * @return              EOK on success or negative error code on failure.
    789790 */
    790 int block_write_direct(devmap_handle_t devmap_handle, aoff64_t ba, size_t cnt,
     791int block_write_direct(service_id_t service_id, aoff64_t ba, size_t cnt,
    791792    const void *data)
    792793{
     
    794795        int rc;
    795796
    796         devcon = devcon_search(devmap_handle);
     797        devcon = devcon_search(service_id);
    797798        assert(devcon);
    798799       
     
    809810/** Get device block size.
    810811 *
    811  * @param devmap_handle Device handle of the block device.
     812 * @param service_id    Service ID of the block device.
    812813 * @param bsize         Output block size.
    813814 *
    814815 * @return              EOK on success or negative error code on failure.
    815816 */
    816 int block_get_bsize(devmap_handle_t devmap_handle, size_t *bsize)
     817int block_get_bsize(service_id_t service_id, size_t *bsize)
    817818{
    818819        devcon_t *devcon;
    819820
    820         devcon = devcon_search(devmap_handle);
     821        devcon = devcon_search(service_id);
    821822        assert(devcon);
    822823       
     
    826827/** Get number of blocks on device.
    827828 *
    828  * @param devmap_handle Device handle of the block device.
     829 * @param service_id    Service ID of the block device.
    829830 * @param nblocks       Output number of blocks.
    830831 *
    831832 * @return              EOK on success or negative error code on failure.
    832833 */
    833 int block_get_nblocks(devmap_handle_t devmap_handle, aoff64_t *nblocks)
    834 {
    835         devcon_t *devcon = devcon_search(devmap_handle);
     834int block_get_nblocks(service_id_t service_id, aoff64_t *nblocks)
     835{
     836        devcon_t *devcon = devcon_search(service_id);
    836837        assert(devcon);
    837838       
     
    841842/** Read bytes directly from the device (bypass cache)
    842843 *
    843  * @param devmap_handle Device handle of the block device.
     844 * @param service_id    Service ID of the block device.
    844845 * @param abs_offset    Absolute offset in bytes where to start reading
    845846 * @param bytes                 Number of bytes to read
     
    848849 * @return              EOK on success or negative error code on failure.
    849850 */
    850 int block_read_bytes_direct(devmap_handle_t devmap_handle, aoff64_t abs_offset,
     851int block_read_bytes_direct(service_id_t service_id, aoff64_t abs_offset,
    851852    size_t bytes, void *data)
    852853{
     
    860861        size_t offset;
    861862       
    862         rc = block_get_bsize(devmap_handle, &phys_block_size);
     863        rc = block_get_bsize(service_id, &phys_block_size);
    863864        if (rc != EOK) {
    864865                return rc;
     
    878879        }
    879880       
    880         rc = block_read_direct(devmap_handle, first_block, blocks, buffer);
     881        rc = block_read_direct(service_id, first_block, blocks, buffer);
    881882        if (rc != EOK) {
    882883                free(buffer);
     
    889890       
    890891        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 */
     904int 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;
    891918}
    892919
     
    912939                printf("Error %d reading %zu blocks starting at block %" PRIuOFF64
    913940                    " from device handle %" PRIun "\n", rc, cnt, ba,
    914                     devcon->devmap_handle);
     941                    devcon->service_id);
    915942#ifndef NDEBUG
    916943                stacktrace_print();
     
    941968        if (rc != EOK) {
    942969                printf("Error %d writing %zu blocks starting at block %" PRIuOFF64
    943                     " to device handle %" PRIun "\n", rc, cnt, ba, devcon->devmap_handle);
     970                    " to device handle %" PRIun "\n", rc, cnt, ba, devcon->service_id);
    944971#ifndef NDEBUG
    945972                stacktrace_print();
     
    9811008}
    9821009
     1010/** Get TOC from block device. */
     1011static 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
    9831020/** Convert logical block address to physical block address. */
    9841021static aoff64_t ba_ltop(devcon_t *devcon, aoff64_t lba)
Note: See TracChangeset for help on using the changeset viewer.