Changeset 7beb220 in mainline for uspace/srv
- Timestamp:
- 2011-08-19T12:06:03Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2f2f1186
- Parents:
- d767cb1
- Location:
- uspace/srv/devman
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
rd767cb1 r7beb220 920 920 } 921 921 922 /** Get list of device functions. */ 923 int dev_get_functions(dev_tree_t *tree, dev_node_t *dev, 924 devman_handle_t *hdl_buf, size_t buf_size, size_t *act_size) 925 { 926 size_t act_cnt; 927 size_t buf_cnt; 928 929 assert(fibril_rwlock_is_locked(&tree->rwlock)); 930 931 buf_cnt = buf_size / sizeof(devman_handle_t); 932 933 act_cnt = list_count(&dev->functions); 934 *act_size = act_cnt * sizeof(devman_handle_t); 935 936 if (buf_size % sizeof(devman_handle_t) != 0) 937 return EINVAL; 938 939 size_t pos = 0; 940 list_foreach(dev->functions, item) { 941 fun_node_t *fun = 942 list_get_instance(item, fun_node_t, dev_functions); 943 944 if (pos < buf_cnt) 945 hdl_buf[pos] = fun->handle; 946 pos++; 947 } 948 949 return EOK; 950 } 951 952 922 953 /* Function nodes */ 923 954 … … 1145 1176 char *rel_path = path; 1146 1177 char *next_path_elem = NULL; 1147 bool cont = true;1178 bool cont = (rel_path[1] != '\0'); 1148 1179 1149 1180 while (cont && fun != NULL) { -
uspace/srv/devman/devman.h
rd767cb1 r7beb220 253 253 extern dev_node_t *find_dev_node(dev_tree_t *tree, devman_handle_t handle); 254 254 extern dev_node_t *find_dev_function(dev_node_t *, const char *); 255 extern int dev_get_functions(dev_tree_t *tree, dev_node_t *, devman_handle_t *, 256 size_t, size_t *); 255 257 256 258 extern fun_node_t *create_fun_node(void); -
uspace/srv/devman/main.c
rd767cb1 r7beb220 497 497 } 498 498 499 /** Find device path by its handle. */ 500 static void devman_get_device_path_by_handle(ipc_callid_t iid, 501 ipc_call_t *icall) 499 /** Get device name. */ 500 static void devman_fun_get_name(ipc_callid_t iid, ipc_call_t *icall) 502 501 { 503 502 devman_handle_t handle = IPC_GET_ARG1(*icall); … … 523 522 } 524 523 524 size_t sent_length = str_size(fun->name); 525 if (sent_length > data_len) { 526 sent_length = data_len; 527 } 528 529 async_data_read_finalize(data_callid, fun->name, sent_length); 530 async_answer_0(iid, EOK); 531 532 free(buffer); 533 } 534 535 536 /** Get device path. */ 537 static void devman_fun_get_path(ipc_callid_t iid, ipc_call_t *icall) 538 { 539 devman_handle_t handle = IPC_GET_ARG1(*icall); 540 541 fun_node_t *fun = find_fun_node(&device_tree, handle); 542 if (fun == NULL) { 543 async_answer_0(iid, ENOMEM); 544 return; 545 } 546 547 ipc_callid_t data_callid; 548 size_t data_len; 549 if (!async_data_read_receive(&data_callid, &data_len)) { 550 async_answer_0(iid, EINVAL); 551 return; 552 } 553 554 void *buffer = malloc(data_len); 555 if (buffer == NULL) { 556 async_answer_0(data_callid, ENOMEM); 557 async_answer_0(iid, ENOMEM); 558 return; 559 } 560 525 561 size_t sent_length = str_size(fun->pathname); 526 562 if (sent_length > data_len) { … … 532 568 533 569 free(buffer); 570 } 571 572 static void devman_dev_get_functions(ipc_callid_t iid, ipc_call_t *icall) 573 { 574 ipc_callid_t callid; 575 size_t size; 576 size_t act_size; 577 int rc; 578 579 if (!async_data_read_receive(&callid, &size)) { 580 async_answer_0(callid, EREFUSED); 581 async_answer_0(iid, EREFUSED); 582 return; 583 } 584 585 fibril_rwlock_read_lock(&device_tree.rwlock); 586 587 dev_node_t *dev = find_dev_node_no_lock(&device_tree, 588 IPC_GET_ARG1(*icall)); 589 if (dev == NULL) { 590 fibril_rwlock_read_unlock(&device_tree.rwlock); 591 async_answer_0(callid, ENOENT); 592 async_answer_0(iid, ENOENT); 593 return; 594 } 595 596 devman_handle_t *hdl_buf = (devman_handle_t *) malloc(size); 597 if (hdl_buf == NULL) { 598 fibril_rwlock_read_unlock(&device_tree.rwlock); 599 async_answer_0(callid, ENOMEM); 600 async_answer_0(iid, ENOMEM); 601 return; 602 } 603 604 rc = dev_get_functions(&device_tree, dev, hdl_buf, size, &act_size); 605 if (rc != EOK) { 606 fibril_rwlock_read_unlock(&device_tree.rwlock); 607 async_answer_0(callid, rc); 608 async_answer_0(iid, rc); 609 return; 610 } 611 612 fibril_rwlock_read_unlock(&device_tree.rwlock); 613 614 sysarg_t retval = async_data_read_finalize(callid, hdl_buf, size); 615 free(hdl_buf); 616 617 async_answer_1(iid, retval, act_size); 618 } 619 620 621 /** Get handle for child device of a function. */ 622 static void devman_fun_get_child(ipc_callid_t iid, ipc_call_t *icall) 623 { 624 fun_node_t *fun; 625 626 fibril_rwlock_read_lock(&device_tree.rwlock); 627 628 fun = find_fun_node(&device_tree, IPC_GET_ARG1(*icall)); 629 if (fun == NULL) { 630 fibril_rwlock_read_unlock(&device_tree.rwlock); 631 async_answer_0(iid, ENOENT); 632 return; 633 } 634 635 if (fun->child == NULL) { 636 fibril_rwlock_read_unlock(&device_tree.rwlock); 637 async_answer_0(iid, ENOENT); 638 return; 639 } 640 641 async_answer_1(iid, EOK, fun->child->handle); 642 643 fibril_rwlock_read_unlock(&device_tree.rwlock); 534 644 } 535 645 … … 566 676 devman_function_get_handle(callid, &call); 567 677 break; 568 case DEVMAN_DEVICE_GET_DEVICE_PATH: 569 devman_get_device_path_by_handle(callid, &call); 678 case DEVMAN_DEV_GET_FUNCTIONS: 679 devman_dev_get_functions(callid, &call); 680 break; 681 case DEVMAN_FUN_GET_CHILD: 682 devman_fun_get_child(callid, &call); 683 break; 684 case DEVMAN_FUN_GET_NAME: 685 devman_fun_get_name(callid, &call); 686 break; 687 case DEVMAN_FUN_GET_PATH: 688 devman_fun_get_path(callid, &call); 570 689 break; 571 690 case DEVMAN_FUN_SID_TO_HANDLE:
Note:
See TracChangeset
for help on using the changeset viewer.