Changeset 15f3c3f in mainline for uspace/lib/block/libblock.c


Ignore:
Timestamp:
2011-06-22T22:00:52Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
86ffa27f
Parents:
ef09a7a
Message:

Rename devmap to loc, devfs to locfs.

File:
1 edited

Legend:

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

    ref09a7a r15f3c3f  
    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;
     
    384384 * @param block                 Pointer to where the function will store the
    385385 *                              block pointer on success.
    386  * @param devmap_handle         Device handle of the block device.
     386 * @param service_id            Service ID of the block device.
    387387 * @param ba                    Block address (logical).
    388388 * @param flags                 If BLOCK_FLAGS_NOREAD is specified, block_get()
     
    392392 * @return                      EOK on success or a negative error code.
    393393 */
    394 int block_get(block_t **block, devmap_handle_t devmap_handle, aoff64_t ba, int flags)
     394int block_get(block_t **block, service_id_t service_id, aoff64_t ba, int flags)
    395395{
    396396        devcon_t *devcon;
     
    401401        int rc;
    402402       
    403         devcon = devcon_search(devmap_handle);
     403        devcon = devcon_search(service_id);
    404404
    405405        assert(devcon);
     
    527527
    528528                block_initialize(b);
    529                 b->devmap_handle = devmap_handle;
     529                b->service_id = service_id;
    530530                b->size = cache->lblock_size;
    531531                b->lba = ba;
     
    577577int block_put(block_t *block)
    578578{
    579         devcon_t *devcon = devcon_search(block->devmap_handle);
     579        devcon_t *devcon = devcon_search(block->service_id);
    580580        cache_t *cache;
    581581        unsigned blocks_cached;
     
    675675/** Read sequential data from a block device.
    676676 *
    677  * @param devmap_handle Device handle of the block device.
     677 * @param service_id    Service ID of the block device.
    678678 * @param bufpos        Pointer to the first unread valid offset within the
    679679 *                      communication buffer.
     
    687687 * @return              EOK on success or a negative return code on failure.
    688688 */
    689 int block_seqread(devmap_handle_t devmap_handle, size_t *bufpos, size_t *buflen,
     689int block_seqread(service_id_t service_id, size_t *bufpos, size_t *buflen,
    690690    aoff64_t *pos, void *dst, size_t size)
    691691{
     
    695695        devcon_t *devcon;
    696696
    697         devcon = devcon_search(devmap_handle);
     697        devcon = devcon_search(service_id);
    698698        assert(devcon);
    699699        block_size = devcon->pblock_size;
     
    741741/** Read blocks directly from device (bypass cache).
    742742 *
    743  * @param devmap_handle Device handle of the block device.
     743 * @param service_id    Service ID of the block device.
    744744 * @param ba            Address of first block (physical).
    745745 * @param cnt           Number of blocks.
     
    748748 * @return              EOK on success or negative error code on failure.
    749749 */
    750 int block_read_direct(devmap_handle_t devmap_handle, aoff64_t ba, size_t cnt, void *buf)
     750int block_read_direct(service_id_t service_id, aoff64_t ba, size_t cnt, void *buf)
    751751{
    752752        devcon_t *devcon;
    753753        int rc;
    754754
    755         devcon = devcon_search(devmap_handle);
     755        devcon = devcon_search(service_id);
    756756        assert(devcon);
    757757       
     
    769769/** Write blocks directly to device (bypass cache).
    770770 *
    771  * @param devmap_handle Device handle of the block device.
     771 * @param service_id    Service ID of the block device.
    772772 * @param ba            Address of first block (physical).
    773773 * @param cnt           Number of blocks.
     
    776776 * @return              EOK on success or negative error code on failure.
    777777 */
    778 int block_write_direct(devmap_handle_t devmap_handle, aoff64_t ba, size_t cnt,
     778int block_write_direct(service_id_t service_id, aoff64_t ba, size_t cnt,
    779779    const void *data)
    780780{
     
    782782        int rc;
    783783
    784         devcon = devcon_search(devmap_handle);
     784        devcon = devcon_search(service_id);
    785785        assert(devcon);
    786786       
     
    797797/** Get device block size.
    798798 *
    799  * @param devmap_handle Device handle of the block device.
     799 * @param service_id    Service ID of the block device.
    800800 * @param bsize         Output block size.
    801801 *
    802802 * @return              EOK on success or negative error code on failure.
    803803 */
    804 int block_get_bsize(devmap_handle_t devmap_handle, size_t *bsize)
     804int block_get_bsize(service_id_t service_id, size_t *bsize)
    805805{
    806806        devcon_t *devcon;
    807807
    808         devcon = devcon_search(devmap_handle);
     808        devcon = devcon_search(service_id);
    809809        assert(devcon);
    810810       
     
    814814/** Get number of blocks on device.
    815815 *
    816  * @param devmap_handle Device handle of the block device.
     816 * @param service_id    Service ID of the block device.
    817817 * @param nblocks       Output number of blocks.
    818818 *
    819819 * @return              EOK on success or negative error code on failure.
    820820 */
    821 int block_get_nblocks(devmap_handle_t devmap_handle, aoff64_t *nblocks)
    822 {
    823         devcon_t *devcon = devcon_search(devmap_handle);
     821int block_get_nblocks(service_id_t service_id, aoff64_t *nblocks)
     822{
     823        devcon_t *devcon = devcon_search(service_id);
    824824        assert(devcon);
    825825       
     
    829829/** Read bytes directly from the device (bypass cache)
    830830 *
    831  * @param devmap_handle Device handle of the block device.
     831 * @param service_id    Service ID of the block device.
    832832 * @param abs_offset    Absolute offset in bytes where to start reading
    833833 * @param bytes                 Number of bytes to read
     
    836836 * @return              EOK on success or negative error code on failure.
    837837 */
    838 int block_read_bytes_direct(devmap_handle_t devmap_handle, aoff64_t abs_offset,
     838int block_read_bytes_direct(service_id_t service_id, aoff64_t abs_offset,
    839839    size_t bytes, void *data)
    840840{
     
    848848        size_t offset;
    849849       
    850         rc = block_get_bsize(devmap_handle, &phys_block_size);
     850        rc = block_get_bsize(service_id, &phys_block_size);
    851851        if (rc != EOK) {
    852852                return rc;
     
    866866        }
    867867       
    868         rc = block_read_direct(devmap_handle, first_block, blocks, buffer);
     868        rc = block_read_direct(service_id, first_block, blocks, buffer);
    869869        if (rc != EOK) {
    870870                free(buffer);
     
    900900                printf("Error %d reading %zu blocks starting at block %" PRIuOFF64
    901901                    " from device handle %" PRIun "\n", rc, cnt, ba,
    902                     devcon->devmap_handle);
     902                    devcon->service_id);
    903903#ifndef NDEBUG
    904904                stacktrace_print();
     
    929929        if (rc != EOK) {
    930930                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);
    932932#ifndef NDEBUG
    933933                stacktrace_print();
Note: See TracChangeset for help on using the changeset viewer.