- Timestamp:
- 2011-08-19T17:36:25Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5fb32c5
- Parents:
- ea186c6 (diff), f00af83 (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. - Location:
- uspace
- Files:
-
- 2 added
- 48 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/Makefile
rea186c6 r921b84f 37 37 app/blkdump \ 38 38 app/bnchmark \ 39 app/devctl \ 39 40 app/edit \ 40 41 app/ext2info \ -
uspace/app/bdsh/exec.c
rea186c6 r921b84f 40 40 #include <str_error.h> 41 41 #include <errno.h> 42 #include <vfs/vfs.h> 42 43 43 44 #include "config.h" … … 99 100 char *tmp; 100 101 int rc, retval, i; 101 fdi_node_t file_nodes[3];102 fdi_node_t *file_nodes_p[4];102 int file_handles[3]; 103 int *file_handles_p[4]; 103 104 FILE *files[3]; 104 105 … … 111 112 112 113 for (i = 0; i < 3 && files[i] != NULL; i++) { 113 if (f node(files[i], &file_nodes[i]) == EOK) {114 file_ nodes_p[i] = &file_nodes[i];114 if (fhandle(files[i], &file_handles[i]) == EOK) { 115 file_handles_p[i] = &file_handles[i]; 115 116 } 116 117 else { 117 file_ nodes_p[i] = NULL;118 file_handles_p[i] = NULL; 118 119 } 119 120 } 120 file_ nodes_p[i] = NULL;121 file_handles_p[i] = NULL; 121 122 122 rc = task_spawnvf(&tid, tmp, (const char **) argv, file_ nodes_p);123 rc = task_spawnvf(&tid, tmp, (const char **) argv, file_handles_p); 123 124 free(tmp); 124 125 -
uspace/app/lsusb/main.c
rea186c6 r921b84f 81 81 } 82 82 char path[MAX_PATH_LENGTH]; 83 rc = devman_ get_device_path(dev_handle, path, MAX_PATH_LENGTH);83 rc = devman_fun_get_path(dev_handle, path, MAX_PATH_LENGTH); 84 84 if (rc != EOK) { 85 85 continue; … … 120 120 } 121 121 char path[MAX_PATH_LENGTH]; 122 rc = devman_ get_device_path(hc_handle, path, MAX_PATH_LENGTH);122 rc = devman_fun_get_path(hc_handle, path, MAX_PATH_LENGTH); 123 123 if (rc != EOK) { 124 124 printf(NAME ": Error resolving path of HC with SID %" -
uspace/app/mkbd/main.c
rea186c6 r921b84f 240 240 241 241 char path[MAX_PATH_LENGTH]; 242 rc = devman_ get_device_path(dev_handle, path, MAX_PATH_LENGTH);242 rc = devman_fun_get_path(dev_handle, path, MAX_PATH_LENGTH); 243 243 if (rc != EOK) { 244 244 return ENOMEM; -
uspace/app/tester/hw/serial/serial1.c
rea186c6 r921b84f 72 72 73 73 devman_handle_t handle; 74 int res = devman_ device_get_handle("/hw/pci0/00:01.0/com1/a", &handle,74 int res = devman_fun_get_handle("/hw/pci0/00:01.0/com1/a", &handle, 75 75 IPC_FLAG_BLOCKING); 76 76 if (res != EOK) -
uspace/app/trace/trace.c
rea186c6 r921b84f 50 50 #include <sys/types.h> 51 51 #include <sys/typefmt.h> 52 #include <vfs/vfs.h> 52 53 53 54 #include <libc.h> … … 586 587 587 588 /* Send default files */ 588 fdi_node_t *files[4];589 fdi_node_t stdin_node;590 fdi_node_t stdout_node;591 fdi_node_t stderr_node;592 593 if ((stdin != NULL) && (f node(stdin, &stdin_node) == EOK))594 files[0] = & stdin_node;589 int *files[4]; 590 int fd_stdin; 591 int fd_stdout; 592 int fd_stderr; 593 594 if ((stdin != NULL) && (fhandle(stdin, &fd_stdin) == EOK)) 595 files[0] = &fd_stdin; 595 596 else 596 597 files[0] = NULL; 597 598 598 if ((stdout != NULL) && (f node(stdout, &stdout_node) == EOK))599 files[1] = & stdout_node;599 if ((stdout != NULL) && (fhandle(stdout, &fd_stdout) == EOK)) 600 files[1] = &fd_stdout; 600 601 else 601 602 files[1] = NULL; 602 603 603 if ((stderr != NULL) && (f node(stderr, &stderr_node) == EOK))604 files[2] = & stderr_node;604 if ((stderr != NULL) && (fhandle(stderr, &fd_stderr) == EOK)) 605 files[2] = &fd_stderr; 605 606 else 606 607 files[2] = NULL; … … 761 762 o = oper_new("open", 2, arg_def, V_INT_ERRNO, 0, resp_def); 762 763 proto_add_oper(p, VFS_IN_OPEN, o); 763 o = oper_new("open_node", 4, arg_def, V_INT_ERRNO, 0, resp_def);764 proto_add_oper(p, VFS_IN_OPEN_NODE, o);765 764 o = oper_new("read", 1, arg_def, V_ERRNO, 1, resp_def); 766 765 proto_add_oper(p, VFS_IN_READ, o); -
uspace/lib/c/arch/ia32/Makefile.common
rea186c6 r921b84f 28 28 29 29 CLANG_ARCH = i386 30 ifeq ($(PROCESSOR),i486) 31 GCC_CFLAGS += -march=i486 -fno-omit-frame-pointer 32 else 30 33 GCC_CFLAGS += -march=pentium -fno-omit-frame-pointer 34 endif 31 35 32 36 ENDIANESS = LE -
uspace/lib/c/arch/ia32/Makefile.inc
rea186c6 r921b84f 28 28 29 29 ARCH_SOURCES = \ 30 arch/$(UARCH)/src/entry. s\30 arch/$(UARCH)/src/entry.S \ 31 31 arch/$(UARCH)/src/entryjmp.s \ 32 32 arch/$(UARCH)/src/thread_entry.s \ -
uspace/lib/c/arch/ia32/src/entry.S
rea186c6 r921b84f 46 46 mov %ax, %fs 47 47 # Do not set %gs, it contains descriptor that can see TLS 48 48 49 #ifndef PROCESSOR_i486 49 50 # Detect the mechanism used for making syscalls 50 51 movl $(INTEL_CPUID_STANDARD), %eax … … 55 56 movl $__syscall_fast, (%eax) 56 57 0: 58 #endif 57 59 # 58 60 # Create the first stack frame. -
uspace/lib/c/generic/async.c
rea186c6 r921b84f 112 112 #include <mem.h> 113 113 #include <stdlib.h> 114 #include <macros.h> 114 115 #include "private/async.h" 115 116 … … 138 139 link_t link; 139 140 140 sysarg_t in_task_hash;141 task_id_t in_task_id; 141 142 atomic_t refcnt; 142 143 void *data; … … 150 151 link_t link; 151 152 152 /** Incoming client task hash. */153 sysarg_t in_task_hash;153 /** Incoming client task ID. */ 154 task_id_t in_task_id; 154 155 155 156 /** Incoming phone hash. */ … … 203 204 } 204 205 205 void *async_get_client_data(void)206 {207 assert(fibril_connection);208 return fibril_connection->client->data;209 }210 211 206 /** Default fibril function that gets called to handle new connection. 212 207 * … … 289 284 { 290 285 assert(key); 286 assert(keys == 2); 291 287 assert(item); 292 288 293 289 client_t *client = hash_table_get_instance(item, client_t, link); 294 return (key[0] == client->in_task_hash); 290 return (key[0] == LOWER32(client->in_task_id) && 291 (key[1] == UPPER32(client->in_task_id))); 295 292 } 296 293 … … 580 577 } 581 578 579 static client_t *async_client_get(task_id_t client_id, bool create) 580 { 581 unsigned long key[2] = { 582 LOWER32(client_id), 583 UPPER32(client_id), 584 }; 585 client_t *client = NULL; 586 587 futex_down(&async_futex); 588 link_t *lnk = hash_table_find(&client_hash_table, key); 589 if (lnk) { 590 client = hash_table_get_instance(lnk, client_t, link); 591 atomic_inc(&client->refcnt); 592 } else if (create) { 593 client = malloc(sizeof(client_t)); 594 if (client) { 595 client->in_task_id = client_id; 596 client->data = async_client_data_create(); 597 598 atomic_set(&client->refcnt, 1); 599 hash_table_insert(&client_hash_table, key, &client->link); 600 } 601 } 602 603 futex_up(&async_futex); 604 return client; 605 } 606 607 static void async_client_put(client_t *client) 608 { 609 bool destroy; 610 unsigned long key[2] = { 611 LOWER32(client->in_task_id), 612 UPPER32(client->in_task_id) 613 }; 614 615 futex_down(&async_futex); 616 617 if (atomic_predec(&client->refcnt) == 0) { 618 hash_table_remove(&client_hash_table, key, 2); 619 destroy = true; 620 } else 621 destroy = false; 622 623 futex_up(&async_futex); 624 625 if (destroy) { 626 if (client->data) 627 async_client_data_destroy(client->data); 628 629 free(client); 630 } 631 } 632 633 void *async_get_client_data(void) 634 { 635 assert(fibril_connection); 636 return fibril_connection->client->data; 637 } 638 639 void *async_get_client_data_by_id(task_id_t client_id) 640 { 641 client_t *client = async_client_get(client_id, false); 642 if (!client) 643 return NULL; 644 if (!client->data) { 645 async_client_put(client); 646 return NULL; 647 } 648 649 return client->data; 650 } 651 652 void async_put_client_data_by_id(task_id_t client_id) 653 { 654 client_t *client = async_client_get(client_id, false); 655 656 assert(client); 657 assert(client->data); 658 659 /* Drop the reference we got in async_get_client_data_by_hash(). */ 660 async_client_put(client); 661 662 /* Drop our own reference we got at the beginning of this function. */ 663 async_client_put(client); 664 } 665 582 666 /** Wrapper for client connection fibril. 583 667 * … … 598 682 */ 599 683 fibril_connection = (connection_t *) arg; 600 601 futex_down(&async_futex);602 684 603 685 /* … … 606 688 * hash in a new tracking structure. 607 689 */ 608 609 unsigned long key = fibril_connection->in_task_hash; 610 link_t *lnk = hash_table_find(&client_hash_table, &key); 611 612 client_t *client; 613 614 if (lnk) { 615 client = hash_table_get_instance(lnk, client_t, link); 616 atomic_inc(&client->refcnt); 617 } else { 618 client = malloc(sizeof(client_t)); 619 if (!client) { 620 ipc_answer_0(fibril_connection->callid, ENOMEM); 621 futex_up(&async_futex); 622 return 0; 623 } 624 625 client->in_task_hash = fibril_connection->in_task_hash; 626 client->data = async_client_data_create(); 627 628 atomic_set(&client->refcnt, 1); 629 hash_table_insert(&client_hash_table, &key, &client->link); 630 } 631 632 futex_up(&async_futex); 633 690 691 client_t *client = async_client_get(fibril_connection->in_task_id, true); 692 if (!client) { 693 ipc_answer_0(fibril_connection->callid, ENOMEM); 694 return 0; 695 } 696 634 697 fibril_connection->client = client; 635 698 … … 643 706 * Remove the reference for this client task connection. 644 707 */ 645 bool destroy; 646 647 futex_down(&async_futex); 648 649 if (atomic_predec(&client->refcnt) == 0) { 650 hash_table_remove(&client_hash_table, &key, 1); 651 destroy = true; 652 } else 653 destroy = false; 654 655 futex_up(&async_futex); 656 657 if (destroy) { 658 if (client->data) 659 async_client_data_destroy(client->data); 660 661 free(client); 662 } 708 async_client_put(client); 663 709 664 710 /* … … 666 712 */ 667 713 futex_down(&async_futex); 668 key = fibril_connection->in_phone_hash;714 unsigned long key = fibril_connection->in_phone_hash; 669 715 hash_table_remove(&conn_hash_table, &key, 1); 670 716 futex_up(&async_futex); … … 700 746 * particular fibrils. 701 747 * 702 * @param in_task_ hashIdentification of the incoming connection.748 * @param in_task_id Identification of the incoming connection. 703 749 * @param in_phone_hash Identification of the incoming connection. 704 750 * @param callid Hash of the opening IPC_M_CONNECT_ME_TO call. … … 714 760 * 715 761 */ 716 fid_t async_new_connection( sysarg_t in_task_hash, sysarg_t in_phone_hash,762 fid_t async_new_connection(task_id_t in_task_id, sysarg_t in_phone_hash, 717 763 ipc_callid_t callid, ipc_call_t *call, 718 764 async_client_conn_t cfibril, void *carg) … … 726 772 } 727 773 728 conn->in_task_ hash = in_task_hash;774 conn->in_task_id = in_task_id; 729 775 conn->in_phone_hash = in_phone_hash; 730 776 list_initialize(&conn->msg_queue); … … 785 831 case IPC_M_CONNECT_ME_TO: 786 832 /* Open new connection with fibril, etc. */ 787 async_new_connection(call->in_task_ hash, IPC_GET_ARG5(*call),833 async_new_connection(call->in_task_id, IPC_GET_ARG5(*call), 788 834 callid, call, client_connection, NULL); 789 835 return; … … 933 979 { 934 980 if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS, 935 1, &client_hash_table_ops))981 2, &client_hash_table_ops)) 936 982 abort(); 937 983 … … 1426 1472 return ENOENT; 1427 1473 1428 sysarg_t task_hash; 1474 task_id_t task_id; 1475 sysarg_t task_id_lo; 1476 sysarg_t task_id_hi; 1429 1477 sysarg_t phone_hash; 1430 1478 int rc = async_req_3_5(exch, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3, 1431 NULL, NULL, NULL, &task_hash, &phone_hash);1479 NULL, NULL, &task_id_lo, &task_id_hi, &phone_hash); 1432 1480 if (rc != EOK) 1433 1481 return rc; 1482 1483 task_id = (task_id_t) MERGE_LOUP32(task_id_lo, task_id_hi); 1434 1484 1435 1485 if (client_receiver != NULL) 1436 async_new_connection(task_ hash, phone_hash, 0, NULL,1486 async_new_connection(task_id, phone_hash, 0, NULL, 1437 1487 client_receiver, carg); 1438 1488 … … 2429 2479 } 2430 2480 2481 int async_state_change_start(async_exch_t *exch, sysarg_t arg1, sysarg_t arg2, 2482 sysarg_t arg3, async_exch_t *other_exch) 2483 { 2484 return async_req_5_0(exch, IPC_M_STATE_CHANGE_AUTHORIZE, 2485 arg1, arg2, arg3, 0, other_exch->phone); 2486 } 2487 2488 bool async_state_change_receive(ipc_callid_t *callid, sysarg_t *arg1, 2489 sysarg_t *arg2, sysarg_t *arg3) 2490 { 2491 assert(callid); 2492 2493 ipc_call_t call; 2494 *callid = async_get_call(&call); 2495 2496 if (IPC_GET_IMETHOD(call) != IPC_M_STATE_CHANGE_AUTHORIZE) 2497 return false; 2498 2499 if (arg1) 2500 *arg1 = IPC_GET_ARG1(call); 2501 if (arg2) 2502 *arg2 = IPC_GET_ARG2(call); 2503 if (arg3) 2504 *arg3 = IPC_GET_ARG3(call); 2505 2506 return true; 2507 } 2508 2509 int async_state_change_finalize(ipc_callid_t callid, async_exch_t *other_exch) 2510 { 2511 return ipc_answer_1(callid, EOK, other_exch->phone); 2512 } 2513 2431 2514 /** @} 2432 2515 */ -
uspace/lib/c/generic/devman.c
rea186c6 r921b84f 1 1 /* 2 2 * Copyright (c) 2007 Josef Cejka 3 * Copyright (c) 20 09Jiri Svoboda3 * Copyright (c) 2011 Jiri Svoboda 4 4 * Copyright (c) 2010 Lenka Trochtova 5 5 * All rights reserved. … … 195 195 196 196 exch = devman_exchange_begin(DEVMAN_DRIVER); 197 async_connect_to_me(exch, 0, 0, 0, NULL, NULL);197 async_connect_to_me(exch, 0, 0, 0, conn, NULL); 198 198 devman_exchange_end(exch); 199 199 … … 342 342 } 343 343 344 int devman_ device_get_handle(const char *pathname, devman_handle_t *handle,344 int devman_fun_get_handle(const char *pathname, devman_handle_t *handle, 345 345 unsigned int flags) 346 346 { … … 383 383 } 384 384 385 int devman_get_device_path(devman_handle_t handle, char *path, size_t path_size) 385 static int devman_get_str_internal(sysarg_t method, sysarg_t arg1, char *buf, 386 size_t buf_size) 387 { 388 async_exch_t *exch; 389 ipc_call_t dreply; 390 size_t act_size; 391 sysarg_t dretval; 392 393 exch = devman_exchange_begin_blocking(LOC_PORT_CONSUMER); 394 395 ipc_call_t answer; 396 aid_t req = async_send_1(exch, method, arg1, &answer); 397 aid_t dreq = async_data_read(exch, buf, buf_size - 1, &dreply); 398 async_wait_for(dreq, &dretval); 399 400 devman_exchange_end(exch); 401 402 if (dretval != EOK) { 403 async_wait_for(req, NULL); 404 return dretval; 405 } 406 407 sysarg_t retval; 408 async_wait_for(req, &retval); 409 410 if (retval != EOK) 411 return retval; 412 413 act_size = IPC_GET_ARG2(dreply); 414 assert(act_size <= buf_size - 1); 415 buf[act_size] = '\0'; 416 417 return EOK; 418 } 419 420 int devman_fun_get_path(devman_handle_t handle, char *buf, size_t buf_size) 421 { 422 return devman_get_str_internal(DEVMAN_FUN_GET_PATH, handle, buf, 423 buf_size); 424 } 425 426 int devman_fun_get_name(devman_handle_t handle, char *buf, size_t buf_size) 427 { 428 return devman_get_str_internal(DEVMAN_FUN_GET_NAME, handle, buf, 429 buf_size); 430 } 431 432 static int devman_get_handles_once(sysarg_t method, sysarg_t arg1, 433 devman_handle_t *handle_buf, size_t buf_size, size_t *act_size) 434 { 435 async_exch_t *exch = devman_exchange_begin_blocking(DEVMAN_CLIENT); 436 437 ipc_call_t answer; 438 aid_t req = async_send_1(exch, method, arg1, &answer); 439 int rc = async_data_read_start(exch, handle_buf, buf_size); 440 441 devman_exchange_end(exch); 442 443 if (rc != EOK) { 444 async_wait_for(req, NULL); 445 return rc; 446 } 447 448 sysarg_t retval; 449 async_wait_for(req, &retval); 450 451 if (retval != EOK) { 452 return retval; 453 } 454 455 *act_size = IPC_GET_ARG1(answer); 456 return EOK; 457 } 458 459 /** Get list of handles. 460 * 461 * Returns an allocated array of handles. 462 * 463 * @param method IPC method 464 * @param arg1 IPC argument 1 465 * @param data Place to store pointer to array of handles 466 * @param count Place to store number of handles 467 * @return EOK on success or negative error code 468 */ 469 static int devman_get_handles_internal(sysarg_t method, sysarg_t arg1, 470 devman_handle_t **data, size_t *count) 471 { 472 devman_handle_t *handles; 473 size_t act_size; 474 size_t alloc_size; 475 int rc; 476 477 *data = NULL; 478 act_size = 0; /* silence warning */ 479 480 rc = devman_get_handles_once(method, arg1, NULL, 0, 481 &act_size); 482 if (rc != EOK) 483 return rc; 484 485 alloc_size = act_size; 486 handles = malloc(alloc_size); 487 if (handles == NULL) 488 return ENOMEM; 489 490 while (true) { 491 rc = devman_get_handles_once(method, arg1, handles, alloc_size, 492 &act_size); 493 if (rc != EOK) 494 return rc; 495 496 if (act_size <= alloc_size) 497 break; 498 499 alloc_size *= 2; 500 free(handles); 501 502 handles = malloc(alloc_size); 503 if (handles == NULL) 504 return ENOMEM; 505 } 506 507 *count = act_size / sizeof(devman_handle_t); 508 *data = handles; 509 return EOK; 510 } 511 512 int devman_fun_get_child(devman_handle_t funh, devman_handle_t *devh) 386 513 { 387 514 async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT); … … 389 516 return ENOMEM; 390 517 391 ipc_call_t answer; 392 aid_t req = async_send_1(exch, DEVMAN_DEVICE_GET_DEVICE_PATH, 393 handle, &answer); 394 395 ipc_call_t data_request_call; 396 aid_t data_request = async_data_read(exch, path, path_size, 397 &data_request_call); 398 399 devman_exchange_end(exch); 400 401 if (data_request == 0) { 402 async_wait_for(req, NULL); 403 return ENOMEM; 404 } 405 406 sysarg_t data_request_rc; 407 async_wait_for(data_request, &data_request_rc); 408 409 sysarg_t opening_request_rc; 410 async_wait_for(req, &opening_request_rc); 411 412 if (data_request_rc != EOK) { 413 /* Prefer the return code of the opening request. */ 414 if (opening_request_rc != EOK) 415 return (int) opening_request_rc; 416 else 417 return (int) data_request_rc; 418 } 419 420 if (opening_request_rc != EOK) 421 return (int) opening_request_rc; 422 423 /* To be on the safe-side. */ 424 path[path_size - 1] = 0; 425 size_t transferred_size = IPC_GET_ARG2(data_request_call); 426 if (transferred_size >= path_size) 427 return ELIMIT; 428 429 /* Terminate the string (trailing 0 not send over IPC). */ 430 path[transferred_size] = 0; 431 return EOK; 518 sysarg_t retval = async_req_1_1(exch, DEVMAN_FUN_GET_CHILD, 519 funh, devh); 520 521 devman_exchange_end(exch); 522 return (int) retval; 523 } 524 525 int devman_dev_get_functions(devman_handle_t devh, devman_handle_t **funcs, 526 size_t *count) 527 { 528 return devman_get_handles_internal(DEVMAN_DEV_GET_FUNCTIONS, 529 devh, funcs, count); 432 530 } 433 531 -
uspace/lib/c/generic/event.c
rea186c6 r921b84f 54 54 } 55 55 56 int event_task_subscribe(event_task_type_t evno, sysarg_t imethod) 57 { 58 return __SYSCALL2(SYS_EVENT_SUBSCRIBE, (sysarg_t) evno, 59 (sysarg_t) imethod); 60 } 61 56 62 /** Unmask event notifications. 57 63 * … … 66 72 } 67 73 74 int event_task_unmask(event_task_type_t evno) 75 { 76 return __SYSCALL1(SYS_EVENT_UNMASK, (sysarg_t) evno); 77 } 78 68 79 /** @} 69 80 */ -
uspace/lib/c/generic/io/io.c
rea186c6 r921b84f 101 101 static LIST_INITIALIZE(files); 102 102 103 void __stdio_init(int filc , fdi_node_t *filv[])103 void __stdio_init(int filc) 104 104 { 105 105 if (filc > 0) { 106 stdin = f open_node(filv[0], "r");106 stdin = fdopen(0, "r"); 107 107 } else { 108 108 stdin = &stdin_null; … … 111 111 112 112 if (filc > 1) { 113 stdout = f open_node(filv[1], "w");113 stdout = fdopen(1, "w"); 114 114 } else { 115 115 stdout = &stdout_klog; … … 118 118 119 119 if (filc > 2) { 120 stderr = f open_node(filv[2], "w");120 stderr = fdopen(2, "w"); 121 121 } else { 122 122 stderr = &stderr_klog; … … 285 285 } 286 286 287 FILE *fopen_node(fdi_node_t *node, const char *mode)288 {289 int flags;290 if (!parse_mode(mode, &flags))291 return NULL;292 293 /* Open file. */294 FILE *stream = malloc(sizeof(FILE));295 if (stream == NULL) {296 errno = ENOMEM;297 return NULL;298 }299 300 stream->fd = open_node(node, flags);301 if (stream->fd < 0) {302 /* errno was set by open_node() */303 free(stream);304 return NULL;305 }306 307 stream->error = false;308 stream->eof = false;309 stream->klog = false;310 stream->sess = NULL;311 stream->need_sync = false;312 _setvbuf(stream);313 314 list_append(&stream->link, &files);315 316 return stream;317 }318 319 287 int fclose(FILE *stream) 320 288 { … … 780 748 } 781 749 782 int fnode(FILE *stream, fdi_node_t *node) 783 { 784 if (stream->fd >= 0) 785 return fd_node(stream->fd, node); 750 int fhandle(FILE *stream, int *handle) 751 { 752 if (stream->fd >= 0) { 753 *handle = stream->fd; 754 return EOK; 755 } 786 756 787 757 return ENOENT; -
uspace/lib/c/generic/io/printf_core.c
rea186c6 r921b84f 206 206 } 207 207 208 return (int) (counter + 1);208 return (int) (counter); 209 209 } 210 210 … … 244 244 } 245 245 246 return (int) (counter + 1);246 return (int) (counter); 247 247 } 248 248 -
uspace/lib/c/generic/libc.c
rea186c6 r921b84f 91 91 argc = 0; 92 92 argv = NULL; 93 __stdio_init(0 , NULL);93 __stdio_init(0); 94 94 } else { 95 95 argc = __pcb->argc; 96 96 argv = __pcb->argv; 97 __stdio_init(__pcb->filc , __pcb->filv);97 __stdio_init(__pcb->filc); 98 98 (void) chdir(__pcb->cwd); 99 99 } -
uspace/lib/c/generic/loader.c
rea186c6 r921b84f 256 256 * 257 257 */ 258 int loader_set_files(loader_t *ldr, fdi_node_t *const files[]) 259 { 260 /* 261 * Serialize the arguments into a single array. First 262 * compute size of the buffer needed. 263 */ 264 fdi_node_t *const *ap = files; 265 size_t count = 0; 266 while (*ap != NULL) { 267 count++; 268 ap++; 269 } 270 271 fdi_node_t *files_buf; 272 files_buf = (fdi_node_t *) malloc(count * sizeof(fdi_node_t)); 273 if (files_buf == NULL) 274 return ENOMEM; 275 276 /* Fill the buffer */ 277 size_t i; 278 for (i = 0; i < count; i++) 279 files_buf[i] = *files[i]; 280 258 int loader_set_files(loader_t *ldr, int * const files[]) 259 { 281 260 /* Send serialized files to the loader */ 282 261 async_exch_t *exch = async_exchange_begin(ldr->sess); 283 284 ipc_call_t answer; 285 aid_t req = async_send_0(exch, LOADER_SET_FILES, &answer); 286 sysarg_t rc = async_data_write_start(exch, (void *) files_buf, 287 count * sizeof(fdi_node_t)); 288 289 async_exchange_end(exch); 290 free(files_buf); 291 262 async_exch_t *vfs_exch = vfs_exchange_begin(); 263 264 int i; 265 for (i = 0; files[i]; i++); 266 267 ipc_call_t answer; 268 aid_t req = async_send_1(exch, LOADER_SET_FILES, i, &answer); 269 270 sysarg_t rc = EOK; 271 272 for (i = 0; files[i]; i++) { 273 rc = async_state_change_start(exch, VFS_PASS_HANDLE, *files[i], 274 0, vfs_exch); 275 if (rc != EOK) 276 break; 277 } 278 279 vfs_exchange_end(vfs_exch); 280 async_exchange_end(exch); 281 292 282 if (rc != EOK) { 293 283 async_wait_for(req, NULL); -
uspace/lib/c/generic/loc.c
rea186c6 r921b84f 315 315 /** Register new service. 316 316 * 317 * @param fqsn 318 * @param sid 317 * @param fqsn Fully qualified service name 318 * @param sid Output: ID of new service 319 319 * 320 320 */ -
uspace/lib/c/generic/private/async.h
rea186c6 r921b84f 36 36 #define LIBC_PRIVATE_ASYNC_H_ 37 37 38 #include <ipc/common.h> 38 39 #include <adt/list.h> 39 40 #include <fibril.h> -
uspace/lib/c/generic/private/io.h
rea186c6 r921b84f 36 36 #define LIBC_PRIVATE_IO_H_ 37 37 38 #include <vfs/vfs.h> 39 40 extern void __stdio_init(int filc, fdi_node_t *filv[]); 38 extern void __stdio_init(int); 41 39 extern void __stdio_done(void); 42 40 -
uspace/lib/c/generic/task.c
rea186c6 r921b84f 46 46 #include <libc.h> 47 47 #include "private/ns.h" 48 #include <vfs/vfs.h> 48 49 49 50 task_id_t task_get_id(void) … … 102 103 { 103 104 /* Send default files */ 104 fdi_node_t *files[4];105 fdi_node_t stdin_node;106 fdi_node_t stdout_node;107 fdi_node_t stderr_node;108 109 if ((stdin != NULL) && (f node(stdin, &stdin_node) == EOK))110 files[0] = & stdin_node;105 int *files[4]; 106 int fd_stdin; 107 int fd_stdout; 108 int fd_stderr; 109 110 if ((stdin != NULL) && (fhandle(stdin, &fd_stdin) == EOK)) 111 files[0] = &fd_stdin; 111 112 else 112 113 files[0] = NULL; 113 114 114 if ((stdout != NULL) && (f node(stdout, &stdout_node) == EOK))115 files[1] = & stdout_node;115 if ((stdout != NULL) && (fhandle(stdout, &fd_stdout) == EOK)) 116 files[1] = &fd_stdout; 116 117 else 117 118 files[1] = NULL; 118 119 119 if ((stderr != NULL) && (f node(stderr, &stderr_node) == EOK))120 files[2] = & stderr_node;120 if ((stderr != NULL) && (fhandle(stderr, &fd_stderr) == EOK)) 121 files[2] = &fd_stderr; 121 122 else 122 123 files[2] = NULL; … … 142 143 */ 143 144 int task_spawnvf(task_id_t *id, const char *path, const char *const args[], 144 fdi_node_t *const files[])145 int *const files[]) 145 146 { 146 147 /* Connect to a program loader. */ -
uspace/lib/c/generic/vfs/vfs.c
rea186c6 r921b84f 69 69 * 70 70 */ 71 staticasync_exch_t *vfs_exchange_begin(void)71 async_exch_t *vfs_exchange_begin(void) 72 72 { 73 73 fibril_mutex_lock(&vfs_mutex); … … 87 87 * 88 88 */ 89 staticvoid vfs_exchange_end(async_exch_t *exch)89 void vfs_exchange_end(async_exch_t *exch) 90 90 { 91 91 async_exchange_end(exch); … … 329 329 } 330 330 331 int open_node(fdi_node_t *node, int oflag)332 {333 async_exch_t *exch = vfs_exchange_begin();334 335 ipc_call_t answer;336 aid_t req = async_send_4(exch, VFS_IN_OPEN_NODE, node->fs_handle,337 node->service_id, node->index, oflag, &answer);338 339 vfs_exchange_end(exch);340 341 sysarg_t rc;342 async_wait_for(req, &rc);343 344 if (rc != EOK)345 return (int) rc;346 347 return (int) IPC_GET_ARG1(answer);348 }349 350 331 int close(int fildes) 351 332 { … … 819 800 } 820 801 821 int fd_node(int fildes, fdi_node_t *node)822 {823 struct stat stat;824 int rc = fstat(fildes, &stat);825 826 if (rc == EOK) {827 node->fs_handle = stat.fs_handle;828 node->service_id = stat.service_id;829 node->index = stat.index;830 }831 832 return rc;833 }834 835 802 int dup2(int oldfd, int newfd) 836 803 { … … 848 815 } 849 816 817 int fd_wait(void) 818 { 819 async_exch_t *exch = vfs_exchange_begin(); 820 821 sysarg_t ret; 822 sysarg_t rc = async_req_0_1(exch, VFS_IN_WAIT_HANDLE, &ret); 823 824 vfs_exchange_end(exch); 825 826 if (rc == EOK) 827 return (int) ret; 828 829 return (int) rc; 830 } 831 850 832 /** @} 851 833 */ -
uspace/lib/c/include/async.h
rea186c6 r921b84f 176 176 extern int async_wait_timeout(aid_t, sysarg_t *, suseconds_t); 177 177 178 extern fid_t async_new_connection( sysarg_t, sysarg_t, ipc_callid_t,178 extern fid_t async_new_connection(task_id_t, sysarg_t, ipc_callid_t, 179 179 ipc_call_t *, async_client_conn_t, void *); 180 180 … … 186 186 extern void async_set_client_data_destructor(async_client_data_dtor_t); 187 187 extern void *async_get_client_data(void); 188 extern void *async_get_client_data_by_id(task_id_t); 189 extern void async_put_client_data_by_id(task_id_t); 188 190 189 191 extern void async_set_client_connection(async_client_conn_t); … … 477 479 extern async_sess_t *async_callback_receive_start(exch_mgmt_t, ipc_call_t *); 478 480 481 extern int async_state_change_start(async_exch_t *, sysarg_t, sysarg_t, 482 sysarg_t, async_exch_t *); 483 extern bool async_state_change_receive(ipc_callid_t *, sysarg_t *, sysarg_t *, 484 sysarg_t *); 485 extern int async_state_change_finalize(ipc_callid_t, async_exch_t *); 486 479 487 #endif 480 488 -
uspace/lib/c/include/devman.h
rea186c6 r921b84f 56 56 unsigned int); 57 57 58 extern int devman_ device_get_handle(const char *, devman_handle_t *,58 extern int devman_fun_get_handle(const char *, devman_handle_t *, 59 59 unsigned int); 60 extern int devman_get_device_path(devman_handle_t, char *, size_t); 60 extern int devman_fun_get_child(devman_handle_t, devman_handle_t *); 61 extern int devman_dev_get_functions(devman_handle_t, devman_handle_t **, 62 size_t *); 63 extern int devman_fun_get_name(devman_handle_t, char *, size_t); 64 extern int devman_fun_get_path(devman_handle_t, char *, size_t); 61 65 62 66 extern int devman_add_device_to_category(devman_handle_t, const char *); -
uspace/lib/c/include/event.h
rea186c6 r921b84f 37 37 38 38 #include <abi/ipc/event.h> 39 #include <libarch/types.h> 39 40 40 41 extern int event_subscribe(event_type_t, sysarg_t); 42 extern int event_task_subscribe(event_task_type_t, sysarg_t); 41 43 extern int event_unmask(event_type_t); 44 extern int event_task_unmask(event_task_type_t); 42 45 43 46 #endif -
uspace/lib/c/include/ipc/common.h
rea186c6 r921b84f 39 39 #include <abi/ipc/ipc.h> 40 40 #include <atomic.h> 41 #include <task.h> 41 42 42 43 #define IPC_FLAG_BLOCKING 0x01 … … 44 45 typedef struct { 45 46 sysarg_t args[IPC_CALL_LEN]; 46 sysarg_t in_task_hash;47 task_id_t in_task_id; 47 48 sysarg_t in_phone_hash; 48 49 } ipc_call_t; -
uspace/lib/c/include/ipc/devman.h
rea186c6 r921b84f 149 149 typedef enum { 150 150 DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD, 151 DEVMAN_DEVICE_GET_DEVICE_PATH, 151 DEVMAN_DEV_GET_FUNCTIONS, 152 DEVMAN_FUN_GET_CHILD, 153 DEVMAN_FUN_GET_NAME, 154 DEVMAN_FUN_GET_PATH, 152 155 DEVMAN_FUN_SID_TO_HANDLE 153 156 } client_to_devman_t; -
uspace/lib/c/include/ipc/vfs.h
rea186c6 r921b84f 62 62 typedef enum { 63 63 VFS_IN_OPEN = IPC_FIRST_USER_METHOD, 64 VFS_IN_OPEN_NODE,65 64 VFS_IN_READ, 66 65 VFS_IN_WRITE, … … 78 77 VFS_IN_RENAME, 79 78 VFS_IN_STAT, 80 VFS_IN_DUP 79 VFS_IN_DUP, 80 VFS_IN_WAIT_HANDLE, 81 81 } vfs_in_request_t; 82 82 -
uspace/lib/c/include/loader/loader.h
rea186c6 r921b84f 38 38 39 39 #include <task.h> 40 #include <vfs/vfs.h>41 40 42 41 /** Forward declararion */ … … 50 49 extern int loader_set_pathname(loader_t *, const char *); 51 50 extern int loader_set_args(loader_t *, const char *const[]); 52 extern int loader_set_files(loader_t *, fdi_node_t *const[]);51 extern int loader_set_files(loader_t *, int *const[]); 53 52 extern int loader_load_program(loader_t *); 54 53 extern int loader_run(loader_t *); -
uspace/lib/c/include/loader/pcb.h
rea186c6 r921b84f 38 38 39 39 #include <sys/types.h> 40 #include <vfs/vfs.h>41 40 42 41 typedef void (*entry_point_t)(void); … … 62 61 63 62 /** Number of preset files. */ 64 int filc; 65 /** Preset files. */ 66 fdi_node_t **filv; 63 unsigned int filc; 67 64 68 65 /* -
uspace/lib/c/include/task.h
rea186c6 r921b84f 37 37 38 38 #include <sys/types.h> 39 #include <vfs/vfs.h>40 39 41 40 typedef uint64_t task_id_t; … … 53 52 extern int task_spawnv(task_id_t *, const char *path, const char *const []); 54 53 extern int task_spawnvf(task_id_t *, const char *path, const char *const [], 55 fdi_node_t *const []);54 int *const []); 56 55 extern int task_spawnl(task_id_t *, const char *path, ...); 57 56 -
uspace/lib/c/include/vfs/vfs.h
rea186c6 r921b84f 40 40 #include <ipc/loc.h> 41 41 #include <stdio.h> 42 #include <async.h> 42 43 43 /** Libc version of the VFS triplet. 44 * 45 * Unique identification of a file system node 46 * within a file system instance. 47 * 48 */ 49 typedef struct { 50 fs_handle_t fs_handle; 51 service_id_t service_id; 52 fs_index_t index; 53 } fdi_node_t; 44 enum vfs_change_state_type { 45 VFS_PASS_HANDLE 46 }; 54 47 55 48 extern char *absolutize(const char *, size_t *); … … 59 52 extern int unmount(const char *); 60 53 61 extern int open_node(fdi_node_t *, int); 62 extern int fd_node(int, fdi_node_t *); 54 extern int fhandle(FILE *, int *); 63 55 64 extern FILE *fopen_node(fdi_node_t *, const char *); 65 extern int fnode(FILE *, fdi_node_t *); 56 extern int fd_wait(void); 57 58 extern async_exch_t *vfs_exchange_begin(void); 59 extern void vfs_exchange_end(async_exch_t *); 66 60 67 61 #endif -
uspace/lib/drv/generic/driver.c
rea186c6 r921b84f 428 428 static void driver_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 429 429 { 430 sysarg_t conn_type; 431 432 if (iid == 0) { 433 /* Callback connection from devman */ 434 /* XXX Use separate handler for this type of connection */ 435 conn_type = DRIVER_DEVMAN; 436 } else { 437 conn_type = IPC_GET_ARG1(*icall); 438 } 439 430 440 /* Select interface */ 431 switch ( (sysarg_t) (IPC_GET_ARG1(*icall))) {441 switch (conn_type) { 432 442 case DRIVER_DEVMAN: 433 443 /* Handle request from device manager */ -
uspace/lib/posix/fcntl.c
rea186c6 r921b84f 52 52 int posix_fcntl(int fd, int cmd, ...) 53 53 { 54 int rc;55 54 int flags; 56 55 57 56 switch (cmd) { 58 57 case F_DUPFD: 59 case F_DUPFD_CLOEXEC: /* FD_CLOEXEC is not supported. */ 60 /* VFS does not provide means to express constraints on the new 61 * file descriptor so the third argument is ignored. */ 62 63 /* Retrieve node triplet corresponding to the file descriptor. */ 64 /* Empty statement after label. */; 65 fdi_node_t node; 66 rc = fd_node(fd, &node); 67 if (rc != EOK) { 68 errno = -rc; 69 return -1; 70 } 71 72 /* Reopen the node so the fresh file descriptor is generated. */ 73 int newfd = open_node(&node, 0); 74 if (newfd < 0) { 75 errno = -newfd; 76 return -1; 77 } 78 79 /* Associate the newly generated descriptor to the file description 80 * of the old file descriptor. Just reopened node will be automatically 81 * closed. */ 82 rc = dup2(fd, newfd); 83 if (rc != EOK) { 84 errno = -rc; 85 return -1; 86 } 87 88 return newfd; 58 case F_DUPFD_CLOEXEC: 59 /* VFS currently does not provide the functionality to duplicate 60 * opened file descriptor. */ 61 // FIXME: implement this once dup() is available 62 errno = ENOTSUP; 63 return -1; 89 64 case F_GETFD: 90 65 /* FD_CLOEXEC is not supported. There are no other flags. */ -
uspace/lib/posix/stdio.c
rea186c6 r921b84f 257 257 assert(stream != NULL); 258 258 259 /* Retrieve the node. */260 struct stat st;261 int rc;262 263 259 if (filename == NULL) { 264 rc = fstat(stream->fd, &st); 265 } else { 266 rc = stat(filename, &st); 267 if (-rc == ENOENT) { 268 /* file does not exist, create new file */ 269 FILE* tmp = fopen(filename, mode); 270 if (tmp != NULL) { 271 fclose(tmp); 272 /* try again */ 273 rc = stat(filename, &st); 274 } 275 } 276 } 277 278 if (rc != EOK) { 279 fclose(stream); 280 errno = -rc; 281 return NULL; 282 } 283 284 fdi_node_t node = { 285 .fs_handle = st.fs_handle, 286 .service_id = st.service_id, 287 .index = st.index 288 }; 260 /* POSIX allows this to be imlementation-defined. HelenOS currently 261 * does not support changing the mode. */ 262 // FIXME: handle mode change once it is supported 263 return stream; 264 } 289 265 290 266 /* Open a new stream. */ 291 FILE* new = fopen _node(&node, mode);267 FILE* new = fopen(filename, mode); 292 268 if (new == NULL) { 293 269 fclose(stream); 294 /* fopen_node() sets errno.*/270 /* errno was set by fopen() */ 295 271 return NULL; 296 272 } -
uspace/lib/usb/src/resolve.c
rea186c6 r921b84f 152 152 if (str_length(func_start) > 0) { 153 153 char tmp_path[MAX_DEVICE_PATH ]; 154 rc = devman_ get_device_path(dev_handle,154 rc = devman_fun_get_path(dev_handle, 155 155 tmp_path, MAX_DEVICE_PATH); 156 156 if (rc != EOK) { … … 173 173 174 174 /* First try to get the device handle. */ 175 rc = devman_ device_get_handle(path, &dev_handle, 0);175 rc = devman_fun_get_handle(path, &dev_handle, 0); 176 176 if (rc != EOK) { 177 177 free(path); … … 184 184 /* Get device handle first. */ 185 185 devman_handle_t tmp_handle; 186 rc = devman_ device_get_handle(path, &tmp_handle, 0);186 rc = devman_fun_get_handle(path, &tmp_handle, 0); 187 187 if (rc != EOK) { 188 188 free(path); -
uspace/lib/usbvirt/src/device.c
rea186c6 r921b84f 87 87 88 88 devman_handle_t handle; 89 int rc = devman_ device_get_handle(vhc_path, &handle, 0);89 int rc = devman_fun_get_handle(vhc_path, &handle, 0); 90 90 if (rc != EOK) 91 91 return rc; -
uspace/srv/devman/devman.c
rea186c6 r921b84f 548 548 549 549 fibril_mutex_lock(&driver->driver_mutex); 550 551 async_exch_t *exch = async_exchange_begin(driver->sess);552 async_sess_t *sess = async_connect_me_to(EXCHANGE_SERIALIZE, exch,553 DRIVER_DEVMAN, 0, 0);554 async_exchange_end(exch);555 556 if (!sess) {557 fibril_mutex_unlock(&driver->driver_mutex);558 return;559 }560 550 561 551 /* … … 583 573 fibril_mutex_unlock(&driver->driver_mutex); 584 574 585 add_device( sess,driver, dev, tree);575 add_device(driver, dev, tree); 586 576 587 577 /* … … 603 593 link = driver->devices.head.next; 604 594 } 605 606 async_hangup(sess);607 595 608 596 /* … … 718 706 * @param node The device's node in the device tree. 719 707 */ 720 void add_device(async_sess_t *sess, driver_t *drv, dev_node_t *dev, 721 dev_tree_t *tree) 708 void add_device(driver_t *drv, dev_node_t *dev, dev_tree_t *tree) 722 709 { 723 710 /* … … 736 723 } 737 724 738 async_exch_t *exch = async_exchange_begin( sess);725 async_exch_t *exch = async_exchange_begin(drv->sess); 739 726 740 727 ipc_call_t answer; … … 806 793 fibril_mutex_unlock(&drv->driver_mutex); 807 794 808 if (is_running) { 809 /* Notify the driver about the new device. */ 810 async_exch_t *exch = async_exchange_begin(drv->sess); 811 async_sess_t *sess = async_connect_me_to(EXCHANGE_SERIALIZE, exch, 812 DRIVER_DEVMAN, 0, 0); 813 async_exchange_end(exch); 814 815 if (sess) { 816 add_device(sess, drv, dev, tree); 817 async_hangup(sess); 818 } 819 } 795 /* Notify the driver about the new device. */ 796 if (is_running) 797 add_device(drv, dev, tree); 820 798 821 799 return true; … … 919 897 return dev; 920 898 } 899 900 /** Get list of device functions. */ 901 int dev_get_functions(dev_tree_t *tree, dev_node_t *dev, 902 devman_handle_t *hdl_buf, size_t buf_size, size_t *act_size) 903 { 904 size_t act_cnt; 905 size_t buf_cnt; 906 907 assert(fibril_rwlock_is_locked(&tree->rwlock)); 908 909 buf_cnt = buf_size / sizeof(devman_handle_t); 910 911 act_cnt = list_count(&dev->functions); 912 *act_size = act_cnt * sizeof(devman_handle_t); 913 914 if (buf_size % sizeof(devman_handle_t) != 0) 915 return EINVAL; 916 917 size_t pos = 0; 918 list_foreach(dev->functions, item) { 919 fun_node_t *fun = 920 list_get_instance(item, fun_node_t, dev_functions); 921 922 if (pos < buf_cnt) 923 hdl_buf[pos] = fun->handle; 924 pos++; 925 } 926 927 return EOK; 928 } 929 921 930 922 931 /* Function nodes */ … … 1145 1154 char *rel_path = path; 1146 1155 char *next_path_elem = NULL; 1147 bool cont = true;1156 bool cont = (rel_path[1] != '\0'); 1148 1157 1149 1158 while (cont && fun != NULL) { -
uspace/srv/devman/devman.h
rea186c6 r921b84f 235 235 extern void add_driver(driver_list_t *, driver_t *); 236 236 extern void attach_driver(dev_node_t *, driver_t *); 237 extern void add_device( async_sess_t *,driver_t *, dev_node_t *, dev_tree_t *);237 extern void add_device(driver_t *, dev_node_t *, dev_tree_t *); 238 238 extern bool start_driver(driver_t *); 239 239 … … 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
rea186c6 r921b84f 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: -
uspace/srv/hid/input/port/adb_mouse.c
rea186c6 r921b84f 42 42 #include <errno.h> 43 43 #include <loc.h> 44 #include <stdio.h> 44 45 45 46 static mouse_dev_t *mouse_dev; -
uspace/srv/hw/irc/apic/apic.c
rea186c6 r921b84f 45 45 #include <errno.h> 46 46 #include <async.h> 47 #include <stdio.h> 47 48 48 49 #define NAME "apic" -
uspace/srv/loader/main.c
rea186c6 r921b84f 61 61 #include <elf/elf.h> 62 62 #include <elf/elf_load.h> 63 #include <vfs/vfs.h> 63 64 64 65 #ifdef CONFIG_RTLD … … 89 90 90 91 /** Number of preset files */ 91 static int filc = 0; 92 /** Preset files vector */ 93 static fdi_node_t **filv = NULL; 94 /** Buffer holding all preset files */ 95 static fdi_node_t *fil_buf = NULL; 92 static unsigned int filc = 0; 96 93 97 94 static elf_info_t prog_info; … … 239 236 static void ldr_set_files(ipc_callid_t rid, ipc_call_t *request) 240 237 { 241 fdi_node_t *buf; 242 size_t buf_size; 243 int rc = async_data_write_accept((void **) &buf, false, 0, 0, 244 sizeof(fdi_node_t), &buf_size); 245 246 if (rc == EOK) { 247 int count = buf_size / sizeof(fdi_node_t); 248 249 /* 250 * Allocate new filv 251 */ 252 fdi_node_t **_filv = (fdi_node_t **) calloc(count + 1, sizeof(fdi_node_t *)); 253 if (_filv == NULL) { 254 free(buf); 255 async_answer_0(rid, ENOMEM); 256 return; 238 size_t count = IPC_GET_ARG1(*request); 239 240 async_exch_t *vfs_exch = vfs_exchange_begin(); 241 242 for (filc = 0; filc < count; filc++) { 243 ipc_callid_t callid; 244 int fd; 245 246 if (!async_state_change_receive(&callid, NULL, NULL, NULL)) { 247 async_answer_0(callid, EINVAL); 248 break; 257 249 } 258 259 /* 260 * Fill the new filv with argument pointers 261 */ 262 int i; 263 for (i = 0; i < count; i++) 264 _filv[i] = &buf[i]; 265 266 _filv[count] = NULL; 267 268 /* 269 * Copy temporary data to global variables 270 */ 271 if (fil_buf != NULL) 272 free(fil_buf); 273 274 if (filv != NULL) 275 free(filv); 276 277 filc = count; 278 fil_buf = buf; 279 filv = _filv; 280 } 281 250 async_state_change_finalize(callid, vfs_exch); 251 fd = fd_wait(); 252 assert(fd == (int) filc); 253 } 254 255 vfs_exchange_end(vfs_exch); 256 282 257 async_answer_0(rid, EOK); 283 258 } … … 308 283 309 284 pcb.filc = filc; 310 pcb.filv = filv;311 285 312 286 if (prog_info.interp == NULL) { -
uspace/srv/loc/loc.h
rea186c6 r921b84f 36 36 #define LOC_H_ 37 37 38 #include <ipc/loc.h> 38 39 #include <async.h> 39 40 #include <fibril_synch.h> -
uspace/srv/vfs/vfs.c
rea186c6 r921b84f 36 36 */ 37 37 38 #include <vfs/vfs.h> 38 39 #include <ipc/services.h> 40 #include <abi/ipc/event.h> 41 #include <event.h> 39 42 #include <ns.h> 40 43 #include <async.h> … … 45 48 #include <as.h> 46 49 #include <atomic.h> 50 #include <macros.h> 47 51 #include "vfs.h" 48 52 49 53 #define NAME "vfs" 54 55 enum { 56 VFS_TASK_STATE_CHANGE 57 }; 50 58 51 59 static void vfs_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) … … 80 88 vfs_open(callid, &call); 81 89 break; 82 case VFS_IN_OPEN_NODE:83 vfs_open_node(callid, &call);84 break;85 90 case VFS_IN_CLOSE: 86 91 vfs_close(callid, &call); … … 118 123 case VFS_IN_DUP: 119 124 vfs_dup(callid, &call); 125 break; 126 case VFS_IN_WAIT_HANDLE: 127 vfs_wait_handle(callid, &call); 128 break; 120 129 default: 121 130 async_answer_0(callid, ENOTSUP); … … 128 137 * connection fibril terminates. 129 138 */ 139 } 140 141 static void notification_received(ipc_callid_t callid, ipc_call_t *call) 142 { 143 switch (IPC_GET_IMETHOD(*call)) { 144 case VFS_TASK_STATE_CHANGE: 145 if (IPC_GET_ARG1(*call) == VFS_PASS_HANDLE) 146 vfs_pass_handle( 147 (task_id_t) MERGE_LOUP32(IPC_GET_ARG4(*call), 148 IPC_GET_ARG5(*call)), call->in_task_id, 149 (int) IPC_GET_ARG2(*call)); 150 break; 151 default: 152 break; 153 } 130 154 } 131 155 … … 170 194 171 195 /* 196 * Set notification handler and subscribe to notifications. 197 */ 198 async_set_interrupt_received(notification_received); 199 event_task_subscribe(EVENT_TASK_STATE_CHANGE, VFS_TASK_STATE_CHANGE); 200 201 /* 172 202 * Register at the naming service. 173 203 */ -
uspace/srv/vfs/vfs.h
rea186c6 r921b84f 41 41 #include <bool.h> 42 42 #include <ipc/vfs.h> 43 #include <task.h> 43 44 44 45 #ifndef dprintf … … 175 176 extern int vfs_lookup_internal(char *, int, vfs_lookup_res_t *, 176 177 vfs_pair_t *, ...); 177 extern int vfs_open_node_internal(vfs_lookup_res_t *);178 178 179 179 extern bool vfs_nodes_init(void); … … 189 189 extern void vfs_client_data_destroy(void *); 190 190 191 extern void vfs_pass_handle(task_id_t, task_id_t, int); 192 extern int vfs_wait_handle_internal(void); 193 191 194 extern vfs_file_t *vfs_file_get(int); 192 195 extern void vfs_file_put(vfs_file_t *); … … 197 200 extern void vfs_node_addref(vfs_node_t *); 198 201 extern void vfs_node_delref(vfs_node_t *); 202 extern int vfs_open_node_remote(vfs_node_t *); 199 203 200 204 extern void vfs_register(ipc_callid_t, ipc_call_t *); … … 202 206 extern void vfs_unmount(ipc_callid_t, ipc_call_t *); 203 207 extern void vfs_open(ipc_callid_t, ipc_call_t *); 204 extern void vfs_open_node(ipc_callid_t, ipc_call_t *);205 208 extern void vfs_sync(ipc_callid_t, ipc_call_t *); 206 209 extern void vfs_dup(ipc_callid_t, ipc_call_t *); … … 215 218 extern void vfs_unlink(ipc_callid_t, ipc_call_t *); 216 219 extern void vfs_rename(ipc_callid_t, ipc_call_t *); 220 extern void vfs_wait_handle(ipc_callid_t, ipc_call_t *); 217 221 218 222 #endif -
uspace/srv/vfs/vfs_file.c
rea186c6 r921b84f 43 43 #include <fibril.h> 44 44 #include <fibril_synch.h> 45 #include <adt/list.h> 46 #include <task.h> 45 47 #include "vfs.h" 46 48 … … 50 52 typedef struct { 51 53 fibril_mutex_t lock; 54 fibril_condvar_t cv; 55 list_t passed_handles; 52 56 vfs_file_t **files; 53 57 } vfs_client_data_t; 54 58 59 typedef struct { 60 link_t link; 61 int handle; 62 } vfs_boxed_handle_t; 63 64 static int _vfs_fd_free(vfs_client_data_t *, int); 65 55 66 /** Initialize the table of open files. */ 56 static bool vfs_files_init(v oid)57 { 58 fibril_mutex_lock(& VFS_DATA->lock);59 if (! FILES) {60 FILES= malloc(MAX_OPEN_FILES * sizeof(vfs_file_t *));61 if (! FILES) {62 fibril_mutex_unlock(& VFS_DATA->lock);67 static bool vfs_files_init(vfs_client_data_t *vfs_data) 68 { 69 fibril_mutex_lock(&vfs_data->lock); 70 if (!vfs_data->files) { 71 vfs_data->files = malloc(MAX_OPEN_FILES * sizeof(vfs_file_t *)); 72 if (!vfs_data->files) { 73 fibril_mutex_unlock(&vfs_data->lock); 63 74 return false; 64 75 } 65 memset( FILES, 0, MAX_OPEN_FILES * sizeof(vfs_file_t *));66 } 67 fibril_mutex_unlock(& VFS_DATA->lock);76 memset(vfs_data->files, 0, MAX_OPEN_FILES * sizeof(vfs_file_t *)); 77 } 78 fibril_mutex_unlock(&vfs_data->lock); 68 79 return true; 69 80 } 70 81 71 82 /** Cleanup the table of open files. */ 72 static void vfs_files_done(v oid)83 static void vfs_files_done(vfs_client_data_t *vfs_data) 73 84 { 74 85 int i; 75 86 76 if (! FILES)87 if (!vfs_data->files) 77 88 return; 78 89 79 90 for (i = 0; i < MAX_OPEN_FILES; i++) { 80 if (FILES[i]) { 81 (void) vfs_fd_free(i); 82 } 83 } 84 85 free(FILES); 91 if (vfs_data->files[i]) 92 (void) _vfs_fd_free(vfs_data, i); 93 } 94 95 free(vfs_data->files); 96 97 while (!list_empty(&vfs_data->passed_handles)) { 98 link_t *lnk; 99 vfs_boxed_handle_t *bh; 100 101 lnk = list_first(&vfs_data->passed_handles); 102 list_remove(lnk); 103 104 bh = list_get_instance(lnk, vfs_boxed_handle_t, link); 105 free(bh); 106 } 86 107 } 87 108 … … 93 114 if (vfs_data) { 94 115 fibril_mutex_initialize(&vfs_data->lock); 116 fibril_condvar_initialize(&vfs_data->cv); 117 list_initialize(&vfs_data->passed_handles); 95 118 vfs_data->files = NULL; 96 119 } … … 103 126 vfs_client_data_t *vfs_data = (vfs_client_data_t *) data; 104 127 105 vfs_files_done( );128 vfs_files_done(vfs_data); 106 129 free(vfs_data); 107 130 } … … 131 154 * incremented. 132 155 */ 133 static void vfs_file_addref(vfs_ file_t *file)134 { 135 assert(fibril_mutex_is_locked(& VFS_DATA->lock));156 static void vfs_file_addref(vfs_client_data_t *vfs_data, vfs_file_t *file) 157 { 158 assert(fibril_mutex_is_locked(&vfs_data->lock)); 136 159 137 160 file->refcnt++; … … 143 166 * decremented. 144 167 */ 145 static int vfs_file_delref(vfs_ file_t *file)168 static int vfs_file_delref(vfs_client_data_t *vfs_data, vfs_file_t *file) 146 169 { 147 170 int rc = EOK; 148 171 149 assert(fibril_mutex_is_locked(& VFS_DATA->lock));172 assert(fibril_mutex_is_locked(&vfs_data->lock)); 150 173 151 174 if (file->refcnt-- == 1) { … … 162 185 } 163 186 164 165 /** Allocate a file descriptor. 166 * 167 * @param desc If true, look for an available file descriptor 168 * in a descending order. 169 * 170 * @return First available file descriptor or a negative error 171 * code. 172 */ 173 int vfs_fd_alloc(bool desc) 174 { 175 if (!vfs_files_init()) 187 static int _vfs_fd_alloc(vfs_client_data_t *vfs_data, bool desc) 188 { 189 if (!vfs_files_init(vfs_data)) 176 190 return ENOMEM; 177 191 … … 182 196 i = 0; 183 197 184 fibril_mutex_lock(& VFS_DATA->lock);198 fibril_mutex_lock(&vfs_data->lock); 185 199 while (true) { 186 if (! FILES[i]) {187 FILES[i] = (vfs_file_t *) malloc(sizeof(vfs_file_t));188 if (! FILES[i]) {189 fibril_mutex_unlock(& VFS_DATA->lock);200 if (!vfs_data->files[i]) { 201 vfs_data->files[i] = (vfs_file_t *) malloc(sizeof(vfs_file_t)); 202 if (!vfs_data->files[i]) { 203 fibril_mutex_unlock(&vfs_data->lock); 190 204 return ENOMEM; 191 205 } 192 206 193 memset( FILES[i], 0, sizeof(vfs_file_t));194 fibril_mutex_initialize(& FILES[i]->lock);195 vfs_file_addref( FILES[i]);196 fibril_mutex_unlock(& VFS_DATA->lock);207 memset(vfs_data->files[i], 0, sizeof(vfs_file_t)); 208 fibril_mutex_initialize(&vfs_data->files[i]->lock); 209 vfs_file_addref(vfs_data, vfs_data->files[i]); 210 fibril_mutex_unlock(&vfs_data->lock); 197 211 return (int) i; 198 212 } … … 210 224 } 211 225 } 212 fibril_mutex_unlock(& VFS_DATA->lock);226 fibril_mutex_unlock(&vfs_data->lock); 213 227 214 228 return EMFILE; 229 } 230 231 /** Allocate a file descriptor. 232 * 233 * @param desc If true, look for an available file descriptor 234 * in a descending order. 235 * 236 * @return First available file descriptor or a negative error 237 * code. 238 */ 239 int vfs_fd_alloc(bool desc) 240 { 241 return _vfs_fd_alloc(VFS_DATA, desc); 242 } 243 244 static int _vfs_fd_free(vfs_client_data_t *vfs_data, int fd) 245 { 246 int rc; 247 248 if (!vfs_files_init(vfs_data)) 249 return ENOMEM; 250 251 fibril_mutex_lock(&vfs_data->lock); 252 if ((fd < 0) || (fd >= MAX_OPEN_FILES) || !vfs_data->files[fd]) { 253 fibril_mutex_unlock(&vfs_data->lock); 254 return EBADF; 255 } 256 257 rc = vfs_file_delref(vfs_data, vfs_data->files[fd]); 258 vfs_data->files[fd] = NULL; 259 fibril_mutex_unlock(&vfs_data->lock); 260 261 return rc; 215 262 } 216 263 … … 224 271 int vfs_fd_free(int fd) 225 272 { 226 int rc; 227 228 if (!vfs_files_init()) 229 return ENOMEM; 230 231 fibril_mutex_lock(&VFS_DATA->lock); 232 if ((fd < 0) || (fd >= MAX_OPEN_FILES) || (FILES[fd] == NULL)) { 233 fibril_mutex_unlock(&VFS_DATA->lock); 234 return EBADF; 235 } 236 237 rc = vfs_file_delref(FILES[fd]); 238 FILES[fd] = NULL; 239 fibril_mutex_unlock(&VFS_DATA->lock); 240 241 return rc; 273 return _vfs_fd_free(VFS_DATA, fd); 242 274 } 243 275 … … 253 285 int vfs_fd_assign(vfs_file_t *file, int fd) 254 286 { 255 if (!vfs_files_init( ))287 if (!vfs_files_init(VFS_DATA)) 256 288 return ENOMEM; 257 289 … … 263 295 264 296 FILES[fd] = file; 265 vfs_file_addref( FILES[fd]);297 vfs_file_addref(VFS_DATA, FILES[fd]); 266 298 fibril_mutex_unlock(&VFS_DATA->lock); 267 299 … … 269 301 } 270 302 271 /** Find VFS file structure for a given file descriptor. 272 * 273 * @param fd File descriptor. 274 * 275 * @return VFS file structure corresponding to fd. 276 */ 277 vfs_file_t *vfs_file_get(int fd) 278 { 279 if (!vfs_files_init()) 303 static vfs_file_t *_vfs_file_get(vfs_client_data_t *vfs_data, int fd) 304 { 305 if (!vfs_files_init(vfs_data)) 280 306 return NULL; 281 307 282 fibril_mutex_lock(& VFS_DATA->lock);308 fibril_mutex_lock(&vfs_data->lock); 283 309 if ((fd >= 0) && (fd < MAX_OPEN_FILES)) { 284 vfs_file_t *file = FILES[fd];310 vfs_file_t *file = vfs_data->files[fd]; 285 311 if (file != NULL) { 286 vfs_file_addref( file);287 fibril_mutex_unlock(& VFS_DATA->lock);312 vfs_file_addref(vfs_data, file); 313 fibril_mutex_unlock(&vfs_data->lock); 288 314 return file; 289 315 } 290 316 } 291 fibril_mutex_unlock(& VFS_DATA->lock);317 fibril_mutex_unlock(&vfs_data->lock); 292 318 293 319 return NULL; 294 320 } 295 321 322 /** Find VFS file structure for a given file descriptor. 323 * 324 * @param fd File descriptor. 325 * 326 * @return VFS file structure corresponding to fd. 327 */ 328 vfs_file_t *vfs_file_get(int fd) 329 { 330 return _vfs_file_get(VFS_DATA, fd); 331 } 332 333 static void _vfs_file_put(vfs_client_data_t *vfs_data, vfs_file_t *file) 334 { 335 fibril_mutex_lock(&vfs_data->lock); 336 vfs_file_delref(vfs_data, file); 337 fibril_mutex_unlock(&vfs_data->lock); 338 } 339 296 340 /** Stop using a file structure. 297 341 * … … 300 344 void vfs_file_put(vfs_file_t *file) 301 345 { 302 fibril_mutex_lock(&VFS_DATA->lock); 303 vfs_file_delref(file); 304 fibril_mutex_unlock(&VFS_DATA->lock); 346 _vfs_file_put(VFS_DATA, file); 347 } 348 349 void vfs_pass_handle(task_id_t donor_id, task_id_t acceptor_id, int donor_fd) 350 { 351 vfs_client_data_t *donor_data = NULL; 352 vfs_client_data_t *acceptor_data = NULL; 353 vfs_file_t *donor_file = NULL; 354 vfs_file_t *acceptor_file = NULL; 355 vfs_boxed_handle_t *bh; 356 int acceptor_fd; 357 358 acceptor_data = async_get_client_data_by_id(acceptor_id); 359 if (!acceptor_data) 360 return; 361 362 bh = malloc(sizeof(vfs_boxed_handle_t)); 363 assert(bh); 364 365 link_initialize(&bh->link); 366 bh->handle = -1; 367 368 donor_data = async_get_client_data_by_id(donor_id); 369 if (!donor_data) 370 goto out; 371 372 donor_file = _vfs_file_get(donor_data, donor_fd); 373 if (!donor_file) 374 goto out; 375 376 acceptor_fd = _vfs_fd_alloc(acceptor_data, false); 377 if (acceptor_fd < 0) 378 goto out; 379 380 bh->handle = acceptor_fd; 381 382 /* 383 * Add a new reference to the underlying VFS node. 384 */ 385 vfs_node_addref(donor_file->node); 386 (void) vfs_open_node_remote(donor_file->node); 387 388 acceptor_file = _vfs_file_get(acceptor_data, acceptor_fd); 389 assert(acceptor_file); 390 391 /* 392 * Inherit attributes from the donor. 393 */ 394 acceptor_file->node = donor_file->node; 395 acceptor_file->append = donor_file->append; 396 acceptor_file->pos = donor_file->pos; 397 398 out: 399 fibril_mutex_lock(&acceptor_data->lock); 400 list_append(&bh->link, &acceptor_data->passed_handles); 401 fibril_condvar_broadcast(&acceptor_data->cv); 402 fibril_mutex_unlock(&acceptor_data->lock); 403 404 if (donor_data) 405 async_put_client_data_by_id(donor_id); 406 if (acceptor_data) 407 async_put_client_data_by_id(acceptor_id); 408 if (donor_file) 409 _vfs_file_put(donor_data, donor_file); 410 if (acceptor_file) 411 _vfs_file_put(acceptor_data, acceptor_file); 412 413 } 414 415 int vfs_wait_handle_internal(void) 416 { 417 vfs_client_data_t *vfs_data = VFS_DATA; 418 int fd; 419 420 fibril_mutex_lock(&vfs_data->lock); 421 while (list_empty(&vfs_data->passed_handles)) 422 fibril_condvar_wait(&vfs_data->cv, &vfs_data->lock); 423 link_t *lnk = list_first(&vfs_data->passed_handles); 424 list_remove(lnk); 425 fibril_mutex_unlock(&vfs_data->lock); 426 427 vfs_boxed_handle_t *bh = list_get_instance(lnk, vfs_boxed_handle_t, link); 428 fd = bh->handle; 429 free(bh); 430 431 return fd; 305 432 } 306 433 -
uspace/srv/vfs/vfs_lookup.c
rea186c6 r921b84f 201 201 } 202 202 203 /** Perform a node open operation.204 *205 * @return EOK on success or an error code from errno.h.206 *207 */208 int vfs_open_node_internal(vfs_lookup_res_t *result)209 {210 async_exch_t *exch = vfs_exchange_grab(result->triplet.fs_handle);211 212 ipc_call_t answer;213 aid_t req = async_send_2(exch, VFS_OUT_OPEN_NODE,214 (sysarg_t) result->triplet.service_id,215 (sysarg_t) result->triplet.index, &answer);216 217 sysarg_t rc;218 async_wait_for(req, &rc);219 vfs_exchange_release(exch);220 221 if (rc == EOK) {222 result->size =223 MERGE_LOUP32(IPC_GET_ARG1(answer), IPC_GET_ARG2(answer));224 result->lnkcnt = (unsigned int) IPC_GET_ARG3(answer);225 if (IPC_GET_ARG4(answer) & L_FILE)226 result->type = VFS_NODE_FILE;227 else if (IPC_GET_ARG4(answer) & L_DIRECTORY)228 result->type = VFS_NODE_DIRECTORY;229 else230 result->type = VFS_NODE_UNKNOWN;231 }232 233 return rc;234 }235 236 203 /** 237 204 * @} -
uspace/srv/vfs/vfs_node.c
rea186c6 r921b84f 293 293 } 294 294 295 296 /** Perform a remote node open operation. 297 * 298 * @return EOK on success or an error code from errno.h. 299 * 300 */ 301 int vfs_open_node_remote(vfs_node_t *node) 302 { 303 async_exch_t *exch = vfs_exchange_grab(node->fs_handle); 304 305 ipc_call_t answer; 306 aid_t req = async_send_2(exch, VFS_OUT_OPEN_NODE, 307 (sysarg_t) node->service_id, (sysarg_t) node->index, &answer); 308 309 vfs_exchange_release(exch); 310 311 sysarg_t rc; 312 async_wait_for(req, &rc); 313 314 return rc; 315 } 316 295 317 /** 296 318 * @} -
uspace/srv/vfs/vfs_ops.c
rea186c6 r921b84f 618 618 } 619 619 620 void vfs_open_node(ipc_callid_t rid, ipc_call_t *request)621 {622 // FIXME: check for sanity of the supplied fs, dev and index623 624 /*625 * The interface is open_node(fs, dev, index, oflag).626 */627 vfs_lookup_res_t lr;628 629 lr.triplet.fs_handle = IPC_GET_ARG1(*request);630 lr.triplet.service_id = IPC_GET_ARG2(*request);631 lr.triplet.index = IPC_GET_ARG3(*request);632 int oflag = IPC_GET_ARG4(*request);633 634 fibril_rwlock_read_lock(&namespace_rwlock);635 636 int rc = vfs_open_node_internal(&lr);637 if (rc != EOK) {638 fibril_rwlock_read_unlock(&namespace_rwlock);639 async_answer_0(rid, rc);640 return;641 }642 643 vfs_node_t *node = vfs_node_get(&lr);644 fibril_rwlock_read_unlock(&namespace_rwlock);645 646 /* Truncate the file if requested and if necessary. */647 if (oflag & O_TRUNC) {648 fibril_rwlock_write_lock(&node->contents_rwlock);649 if (node->size) {650 rc = vfs_truncate_internal(node->fs_handle,651 node->service_id, node->index, 0);652 if (rc) {653 fibril_rwlock_write_unlock(&node->contents_rwlock);654 vfs_node_put(node);655 async_answer_0(rid, rc);656 return;657 }658 node->size = 0;659 }660 fibril_rwlock_write_unlock(&node->contents_rwlock);661 }662 663 /*664 * Get ourselves a file descriptor and the corresponding vfs_file_t665 * structure.666 */667 int fd = vfs_fd_alloc((oflag & O_DESC) != 0);668 if (fd < 0) {669 vfs_node_put(node);670 async_answer_0(rid, fd);671 return;672 }673 vfs_file_t *file = vfs_file_get(fd);674 file->node = node;675 if (oflag & O_APPEND)676 file->append = true;677 678 /*679 * The following increase in reference count is for the fact that the680 * file is being opened and that a file structure is pointing to it.681 * It is necessary so that the file will not disappear when682 * vfs_node_put() is called. The reference will be dropped by the683 * respective VFS_IN_CLOSE.684 */685 vfs_node_addref(node);686 vfs_node_put(node);687 vfs_file_put(file);688 689 /* Success! Return the new file descriptor to the client. */690 async_answer_1(rid, EOK, fd);691 }692 693 620 void vfs_sync(ipc_callid_t rid, ipc_call_t *request) 694 621 { … … 1349 1276 } 1350 1277 1278 void vfs_wait_handle(ipc_callid_t rid, ipc_call_t *request) 1279 { 1280 int fd = vfs_wait_handle_internal(); 1281 async_answer_1(rid, EOK, fd); 1282 } 1283 1351 1284 /** 1352 1285 * @}
Note:
See TracChangeset
for help on using the changeset viewer.