Changes in uspace/srv/bd/rd/rd.c [1ee00b7:52e4f52] in mainline


Ignore:
File:
1 edited

Legend:

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

    r1ee00b7 r52e4f52  
    5555#include <devmap.h>
    5656#include <ipc/bd.h>
    57 #include <macros.h>
    5857
    5958#define NAME "rd"
    6059
    61 /** Pointer to the ramdisk's image */
     60/** Pointer to the ramdisk's image. */
    6261static void *rd_addr;
    63 /** Size of the ramdisk */
     62/** Size of the ramdisk. */
    6463static size_t rd_size;
    65 
    66 /** Block size */
    67 static const size_t block_size = 512;
    68 
    69 static int rd_read_blocks(uint64_t ba, size_t cnt, void *buf);
    70 static int rd_write_blocks(uint64_t ba, size_t cnt, const void *buf);
    7164
    7265/**
     
    8982        int retval;
    9083        void *fs_va = NULL;
    91         uint64_t ba;
    92         size_t cnt;
    93         size_t comm_size;
     84        off_t offset;
     85        size_t block_size;
     86        size_t maxblock_size;
    9487
    9588        /*
     
    10295         */
    10396        int flags;
    104         if (ipc_share_out_receive(&callid, &comm_size, &flags)) {
    105                 fs_va = as_get_mappable_page(comm_size);
     97        if (ipc_share_out_receive(&callid, &maxblock_size, &flags)) {
     98                fs_va = as_get_mappable_page(maxblock_size);
    10699                if (fs_va) {
    107100                        (void) ipc_share_out_finalize(callid, fs_va);
     
    130123                        ipc_answer_0(callid, EOK);
    131124                        return;
    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) {
    137                                 retval = ELIMIT;
    138                                 break;
    139                         }
    140                         retval = rd_read_blocks(ba, cnt, fs_va);
     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                                retval = ELIMIT;
     133                                break;
     134                        }
     135                        if (offset * block_size > rd_size - block_size) {
     136                                /*
     137                                 * Reading past the end of the device.
     138                                 */
     139                                retval = ELIMIT;
     140                                break;
     141                        }
     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;
    141146                        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) {
    147                                 retval = ELIMIT;
    148                                 break;
    149                         }
    150                         retval = rd_write_blocks(ba, cnt, fs_va);
     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;
    151168                        break;
    152                 case BD_GET_BLOCK_SIZE:
    153                         ipc_answer_1(callid, EOK, block_size);
    154                         continue;
    155169                default:
    156170                        /*
     
    167181}
    168182
    169 /** Read blocks from the device. */
    170 static 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. */
    185 static 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 
    199183/** Prepare the ramdisk image for operation. */
    200184static bool rd_init(void)
Note: See TracChangeset for help on using the changeset viewer.