Changes in uspace/srv/bd/file_bd/file_bd.c [4802dd7:faba839] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/file_bd/file_bd.c
r4802dd7 rfaba839 41 41 #include <stdio.h> 42 42 #include <unistd.h> 43 #include <ipc/bd.h> 43 44 #include <async.h> 44 45 #include <as.h> 45 #include <bd_srv.h>46 46 #include <fibril_synch.h> 47 47 #include <loc.h> … … 62 62 63 63 static service_id_t service_id; 64 static bd_srv_t bd_srv;65 64 static fibril_mutex_t dev_lock; 66 65 … … 68 67 static int file_bd_init(const char *fname); 69 68 static void file_bd_connection(ipc_callid_t iid, ipc_call_t *icall, void *); 70 71 static int file_bd_open(bd_srv_t *); 72 static int file_bd_close(bd_srv_t *); 73 static int file_bd_read_blocks(bd_srv_t *, aoff64_t, size_t, void *, size_t); 74 static int file_bd_write_blocks(bd_srv_t *, aoff64_t, size_t, const void *, size_t); 75 static int file_bd_get_block_size(bd_srv_t *, size_t *); 76 static int file_bd_get_num_blocks(bd_srv_t *, aoff64_t *); 77 78 static 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 }; 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); 86 71 87 72 int main(int argc, char **argv) … … 154 139 static int file_bd_init(const char *fname) 155 140 { 156 bd_srv_init(&bd_srv);157 bd_srv.ops = &file_bd_ops;158 159 141 async_set_client_connection(file_bd_connection); 160 142 int rc = loc_server_register(NAME); … … 188 170 static void file_bd_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 189 171 { 190 bd_conn(iid, icall, &bd_srv); 191 } 192 193 /** Open device. */ 194 static int file_bd_open(bd_srv_t *bd) 195 { 196 return EOK; 197 } 198 199 /** Close device. */ 200 static int file_bd_close(bd_srv_t *bd) 201 { 202 return EOK; 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 } 203 240 } 204 241 205 242 /** Read blocks from the device. */ 206 static int file_bd_read_blocks(bd_srv_t *bd, uint64_t ba, size_t cnt, void *buf, 207 size_t size) 243 static int file_bd_read_blocks(uint64_t ba, size_t cnt, void *buf) 208 244 { 209 245 size_t n_rd; 210 246 int rc; 211 212 if (size < cnt * block_size)213 return EINVAL;214 247 215 248 /* Check whether access is within device address bounds. */ … … 246 279 247 280 /** Write blocks to the device. */ 248 static int file_bd_write_blocks(bd_srv_t *bd, uint64_t ba, size_t cnt, 249 const void *buf, size_t size) 281 static int file_bd_write_blocks(uint64_t ba, size_t cnt, const void *buf) 250 282 { 251 283 size_t n_wr; 252 284 int rc; 253 254 if (size < cnt * block_size)255 return EINVAL;256 285 257 286 /* Check whether access is within device address bounds. */ … … 289 318 } 290 319 291 /** Get device block size. */292 static 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. */299 static int file_bd_get_num_blocks(bd_srv_t *bd, aoff64_t *rnb)300 {301 *rnb = num_blocks;302 return EOK;303 }304 305 320 /** 306 321 * @}
Note:
See TracChangeset
for help on using the changeset viewer.