Changes in uspace/srv/fs/devfs/devfs_ops.c [cfd630af:19f857a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/devfs/devfs_ops.c
rcfd630af r19f857a 36 36 */ 37 37 38 #include <ipc/ipc.h> 38 39 #include <macros.h> 39 40 #include <bool.h> … … 53 54 typedef struct { 54 55 devmap_handle_type_t type; 55 dev map_handle_t handle;56 dev_handle_t handle; 56 57 } devfs_node_t; 57 58 58 59 /** Opened devices structure */ 59 60 typedef struct { 60 dev map_handle_t handle;61 int phone; /**< When < 0, the structure is incomplete. */61 dev_handle_t handle; 62 int phone; 62 63 size_t refcount; 63 64 link_t link; 64 fibril_condvar_t cv; /**< Broadcast when completed. */65 65 } device_t; 66 66 … … 84 84 { 85 85 device_t *dev = hash_table_get_instance(item, device_t, link); 86 return (dev->handle == (dev map_handle_t) key[DEVICES_KEY_HANDLE]);86 return (dev->handle == (dev_handle_t) key[DEVICES_KEY_HANDLE]); 87 87 } 88 88 … … 99 99 100 100 static int devfs_node_get_internal(fs_node_t **rfn, devmap_handle_type_t type, 101 dev map_handle_t handle)101 dev_handle_t handle) 102 102 { 103 103 devfs_node_t *node = (devfs_node_t *) malloc(sizeof(devfs_node_t)); … … 122 122 } 123 123 124 static int devfs_root_get(fs_node_t **rfn, dev map_handle_t devmap_handle)124 static int devfs_root_get(fs_node_t **rfn, dev_handle_t dev_handle) 125 125 { 126 126 return devfs_node_get_internal(rfn, DEV_HANDLE_NONE, 0); … … 130 130 { 131 131 devfs_node_t *node = (devfs_node_t *) pfn->data; 132 int ret;133 132 134 133 if (node->handle == 0) { … … 146 145 147 146 if (str_cmp(devs[pos].name, component) == 0) { 148 ret = devfs_node_get_internal(rfn, DEV_HANDLE_NAMESPACE, devs[pos].handle);149 147 free(devs); 150 return ret;148 return devfs_node_get_internal(rfn, DEV_HANDLE_NAMESPACE, devs[pos].handle); 151 149 } 152 150 } … … 156 154 157 155 /* Search root namespace */ 158 dev map_handle_t namespace;156 dev_handle_t namespace; 159 157 if (devmap_namespace_get_handle("", &namespace, 0) == EOK) { 160 158 count = devmap_get_devices(namespace, &devs); … … 164 162 for (pos = 0; pos < count; pos++) { 165 163 if (str_cmp(devs[pos].name, component) == 0) { 166 ret = devfs_node_get_internal(rfn, DEV_HANDLE_DEVICE, devs[pos].handle);167 164 free(devs); 168 return ret;165 return devfs_node_get_internal(rfn, DEV_HANDLE_DEVICE, devs[pos].handle); 169 166 } 170 167 } … … 187 184 for (pos = 0; pos < count; pos++) { 188 185 if (str_cmp(devs[pos].name, component) == 0) { 189 ret = devfs_node_get_internal(rfn, DEV_HANDLE_DEVICE, devs[pos].handle);190 186 free(devs); 191 return ret;187 return devfs_node_get_internal(rfn, DEV_HANDLE_DEVICE, devs[pos].handle); 192 188 } 193 189 } … … 204 200 } 205 201 206 static int devfs_node_get(fs_node_t **rfn, dev map_handle_t devmap_handle, fs_index_t index)202 static int devfs_node_get(fs_node_t **rfn, dev_handle_t dev_handle, fs_index_t index) 207 203 { 208 204 return devfs_node_get_internal(rfn, devmap_handle_probe(index), index); … … 231 227 [DEVICES_KEY_HANDLE] = (unsigned long) node->handle 232 228 }; 233 link_t *lnk; 234 229 235 230 fibril_mutex_lock(&devices_mutex); 236 restart: 237 lnk = hash_table_find(&devices, key); 231 link_t *lnk = hash_table_find(&devices, key); 238 232 if (lnk == NULL) { 239 233 device_t *dev = (device_t *) malloc(sizeof(device_t)); … … 243 237 } 244 238 245 dev->handle = node->handle;246 dev->phone = -1; /* mark as incomplete */247 dev->refcount = 1;248 fibril_condvar_initialize(&dev->cv);249 250 /*251 * Insert the incomplete device structure so that other252 * fibrils will not race with us when we drop the mutex253 * below.254 */255 hash_table_insert(&devices, key, &dev->link);256 257 /*258 * Drop the mutex to allow recursive devfs requests.259 */260 fibril_mutex_unlock(&devices_mutex);261 262 239 int phone = devmap_device_connect(node->handle, 0); 263 264 fibril_mutex_lock(&devices_mutex);265 266 /*267 * Notify possible waiters about this device structure268 * being completed (or destroyed).269 */270 fibril_condvar_broadcast(&dev->cv);271 272 240 if (phone < 0) { 273 /*274 * Connecting failed, need to remove the275 * entry and free the device structure.276 */277 hash_table_remove(&devices, key, DEVICES_KEYS);278 241 fibril_mutex_unlock(&devices_mutex); 279 242 free(dev); 280 243 return ENOENT; 281 244 } 282 245 283 /* Set the correct phone. */246 dev->handle = node->handle; 284 247 dev->phone = phone; 248 dev->refcount = 1; 249 250 hash_table_insert(&devices, key, &dev->link); 285 251 } else { 286 252 device_t *dev = hash_table_get_instance(lnk, device_t, link); 287 288 if (dev->phone < 0) {289 /*290 * Wait until the device structure is completed291 * and start from the beginning as the device292 * structure might have entirely disappeared293 * while we were not holding the mutex in294 * fibril_condvar_wait().295 */296 fibril_condvar_wait(&dev->cv, &devices_mutex);297 goto restart;298 }299 300 253 dev->refcount++; 301 254 } … … 316 269 } 317 270 318 static int devfs_create_node(fs_node_t **rfn, dev map_handle_t devmap_handle, int lflag)271 static int devfs_create_node(fs_node_t **rfn, dev_handle_t dev_handle, int lflag) 319 272 { 320 273 assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY)); … … 351 304 352 305 /* Root namespace */ 353 dev map_handle_t namespace;306 dev_handle_t namespace; 354 307 if (devmap_namespace_get_handle("", &namespace, 0) == EOK) { 355 308 count = devmap_count_devices(namespace); … … 419 372 } 420 373 421 static dev map_handle_t devfs_device_get(fs_node_t *fn)374 static dev_handle_t devfs_device_get(fs_node_t *fn) 422 375 { 423 376 devfs_node_t *node = (devfs_node_t *) fn->data; … … 456 409 return false; 457 410 411 if (devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING) < 0) 412 return false; 413 458 414 return true; 459 415 } … … 464 420 465 421 /* Accept the mount options */ 466 sysarg_t retval = async_data_write_accept((void **) &opts, true, 0, 0,422 ipcarg_t retval = async_data_write_accept((void **) &opts, true, 0, 0, 467 423 0, NULL); 468 424 if (retval != EOK) { 469 async_answer_0(rid, retval);425 ipc_answer_0(rid, retval); 470 426 return; 471 427 } 472 428 473 429 free(opts); 474 async_answer_3(rid, EOK, 0, 0, 0);430 ipc_answer_3(rid, EOK, 0, 0, 0); 475 431 } 476 432 … … 482 438 void devfs_unmounted(ipc_callid_t rid, ipc_call_t *request) 483 439 { 484 async_answer_0(rid, ENOTSUP);440 ipc_answer_0(rid, ENOTSUP); 485 441 } 486 442 … … 515 471 size_t size; 516 472 if (!async_data_read_receive(&callid, &size)) { 517 async_answer_0(callid, EINVAL);518 async_answer_0(rid, EINVAL);473 ipc_answer_0(callid, EINVAL); 474 ipc_answer_0(rid, EINVAL); 519 475 return; 520 476 } … … 537 493 async_data_read_finalize(callid, desc[pos].name, str_size(desc[pos].name) + 1); 538 494 free(desc); 539 async_answer_1(rid, EOK, 1);495 ipc_answer_1(rid, EOK, 1); 540 496 return; 541 497 } … … 545 501 546 502 /* Search root namespace */ 547 dev map_handle_t namespace;503 dev_handle_t namespace; 548 504 if (devmap_namespace_get_handle("", &namespace, 0) == EOK) { 549 505 count = devmap_get_devices(namespace, &desc); … … 552 508 async_data_read_finalize(callid, desc[pos].name, str_size(desc[pos].name) + 1); 553 509 free(desc); 554 async_answer_1(rid, EOK, 1);510 ipc_answer_1(rid, EOK, 1); 555 511 return; 556 512 } … … 559 515 } 560 516 561 async_answer_0(callid, ENOENT);562 async_answer_1(rid, ENOENT, 0);517 ipc_answer_0(callid, ENOENT); 518 ipc_answer_1(rid, ENOENT, 0); 563 519 return; 564 520 } … … 571 527 size_t size; 572 528 if (!async_data_read_receive(&callid, &size)) { 573 async_answer_0(callid, EINVAL);574 async_answer_0(rid, EINVAL);529 ipc_answer_0(callid, EINVAL); 530 ipc_answer_0(rid, EINVAL); 575 531 return; 576 532 } … … 582 538 async_data_read_finalize(callid, desc[pos].name, str_size(desc[pos].name) + 1); 583 539 free(desc); 584 async_answer_1(rid, EOK, 1);540 ipc_answer_1(rid, EOK, 1); 585 541 return; 586 542 } 587 543 588 544 free(desc); 589 async_answer_0(callid, ENOENT);590 async_answer_1(rid, ENOENT, 0);545 ipc_answer_0(callid, ENOENT); 546 ipc_answer_1(rid, ENOENT, 0); 591 547 return; 592 548 } … … 603 559 if (lnk == NULL) { 604 560 fibril_mutex_unlock(&devices_mutex); 605 async_answer_0(rid, ENOENT);561 ipc_answer_0(rid, ENOENT); 606 562 return; 607 563 } 608 564 609 565 device_t *dev = hash_table_get_instance(lnk, device_t, link); 610 assert(dev->phone >= 0);611 566 612 567 ipc_callid_t callid; 613 568 if (!async_data_read_receive(&callid, NULL)) { 614 569 fibril_mutex_unlock(&devices_mutex); 615 async_answer_0(callid, EINVAL);616 async_answer_0(rid, EINVAL);570 ipc_answer_0(callid, EINVAL); 571 ipc_answer_0(rid, EINVAL); 617 572 return; 618 573 } … … 620 575 /* Make a request at the driver */ 621 576 ipc_call_t answer; 622 aid_t msg = async_send_3(dev->phone, IPC_GET_ IMETHOD(*request),577 aid_t msg = async_send_3(dev->phone, IPC_GET_METHOD(*request), 623 578 IPC_GET_ARG1(*request), IPC_GET_ARG2(*request), 624 579 IPC_GET_ARG3(*request), &answer); 625 580 626 581 /* 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);582 ipc_forward_fast(callid, dev->phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); 628 583 fibril_mutex_unlock(&devices_mutex); 629 584 630 585 /* Wait for reply from the driver. */ 631 sysarg_t rc;586 ipcarg_t rc; 632 587 async_wait_for(msg, &rc); 633 588 size_t bytes = IPC_GET_ARG1(answer); 634 589 635 590 /* 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);591 ipc_answer_1(rid, rc, bytes); 592 return; 593 } 594 595 ipc_answer_0(rid, ENOENT); 641 596 } 642 597 … … 645 600 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 646 601 if (index == 0) { 647 async_answer_0(rid, ENOTSUP);602 ipc_answer_0(rid, ENOTSUP); 648 603 return; 649 604 } … … 653 608 if (type == DEV_HANDLE_NAMESPACE) { 654 609 /* Namespace directory */ 655 async_answer_0(rid, ENOTSUP);610 ipc_answer_0(rid, ENOTSUP); 656 611 return; 657 612 } … … 667 622 if (lnk == NULL) { 668 623 fibril_mutex_unlock(&devices_mutex); 669 async_answer_0(rid, ENOENT);624 ipc_answer_0(rid, ENOENT); 670 625 return; 671 626 } 672 627 673 628 device_t *dev = hash_table_get_instance(lnk, device_t, link); 674 assert(dev->phone >= 0);675 629 676 630 ipc_callid_t callid; 677 631 if (!async_data_write_receive(&callid, NULL)) { 678 632 fibril_mutex_unlock(&devices_mutex); 679 async_answer_0(callid, EINVAL);680 async_answer_0(rid, EINVAL);633 ipc_answer_0(callid, EINVAL); 634 ipc_answer_0(rid, EINVAL); 681 635 return; 682 636 } … … 684 638 /* Make a request at the driver */ 685 639 ipc_call_t answer; 686 aid_t msg = async_send_3(dev->phone, IPC_GET_ IMETHOD(*request),640 aid_t msg = async_send_3(dev->phone, IPC_GET_METHOD(*request), 687 641 IPC_GET_ARG1(*request), IPC_GET_ARG2(*request), 688 642 IPC_GET_ARG3(*request), &answer); 689 643 690 644 /* 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);645 ipc_forward_fast(callid, dev->phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); 692 646 693 647 fibril_mutex_unlock(&devices_mutex); 694 648 695 649 /* Wait for reply from the driver. */ 696 sysarg_t rc;650 ipcarg_t rc; 697 651 async_wait_for(msg, &rc); 698 652 size_t bytes = IPC_GET_ARG1(answer); 699 653 700 654 /* 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);655 ipc_answer_1(rid, rc, bytes); 656 return; 657 } 658 659 ipc_answer_0(rid, ENOENT); 706 660 } 707 661 708 662 void devfs_truncate(ipc_callid_t rid, ipc_call_t *request) 709 663 { 710 async_answer_0(rid, ENOTSUP);664 ipc_answer_0(rid, ENOTSUP); 711 665 } 712 666 … … 716 670 717 671 if (index == 0) { 718 async_answer_0(rid, EOK);672 ipc_answer_0(rid, EOK); 719 673 return; 720 674 } … … 724 678 if (type == DEV_HANDLE_NAMESPACE) { 725 679 /* Namespace directory */ 726 async_answer_0(rid, EOK);680 ipc_answer_0(rid, EOK); 727 681 return; 728 682 } … … 737 691 if (lnk == NULL) { 738 692 fibril_mutex_unlock(&devices_mutex); 739 async_answer_0(rid, ENOENT);693 ipc_answer_0(rid, ENOENT); 740 694 return; 741 695 } 742 696 743 697 device_t *dev = hash_table_get_instance(lnk, device_t, link); 744 assert(dev->phone >= 0);745 698 dev->refcount--; 746 699 747 700 if (dev->refcount == 0) { 748 async_hangup(dev->phone);701 ipc_hangup(dev->phone); 749 702 hash_table_remove(&devices, key, DEVICES_KEYS); 750 703 } … … 752 705 fibril_mutex_unlock(&devices_mutex); 753 706 754 async_answer_0(rid, EOK);755 return; 756 } 757 758 async_answer_0(rid, ENOENT);707 ipc_answer_0(rid, EOK); 708 return; 709 } 710 711 ipc_answer_0(rid, ENOENT); 759 712 } 760 713 … … 764 717 765 718 if (index == 0) { 766 async_answer_0(rid, EOK);719 ipc_answer_0(rid, EOK); 767 720 return; 768 721 } … … 772 725 if (type == DEV_HANDLE_NAMESPACE) { 773 726 /* Namespace directory */ 774 async_answer_0(rid, EOK);727 ipc_answer_0(rid, EOK); 775 728 return; 776 729 } … … 785 738 if (lnk == NULL) { 786 739 fibril_mutex_unlock(&devices_mutex); 787 async_answer_0(rid, ENOENT);740 ipc_answer_0(rid, ENOENT); 788 741 return; 789 742 } 790 743 791 744 device_t *dev = hash_table_get_instance(lnk, device_t, link); 792 assert(dev->phone >= 0);793 745 794 746 /* Make a request at the driver */ 795 747 ipc_call_t answer; 796 aid_t msg = async_send_2(dev->phone, IPC_GET_ IMETHOD(*request),748 aid_t msg = async_send_2(dev->phone, IPC_GET_METHOD(*request), 797 749 IPC_GET_ARG1(*request), IPC_GET_ARG2(*request), &answer); 798 750 … … 800 752 801 753 /* Wait for reply from the driver */ 802 sysarg_t rc;754 ipcarg_t rc; 803 755 async_wait_for(msg, &rc); 804 756 805 757 /* 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);758 ipc_answer_0(rid, rc); 759 return; 760 } 761 762 ipc_answer_0(rid, ENOENT); 811 763 } 812 764 813 765 void devfs_destroy(ipc_callid_t rid, ipc_call_t *request) 814 766 { 815 async_answer_0(rid, ENOTSUP);767 ipc_answer_0(rid, ENOTSUP); 816 768 } 817 769
Note:
See TracChangeset
for help on using the changeset viewer.