Changeset 4802dd7 in mainline for uspace/srv/bd/part/guid_part/guid_part.c
- Timestamp:
- 2012-08-13T22:01:04Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 135486d, 71b0d4d4, 9dec6d4, cddcc4a3
- Parents:
- 4820360
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/part/guid_part/guid_part.c
r4820360 r4802dd7 47 47 #include <stdlib.h> 48 48 #include <unistd.h> 49 #include <ipc/bd.h>50 49 #include <async.h> 51 50 #include <as.h> 51 #include <bd_srv.h> 52 52 #include <fibril_synch.h> 53 53 #include <loc.h> … … 83 83 /** Service representing the partition (outbound device) */ 84 84 service_id_t dsid; 85 /** Block device server structure */ 86 bd_srv_t bd; 85 87 /** Points to next partition structure. */ 86 88 struct part *next; … … 100 102 static void gpt_pte_to_part(const gpt_entry_t *pte, part_t *part); 101 103 static void gpt_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg); 102 static int gpt_bd_read(part_t *p, aoff64_t ba, size_t cnt, void *buf);103 static int gpt_bd_write(part_t *p, aoff64_t ba, size_t cnt, const void *buf);104 104 static int gpt_bsa_translate(part_t *p, aoff64_t ba, size_t cnt, aoff64_t *gba); 105 106 static int gpt_bd_open(bd_srv_t *); 107 static int gpt_bd_close(bd_srv_t *); 108 static int gpt_bd_read_blocks(bd_srv_t *, aoff64_t, size_t, void *, size_t); 109 static int gpt_bd_write_blocks(bd_srv_t *, aoff64_t, size_t, const void *, size_t); 110 static int gpt_bd_get_block_size(bd_srv_t *, size_t *); 111 static int gpt_bd_get_num_blocks(bd_srv_t *, aoff64_t *); 112 113 static bd_ops_t gpt_bd_ops = { 114 .open = gpt_bd_open, 115 .close = gpt_bd_close, 116 .read_blocks = gpt_bd_read_blocks, 117 .write_blocks = gpt_bd_write_blocks, 118 .get_block_size = gpt_bd_get_block_size, 119 .get_num_blocks = gpt_bd_get_num_blocks 120 }; 121 122 static part_t *bd_srv_part(bd_srv_t *bd) 123 { 124 return (part_t *)bd->arg; 125 } 105 126 106 127 int main(int argc, char **argv) … … 304 325 } 305 326 327 bd_srv_init(&part->bd); 328 part->bd.ops = &gpt_bd_ops; 329 part->bd.arg = part; 330 306 331 part->dsid = 0; 307 332 part->next = NULL; … … 310 335 static void gpt_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 311 336 { 312 size_t comm_size;313 void *fs_va = NULL;314 ipc_callid_t callid;315 ipc_call_t call;316 sysarg_t method;317 337 service_id_t dh; 318 unsigned int flags;319 int retval;320 aoff64_t ba;321 size_t cnt;322 338 part_t *part; 323 339 … … 341 357 assert(part->present == true); 342 358 343 /* Answer the IPC_M_CONNECT_ME_TO call. */ 344 async_answer_0(iid, EOK); 345 346 if (!async_share_out_receive(&callid, &comm_size, &flags)) { 347 async_answer_0(callid, EHANGUP); 348 return; 349 } 350 351 (void) async_share_out_finalize(callid, &fs_va); 352 if (fs_va == AS_MAP_FAILED) { 353 async_answer_0(callid, EHANGUP); 354 return; 355 } 356 357 while (true) { 358 callid = async_get_call(&call); 359 method = IPC_GET_IMETHOD(call); 360 361 if (!method) { 362 /* The other side has hung up. */ 363 async_answer_0(callid, EOK); 364 return; 365 } 366 367 switch (method) { 368 case BD_READ_BLOCKS: 369 ba = MERGE_LOUP32(IPC_GET_ARG1(call), 370 IPC_GET_ARG2(call)); 371 cnt = IPC_GET_ARG3(call); 372 if (cnt * block_size > comm_size) { 373 retval = ELIMIT; 374 break; 375 } 376 retval = gpt_bd_read(part, ba, cnt, fs_va); 377 break; 378 case BD_WRITE_BLOCKS: 379 ba = MERGE_LOUP32(IPC_GET_ARG1(call), 380 IPC_GET_ARG2(call)); 381 cnt = IPC_GET_ARG3(call); 382 if (cnt * block_size > comm_size) { 383 retval = ELIMIT; 384 break; 385 } 386 retval = gpt_bd_write(part, ba, cnt, fs_va); 387 break; 388 case BD_GET_BLOCK_SIZE: 389 async_answer_1(callid, EOK, block_size); 390 continue; 391 case BD_GET_NUM_BLOCKS: 392 async_answer_2(callid, EOK, LOWER32(part->length), 393 UPPER32(part->length)); 394 continue; 395 default: 396 retval = EINVAL; 397 break; 398 } 399 async_answer_0(callid, retval); 400 } 359 bd_conn(iid, icall, &part->bd); 360 } 361 362 /** Open device. */ 363 static int gpt_bd_open(bd_srv_t *bd) 364 { 365 return EOK; 366 } 367 368 /** Close device. */ 369 static int gpt_bd_close(bd_srv_t *bd) 370 { 371 return EOK; 401 372 } 402 373 403 374 /** Read blocks from partition. */ 404 static int gpt_bd_read(part_t *p, aoff64_t ba, size_t cnt, void *buf) 405 { 375 static int gpt_bd_read_blocks(bd_srv_t *bd, aoff64_t ba, size_t cnt, void *buf, 376 size_t size) 377 { 378 part_t *p = bd_srv_part(bd); 406 379 aoff64_t gba; 380 381 if (cnt * block_size < size) 382 return EINVAL; 407 383 408 384 if (gpt_bsa_translate(p, ba, cnt, &gba) != EOK) … … 413 389 414 390 /** Write blocks to partition. */ 415 static int gpt_bd_write(part_t *p, aoff64_t ba, size_t cnt, const void *buf) 416 { 391 static int gpt_bd_write_blocks(bd_srv_t *bd, aoff64_t ba, size_t cnt, 392 const void *buf, size_t size) 393 { 394 part_t *p = bd_srv_part(bd); 417 395 aoff64_t gba; 396 397 if (cnt * block_size < size) 398 return EINVAL; 418 399 419 400 if (gpt_bsa_translate(p, ba, cnt, &gba) != EOK) … … 422 403 return block_write_direct(indev_sid, gba, cnt, buf); 423 404 } 405 406 /** Get device block size. */ 407 static int gpt_bd_get_block_size(bd_srv_t *bd, size_t *rsize) 408 { 409 *rsize = block_size; 410 return EOK; 411 } 412 413 /** Get number of blocks on device. */ 414 static int gpt_bd_get_num_blocks(bd_srv_t *bd, aoff64_t *rnb) 415 { 416 part_t *part = bd_srv_part(bd); 417 418 *rnb = part->length; 419 return EOK; 420 } 421 424 422 425 423 /** Translate block segment address with range checking. */
Note:
See TracChangeset
for help on using the changeset viewer.