Changeset 1787e527 in mainline for uspace/srv/bd/rd/rd.c


Ignore:
Timestamp:
2009-11-16T21:22:54Z (14 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5ebdf94
Parents:
fcbd1be (diff), 9c70ed6 (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 head (unstable)

File:
1 edited

Legend:

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

    rfcbd1be r1787e527  
    5555#include <devmap.h>
    5656#include <ipc/bd.h>
     57#include <macros.h>
    5758
    5859#define NAME "rd"
    5960
    60 /** Pointer to the ramdisk's image. */
     61/** Pointer to the ramdisk's image */
    6162static void *rd_addr;
    62 /** Size of the ramdisk. */
     63/** Size of the ramdisk */
    6364static size_t rd_size;
     65
     66/** Block size */
     67static const size_t block_size = 512;
     68
     69static int rd_read_blocks(uint64_t ba, size_t cnt, void *buf);
     70static int rd_write_blocks(uint64_t ba, size_t cnt, const void *buf);
    6471
    6572/**
     
    8289        int retval;
    8390        void *fs_va = NULL;
    84         off_t offset;
    85         size_t block_size;
    86         size_t maxblock_size;
     91        uint64_t ba;
     92        size_t cnt;
     93        size_t comm_size;
    8794
    8895        /*
     
    95102         */
    96103        int flags;
    97         if (ipc_share_out_receive(&callid, &maxblock_size, &flags)) {
    98                 fs_va = as_get_mappable_page(maxblock_size);
     104        if (async_share_out_receive(&callid, &comm_size, &flags)) {
     105                fs_va = as_get_mappable_page(comm_size);
    99106                if (fs_va) {
    100                         (void) ipc_share_out_finalize(callid, fs_va);
     107                        (void) async_share_out_finalize(callid, fs_va);
    101108                } else {
    102109                        ipc_answer_0(callid, EHANGUP);
     
    123130                        ipc_answer_0(callid, EOK);
    124131                        return;
    125                 case BD_READ_BLOCK:
    126                         offset = IPC_GET_ARG1(call);
    127                         block_size = IPC_GET_ARG2(call);
    128                         if (block_size > maxblock_size) {
    129                                 /*
    130                                  * Maximum block size exceeded.
    131                                  */
     132                case BD_READ_BLOCKS:
     133                        ba = MERGE_LOUP32(IPC_GET_ARG1(call),
     134                            IPC_GET_ARG2(call));
     135                        cnt = IPC_GET_ARG3(call);
     136                        if (cnt * block_size > comm_size) {
    132137                                retval = ELIMIT;
    133138                                break;
    134139                        }
    135                         if (offset * block_size > rd_size - block_size) {
    136                                 /*
    137                                  * Reading past the end of the device.
    138                                  */
     140                        retval = rd_read_blocks(ba, cnt, fs_va);
     141                        break;
     142                case BD_WRITE_BLOCKS:
     143                        ba = MERGE_LOUP32(IPC_GET_ARG1(call),
     144                            IPC_GET_ARG2(call));
     145                        cnt = IPC_GET_ARG3(call);
     146                        if (cnt * block_size > comm_size) {
    139147                                retval = ELIMIT;
    140148                                break;
    141149                        }
    142                         fibril_rwlock_read_lock(&rd_lock);
    143                         memcpy(fs_va, rd_addr + offset * block_size, block_size);
    144                         fibril_rwlock_read_unlock(&rd_lock);
    145                         retval = EOK;
     150                        retval = rd_write_blocks(ba, cnt, fs_va);
    146151                        break;
    147                 case BD_WRITE_BLOCK:
    148                         offset = IPC_GET_ARG1(call);
    149                         block_size = IPC_GET_ARG2(call);
    150                         if (block_size > maxblock_size) {
    151                                 /*
    152                                  * Maximum block size exceeded.
    153                                  */
    154                                 retval = ELIMIT;
    155                                 break;
    156                         }
    157                         if (offset * block_size > rd_size - block_size) {
    158                                 /*
    159                                  * Writing past the end of the device.
    160                                  */
    161                                 retval = ELIMIT;
    162                                 break;
    163                         }
    164                         fibril_rwlock_write_lock(&rd_lock);
    165                         memcpy(rd_addr + offset * block_size, fs_va, block_size);
    166                         fibril_rwlock_write_unlock(&rd_lock);
    167                         retval = EOK;
    168                         break;
     152                case BD_GET_BLOCK_SIZE:
     153                        ipc_answer_1(callid, EOK, block_size);
     154                        continue;
    169155                default:
    170156                        /*
     
    181167}
    182168
     169/** Read blocks from the device. */
     170static int rd_read_blocks(uint64_t ba, size_t cnt, void *buf)
     171{
     172        if ((ba + cnt) * block_size > rd_size) {
     173                /* Reading past the end of the device. */
     174                return ELIMIT;
     175        }
     176
     177        fibril_rwlock_read_lock(&rd_lock);
     178        memcpy(buf, rd_addr + ba * block_size, block_size * cnt);
     179        fibril_rwlock_read_unlock(&rd_lock);
     180
     181        return EOK;
     182}
     183
     184/** Write blocks to the device. */
     185static int rd_write_blocks(uint64_t ba, size_t cnt, const void *buf)
     186{
     187        if ((ba + cnt) * block_size > rd_size) {
     188                /* Writing past the end of the device. */
     189                return ELIMIT;
     190        }
     191
     192        fibril_rwlock_write_lock(&rd_lock);
     193        memcpy(rd_addr + ba * block_size, buf, block_size * cnt);
     194        fibril_rwlock_write_unlock(&rd_lock);
     195
     196        return EOK;
     197}
     198
    183199/** Prepare the ramdisk image for operation. */
    184200static bool rd_init(void)
Note: See TracChangeset for help on using the changeset viewer.