Ignore:
File:
1 edited

Legend:

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

    r867e2555 r08cba4b  
    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;
     
    9595static aoff64_t ba_ltop(devcon_t *, aoff64_t);
    9696
    97 static devcon_t *devcon_search(devmap_handle_t devmap_handle)
     97static devcon_t *devcon_search(service_id_t service_id)
    9898{
    9999        fibril_mutex_lock(&dcl_lock);
     
    101101        list_foreach(dcl, cur) {
    102102                devcon_t *devcon = list_get_instance(cur, devcon_t, link);
    103                 if (devcon->devmap_handle == devmap_handle) {
     103                if (devcon->service_id == service_id) {
    104104                        fibril_mutex_unlock(&dcl_lock);
    105105                        return devcon;
     
    111111}
    112112
    113 static int devcon_add(devmap_handle_t devmap_handle, async_sess_t *sess,
     113static int devcon_add(service_id_t service_id, async_sess_t *sess,
    114114    size_t bsize, void *comm_area, size_t comm_size)
    115115{
     
    124124       
    125125        link_initialize(&devcon->link);
    126         devcon->devmap_handle = devmap_handle;
     126        devcon->service_id = service_id;
    127127        devcon->sess = sess;
    128128        fibril_mutex_initialize(&devcon->comm_area_lock);
     
    137137        list_foreach(dcl, cur) {
    138138                devcon_t *d = list_get_instance(cur, devcon_t, link);
    139                 if (d->devmap_handle == devmap_handle) {
     139                if (d->service_id == service_id) {
    140140                        fibril_mutex_unlock(&dcl_lock);
    141141                        free(devcon);
     
    155155}
    156156
    157 int block_init(exch_mgmt_t mgmt, devmap_handle_t devmap_handle,
     157int block_init(exch_mgmt_t mgmt, service_id_t service_id,
    158158    size_t comm_size)
    159159{
     
    163163                return ENOMEM;
    164164       
    165         async_sess_t *sess = devmap_device_connect(mgmt, devmap_handle,
     165        async_sess_t *sess = loc_service_connect(mgmt, service_id,
    166166            IPC_FLAG_BLOCKING);
    167167        if (!sess) {
     
    190190        }
    191191       
    192         rc = devcon_add(devmap_handle, sess, bsize, comm_area, comm_size);
     192        rc = devcon_add(service_id, sess, bsize, comm_area, comm_size);
    193193        if (rc != EOK) {
    194194                munmap(comm_area, comm_size);
     
    200200}
    201201
    202 void block_fini(devmap_handle_t devmap_handle)
    203 {
    204         devcon_t *devcon = devcon_search(devmap_handle);
     202void block_fini(service_id_t service_id)
     203{
     204        devcon_t *devcon = devcon_search(service_id);
    205205        assert(devcon);
    206206       
    207207        if (devcon->cache)
    208                 (void) block_cache_fini(devmap_handle);
     208                (void) block_cache_fini(service_id);
    209209       
    210210        devcon_remove(devcon);
     
    219219}
    220220
    221 int block_bb_read(devmap_handle_t devmap_handle, aoff64_t ba)
     221int block_bb_read(service_id_t service_id, aoff64_t ba)
    222222{
    223223        void *bb_buf;
    224224        int rc;
    225225
    226         devcon_t *devcon = devcon_search(devmap_handle);
     226        devcon_t *devcon = devcon_search(service_id);
    227227        if (!devcon)
    228228                return ENOENT;
     
    249249}
    250250
    251 void *block_bb_get(devmap_handle_t devmap_handle)
    252 {
    253         devcon_t *devcon = devcon_search(devmap_handle);
     251void *block_bb_get(service_id_t service_id)
     252{
     253        devcon_t *devcon = devcon_search(service_id);
    254254        assert(devcon);
    255255        return devcon->bb_buf;
     
    277277};
    278278
    279 int block_cache_init(devmap_handle_t devmap_handle, size_t size, unsigned blocks,
     279int block_cache_init(service_id_t service_id, size_t size, unsigned blocks,
    280280    enum cache_mode mode)
    281281{
    282         devcon_t *devcon = devcon_search(devmap_handle);
     282        devcon_t *devcon = devcon_search(service_id);
    283283        cache_t *cache;
    284284        if (!devcon)
     
    315315}
    316316
    317 int block_cache_fini(devmap_handle_t devmap_handle)
    318 {
    319         devcon_t *devcon = devcon_search(devmap_handle);
     317int block_cache_fini(service_id_t service_id)
     318{
     319        devcon_t *devcon = devcon_search(service_id);
    320320        cache_t *cache;
    321321        int rc;
     
    387387 * @param block                 Pointer to where the function will store the
    388388 *                              block pointer on success.
    389  * @param devmap_handle         Device handle of the block device.
     389 * @param service_id            Service ID of the block device.
    390390 * @param ba                    Block address (logical).
    391391 * @param flags                 If BLOCK_FLAGS_NOREAD is specified, block_get()
     
    395395 * @return                      EOK on success or a negative error code.
    396396 */
    397 int block_get(block_t **block, devmap_handle_t devmap_handle, aoff64_t ba, int flags)
     397int block_get(block_t **block, service_id_t service_id, aoff64_t ba, int flags)
    398398{
    399399        devcon_t *devcon;
     
    408408        int rc;
    409409       
    410         devcon = devcon_search(devmap_handle);
     410        devcon = devcon_search(service_id);
    411411
    412412        assert(devcon);
     
    536536
    537537                block_initialize(b);
    538                 b->devmap_handle = devmap_handle;
     538                b->service_id = service_id;
    539539                b->size = cache->lblock_size;
    540540                b->lba = ba;
     
    586586int block_put(block_t *block)
    587587{
    588         devcon_t *devcon = devcon_search(block->devmap_handle);
     588        devcon_t *devcon = devcon_search(block->service_id);
    589589        cache_t *cache;
    590590        unsigned blocks_cached;
     
    687687/** Read sequential data from a block device.
    688688 *
    689  * @param devmap_handle Device handle of the block device.
     689 * @param service_id    Service ID of the block device.
    690690 * @param bufpos        Pointer to the first unread valid offset within the
    691691 *                      communication buffer.
     
    699699 * @return              EOK on success or a negative return code on failure.
    700700 */
    701 int block_seqread(devmap_handle_t devmap_handle, size_t *bufpos, size_t *buflen,
     701int block_seqread(service_id_t service_id, size_t *bufpos, size_t *buflen,
    702702    aoff64_t *pos, void *dst, size_t size)
    703703{
     
    707707        devcon_t *devcon;
    708708
    709         devcon = devcon_search(devmap_handle);
     709        devcon = devcon_search(service_id);
    710710        assert(devcon);
    711711        block_size = devcon->pblock_size;
     
    753753/** Read blocks directly from device (bypass cache).
    754754 *
    755  * @param devmap_handle Device handle of the block device.
     755 * @param service_id    Service ID of the block device.
    756756 * @param ba            Address of first block (physical).
    757757 * @param cnt           Number of blocks.
     
    760760 * @return              EOK on success or negative error code on failure.
    761761 */
    762 int block_read_direct(devmap_handle_t devmap_handle, aoff64_t ba, size_t cnt, void *buf)
     762int block_read_direct(service_id_t service_id, aoff64_t ba, size_t cnt, void *buf)
    763763{
    764764        devcon_t *devcon;
    765765        int rc;
    766766
    767         devcon = devcon_search(devmap_handle);
     767        devcon = devcon_search(service_id);
    768768        assert(devcon);
    769769       
     
    781781/** Write blocks directly to device (bypass cache).
    782782 *
    783  * @param devmap_handle Device handle of the block device.
     783 * @param service_id    Service ID of the block device.
    784784 * @param ba            Address of first block (physical).
    785785 * @param cnt           Number of blocks.
     
    788788 * @return              EOK on success or negative error code on failure.
    789789 */
    790 int block_write_direct(devmap_handle_t devmap_handle, aoff64_t ba, size_t cnt,
     790int block_write_direct(service_id_t service_id, aoff64_t ba, size_t cnt,
    791791    const void *data)
    792792{
     
    794794        int rc;
    795795
    796         devcon = devcon_search(devmap_handle);
     796        devcon = devcon_search(service_id);
    797797        assert(devcon);
    798798       
     
    809809/** Get device block size.
    810810 *
    811  * @param devmap_handle Device handle of the block device.
     811 * @param service_id    Service ID of the block device.
    812812 * @param bsize         Output block size.
    813813 *
    814814 * @return              EOK on success or negative error code on failure.
    815815 */
    816 int block_get_bsize(devmap_handle_t devmap_handle, size_t *bsize)
     816int block_get_bsize(service_id_t service_id, size_t *bsize)
    817817{
    818818        devcon_t *devcon;
    819819
    820         devcon = devcon_search(devmap_handle);
     820        devcon = devcon_search(service_id);
    821821        assert(devcon);
    822822       
     
    826826/** Get number of blocks on device.
    827827 *
    828  * @param devmap_handle Device handle of the block device.
     828 * @param service_id    Service ID of the block device.
    829829 * @param nblocks       Output number of blocks.
    830830 *
    831831 * @return              EOK on success or negative error code on failure.
    832832 */
    833 int block_get_nblocks(devmap_handle_t devmap_handle, aoff64_t *nblocks)
    834 {
    835         devcon_t *devcon = devcon_search(devmap_handle);
     833int block_get_nblocks(service_id_t service_id, aoff64_t *nblocks)
     834{
     835        devcon_t *devcon = devcon_search(service_id);
    836836        assert(devcon);
    837837       
     
    841841/** Read bytes directly from the device (bypass cache)
    842842 *
    843  * @param devmap_handle Device handle of the block device.
     843 * @param service_id    Service ID of the block device.
    844844 * @param abs_offset    Absolute offset in bytes where to start reading
    845845 * @param bytes                 Number of bytes to read
     
    848848 * @return              EOK on success or negative error code on failure.
    849849 */
    850 int block_read_bytes_direct(devmap_handle_t devmap_handle, aoff64_t abs_offset,
     850int block_read_bytes_direct(service_id_t service_id, aoff64_t abs_offset,
    851851    size_t bytes, void *data)
    852852{
     
    860860        size_t offset;
    861861       
    862         rc = block_get_bsize(devmap_handle, &phys_block_size);
     862        rc = block_get_bsize(service_id, &phys_block_size);
    863863        if (rc != EOK) {
    864864                return rc;
     
    878878        }
    879879       
    880         rc = block_read_direct(devmap_handle, first_block, blocks, buffer);
     880        rc = block_read_direct(service_id, first_block, blocks, buffer);
    881881        if (rc != EOK) {
    882882                free(buffer);
     
    889889       
    890890        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 */
     902toc_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;
    891928}
    892929
     
    912949                printf("Error %d reading %zu blocks starting at block %" PRIuOFF64
    913950                    " from device handle %" PRIun "\n", rc, cnt, ba,
    914                     devcon->devmap_handle);
     951                    devcon->service_id);
    915952#ifndef NDEBUG
    916953                stacktrace_print();
     
    941978        if (rc != EOK) {
    942979                printf("Error %d writing %zu blocks starting at block %" PRIuOFF64
    943                     " to device handle %" PRIun "\n", rc, cnt, ba, devcon->devmap_handle);
     980                    " to device handle %" PRIun "\n", rc, cnt, ba, devcon->service_id);
    944981#ifndef NDEBUG
    945982                stacktrace_print();
Note: See TracChangeset for help on using the changeset viewer.