Changes in uspace/srv/fs/devfs/devfs_ops.c [cfd630af:efcebe1] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/devfs/devfs_ops.c
rcfd630af refcebe1 59 59 typedef struct { 60 60 devmap_handle_t handle; 61 int phone; /**< When < 0, the structure is incomplete. */61 async_sess_t *sess; /**< If NULL, the structure is incomplete. */ 62 62 size_t refcount; 63 63 link_t link; 64 fibril_condvar_t cv; 64 fibril_condvar_t cv; /**< Broadcast when completed. */ 65 65 } device_t; 66 66 … … 232 232 }; 233 233 link_t *lnk; 234 234 235 235 fibril_mutex_lock(&devices_mutex); 236 236 restart: … … 244 244 245 245 dev->handle = node->handle; 246 dev->phone = -1; /* mark as incomplete */ 246 247 /* Mark as incomplete */ 248 dev->sess = NULL; 247 249 dev->refcount = 1; 248 250 fibril_condvar_initialize(&dev->cv); 249 251 250 252 /* 251 253 * Insert the incomplete device structure so that other … … 254 256 */ 255 257 hash_table_insert(&devices, key, &dev->link); 256 258 257 259 /* 258 260 * Drop the mutex to allow recursive devfs requests. 259 261 */ 260 262 fibril_mutex_unlock(&devices_mutex); 261 262 int phone = devmap_device_connect(node->handle, 0); 263 263 264 async_sess_t *sess = devmap_device_connect(EXCHANGE_SERIALIZE, 265 node->handle, 0); 266 264 267 fibril_mutex_lock(&devices_mutex); 265 268 266 269 /* 267 270 * Notify possible waiters about this device structure … … 269 272 */ 270 273 fibril_condvar_broadcast(&dev->cv); 271 272 if ( phone < 0) {274 275 if (!sess) { 273 276 /* 274 277 * Connecting failed, need to remove the … … 277 280 hash_table_remove(&devices, key, DEVICES_KEYS); 278 281 fibril_mutex_unlock(&devices_mutex); 279 282 280 283 return ENOENT; 281 284 } 282 285 283 /* Set the correct phone. */284 dev-> phone = phone;286 /* Set the correct session. */ 287 dev->sess = sess; 285 288 } else { 286 289 device_t *dev = hash_table_get_instance(lnk, device_t, link); 287 288 if ( dev->phone < 0) {290 291 if (!dev->sess) { 289 292 /* 290 293 * Wait until the device structure is completed … … 398 401 399 402 return 1; 400 }401 402 static char devfs_plb_get_char(unsigned pos)403 {404 return devfs_reg.plb_ro[pos % PLB_SIZE];405 403 } 406 404 … … 444 442 .size_get = devfs_size_get, 445 443 .lnkcnt_get = devfs_lnkcnt_get, 446 .plb_get_char = devfs_plb_get_char,447 444 .is_directory = devfs_is_directory, 448 445 .is_file = devfs_is_file, … … 459 456 } 460 457 461 void devfs_mounted(ipc_callid_t rid, ipc_call_t *request) 462 { 463 char *opts; 464 465 /* Accept the mount options */ 466 sysarg_t retval = async_data_write_accept((void **) &opts, true, 0, 0, 467 0, NULL); 468 if (retval != EOK) { 469 async_answer_0(rid, retval); 470 return; 471 } 472 473 free(opts); 474 async_answer_3(rid, EOK, 0, 0, 0); 475 } 476 477 void devfs_mount(ipc_callid_t rid, ipc_call_t *request) 478 { 479 libfs_mount(&devfs_libfs_ops, devfs_reg.fs_handle, rid, request); 480 } 481 482 void devfs_unmounted(ipc_callid_t rid, ipc_call_t *request) 483 { 484 async_answer_0(rid, ENOTSUP); 485 } 486 487 void devfs_unmount(ipc_callid_t rid, ipc_call_t *request) 488 { 489 libfs_unmount(&devfs_libfs_ops, rid, request); 490 } 491 492 void devfs_lookup(ipc_callid_t rid, ipc_call_t *request) 493 { 494 libfs_lookup(&devfs_libfs_ops, devfs_reg.fs_handle, rid, request); 495 } 496 497 void devfs_open_node(ipc_callid_t rid, ipc_call_t *request) 498 { 499 libfs_open_node(&devfs_libfs_ops, devfs_reg.fs_handle, rid, request); 500 } 501 502 void devfs_stat(ipc_callid_t rid, ipc_call_t *request) 503 { 504 libfs_stat(&devfs_libfs_ops, devfs_reg.fs_handle, rid, request); 505 } 506 507 void devfs_read(ipc_callid_t rid, ipc_call_t *request) 508 { 509 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 510 aoff64_t pos = 511 (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request)); 512 458 static int devfs_mounted(devmap_handle_t devmap_handle, const char *opts, 459 fs_index_t *index, aoff64_t *size, unsigned *lnkcnt) 460 { 461 *index = 0; 462 *size = 0; 463 *lnkcnt = 0; 464 return EOK; 465 } 466 467 static int devfs_unmounted(devmap_handle_t devmap_handle) 468 { 469 return ENOTSUP; 470 } 471 472 static int 473 devfs_read(devmap_handle_t devmap_handle, fs_index_t index, aoff64_t pos, 474 size_t *rbytes) 475 { 513 476 if (index == 0) { 514 477 ipc_callid_t callid; … … 516 479 if (!async_data_read_receive(&callid, &size)) { 517 480 async_answer_0(callid, EINVAL); 518 async_answer_0(rid, EINVAL); 519 return; 481 return EINVAL; 520 482 } 521 483 … … 537 499 async_data_read_finalize(callid, desc[pos].name, str_size(desc[pos].name) + 1); 538 500 free(desc); 539 async_answer_1(rid, EOK, 1);540 return ;501 *rbytes = 1; 502 return EOK; 541 503 } 542 504 … … 552 514 async_data_read_finalize(callid, desc[pos].name, str_size(desc[pos].name) + 1); 553 515 free(desc); 554 async_answer_1(rid, EOK, 1);555 return ;516 *rbytes = 1; 517 return EOK; 556 518 } 557 519 … … 560 522 561 523 async_answer_0(callid, ENOENT); 562 async_answer_1(rid, ENOENT, 0); 563 return; 524 return ENOENT; 564 525 } 565 526 … … 572 533 if (!async_data_read_receive(&callid, &size)) { 573 534 async_answer_0(callid, EINVAL); 574 async_answer_0(rid, EINVAL); 575 return; 535 return EINVAL; 576 536 } 577 537 … … 582 542 async_data_read_finalize(callid, desc[pos].name, str_size(desc[pos].name) + 1); 583 543 free(desc); 584 async_answer_1(rid, EOK, 1);585 return ;544 *rbytes = 1; 545 return EOK; 586 546 } 587 547 588 548 free(desc); 589 549 async_answer_0(callid, ENOENT); 590 async_answer_1(rid, ENOENT, 0); 591 return; 550 return ENOENT; 592 551 } 593 552 … … 603 562 if (lnk == NULL) { 604 563 fibril_mutex_unlock(&devices_mutex); 605 async_answer_0(rid, ENOENT); 606 return; 564 return ENOENT; 607 565 } 608 566 609 567 device_t *dev = hash_table_get_instance(lnk, device_t, link); 610 assert(dev-> phone >= 0);568 assert(dev->sess); 611 569 612 570 ipc_callid_t callid; … … 614 572 fibril_mutex_unlock(&devices_mutex); 615 573 async_answer_0(callid, EINVAL); 616 async_answer_0(rid, EINVAL); 617 return; 574 return EINVAL; 618 575 } 619 576 620 577 /* Make a request at the driver */ 578 async_exch_t *exch = async_exchange_begin(dev->sess); 579 621 580 ipc_call_t answer; 622 aid_t msg = async_send_3(dev->phone, IPC_GET_IMETHOD(*request), 623 IPC_GET_ARG1(*request), IPC_GET_ARG2(*request), 624 IPC_GET_ARG3(*request), &answer); 581 aid_t msg = async_send_4(exch, VFS_OUT_READ, devmap_handle, 582 index, LOWER32(pos), UPPER32(pos), &answer); 625 583 626 584 /* Forward the IPC_M_DATA_READ request to the driver */ 627 async_forward_fast(callid, dev->phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); 585 async_forward_fast(callid, exch, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); 586 587 async_exchange_end(exch); 588 628 589 fibril_mutex_unlock(&devices_mutex); 629 590 … … 631 592 sysarg_t rc; 632 593 async_wait_for(msg, &rc); 633 size_t bytes = IPC_GET_ARG1(answer); 634 635 /* Driver reply is the final result of the whole operation */ 636 async_answer_1(rid, rc, bytes); 637 return; 638 } 639 640 async_answer_0(rid, ENOENT); 641 } 642 643 void devfs_write(ipc_callid_t rid, ipc_call_t *request) 644 { 645 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 646 if (index == 0) { 647 async_answer_0(rid, ENOTSUP); 648 return; 649 } 594 595 *rbytes = IPC_GET_ARG1(answer); 596 return rc; 597 } 598 599 return ENOENT; 600 } 601 602 static int 603 devfs_write(devmap_handle_t devmap_handle, fs_index_t index, aoff64_t pos, 604 size_t *wbytes, aoff64_t *nsize) 605 { 606 if (index == 0) 607 return ENOTSUP; 650 608 651 609 devmap_handle_type_t type = devmap_handle_probe(index); … … 653 611 if (type == DEV_HANDLE_NAMESPACE) { 654 612 /* Namespace directory */ 655 async_answer_0(rid, ENOTSUP); 656 return; 613 return ENOTSUP; 657 614 } 658 615 … … 667 624 if (lnk == NULL) { 668 625 fibril_mutex_unlock(&devices_mutex); 669 async_answer_0(rid, ENOENT); 670 return; 626 return ENOENT; 671 627 } 672 628 673 629 device_t *dev = hash_table_get_instance(lnk, device_t, link); 674 assert(dev-> phone >= 0);630 assert(dev->sess); 675 631 676 632 ipc_callid_t callid; … … 678 634 fibril_mutex_unlock(&devices_mutex); 679 635 async_answer_0(callid, EINVAL); 680 async_answer_0(rid, EINVAL); 681 return; 636 return EINVAL; 682 637 } 683 638 684 639 /* Make a request at the driver */ 640 async_exch_t *exch = async_exchange_begin(dev->sess); 641 685 642 ipc_call_t answer; 686 aid_t msg = async_send_3(dev->phone, IPC_GET_IMETHOD(*request), 687 IPC_GET_ARG1(*request), IPC_GET_ARG2(*request), 688 IPC_GET_ARG3(*request), &answer); 643 aid_t msg = async_send_4(exch, VFS_OUT_WRITE, devmap_handle, 644 index, LOWER32(pos), UPPER32(pos), &answer); 689 645 690 646 /* Forward the IPC_M_DATA_WRITE request to the driver */ 691 async_forward_fast(callid, dev->phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); 647 async_forward_fast(callid, exch, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); 648 649 async_exchange_end(exch); 692 650 693 651 fibril_mutex_unlock(&devices_mutex); … … 696 654 sysarg_t rc; 697 655 async_wait_for(msg, &rc); 698 size_t bytes = IPC_GET_ARG1(answer); 699 700 /* Driver reply is the final result of the whole operation */ 701 async_answer_1(rid, rc, bytes); 702 return; 703 } 704 705 async_answer_0(rid, ENOENT); 706 } 707 708 void devfs_truncate(ipc_callid_t rid, ipc_call_t *request) 709 { 710 async_answer_0(rid, ENOTSUP); 711 } 712 713 void devfs_close(ipc_callid_t rid, ipc_call_t *request) 714 { 715 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 716 717 if (index == 0) { 718 async_answer_0(rid, EOK); 719 return; 720 } 656 657 *wbytes = IPC_GET_ARG1(answer); 658 *nsize = 0; 659 return rc; 660 } 661 662 return ENOENT; 663 } 664 665 static int 666 devfs_truncate(devmap_handle_t devmap_handle, fs_index_t index, aoff64_t size) 667 { 668 return ENOTSUP; 669 } 670 671 static int devfs_close(devmap_handle_t devmap_handle, fs_index_t index) 672 { 673 if (index == 0) 674 return EOK; 721 675 722 676 devmap_handle_type_t type = devmap_handle_probe(index); … … 724 678 if (type == DEV_HANDLE_NAMESPACE) { 725 679 /* Namespace directory */ 726 async_answer_0(rid, EOK); 727 return; 680 return EOK; 728 681 } 729 682 … … 737 690 if (lnk == NULL) { 738 691 fibril_mutex_unlock(&devices_mutex); 739 async_answer_0(rid, ENOENT); 740 return; 692 return ENOENT; 741 693 } 742 694 743 695 device_t *dev = hash_table_get_instance(lnk, device_t, link); 744 assert(dev-> phone >= 0);696 assert(dev->sess); 745 697 dev->refcount--; 746 698 747 699 if (dev->refcount == 0) { 748 async_hangup(dev-> phone);700 async_hangup(dev->sess); 749 701 hash_table_remove(&devices, key, DEVICES_KEYS); 750 702 } … … 752 704 fibril_mutex_unlock(&devices_mutex); 753 705 754 async_answer_0(rid, EOK); 755 return; 756 } 757 758 async_answer_0(rid, ENOENT); 759 } 760 761 void devfs_sync(ipc_callid_t rid, ipc_call_t *request) 762 { 763 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 764 765 if (index == 0) { 766 async_answer_0(rid, EOK); 767 return; 768 } 706 return EOK; 707 } 708 709 return ENOENT; 710 } 711 712 static int devfs_sync(devmap_handle_t devmap_handle, fs_index_t index) 713 { 714 if (index == 0) 715 return EOK; 769 716 770 717 devmap_handle_type_t type = devmap_handle_probe(index); … … 772 719 if (type == DEV_HANDLE_NAMESPACE) { 773 720 /* Namespace directory */ 774 async_answer_0(rid, EOK); 775 return; 721 return EOK; 776 722 } 777 723 … … 785 731 if (lnk == NULL) { 786 732 fibril_mutex_unlock(&devices_mutex); 787 async_answer_0(rid, ENOENT); 788 return; 733 return ENOENT; 789 734 } 790 735 791 736 device_t *dev = hash_table_get_instance(lnk, device_t, link); 792 assert(dev-> phone >= 0);737 assert(dev->sess); 793 738 794 739 /* Make a request at the driver */ 740 async_exch_t *exch = async_exchange_begin(dev->sess); 741 795 742 ipc_call_t answer; 796 aid_t msg = async_send_2(dev->phone, IPC_GET_IMETHOD(*request), 797 IPC_GET_ARG1(*request), IPC_GET_ARG2(*request), &answer); 743 aid_t msg = async_send_2(exch, VFS_OUT_SYNC, devmap_handle, 744 index, &answer); 745 746 async_exchange_end(exch); 798 747 799 748 fibril_mutex_unlock(&devices_mutex); … … 803 752 async_wait_for(msg, &rc); 804 753 805 /* Driver reply is the final result of the whole operation */ 806 async_answer_0(rid, rc); 807 return; 808 } 809 810 async_answer_0(rid, ENOENT); 811 } 812 813 void devfs_destroy(ipc_callid_t rid, ipc_call_t *request) 814 { 815 async_answer_0(rid, ENOTSUP); 816 } 754 return rc; 755 } 756 757 return ENOENT; 758 } 759 760 static int devfs_destroy(devmap_handle_t devmap_handle, fs_index_t index) 761 { 762 return ENOTSUP; 763 } 764 765 vfs_out_ops_t devfs_ops = { 766 .mounted = devfs_mounted, 767 .unmounted = devfs_unmounted, 768 .read = devfs_read, 769 .write = devfs_write, 770 .truncate = devfs_truncate, 771 .close = devfs_close, 772 .destroy = devfs_destroy, 773 .sync = devfs_sync, 774 }; 817 775 818 776 /**
Note:
See TracChangeset
for help on using the changeset viewer.