Changeset 7cfe5c0 in mainline for uspace/srv/bd/file_bd/file_bd.c


Ignore:
Timestamp:
2012-08-20T19:16:24Z (12 years ago)
Author:
Adam Hraska <adam.hraska+hos@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6b99156
Parents:
b9cb911 (diff), 01e397ac (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merged with mainline 0.5.0 changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/bd/file_bd/file_bd.c

    rb9cb911 r7cfe5c0  
    4141#include <stdio.h>
    4242#include <unistd.h>
    43 #include <ipc/bd.h>
    4443#include <async.h>
    4544#include <as.h>
     45#include <bd_srv.h>
    4646#include <fibril_synch.h>
    4747#include <loc.h>
     
    6262
    6363static service_id_t service_id;
     64static bd_srvs_t bd_srvs;
    6465static fibril_mutex_t dev_lock;
    6566
     
    6768static int file_bd_init(const char *fname);
    6869static void file_bd_connection(ipc_callid_t iid, ipc_call_t *icall, void *);
    69 static int file_bd_read_blocks(uint64_t ba, size_t cnt, void *buf);
    70 static int file_bd_write_blocks(uint64_t ba, size_t cnt, const void *buf);
     70
     71static int file_bd_open(bd_srvs_t *, bd_srv_t *);
     72static int file_bd_close(bd_srv_t *);
     73static int file_bd_read_blocks(bd_srv_t *, aoff64_t, size_t, void *, size_t);
     74static int file_bd_write_blocks(bd_srv_t *, aoff64_t, size_t, const void *, size_t);
     75static int file_bd_get_block_size(bd_srv_t *, size_t *);
     76static int file_bd_get_num_blocks(bd_srv_t *, aoff64_t *);
     77
     78static bd_ops_t file_bd_ops = {
     79        .open = file_bd_open,
     80        .close = file_bd_close,
     81        .read_blocks = file_bd_read_blocks,
     82        .write_blocks = file_bd_write_blocks,
     83        .get_block_size = file_bd_get_block_size,
     84        .get_num_blocks = file_bd_get_num_blocks
     85};
    7186
    7287int main(int argc, char **argv)
     
    139154static int file_bd_init(const char *fname)
    140155{
     156        bd_srvs_init(&bd_srvs);
     157        bd_srvs.ops = &file_bd_ops;
     158       
    141159        async_set_client_connection(file_bd_connection);
    142160        int rc = loc_server_register(NAME);
     
    170188static void file_bd_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    171189{
    172         void *fs_va = NULL;
    173         ipc_callid_t callid;
    174         ipc_call_t call;
    175         sysarg_t method;
    176         size_t comm_size;
    177         unsigned int flags;
    178         int retval;
    179         uint64_t ba;
    180         size_t cnt;
    181 
    182         /* Answer the IPC_M_CONNECT_ME_TO call. */
    183         async_answer_0(iid, EOK);
    184 
    185         if (!async_share_out_receive(&callid, &comm_size, &flags)) {
    186                 async_answer_0(callid, EHANGUP);
    187                 return;
    188         }
    189 
    190         (void) async_share_out_finalize(callid, &fs_va);
    191         if (fs_va == AS_MAP_FAILED) {
    192                 async_answer_0(callid, EHANGUP);
    193                 return;
    194         }
    195 
    196         while (true) {
    197                 callid = async_get_call(&call);
    198                 method = IPC_GET_IMETHOD(call);
    199                
    200                 if (!method) {
    201                         /* The other side has hung up. */
    202                         async_answer_0(callid, EOK);
    203                         return;
    204                 }
    205                
    206                 switch (method) {
    207                 case BD_READ_BLOCKS:
    208                         ba = MERGE_LOUP32(IPC_GET_ARG1(call),
    209                             IPC_GET_ARG2(call));
    210                         cnt = IPC_GET_ARG3(call);
    211                         if (cnt * block_size > comm_size) {
    212                                 retval = ELIMIT;
    213                                 break;
    214                         }
    215                         retval = file_bd_read_blocks(ba, cnt, fs_va);
    216                         break;
    217                 case BD_WRITE_BLOCKS:
    218                         ba = MERGE_LOUP32(IPC_GET_ARG1(call),
    219                             IPC_GET_ARG2(call));
    220                         cnt = IPC_GET_ARG3(call);
    221                         if (cnt * block_size > comm_size) {
    222                                 retval = ELIMIT;
    223                                 break;
    224                         }
    225                         retval = file_bd_write_blocks(ba, cnt, fs_va);
    226                         break;
    227                 case BD_GET_BLOCK_SIZE:
    228                         async_answer_1(callid, EOK, block_size);
    229                         continue;
    230                 case BD_GET_NUM_BLOCKS:
    231                         async_answer_2(callid, EOK, LOWER32(num_blocks),
    232                             UPPER32(num_blocks));
    233                         continue;
    234                 default:
    235                         retval = EINVAL;
    236                         break;
    237                 }
    238                 async_answer_0(callid, retval);
    239         }
     190        bd_conn(iid, icall, &bd_srvs);
     191}
     192
     193/** Open device. */
     194static int file_bd_open(bd_srvs_t *bds, bd_srv_t *bd)
     195{
     196        return EOK;
     197}
     198
     199/** Close device. */
     200static int file_bd_close(bd_srv_t *bd)
     201{
     202        return EOK;
    240203}
    241204
    242205/** Read blocks from the device. */
    243 static int file_bd_read_blocks(uint64_t ba, size_t cnt, void *buf)
     206static int file_bd_read_blocks(bd_srv_t *bd, uint64_t ba, size_t cnt, void *buf,
     207    size_t size)
    244208{
    245209        size_t n_rd;
    246210        int rc;
     211
     212        if (size < cnt * block_size)
     213                return EINVAL;
    247214
    248215        /* Check whether access is within device address bounds. */
     
    279246
    280247/** Write blocks to the device. */
    281 static int file_bd_write_blocks(uint64_t ba, size_t cnt, const void *buf)
     248static int file_bd_write_blocks(bd_srv_t *bd, uint64_t ba, size_t cnt,
     249    const void *buf, size_t size)
    282250{
    283251        size_t n_wr;
    284252        int rc;
     253
     254        if (size < cnt * block_size)
     255                return EINVAL;
    285256
    286257        /* Check whether access is within device address bounds. */
     
    318289}
    319290
     291/** Get device block size. */
     292static int file_bd_get_block_size(bd_srv_t *bd, size_t *rsize)
     293{
     294        *rsize = block_size;
     295        return EOK;
     296}
     297
     298/** Get number of blocks on device. */
     299static int file_bd_get_num_blocks(bd_srv_t *bd, aoff64_t *rnb)
     300{
     301        *rnb = num_blocks;
     302        return EOK;
     303}
     304
    320305/**
    321306 * @}
Note: See TracChangeset for help on using the changeset viewer.