Changes in uspace/srv/bd/rd/rd.c [0da4e41:52e4f52] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/rd/rd.c
r0da4e41 r52e4f52 55 55 #include <devmap.h> 56 56 #include <ipc/bd.h> 57 #include <macros.h>58 57 59 58 #define NAME "rd" 60 59 61 /** Pointer to the ramdisk's image */60 /** Pointer to the ramdisk's image. */ 62 61 static void *rd_addr; 63 /** Size of the ramdisk */62 /** Size of the ramdisk. */ 64 63 static 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);71 64 72 65 /** … … 89 82 int retval; 90 83 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; 94 87 95 88 /* … … 102 95 */ 103 96 int flags; 104 if ( async_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); 106 99 if (fs_va) { 107 (void) async_share_out_finalize(callid, fs_va);100 (void) ipc_share_out_finalize(callid, fs_va); 108 101 } else { 109 102 ipc_answer_0(callid, EHANGUP); … … 130 123 ipc_answer_0(callid, EOK); 131 124 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; 141 146 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; 151 168 break; 152 case BD_GET_BLOCK_SIZE:153 ipc_answer_1(callid, EOK, block_size);154 continue;155 169 default: 156 170 /* … … 167 181 } 168 182 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 199 183 /** Prepare the ramdisk image for operation. */ 200 184 static bool rd_init(void)
Note:
See TracChangeset
for help on using the changeset viewer.