Changeset affaf2e in mainline for uspace/srv/bd/file_bd/file_bd.c
- Timestamp:
- 2012-08-15T15:13:20Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b546231
- Parents:
- f66ca57f (diff), 135486d (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/file_bd/file_bd.c
rf66ca57f raffaf2e 41 41 #include <stdio.h> 42 42 #include <unistd.h> 43 #include <ipc/bd.h>44 43 #include <async.h> 45 44 #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_srvs_t bd_srvs; 64 65 static fibril_mutex_t dev_lock; 65 66 … … 67 68 static int file_bd_init(const char *fname); 68 69 static 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 71 static int file_bd_open(bd_srvs_t *, 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 }; 71 86 72 87 int main(int argc, char **argv) … … 139 154 static int file_bd_init(const char *fname) 140 155 { 156 bd_srvs_init(&bd_srvs); 157 bd_srvs.ops = &file_bd_ops; 158 141 159 async_set_client_connection(file_bd_connection); 142 160 int rc = loc_server_register(NAME); … … 170 188 static void file_bd_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 171 189 { 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. */ 194 static int file_bd_open(bd_srvs_t *bds, 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; 240 203 } 241 204 242 205 /** Read blocks from the device. */ 243 static int file_bd_read_blocks(uint64_t ba, size_t cnt, void *buf) 206 static int file_bd_read_blocks(bd_srv_t *bd, uint64_t ba, size_t cnt, void *buf, 207 size_t size) 244 208 { 245 209 size_t n_rd; 246 210 int rc; 211 212 if (size < cnt * block_size) 213 return EINVAL; 247 214 248 215 /* Check whether access is within device address bounds. */ … … 279 246 280 247 /** Write blocks to the device. */ 281 static int file_bd_write_blocks(uint64_t ba, size_t cnt, const void *buf) 248 static int file_bd_write_blocks(bd_srv_t *bd, uint64_t ba, size_t cnt, 249 const void *buf, size_t size) 282 250 { 283 251 size_t n_wr; 284 252 int rc; 253 254 if (size < cnt * block_size) 255 return EINVAL; 285 256 286 257 /* Check whether access is within device address bounds. */ … … 318 289 } 319 290 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 320 305 /** 321 306 * @}
Note:
See TracChangeset
for help on using the changeset viewer.