Changeset ff381a7 in mainline for uspace/lib/c
- Timestamp:
- 2015-11-02T20:54:19Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d8513177
- Parents:
- 3feeab2 (diff), 5265eea4 (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/lib/c
- Files:
-
- 18 added
- 2 deleted
- 62 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/Makefile
r3feeab2 rff381a7 67 67 generic/bd_srv.c \ 68 68 generic/cap.c \ 69 generic/cfg.c \70 69 generic/clipboard.c \ 71 70 generic/corecfg.c \ -
uspace/lib/c/arch/abs32le/include/libarch/stddef.h
r3feeab2 rff381a7 1 1 /* 2 * Copyright (c) 20 12 Frantisek Princ2 * Copyright (c) 2006 Ondrej Palkovsky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup lib ext429 /** @addtogroup libcabs32 30 30 * @{ 31 31 */ 32 33 /** 34 * @file libext4_crc.c 32 /** @file 35 33 */ 36 34 37 #include "libext4.h" 35 #ifndef LIBC_abs32_STDDEF_H_ 36 #define LIBC_abs32_STDDEF_H_ 38 37 39 uint16_t crc16(uint16_t crc, const uint8_t *buffer, size_t len) 40 { 41 // TODO 42 return 0; 43 } 38 #include <libarch/common.h> 44 39 45 /** 46 * @} 40 typedef uint32_t size_t; 41 typedef int32_t ptrdiff_t; 42 43 #endif 44 45 /** @} 47 46 */ -
uspace/lib/c/arch/abs32le/include/libarch/types.h
r3feeab2 rff381a7 36 36 #define LIBC_abs32le_TYPES_H_ 37 37 38 #include <libarch/common.h> 39 #include <libarch/stddef.h> 40 #include <libarch/stdint.h> 41 38 42 #define __32_BITS__ 39 40 #include <libarch/common.h>41 42 #define SIZE_MIN UINT32_MIN43 #define SIZE_MAX UINT32_MAX44 43 45 44 #define SSIZE_MIN INT32_MIN … … 50 49 51 50 typedef int32_t ssize_t; 52 typedef uint32_t size_t;53 51 54 typedef uint32_t uintptr_t;55 typedef int32_t intptr_t;56 52 typedef uint32_t atomic_count_t; 57 53 typedef int32_t atomic_signed_t; -
uspace/lib/c/arch/amd64/include/libarch/types.h
r3feeab2 rff381a7 36 36 #define LIBC_amd64_TYPES_H_ 37 37 38 #include <libarch/common.h> 39 #include <libarch/stddef.h> 40 #include <libarch/stdint.h> 41 38 42 #define __64_BITS__ 39 40 #include <libarch/common.h>41 42 #define SIZE_MIN UINT64_MIN43 #define SIZE_MAX UINT64_MAX44 43 45 44 #define SSIZE_MIN INT64_MIN … … 50 49 51 50 typedef int64_t ssize_t; 52 typedef uint64_t size_t;53 51 54 typedef uint64_t uintptr_t;55 typedef int64_t intptr_t;56 52 typedef uint64_t atomic_count_t; 57 53 typedef int64_t atomic_signed_t; -
uspace/lib/c/arch/arm32/include/libarch/types.h
r3feeab2 rff381a7 37 37 #define LIBC_arm32_TYPES_H_ 38 38 39 #include <libarch/common.h> 40 #include <libarch/stddef.h> 41 #include <libarch/stdint.h> 42 39 43 #define __32_BITS__ 40 41 #include <libarch/common.h>42 43 #define SIZE_MIN UINT32_MIN44 #define SIZE_MAX UINT32_MAX45 44 46 45 #define SSIZE_MIN INT32_MIN … … 51 50 52 51 typedef int32_t ssize_t; 53 typedef uint32_t size_t;54 52 55 typedef uint32_t uintptr_t;56 typedef int32_t intptr_t;57 53 typedef uint32_t atomic_count_t; 58 54 typedef int32_t atomic_signed_t; -
uspace/lib/c/arch/ia32/include/libarch/stddef.h
r3feeab2 rff381a7 1 1 /* 2 * Copyright (c) 20 10 Lenka Trochtova2 * Copyright (c) 2006 Ondrej Palkovsky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup lib drv29 /** @addtogroup libcia32 30 30 * @{ 31 31 */ … … 33 33 */ 34 34 35 #ifndef IPC_DRIVER_H_36 #define IPC_DRIVER_H_35 #ifndef LIBC_ia32_STDDEF_H_ 36 #define LIBC_ia32_STDDEF_H_ 37 37 38 typedef enum { 39 DRIVER_DEVMAN = 1, 40 DRIVER_CLIENT, 41 DRIVER_DRIVER 42 } driver_interface_t; 38 #include <libarch/common.h> 43 39 40 typedef uint32_t size_t; 41 typedef int32_t ptrdiff_t; 44 42 45 43 #endif 46 44 47 48 /** 49 * @} 45 /** @} 50 46 */ -
uspace/lib/c/arch/ia32/include/libarch/types.h
r3feeab2 rff381a7 36 36 #define LIBC_ia32_TYPES_H_ 37 37 38 #include <libarch/common.h> 39 #include <libarch/stddef.h> 40 #include <libarch/stdint.h> 41 38 42 #define __32_BITS__ 39 40 #include <libarch/common.h>41 42 #define SIZE_MIN UINT32_MIN43 #define SIZE_MAX UINT32_MAX44 43 45 44 #define SSIZE_MIN INT32_MIN … … 52 51 typedef uint32_t size_t; 53 52 54 typedef uint32_t uintptr_t;55 typedef int32_t intptr_t;56 53 typedef uint32_t atomic_count_t; 57 54 typedef int32_t atomic_signed_t; -
uspace/lib/c/arch/ia64/include/libarch/stddef.h
r3feeab2 rff381a7 1 1 /* 2 * Copyright (c) 20 12 Frantisek Princ2 * Copyright (c) 2006 Ondrej Palkovsky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup lib ext429 /** @addtogroup libcia64 30 30 * @{ 31 31 */ 32 /** @file 33 */ 32 34 33 #ifndef LIB EXT4_LIBEXT4_CRC_H_34 #define LIB EXT4_LIBEXT4_CRC_H_35 #ifndef LIBC_ia64_STDDEF_H_ 36 #define LIBC_ia64_STDDEF_H_ 35 37 36 extern uint16_t crc16(uint16_t, const uint8_t *, size_t); 38 #include <libarch/common.h> 39 40 typedef uint64_t size_t; 41 typedef int64_t ptrdiff_t; 37 42 38 43 #endif 39 44 40 /** 41 * @} 45 /** @} 42 46 */ -
uspace/lib/c/arch/ia64/include/libarch/types.h
r3feeab2 rff381a7 36 36 #define LIBC_ia64_TYPES_H_ 37 37 38 #include <libarch/common.h> 39 #include <libarch/stddef.h> 40 #include <libarch/stdint.h> 41 38 42 #define __64_BITS__ 39 40 #include <libarch/common.h>41 42 #define SIZE_MIN UINT64_MIN43 #define SIZE_MAX UINT64_MAX44 43 45 44 #define SSIZE_MIN INT64_MIN … … 50 49 51 50 typedef int64_t ssize_t; 52 typedef uint64_t size_t;53 51 54 typedef uint64_t uintptr_t;55 typedef int64_t intptr_t;56 52 typedef uint64_t atomic_count_t; 57 53 typedef int64_t atomic_signed_t; -
uspace/lib/c/arch/mips32/include/libarch/types.h
r3feeab2 rff381a7 37 37 #define LIBC_mips32_TYPES_H_ 38 38 39 #include <libarch/common.h> 40 #include <libarch/stddef.h> 41 #include <libarch/stdint.h> 42 39 43 #define __32_BITS__ 40 41 #include <libarch/common.h>42 43 #define SIZE_MIN UINT32_MIN44 #define SIZE_MAX UINT32_MAX45 44 46 45 #define SSIZE_MIN INT32_MIN … … 51 50 52 51 typedef int32_t ssize_t; 53 typedef uint32_t size_t;54 52 55 typedef uint32_t uintptr_t;56 typedef int32_t intptr_t;57 53 typedef uint32_t atomic_count_t; 58 54 typedef int32_t atomic_signed_t; -
uspace/lib/c/arch/ppc32/include/libarch/types.h
r3feeab2 rff381a7 36 36 #define LIBC_ppc32_TYPES_H_ 37 37 38 #include <libarch/common.h> 39 #include <libarch/stddef.h> 40 #include <libarch/stdint.h> 41 38 42 #define __32_BITS__ 39 40 #include <libarch/common.h>41 42 #define SIZE_MIN UINT32_MIN43 #define SIZE_MAX UINT32_MAX44 43 45 44 #define SSIZE_MIN INT32_MIN … … 50 49 51 50 typedef int32_t ssize_t; 52 typedef uint32_t size_t;53 51 54 typedef uint32_t uintptr_t;55 typedef int32_t intptr_t;56 52 typedef uint32_t atomic_count_t; 57 53 typedef int32_t atomic_signed_t; -
uspace/lib/c/arch/sparc32/include/libarch/types.h
r3feeab2 rff381a7 36 36 #define LIBC_sparc32_TYPES_H_ 37 37 38 #include <libarch/common.h> 39 #include <libarch/stddef.h> 40 #include <libarch/stdint.h> 41 38 42 #define __32_BITS__ 39 40 #include <libarch/common.h>41 42 #define SIZE_MIN UINT32_MIN43 #define SIZE_MAX UINT32_MAX44 43 45 44 #define SSIZE_MIN INT32_MIN … … 50 49 51 50 typedef int32_t ssize_t; 52 typedef uint32_t size_t;53 51 54 typedef uint32_t uintptr_t;55 typedef int32_t intptr_t;56 52 typedef uint32_t atomic_count_t; 57 53 typedef int32_t atomic_signed_t; -
uspace/lib/c/arch/sparc64/include/libarch/types.h
r3feeab2 rff381a7 36 36 #define LIBC_sparc64_TYPES_H_ 37 37 38 #include <libarch/common.h> 39 #include <libarch/stddef.h> 40 #include <libarch/stdint.h> 41 38 42 #define __64_BITS__ 39 40 #include <libarch/common.h>41 42 #define SIZE_MIN UINT64_MIN43 #define SIZE_MAX UINT64_MAX44 43 45 44 #define SSIZE_MIN INT64_MIN … … 50 49 51 50 typedef int64_t ssize_t; 52 typedef uint64_t size_t;53 51 54 typedef uint64_t uintptr_t;55 typedef int64_t intptr_t;56 52 typedef uint64_t atomic_count_t; 57 53 typedef int64_t atomic_signed_t; -
uspace/lib/c/generic/adt/list.c
r3feeab2 rff381a7 53 53 * 54 54 */ 55 intlist_member(const link_t *link, const list_t *list)55 bool list_member(const link_t *link, const list_t *list) 56 56 { 57 57 bool found = false; … … 98 98 * @return Number of items in the list. 99 99 */ 100 unsigned intlist_count(const list_t *list)100 unsigned long list_count(const list_t *list) 101 101 { 102 unsigned intcount = 0;102 unsigned long count = 0; 103 103 104 104 link_t *link = list_first(list); -
uspace/lib/c/generic/async.c
r3feeab2 rff381a7 77 77 * } 78 78 * 79 * my_client_connection(icallid, *icall)79 * port_handler(icallid, *icall) 80 80 * { 81 81 * if (want_refuse) { … … 123 123 list_t exch_list; 124 124 125 /** Session interface */ 126 iface_t iface; 127 125 128 /** Exchange management style */ 126 129 exch_mgmt_t mgmt; … … 189 192 /** If reply was received. */ 190 193 bool done; 191 194 192 195 /** If the message / reply should be discarded on arrival. */ 193 196 bool forget; 194 197 195 198 /** If already destroyed. */ 196 199 bool destroyed; … … 232 235 /** Identification of the opening call. */ 233 236 ipc_callid_t callid; 237 234 238 /** Call data of the opening call. */ 235 239 ipc_call_t call; 236 /** Local argument or NULL if none. */237 void *carg;238 240 239 241 /** Identification of the closing call. */ … … 241 243 242 244 /** Fibril function that will be used to handle the connection. */ 243 async_client_conn_t cfibril; 245 async_port_handler_t handler; 246 247 /** Client data */ 248 void *data; 244 249 } connection_t; 250 251 /** Interface data */ 252 typedef struct { 253 ht_link_t link; 254 255 /** Interface ID */ 256 iface_t iface; 257 258 /** Futex protecting the hash table */ 259 futex_t futex; 260 261 /** Interface ports */ 262 hash_table_t port_hash_table; 263 264 /** Next available port ID */ 265 port_id_t port_id_avail; 266 } interface_t; 267 268 /* Port data */ 269 typedef struct { 270 ht_link_t link; 271 272 /** Port ID */ 273 port_id_t id; 274 275 /** Port connection handler */ 276 async_port_handler_t handler; 277 278 /** Client data */ 279 void *data; 280 } port_t; 245 281 246 282 /* Notification data */ … … 264 300 { 265 301 struct timeval tv = { 0, 0 }; 266 302 267 303 to->inlist = false; 268 304 to->occurred = false; … … 287 323 static amsg_t *amsg_create(void) 288 324 { 289 amsg_t *msg; 290 291 msg = malloc(sizeof(amsg_t)); 325 amsg_t *msg = malloc(sizeof(amsg_t)); 292 326 if (msg) { 293 327 msg->done = false; … … 298 332 awaiter_initialize(&msg->wdata); 299 333 } 300 334 301 335 return msg; 302 336 } … … 335 369 } 336 370 337 /** Default fibril function that gets called to handle new connection. 338 * 339 * This function is defined as a weak symbol - to be redefined in user code. 371 /** Default fallback fibril function. 372 * 373 * This fallback fibril function gets called on incomming 374 * connections that do not have a specific handler defined. 340 375 * 341 376 * @param callid Hash of the incoming call. … … 344 379 * 345 380 */ 346 static void default_ client_connection(ipc_callid_t callid, ipc_call_t *call,381 static void default_fallback_port_handler(ipc_callid_t callid, ipc_call_t *call, 347 382 void *arg) 348 383 { … … 350 385 } 351 386 352 static async_client_conn_t client_connection = default_client_connection; 387 static async_port_handler_t fallback_port_handler = 388 default_fallback_port_handler; 389 static void *fallback_port_data = NULL; 390 391 static hash_table_t interface_hash_table; 392 393 static size_t interface_key_hash(void *key) 394 { 395 iface_t iface = *(iface_t *) key; 396 return iface; 397 } 398 399 static size_t interface_hash(const ht_link_t *item) 400 { 401 interface_t *interface = hash_table_get_inst(item, interface_t, link); 402 return interface_key_hash(&interface->iface); 403 } 404 405 static bool interface_key_equal(void *key, const ht_link_t *item) 406 { 407 iface_t iface = *(iface_t *) key; 408 interface_t *interface = hash_table_get_inst(item, interface_t, link); 409 return iface == interface->iface; 410 } 411 412 /** Operations for the port hash table. */ 413 static hash_table_ops_t interface_hash_table_ops = { 414 .hash = interface_hash, 415 .key_hash = interface_key_hash, 416 .key_equal = interface_key_equal, 417 .equal = NULL, 418 .remove_callback = NULL 419 }; 420 421 static size_t port_key_hash(void *key) 422 { 423 port_id_t port_id = *(port_id_t *) key; 424 return port_id; 425 } 426 427 static size_t port_hash(const ht_link_t *item) 428 { 429 port_t *port = hash_table_get_inst(item, port_t, link); 430 return port_key_hash(&port->id); 431 } 432 433 static bool port_key_equal(void *key, const ht_link_t *item) 434 { 435 port_id_t port_id = *(port_id_t *) key; 436 port_t *port = hash_table_get_inst(item, port_t, link); 437 return port_id == port->id; 438 } 439 440 /** Operations for the port hash table. */ 441 static hash_table_ops_t port_hash_table_ops = { 442 .hash = port_hash, 443 .key_hash = port_key_hash, 444 .key_equal = port_key_equal, 445 .equal = NULL, 446 .remove_callback = NULL 447 }; 448 449 static interface_t *async_new_interface(iface_t iface) 450 { 451 interface_t *interface = 452 (interface_t *) malloc(sizeof(interface_t)); 453 if (!interface) 454 return NULL; 455 456 bool ret = hash_table_create(&interface->port_hash_table, 0, 0, 457 &port_hash_table_ops); 458 if (!ret) { 459 free(interface); 460 return NULL; 461 } 462 463 interface->iface = iface; 464 futex_initialize(&interface->futex, 1); 465 interface->port_id_avail = 0; 466 467 hash_table_insert(&interface_hash_table, &interface->link); 468 469 return interface; 470 } 471 472 static port_t *async_new_port(interface_t *interface, 473 async_port_handler_t handler, void *data) 474 { 475 port_t *port = (port_t *) malloc(sizeof(port_t)); 476 if (!port) 477 return NULL; 478 479 futex_down(&interface->futex); 480 481 port_id_t id = interface->port_id_avail; 482 interface->port_id_avail++; 483 484 port->id = id; 485 port->handler = handler; 486 port->data = data; 487 488 hash_table_insert(&interface->port_hash_table, &port->link); 489 490 futex_up(&interface->futex); 491 492 return port; 493 } 494 353 495 static size_t notification_handler_stksz = FIBRIL_DFLT_STK_SIZE; 354 496 355 /** Setter for client_connection function pointer.356 *357 * @param conn Function that will implement a new connection fibril.358 *359 */360 void async_set_client_connection(async_client_conn_t conn)361 {362 assert(client_connection == default_client_connection);363 client_connection = conn;364 }365 366 497 /** Set the stack size for the notification handler notification fibrils. 367 498 * … … 387 518 */ 388 519 static FIBRIL_CONDVAR_INITIALIZE(avail_phone_cv); 520 521 int async_create_port(iface_t iface, async_port_handler_t handler, 522 void *data, port_id_t *port_id) 523 { 524 if ((iface & IFACE_MOD_MASK) == IFACE_MOD_CALLBACK) 525 return EINVAL; 526 527 interface_t *interface; 528 529 futex_down(&async_futex); 530 531 ht_link_t *link = hash_table_find(&interface_hash_table, &iface); 532 if (link) 533 interface = hash_table_get_inst(link, interface_t, link); 534 else 535 interface = async_new_interface(iface); 536 537 if (!interface) { 538 futex_up(&async_futex); 539 return ENOMEM; 540 } 541 542 port_t *port = async_new_port(interface, handler, data); 543 if (!port) { 544 futex_up(&async_futex); 545 return ENOMEM; 546 } 547 548 *port_id = port->id; 549 550 futex_up(&async_futex); 551 552 return EOK; 553 } 554 555 void async_set_fallback_port_handler(async_port_handler_t handler, void *data) 556 { 557 assert(handler != NULL); 558 559 fallback_port_handler = handler; 560 fallback_port_data = data; 561 } 389 562 390 563 static hash_table_t client_hash_table; … … 457 630 .remove_callback = NULL 458 631 }; 632 633 static client_t *async_client_get(task_id_t client_id, bool create) 634 { 635 client_t *client = NULL; 636 637 futex_down(&async_futex); 638 ht_link_t *link = hash_table_find(&client_hash_table, &client_id); 639 if (link) { 640 client = hash_table_get_inst(link, client_t, link); 641 atomic_inc(&client->refcnt); 642 } else if (create) { 643 client = malloc(sizeof(client_t)); 644 if (client) { 645 client->in_task_id = client_id; 646 client->data = async_client_data_create(); 647 648 atomic_set(&client->refcnt, 1); 649 hash_table_insert(&client_hash_table, &client->link); 650 } 651 } 652 653 futex_up(&async_futex); 654 return client; 655 } 656 657 static void async_client_put(client_t *client) 658 { 659 bool destroy; 660 661 futex_down(&async_futex); 662 663 if (atomic_predec(&client->refcnt) == 0) { 664 hash_table_remove(&client_hash_table, &client->in_task_id); 665 destroy = true; 666 } else 667 destroy = false; 668 669 futex_up(&async_futex); 670 671 if (destroy) { 672 if (client->data) 673 async_client_data_destroy(client->data); 674 675 free(client); 676 } 677 } 678 679 /** Wrapper for client connection fibril. 680 * 681 * When a new connection arrives, a fibril with this implementing 682 * function is created. 683 * 684 * @param arg Connection structure pointer. 685 * 686 * @return Always zero. 687 * 688 */ 689 static int connection_fibril(void *arg) 690 { 691 assert(arg); 692 693 /* 694 * Setup fibril-local connection pointer. 695 */ 696 fibril_connection = (connection_t *) arg; 697 698 /* 699 * Add our reference for the current connection in the client task 700 * tracking structure. If this is the first reference, create and 701 * hash in a new tracking structure. 702 */ 703 704 client_t *client = async_client_get(fibril_connection->in_task_id, true); 705 if (!client) { 706 ipc_answer_0(fibril_connection->callid, ENOMEM); 707 return 0; 708 } 709 710 fibril_connection->client = client; 711 712 /* 713 * Call the connection handler function. 714 */ 715 fibril_connection->handler(fibril_connection->callid, 716 &fibril_connection->call, fibril_connection->data); 717 718 /* 719 * Remove the reference for this client task connection. 720 */ 721 async_client_put(client); 722 723 /* 724 * Remove myself from the connection hash table. 725 */ 726 futex_down(&async_futex); 727 hash_table_remove(&conn_hash_table, &fibril_connection->in_phone_hash); 728 futex_up(&async_futex); 729 730 /* 731 * Answer all remaining messages with EHANGUP. 732 */ 733 while (!list_empty(&fibril_connection->msg_queue)) { 734 msg_t *msg = 735 list_get_instance(list_first(&fibril_connection->msg_queue), 736 msg_t, link); 737 738 list_remove(&msg->link); 739 ipc_answer_0(msg->callid, EHANGUP); 740 free(msg); 741 } 742 743 /* 744 * If the connection was hung-up, answer the last call, 745 * i.e. IPC_M_PHONE_HUNGUP. 746 */ 747 if (fibril_connection->close_callid) 748 ipc_answer_0(fibril_connection->close_callid, EOK); 749 750 free(fibril_connection); 751 return 0; 752 } 753 754 /** Create a new fibril for a new connection. 755 * 756 * Create new fibril for connection, fill in connection structures 757 * and insert it into the hash table, so that later we can easily 758 * do routing of messages to particular fibrils. 759 * 760 * @param in_task_id Identification of the incoming connection. 761 * @param in_phone_hash Identification of the incoming connection. 762 * @param callid Hash of the opening IPC_M_CONNECT_ME_TO call. 763 * If callid is zero, the connection was opened by 764 * accepting the IPC_M_CONNECT_TO_ME call and this 765 * function is called directly by the server. 766 * @param call Call data of the opening call. 767 * @param handler Connection handler. 768 * @param data Client argument to pass to the connection handler. 769 * 770 * @return New fibril id or NULL on failure. 771 * 772 */ 773 static fid_t async_new_connection(task_id_t in_task_id, sysarg_t in_phone_hash, 774 ipc_callid_t callid, ipc_call_t *call, async_port_handler_t handler, 775 void *data) 776 { 777 connection_t *conn = malloc(sizeof(*conn)); 778 if (!conn) { 779 if (callid) 780 ipc_answer_0(callid, ENOMEM); 781 782 return (uintptr_t) NULL; 783 } 784 785 conn->in_task_id = in_task_id; 786 conn->in_phone_hash = in_phone_hash; 787 list_initialize(&conn->msg_queue); 788 conn->callid = callid; 789 conn->close_callid = 0; 790 conn->handler = handler; 791 conn->data = data; 792 793 if (call) 794 conn->call = *call; 795 796 /* We will activate the fibril ASAP */ 797 conn->wdata.active = true; 798 conn->wdata.fid = fibril_create(connection_fibril, conn); 799 800 if (conn->wdata.fid == 0) { 801 free(conn); 802 803 if (callid) 804 ipc_answer_0(callid, ENOMEM); 805 806 return (uintptr_t) NULL; 807 } 808 809 /* Add connection to the connection hash table */ 810 811 futex_down(&async_futex); 812 hash_table_insert(&conn_hash_table, &conn->link); 813 futex_up(&async_futex); 814 815 fibril_add_ready(conn->wdata.fid); 816 817 return conn->wdata.fid; 818 } 819 820 /** Wrapper for making IPC_M_CONNECT_TO_ME calls using the async framework. 821 * 822 * Ask through phone for a new connection to some service. 823 * 824 * @param exch Exchange for sending the message. 825 * @param iface Callback interface. 826 * @param arg1 User defined argument. 827 * @param arg2 User defined argument. 828 * @param handler Callback handler. 829 * @param data Handler data. 830 * @param port_id ID of the newly created port. 831 * 832 * @return Zero on success or a negative error code. 833 * 834 */ 835 int async_create_callback_port(async_exch_t *exch, iface_t iface, sysarg_t arg1, 836 sysarg_t arg2, async_port_handler_t handler, void *data, port_id_t *port_id) 837 { 838 if ((iface & IFACE_MOD_CALLBACK) != IFACE_MOD_CALLBACK) 839 return EINVAL; 840 841 if (exch == NULL) 842 return ENOENT; 843 844 ipc_call_t answer; 845 aid_t req = async_send_3(exch, IPC_M_CONNECT_TO_ME, iface, arg1, arg2, 846 &answer); 847 848 sysarg_t ret; 849 async_wait_for(req, &ret); 850 if (ret != EOK) 851 return (int) ret; 852 853 sysarg_t phone_hash = IPC_GET_ARG5(answer); 854 interface_t *interface; 855 856 futex_down(&async_futex); 857 858 ht_link_t *link = hash_table_find(&interface_hash_table, &iface); 859 if (link) 860 interface = hash_table_get_inst(link, interface_t, link); 861 else 862 interface = async_new_interface(iface); 863 864 if (!interface) { 865 futex_up(&async_futex); 866 return ENOMEM; 867 } 868 869 port_t *port = async_new_port(interface, handler, data); 870 if (!port) { 871 futex_up(&async_futex); 872 return ENOMEM; 873 } 874 875 *port_id = port->id; 876 877 futex_up(&async_futex); 878 879 fid_t fid = async_new_connection(answer.in_task_id, phone_hash, 880 0, NULL, handler, data); 881 if (fid == (uintptr_t) NULL) 882 return ENOMEM; 883 884 return EOK; 885 } 459 886 460 887 static size_t notification_key_hash(void *key) … … 866 1293 } 867 1294 868 msg_t *msg = list_get_instance(list_first(&conn->msg_queue), msg_t, link); 1295 msg_t *msg = list_get_instance(list_first(&conn->msg_queue), 1296 msg_t, link); 869 1297 list_remove(&msg->link); 870 1298 … … 877 1305 } 878 1306 879 static client_t *async_client_get(task_id_t client_id, bool create)880 {881 client_t *client = NULL;882 883 futex_down(&async_futex);884 ht_link_t *link = hash_table_find(&client_hash_table, &client_id);885 if (link) {886 client = hash_table_get_inst(link, client_t, link);887 atomic_inc(&client->refcnt);888 } else if (create) {889 client = malloc(sizeof(client_t));890 if (client) {891 client->in_task_id = client_id;892 client->data = async_client_data_create();893 894 atomic_set(&client->refcnt, 1);895 hash_table_insert(&client_hash_table, &client->link);896 }897 }898 899 futex_up(&async_futex);900 return client;901 }902 903 static void async_client_put(client_t *client)904 {905 bool destroy;906 907 futex_down(&async_futex);908 909 if (atomic_predec(&client->refcnt) == 0) {910 hash_table_remove(&client_hash_table, &client->in_task_id);911 destroy = true;912 } else913 destroy = false;914 915 futex_up(&async_futex);916 917 if (destroy) {918 if (client->data)919 async_client_data_destroy(client->data);920 921 free(client);922 }923 }924 925 1307 void *async_get_client_data(void) 926 1308 { … … 934 1316 if (!client) 935 1317 return NULL; 1318 936 1319 if (!client->data) { 937 1320 async_client_put(client); 938 1321 return NULL; 939 1322 } 940 1323 941 1324 return client->data; 942 1325 } … … 945 1328 { 946 1329 client_t *client = async_client_get(client_id, false); 947 1330 948 1331 assert(client); 949 1332 assert(client->data); 950 1333 951 1334 /* Drop the reference we got in async_get_client_data_by_hash(). */ 952 1335 async_client_put(client); 953 1336 954 1337 /* Drop our own reference we got at the beginning of this function. */ 955 1338 async_client_put(client); 956 1339 } 957 1340 958 /** Wrapper for client connection fibril. 959 * 960 * When a new connection arrives, a fibril with this implementing function is 961 * created. It calls client_connection() and does the final cleanup. 962 * 963 * @param arg Connection structure pointer. 964 * 965 * @return Always zero. 966 * 967 */ 968 static int connection_fibril(void *arg) 969 { 970 assert(arg); 971 972 /* 973 * Setup fibril-local connection pointer. 974 */ 975 fibril_connection = (connection_t *) arg; 976 977 /* 978 * Add our reference for the current connection in the client task 979 * tracking structure. If this is the first reference, create and 980 * hash in a new tracking structure. 981 */ 982 983 client_t *client = async_client_get(fibril_connection->in_task_id, true); 984 if (!client) { 985 ipc_answer_0(fibril_connection->callid, ENOMEM); 986 return 0; 987 } 988 989 fibril_connection->client = client; 990 991 /* 992 * Call the connection handler function. 993 */ 994 fibril_connection->cfibril(fibril_connection->callid, 995 &fibril_connection->call, fibril_connection->carg); 996 997 /* 998 * Remove the reference for this client task connection. 999 */ 1000 async_client_put(client); 1001 1002 /* 1003 * Remove myself from the connection hash table. 1004 */ 1341 static port_t *async_find_port(iface_t iface, port_id_t port_id) 1342 { 1343 port_t *port = NULL; 1344 1005 1345 futex_down(&async_futex); 1006 hash_table_remove(&conn_hash_table, &fibril_connection->in_phone_hash); 1346 1347 ht_link_t *link = hash_table_find(&interface_hash_table, &iface); 1348 if (link) { 1349 interface_t *interface = 1350 hash_table_get_inst(link, interface_t, link); 1351 1352 link = hash_table_find(&interface->port_hash_table, &port_id); 1353 if (link) 1354 port = hash_table_get_inst(link, port_t, link); 1355 } 1356 1007 1357 futex_up(&async_futex); 1008 1358 1009 /* 1010 * Answer all remaining messages with EHANGUP. 1011 */ 1012 while (!list_empty(&fibril_connection->msg_queue)) { 1013 msg_t *msg = 1014 list_get_instance(list_first(&fibril_connection->msg_queue), 1015 msg_t, link); 1016 1017 list_remove(&msg->link); 1018 ipc_answer_0(msg->callid, EHANGUP); 1019 free(msg); 1020 } 1021 1022 /* 1023 * If the connection was hung-up, answer the last call, 1024 * i.e. IPC_M_PHONE_HUNGUP. 1025 */ 1026 if (fibril_connection->close_callid) 1027 ipc_answer_0(fibril_connection->close_callid, EOK); 1028 1029 free(fibril_connection); 1030 return 0; 1031 } 1032 1033 /** Create a new fibril for a new connection. 1034 * 1035 * Create new fibril for connection, fill in connection structures and insert 1036 * it into the hash table, so that later we can easily do routing of messages to 1037 * particular fibrils. 1038 * 1039 * @param in_task_id Identification of the incoming connection. 1040 * @param in_phone_hash Identification of the incoming connection. 1041 * @param callid Hash of the opening IPC_M_CONNECT_ME_TO call. 1042 * If callid is zero, the connection was opened by 1043 * accepting the IPC_M_CONNECT_TO_ME call and this function 1044 * is called directly by the server. 1045 * @param call Call data of the opening call. 1046 * @param cfibril Fibril function that should be called upon opening the 1047 * connection. 1048 * @param carg Extra argument to pass to the connection fibril 1049 * 1050 * @return New fibril id or NULL on failure. 1051 * 1052 */ 1053 fid_t async_new_connection(task_id_t in_task_id, sysarg_t in_phone_hash, 1054 ipc_callid_t callid, ipc_call_t *call, 1055 async_client_conn_t cfibril, void *carg) 1056 { 1057 connection_t *conn = malloc(sizeof(*conn)); 1058 if (!conn) { 1059 if (callid) 1060 ipc_answer_0(callid, ENOMEM); 1061 1062 return (uintptr_t) NULL; 1063 } 1064 1065 conn->in_task_id = in_task_id; 1066 conn->in_phone_hash = in_phone_hash; 1067 list_initialize(&conn->msg_queue); 1068 conn->callid = callid; 1069 conn->close_callid = 0; 1070 conn->carg = carg; 1071 1072 if (call) 1073 conn->call = *call; 1074 1075 /* We will activate the fibril ASAP */ 1076 conn->wdata.active = true; 1077 conn->cfibril = cfibril; 1078 conn->wdata.fid = fibril_create(connection_fibril, conn); 1079 1080 if (conn->wdata.fid == 0) { 1081 free(conn); 1082 1083 if (callid) 1084 ipc_answer_0(callid, ENOMEM); 1085 1086 return (uintptr_t) NULL; 1087 } 1088 1089 /* Add connection to the connection hash table */ 1090 1091 futex_down(&async_futex); 1092 hash_table_insert(&conn_hash_table, &conn->link); 1093 futex_up(&async_futex); 1094 1095 fibril_add_ready(conn->wdata.fid); 1096 1097 return conn->wdata.fid; 1359 return port; 1098 1360 } 1099 1361 … … 1111 1373 assert(call); 1112 1374 1113 /* Unrouted call - take some default action */1375 /* Kernel notification */ 1114 1376 if ((callid & IPC_CALLID_NOTIFICATION)) { 1115 1377 process_notification(callid, call); … … 1117 1379 } 1118 1380 1119 switch (IPC_GET_IMETHOD(*call)) { 1120 case IPC_M_CLONE_ESTABLISH: 1121 case IPC_M_CONNECT_ME_TO: 1381 /* New connection */ 1382 if (IPC_GET_IMETHOD(*call) == IPC_M_CONNECT_ME_TO) { 1383 iface_t iface = (iface_t) IPC_GET_ARG1(*call); 1384 sysarg_t in_phone_hash = IPC_GET_ARG5(*call); 1385 1386 async_notification_handler_t handler = fallback_port_handler; 1387 void *data = fallback_port_data; 1388 1389 // TODO: Currently ignores all ports but the first one 1390 port_t *port = async_find_port(iface, 0); 1391 if (port) { 1392 handler = port->handler; 1393 data = port->data; 1394 } 1395 1396 async_new_connection(call->in_task_id, in_phone_hash, callid, 1397 call, handler, data); 1398 return; 1399 } 1400 1401 /* Cloned connection */ 1402 if (IPC_GET_IMETHOD(*call) == IPC_M_CLONE_ESTABLISH) { 1403 // TODO: Currently ignores ports altogether 1404 1122 1405 /* Open new connection with fibril, etc. */ 1123 1406 async_new_connection(call->in_task_id, IPC_GET_ARG5(*call), 1124 callid, call, client_connection, NULL);1407 callid, call, fallback_port_handler, fallback_port_data); 1125 1408 return; 1126 1409 } … … 1283 1566 void __async_init(void) 1284 1567 { 1568 if (!hash_table_create(&interface_hash_table, 0, 0, 1569 &interface_hash_table_ops)) 1570 abort(); 1571 1285 1572 if (!hash_table_create(&client_hash_table, 0, 0, &client_hash_table_ops)) 1286 1573 abort(); … … 1297 1584 abort(); 1298 1585 1586 session_ns->iface = 0; 1299 1587 session_ns->mgmt = EXCHANGE_ATOMIC; 1300 1588 session_ns->phone = PHONE_NS; … … 1343 1631 1344 1632 msg->done = true; 1345 1633 1346 1634 if (msg->forget) { 1347 1635 assert(msg->wdata.active); … … 1351 1639 fibril_add_ready(msg->wdata.fid); 1352 1640 } 1353 1641 1354 1642 futex_up(&async_futex); 1355 1643 } … … 1443 1731 1444 1732 futex_down(&async_futex); 1445 1733 1446 1734 assert(!msg->forget); 1447 1735 assert(!msg->destroyed); 1448 1736 1449 1737 if (msg->done) { 1450 1738 futex_up(&async_futex); … … 1487 1775 1488 1776 amsg_t *msg = (amsg_t *) amsgid; 1489 1777 1490 1778 futex_down(&async_futex); 1491 1779 1492 1780 assert(!msg->forget); 1493 1781 assert(!msg->destroyed); 1494 1782 1495 1783 if (msg->done) { 1496 1784 futex_up(&async_futex); … … 1504 1792 if (timeout < 0) 1505 1793 timeout = 0; 1506 1794 1507 1795 getuptime(&msg->wdata.to_event.expires); 1508 1796 tv_add_diff(&msg->wdata.to_event.expires, timeout); … … 1557 1845 { 1558 1846 amsg_t *msg = (amsg_t *) amsgid; 1559 1847 1560 1848 assert(msg); 1561 1849 assert(!msg->forget); 1562 1850 assert(!msg->destroyed); 1563 1851 1564 1852 futex_down(&async_futex); 1853 1565 1854 if (msg->done) { 1566 1855 amsg_destroy(msg); … … 1569 1858 msg->forget = true; 1570 1859 } 1860 1571 1861 futex_up(&async_futex); 1572 1862 } … … 1814 2104 * @param arg2 User defined argument. 1815 2105 * @param arg3 User defined argument. 1816 * @param client_receiver Connection handing routine.1817 2106 * 1818 2107 * @return Zero on success or a negative error code. … … 1820 2109 */ 1821 2110 int async_connect_to_me(async_exch_t *exch, sysarg_t arg1, sysarg_t arg2, 1822 sysarg_t arg3 , async_client_conn_t client_receiver, void *carg)2111 sysarg_t arg3) 1823 2112 { 1824 2113 if (exch == NULL) 1825 2114 return ENOENT; 1826 2115 1827 sysarg_t phone_hash; 2116 ipc_call_t answer; 2117 aid_t req = async_send_3(exch, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3, 2118 &answer); 2119 1828 2120 sysarg_t rc; 1829 1830 aid_t req;1831 ipc_call_t answer;1832 req = async_send_3(exch, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3,1833 &answer);1834 2121 async_wait_for(req, &rc); 1835 2122 if (rc != EOK) 1836 2123 return (int) rc; 1837 1838 phone_hash = IPC_GET_ARG5(answer);1839 1840 if (client_receiver != NULL)1841 async_new_connection(answer.in_task_id, phone_hash, 0, NULL,1842 client_receiver, carg);1843 2124 1844 2125 return EOK; … … 1900 2181 } 1901 2182 2183 sess->iface = 0; 1902 2184 sess->mgmt = mgmt; 1903 2185 sess->phone = phone; … … 1969 2251 int phone = async_connect_me_to_internal(exch->phone, arg1, arg2, arg3, 1970 2252 0); 1971 1972 2253 if (phone < 0) { 1973 2254 errno = phone; … … 1976 2257 } 1977 2258 2259 sess->iface = 0; 1978 2260 sess->mgmt = mgmt; 1979 2261 sess->phone = phone; … … 1992 2274 } 1993 2275 2276 /** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework. 2277 * 2278 * Ask through phone for a new connection to some service and block until 2279 * success. 2280 * 2281 * @param exch Exchange for sending the message. 2282 * @param iface Connection interface. 2283 * @param arg2 User defined argument. 2284 * @param arg3 User defined argument. 2285 * 2286 * @return New session on success or NULL on error. 2287 * 2288 */ 2289 async_sess_t *async_connect_me_to_iface(async_exch_t *exch, iface_t iface, 2290 sysarg_t arg2, sysarg_t arg3) 2291 { 2292 if (exch == NULL) { 2293 errno = ENOENT; 2294 return NULL; 2295 } 2296 2297 async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t)); 2298 if (sess == NULL) { 2299 errno = ENOMEM; 2300 return NULL; 2301 } 2302 2303 int phone = async_connect_me_to_internal(exch->phone, iface, arg2, 2304 arg3, 0); 2305 if (phone < 0) { 2306 errno = phone; 2307 free(sess); 2308 return NULL; 2309 } 2310 2311 sess->iface = iface; 2312 sess->phone = phone; 2313 sess->arg1 = iface; 2314 sess->arg2 = arg2; 2315 sess->arg3 = arg3; 2316 2317 fibril_mutex_initialize(&sess->remote_state_mtx); 2318 sess->remote_state_data = NULL; 2319 2320 list_initialize(&sess->exch_list); 2321 fibril_mutex_initialize(&sess->mutex); 2322 atomic_set(&sess->refcnt, 0); 2323 2324 return sess; 2325 } 2326 1994 2327 /** Set arguments for new connections. 1995 2328 * … … 2047 2380 } 2048 2381 2382 sess->iface = 0; 2049 2383 sess->mgmt = mgmt; 2050 2384 sess->phone = phone; … … 2063 2397 } 2064 2398 2399 /** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework. 2400 * 2401 * Ask through phone for a new connection to some service and block until 2402 * success. 2403 * 2404 * @param exch Exchange for sending the message. 2405 * @param iface Connection interface. 2406 * @param arg2 User defined argument. 2407 * @param arg3 User defined argument. 2408 * 2409 * @return New session on success or NULL on error. 2410 * 2411 */ 2412 async_sess_t *async_connect_me_to_blocking_iface(async_exch_t *exch, iface_t iface, 2413 sysarg_t arg2, sysarg_t arg3) 2414 { 2415 if (exch == NULL) { 2416 errno = ENOENT; 2417 return NULL; 2418 } 2419 2420 async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t)); 2421 if (sess == NULL) { 2422 errno = ENOMEM; 2423 return NULL; 2424 } 2425 2426 int phone = async_connect_me_to_internal(exch->phone, iface, arg2, 2427 arg3, IPC_FLAG_BLOCKING); 2428 if (phone < 0) { 2429 errno = phone; 2430 free(sess); 2431 return NULL; 2432 } 2433 2434 sess->iface = iface; 2435 sess->phone = phone; 2436 sess->arg1 = iface; 2437 sess->arg2 = arg2; 2438 sess->arg3 = arg3; 2439 2440 fibril_mutex_initialize(&sess->remote_state_mtx); 2441 sess->remote_state_data = NULL; 2442 2443 list_initialize(&sess->exch_list); 2444 fibril_mutex_initialize(&sess->mutex); 2445 atomic_set(&sess->refcnt, 0); 2446 2447 return sess; 2448 } 2449 2065 2450 /** Connect to a task specified by id. 2066 2451 * … … 2081 2466 } 2082 2467 2468 sess->iface = 0; 2083 2469 sess->mgmt = EXCHANGE_ATOMIC; 2084 2470 sess->phone = phone; … … 2158 2544 return NULL; 2159 2545 2160 async_exch_t *exch; 2546 exch_mgmt_t mgmt = sess->mgmt; 2547 if (sess->iface != 0) 2548 mgmt = sess->iface & IFACE_EXCHANGE_MASK; 2549 2550 async_exch_t *exch = NULL; 2161 2551 2162 2552 fibril_mutex_lock(&async_sess_mutex); … … 2177 2567 */ 2178 2568 2179 if (( sess->mgmt == EXCHANGE_ATOMIC) ||2180 ( sess->mgmt == EXCHANGE_SERIALIZE)) {2569 if ((mgmt == EXCHANGE_ATOMIC) || 2570 (mgmt == EXCHANGE_SERIALIZE)) { 2181 2571 exch = (async_exch_t *) malloc(sizeof(async_exch_t)); 2182 2572 if (exch != NULL) { … … 2186 2576 exch->phone = sess->phone; 2187 2577 } 2188 } else { /* EXCHANGE_PARALLEL */ 2578 } else if (mgmt == EXCHANGE_PARALLEL) { 2579 int phone; 2580 2581 retry: 2189 2582 /* 2190 2583 * Make a one-time attempt to connect a new data phone. 2191 2584 */ 2192 2193 int phone;2194 2195 retry:2196 2585 phone = async_connect_me_to_internal(sess->phone, sess->arg1, 2197 2586 sess->arg2, sess->arg3, 0); … … 2235 2624 atomic_inc(&sess->refcnt); 2236 2625 2237 if ( sess->mgmt == EXCHANGE_SERIALIZE)2626 if (mgmt == EXCHANGE_SERIALIZE) 2238 2627 fibril_mutex_lock(&sess->mutex); 2239 2628 } … … 2255 2644 assert(sess != NULL); 2256 2645 2646 exch_mgmt_t mgmt = sess->mgmt; 2647 if (sess->iface != 0) 2648 mgmt = sess->iface & IFACE_EXCHANGE_MASK; 2649 2257 2650 atomic_dec(&sess->refcnt); 2258 2651 2259 if ( sess->mgmt == EXCHANGE_SERIALIZE)2652 if (mgmt == EXCHANGE_SERIALIZE) 2260 2653 fibril_mutex_unlock(&sess->mutex); 2261 2654 … … 2694 3087 } 2695 3088 2696 void * _data;3089 void *arg_data; 2697 3090 2698 3091 if (nullterm) 2699 _data = malloc(size + 1);3092 arg_data = malloc(size + 1); 2700 3093 else 2701 _data = malloc(size);2702 2703 if ( _data == NULL) {3094 arg_data = malloc(size); 3095 3096 if (arg_data == NULL) { 2704 3097 ipc_answer_0(callid, ENOMEM); 2705 3098 return ENOMEM; 2706 3099 } 2707 3100 2708 int rc = async_data_write_finalize(callid, _data, size);3101 int rc = async_data_write_finalize(callid, arg_data, size); 2709 3102 if (rc != EOK) { 2710 free( _data);3103 free(arg_data); 2711 3104 return rc; 2712 3105 } 2713 3106 2714 3107 if (nullterm) 2715 ((char *) _data)[size] = 0;2716 2717 *data = _data;3108 ((char *) arg_data)[size] = 0; 3109 3110 *data = arg_data; 2718 3111 if (received != NULL) 2719 3112 *received = size; … … 2813 3206 } 2814 3207 3208 sess->iface = 0; 2815 3209 sess->mgmt = mgmt; 2816 3210 sess->phone = phone; … … 2862 3256 } 2863 3257 3258 sess->iface = 0; 2864 3259 sess->mgmt = mgmt; 2865 3260 sess->phone = phone; … … 2907 3302 return NULL; 2908 3303 3304 sess->iface = 0; 2909 3305 sess->mgmt = mgmt; 2910 3306 sess->phone = phone; … … 2934 3330 { 2935 3331 assert(callid); 2936 3332 2937 3333 ipc_call_t call; 2938 3334 *callid = async_get_call(&call); 2939 3335 2940 3336 if (IPC_GET_IMETHOD(call) != IPC_M_STATE_CHANGE_AUTHORIZE) 2941 3337 return false; … … 2947 3343 if (arg3) 2948 3344 *arg3 = IPC_GET_ARG3(call); 2949 3345 2950 3346 return true; 2951 3347 } -
uspace/lib/c/generic/bd.c
r3feeab2 rff381a7 57 57 async_exch_t *exch = async_exchange_begin(sess); 58 58 59 int rc = async_connect_to_me(exch, 0, 0, 0, bd_cb_conn, bd); 59 port_id_t port; 60 int rc = async_create_callback_port(exch, INTERFACE_BLOCK_CB, 0, 0, 61 bd_cb_conn, bd, &port); 62 60 63 async_exchange_end(exch); 61 64 -
uspace/lib/c/generic/clipboard.c
r3feeab2 rff381a7 61 61 62 62 while (clip_sess == NULL) 63 clip_sess = service_connect_blocking( EXCHANGE_SERIALIZE,64 SERVICE_CLIPBOARD, 0, 0);63 clip_sess = service_connect_blocking(SERVICE_CLIPBOARD, 64 INTERFACE_CLIPBOARD, 0); 65 65 66 66 fibril_mutex_unlock(&clip_mutex); -
uspace/lib/c/generic/corecfg.c
r3feeab2 rff381a7 50 50 return ENOENT; 51 51 52 corecfg_sess = loc_service_connect( EXCHANGE_SERIALIZE, corecfg_svc,52 corecfg_sess = loc_service_connect(corecfg_svc, INTERFACE_CORECFG, 53 53 IPC_FLAG_BLOCKING); 54 54 if (corecfg_sess == NULL) -
uspace/lib/c/generic/devman.c
r3feeab2 rff381a7 77 77 * 78 78 */ 79 async_exch_t *devman_exchange_begin_blocking( devman_interface_t iface)79 async_exch_t *devman_exchange_begin_blocking(iface_t iface) 80 80 { 81 81 switch (iface) { 82 case DEVMAN_DRIVER:82 case INTERFACE_DDF_DRIVER: 83 83 fibril_mutex_lock(&devman_driver_block_mutex); 84 84 … … 89 89 if (devman_driver_block_sess == NULL) 90 90 devman_driver_block_sess = 91 service_connect_blocking( EXCHANGE_PARALLEL,92 SERVICE_DEVMAN, DEVMAN_DRIVER, 0);91 service_connect_blocking(SERVICE_DEVMAN, 92 INTERFACE_DDF_DRIVER, 0); 93 93 } 94 94 … … 99 99 100 100 return async_exchange_begin(devman_driver_block_sess); 101 case DEVMAN_CLIENT:101 case INTERFACE_DDF_CLIENT: 102 102 fibril_mutex_lock(&devman_client_block_mutex); 103 103 … … 108 108 if (devman_client_block_sess == NULL) 109 109 devman_client_block_sess = 110 service_connect_blocking( EXCHANGE_SERIALIZE,111 SERVICE_DEVMAN, DEVMAN_CLIENT, 0);110 service_connect_blocking(SERVICE_DEVMAN, 111 INTERFACE_DDF_CLIENT, 0); 112 112 } 113 113 … … 130 130 * 131 131 */ 132 async_exch_t *devman_exchange_begin( devman_interface_t iface)132 async_exch_t *devman_exchange_begin(iface_t iface) 133 133 { 134 134 switch (iface) { 135 case DEVMAN_DRIVER:135 case INTERFACE_DDF_DRIVER: 136 136 fibril_mutex_lock(&devman_driver_mutex); 137 137 138 138 if (devman_driver_sess == NULL) 139 139 devman_driver_sess = 140 service_connect( EXCHANGE_PARALLEL,SERVICE_DEVMAN,141 DEVMAN_DRIVER, 0);140 service_connect(SERVICE_DEVMAN, 141 INTERFACE_DDF_DRIVER, 0); 142 142 143 143 fibril_mutex_unlock(&devman_driver_mutex); … … 147 147 148 148 return async_exchange_begin(devman_driver_sess); 149 case DEVMAN_CLIENT:149 case INTERFACE_DDF_CLIENT: 150 150 fibril_mutex_lock(&devman_client_mutex); 151 151 152 152 if (devman_client_sess == NULL) 153 153 devman_client_sess = 154 service_connect( EXCHANGE_SERIALIZE,SERVICE_DEVMAN,155 DEVMAN_CLIENT, 0);154 service_connect(SERVICE_DEVMAN, 155 INTERFACE_DDF_CLIENT, 0); 156 156 157 157 fibril_mutex_unlock(&devman_client_mutex); … … 179 179 int devman_driver_register(const char *name) 180 180 { 181 async_exch_t *exch = devman_exchange_begin_blocking( DEVMAN_DRIVER);181 async_exch_t *exch = devman_exchange_begin_blocking(INTERFACE_DDF_DRIVER); 182 182 183 183 ipc_call_t answer; … … 192 192 } 193 193 194 exch = devman_exchange_begin( DEVMAN_DRIVER);195 async_connect_to_me(exch, 0, 0, 0 , NULL, NULL);194 exch = devman_exchange_begin(INTERFACE_DDF_DRIVER); 195 async_connect_to_me(exch, 0, 0, 0); 196 196 devman_exchange_end(exch); 197 197 … … 217 217 match_id_list_t *match_ids, devman_handle_t devh, devman_handle_t *funh) 218 218 { 219 intmatch_count = list_count(&match_ids->ids);220 async_exch_t *exch = devman_exchange_begin_blocking( DEVMAN_DRIVER);219 unsigned long match_count = list_count(&match_ids->ids); 220 async_exch_t *exch = devman_exchange_begin_blocking(INTERFACE_DDF_DRIVER); 221 221 222 222 ipc_call_t answer; … … 268 268 const char *cat_name) 269 269 { 270 async_exch_t *exch = devman_exchange_begin_blocking( DEVMAN_DRIVER);270 async_exch_t *exch = devman_exchange_begin_blocking(INTERFACE_DDF_DRIVER); 271 271 272 272 ipc_call_t answer; … … 287 287 } 288 288 289 async_sess_t *devman_device_connect(exch_mgmt_t mgmt, devman_handle_t handle, 290 unsigned int flags) 289 async_sess_t *devman_device_connect(devman_handle_t handle, unsigned int flags) 291 290 { 292 291 async_sess_t *sess; 293 292 294 293 if (flags & IPC_FLAG_BLOCKING) 295 sess = service_connect_blocking( mgmt,SERVICE_DEVMAN,296 DEVMAN_CONNECT_TO_DEVICE, handle);294 sess = service_connect_blocking(SERVICE_DEVMAN, 295 INTERFACE_DEVMAN_DEVICE, handle); 297 296 else 298 sess = service_connect( mgmt,SERVICE_DEVMAN,299 DEVMAN_CONNECT_TO_DEVICE, handle);297 sess = service_connect(SERVICE_DEVMAN, 298 INTERFACE_DEVMAN_DEVICE, handle); 300 299 301 300 return sess; … … 314 313 sysarg_t retval; 315 314 316 exch = devman_exchange_begin_blocking( DEVMAN_DRIVER);315 exch = devman_exchange_begin_blocking(INTERFACE_DDF_DRIVER); 317 316 retval = async_req_1_0(exch, DEVMAN_REMOVE_FUNCTION, (sysarg_t) funh); 318 317 devman_exchange_end(exch); … … 323 322 int devman_drv_fun_online(devman_handle_t funh) 324 323 { 325 async_exch_t *exch = devman_exchange_begin( DEVMAN_DRIVER);324 async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_DRIVER); 326 325 if (exch == NULL) 327 326 return ENOMEM; … … 335 334 int devman_drv_fun_offline(devman_handle_t funh) 336 335 { 337 async_exch_t *exch = devman_exchange_begin( DEVMAN_DRIVER);336 async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_DRIVER); 338 337 if (exch == NULL) 339 338 return ENOMEM; … … 345 344 } 346 345 347 async_sess_t *devman_parent_device_connect( exch_mgmt_t mgmt,348 devman_handle_t handle,unsigned int flags)346 async_sess_t *devman_parent_device_connect(devman_handle_t handle, 347 unsigned int flags) 349 348 { 350 349 async_sess_t *sess; 351 350 352 351 if (flags & IPC_FLAG_BLOCKING) 353 sess = service_connect_blocking( mgmt,SERVICE_DEVMAN,354 DEVMAN_CONNECT_TO_PARENTS_DEVICE, handle);352 sess = service_connect_blocking(SERVICE_DEVMAN, 353 INTERFACE_DEVMAN_PARENT, handle); 355 354 else 356 sess = service_connect (mgmt,SERVICE_DEVMAN,357 DEVMAN_CONNECT_TO_PARENTS_DEVICE, handle);355 sess = service_connect_blocking(SERVICE_DEVMAN, 356 INTERFACE_DEVMAN_PARENT, handle); 358 357 359 358 return sess; … … 366 365 367 366 if (flags & IPC_FLAG_BLOCKING) 368 exch = devman_exchange_begin_blocking( DEVMAN_CLIENT);367 exch = devman_exchange_begin_blocking(INTERFACE_DDF_CLIENT); 369 368 else { 370 exch = devman_exchange_begin( DEVMAN_CLIENT);369 exch = devman_exchange_begin(INTERFACE_DDF_CLIENT); 371 370 if (exch == NULL) 372 371 return ENOMEM; … … 409 408 sysarg_t dretval; 410 409 411 exch = devman_exchange_begin_blocking( DEVMAN_CLIENT);410 exch = devman_exchange_begin_blocking(INTERFACE_DDF_CLIENT); 412 411 413 412 ipc_call_t answer; … … 474 473 int devman_fun_online(devman_handle_t funh) 475 474 { 476 async_exch_t *exch = devman_exchange_begin( DEVMAN_CLIENT);475 async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_CLIENT); 477 476 if (exch == NULL) 478 477 return ENOMEM; … … 486 485 int devman_fun_offline(devman_handle_t funh) 487 486 { 488 async_exch_t *exch = devman_exchange_begin( DEVMAN_CLIENT);487 async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_CLIENT); 489 488 if (exch == NULL) 490 489 return ENOMEM; … … 499 498 devman_handle_t *handle_buf, size_t buf_size, size_t *act_size) 500 499 { 501 async_exch_t *exch = devman_exchange_begin_blocking( DEVMAN_CLIENT);500 async_exch_t *exch = devman_exchange_begin_blocking(INTERFACE_DDF_CLIENT); 502 501 503 502 ipc_call_t answer; … … 578 577 int devman_fun_get_child(devman_handle_t funh, devman_handle_t *devh) 579 578 { 580 async_exch_t *exch = devman_exchange_begin( DEVMAN_CLIENT);579 async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_CLIENT); 581 580 if (exch == NULL) 582 581 return ENOMEM; … … 598 597 int devman_dev_get_parent(devman_handle_t devh, devman_handle_t *funh) 599 598 { 600 async_exch_t *exch = devman_exchange_begin( DEVMAN_CLIENT);599 async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_CLIENT); 601 600 if (exch == NULL) 602 601 return ENOMEM; … … 611 610 int devman_fun_sid_to_handle(service_id_t sid, devman_handle_t *handle) 612 611 { 613 async_exch_t *exch = devman_exchange_begin( DEVMAN_CLIENT);612 async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_CLIENT); 614 613 if (exch == NULL) 615 614 return ENOMEM; … … 639 638 async_exch_t *exch; 640 639 641 exch = devman_exchange_begin( DEVMAN_CLIENT);640 exch = devman_exchange_begin(INTERFACE_DDF_CLIENT); 642 641 if (exch == NULL) 643 642 return ENOMEM; … … 694 693 { 695 694 sysarg_t state; 696 async_exch_t *exch = devman_exchange_begin( DEVMAN_CLIENT);695 async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_CLIENT); 697 696 if (exch == NULL) 698 697 return ENOMEM; … … 711 710 int devman_driver_load(devman_handle_t drvh) 712 711 { 713 async_exch_t *exch = devman_exchange_begin( DEVMAN_CLIENT);712 async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_CLIENT); 714 713 if (exch == NULL) 715 714 return ENOMEM; -
uspace/lib/c/generic/dhcp.c
r3feeab2 rff381a7 56 56 return ENOENT; 57 57 58 dhcp_sess = loc_service_connect( EXCHANGE_SERIALIZE, dhcp_svc,58 dhcp_sess = loc_service_connect(dhcp_svc, INTERFACE_DHCP, 59 59 IPC_FLAG_BLOCKING); 60 60 if (dhcp_sess == NULL) -
uspace/lib/c/generic/dnsr.c
r3feeab2 rff381a7 52 52 IPC_FLAG_BLOCKING); 53 53 54 dnsr_sess = loc_service_connect( EXCHANGE_SERIALIZE, dnsr_svc,54 dnsr_sess = loc_service_connect(dnsr_svc, INTERFACE_DNSR, 55 55 IPC_FLAG_BLOCKING); 56 56 } -
uspace/lib/c/generic/elf/elf_load.c
r3feeab2 rff381a7 97 97 int fd; 98 98 int rc; 99 99 100 100 fd = open(file_name, O_RDONLY); 101 101 if (fd < 0) { … … 147 147 int i, rc; 148 148 149 rc = read _all(elf->fd, header, sizeof(elf_header_t));149 rc = read(elf->fd, header, sizeof(elf_header_t)); 150 150 if (rc != sizeof(elf_header_t)) { 151 151 DPRINTF("Read error.\n"); … … 209 209 + i * sizeof(elf_segment_header_t), SEEK_SET); 210 210 211 rc = read _all(elf->fd, &segment_hdr,211 rc = read(elf->fd, &segment_hdr, 212 212 sizeof(elf_segment_header_t)); 213 213 if (rc != sizeof(elf_segment_header_t)) { … … 231 231 + i * sizeof(elf_section_header_t), SEEK_SET); 232 232 233 rc = read _all(elf->fd, §ion_hdr,233 rc = read(elf->fd, §ion_hdr, 234 234 sizeof(elf_section_header_t)); 235 235 if (rc != sizeof(elf_section_header_t)) { … … 399 399 if (now > left) now = left; 400 400 401 rc = read _all(elf->fd, dp, now);401 rc = read(elf->fd, dp, now); 402 402 403 403 if (rc != (ssize_t) now) { -
uspace/lib/c/generic/inet.c
r3feeab2 rff381a7 48 48 ipc_call_t answer; 49 49 aid_t req = async_send_0(exch, INET_CALLBACK_CREATE, &answer); 50 int rc = async_connect_to_me(exch, 0, 0, 0, inet_cb_conn, NULL); 50 51 port_id_t port; 52 int rc = async_create_callback_port(exch, INTERFACE_INET_CB, 0, 0, 53 inet_cb_conn, NULL, &port); 54 51 55 async_exchange_end(exch); 52 56 … … 83 87 return ENOENT; 84 88 85 inet_sess = loc_service_connect( EXCHANGE_SERIALIZE, inet_svc,89 inet_sess = loc_service_connect(inet_svc, INTERFACE_INET, 86 90 IPC_FLAG_BLOCKING); 87 91 if (inet_sess == NULL) -
uspace/lib/c/generic/inet/addr.c
r3feeab2 rff381a7 306 306 i++; 307 307 308 if (*cur == '\0' )308 if (*cur == '\0' || *cur == '/') 309 309 break; 310 310 … … 317 317 318 318 if (prefix != NULL) { 319 if (*cur != '/') 320 return EINVAL; 321 cur++; 322 319 323 *prefix = strtoul(cur, &cur, 10); 320 324 if (*prefix > 32) -
uspace/lib/c/generic/inet/endpoint.c
r3feeab2 rff381a7 36 36 #include <mem.h> 37 37 38 /** Initialize endpoint structure. 39 * 40 * Sets any address, any port number. 41 * 42 * @param ep Endpoint 43 */ 38 44 void inet_ep_init(inet_ep_t *ep) 39 45 { … … 41 47 } 42 48 49 /** Initialize endpoint pair structure. 50 * 51 * Sets any address, any port number for both local and remote sides. 52 * 53 * @param ep2 Endpoint pair 54 */ 43 55 void inet_ep2_init(inet_ep2_t *ep2) 44 56 { -
uspace/lib/c/generic/inet/tcp.c
r3feeab2 rff381a7 44 44 static int tcp_conn_fibril(void *); 45 45 46 /** Incoming TCP connection info */ 46 /** Incoming TCP connection info 47 * 48 * Used to pass information about incoming TCP connection to the connection 49 * fibril 50 */ 47 51 typedef struct { 52 /** Listener who received the connection */ 48 53 tcp_listener_t *lst; 54 /** Incoming connection */ 49 55 tcp_conn_t *conn; 50 56 } tcp_in_conn_t; 51 57 58 /** Create callback connection from TCP service. 59 * 60 * @param tcp TCP service 61 * @return EOK on success or negative error code 62 */ 52 63 static int tcp_callback_create(tcp_t *tcp) 53 64 { … … 55 66 56 67 aid_t req = async_send_0(exch, TCP_CALLBACK_CREATE, NULL); 57 int rc = async_connect_to_me(exch, 0, 0, 0, tcp_cb_conn, tcp); 68 69 port_id_t port; 70 int rc = async_create_callback_port(exch, INTERFACE_TCP_CB, 0, 0, 71 tcp_cb_conn, tcp, &port); 72 58 73 async_exchange_end(exch); 59 74 … … 67 82 } 68 83 84 /** Create TCP client instance. 85 * 86 * @param rtcp Place to store pointer to new TCP client 87 * @return EOK on success, ENOMEM if out of memory, EIO if service 88 * cannot be contacted 89 */ 69 90 int tcp_create(tcp_t **rtcp) 70 91 { … … 91 112 } 92 113 93 tcp->sess = loc_service_connect( EXCHANGE_SERIALIZE, tcp_svcid,114 tcp->sess = loc_service_connect(tcp_svcid, INTERFACE_TCP, 94 115 IPC_FLAG_BLOCKING); 95 116 if (tcp->sess == NULL) { … … 111 132 } 112 133 134 /** Destroy TCP client instance. 135 * 136 * @param tcp TCP client 137 */ 113 138 void tcp_destroy(tcp_t *tcp) 114 139 { … … 126 151 } 127 152 153 /** Create new TCP connection 154 * 155 * @param tcp TCP client instance 156 * @param id Connection ID 157 * @param cb Callbacks 158 * @param arg Callback argument 159 * @param rconn Place to store pointer to new connection 160 * 161 * @return EOK on success, ENOMEM if out of memory 162 */ 128 163 static int tcp_conn_new(tcp_t *tcp, sysarg_t id, tcp_cb_t *cb, void *arg, 129 164 tcp_conn_t **rconn) … … 150 185 } 151 186 187 /** Create new TCP connection. 188 * 189 * Open a connection to the specified destination. This function returns 190 * even before the connection is established (or not). When the connection 191 * is established, @a cb->connected is called. If the connection fails, 192 * @a cb->conn_failed is called. Alternatively, the caller can call 193 * @c tcp_conn_wait_connected() to wait for connection to complete or fail. 194 * Other callbacks are available to monitor the changes in connection state. 195 * 196 * @a epp must specify the remote address and port. Both local address and 197 * port are optional. If local address is not specified, address selection 198 * will take place. If local port number is not specified, a suitable 199 * free dynamic port number will be allocated. 200 * 201 * @param tcp TCP client 202 * @param epp Internet endpoint pair 203 * @param cb Callbacks 204 * @param arg Argument to callbacks 205 * @param rconn Place to store pointer to new connection 206 * 207 * @return EOK on success or negative error code. 208 */ 152 209 int tcp_conn_create(tcp_t *tcp, inet_ep2_t *epp, tcp_cb_t *cb, void *arg, 153 210 tcp_conn_t **rconn) … … 186 243 } 187 244 245 /** Destroy TCP connection. 246 * 247 * Destroy TCP connection. The caller should destroy all connections 248 * he created before destroying the TCP client and before terminating. 249 * 250 * @param conn TCP connection 251 */ 188 252 void tcp_conn_destroy(tcp_conn_t *conn) 189 253 { … … 203 267 } 204 268 269 /** Get connection based on its ID. 270 * 271 * @param tcp TCP client 272 * @param id Connection ID 273 * @param rconn Place to store pointer to connection 274 * 275 * @return EOK on success, EINVAL if no connection with the given ID exists 276 */ 205 277 static int tcp_conn_get(tcp_t *tcp, sysarg_t id, tcp_conn_t **rconn) 206 278 { … … 215 287 } 216 288 289 /** Get the user/callback argument for a connection. 290 * 291 * @param conn TCP connection 292 * @return User argument associated with connection 293 */ 217 294 void *tcp_conn_userptr(tcp_conn_t *conn) 218 295 { … … 220 297 } 221 298 299 /** Create a TCP connection listener. 300 * 301 * A listener listens for connections on the set of endpoints specified 302 * by @a ep. Each time a new incoming connection is established, 303 * @a lcb->new_conn is called (and passed @a larg). Also, the new connection 304 * will have callbacks set to @a cb and argument to @a arg. 305 * 306 * @a ep must specify a valid port number. @a ep may specify an address 307 * or link to listen on. If it does not, the listener will listen on 308 * all links/addresses. 309 * 310 * @param tcp TCP client 311 * @param ep Internet endpoint 312 * @param lcb Listener callbacks 313 * @param larg Listener callback argument 314 * @param cb Connection callbacks for every new connection 315 * @param arg Connection argument for every new connection 316 * @param rlst Place to store pointer to new listener 317 * 318 * @return EOK on success or negative error code 319 */ 222 320 int tcp_listener_create(tcp_t *tcp, inet_ep_t *ep, tcp_listen_cb_t *lcb, 223 321 void *larg, tcp_cb_t *cb, void *arg, tcp_listener_t **rlst) … … 265 363 } 266 364 365 /** Destroy TCP connection listener. 366 * 367 * @param lst Listener 368 */ 267 369 void tcp_listener_destroy(tcp_listener_t *lst) 268 370 { … … 282 384 } 283 385 386 /** Get TCP connection listener based on its ID. 387 * 388 * @param tcp TCP client 389 * @param id Listener ID 390 * @param rlst Place to store pointer to listener 391 * 392 * @return EOK on success, EINVAL if no listener with the given ID is found 393 */ 284 394 static int tcp_listener_get(tcp_t *tcp, sysarg_t id, tcp_listener_t **rlst) 285 395 { … … 294 404 } 295 405 406 /** Get callback/user argument associated with listener. 407 * 408 * @param lst Listener 409 * @return Callback/user argument 410 */ 296 411 void *tcp_listener_userptr(tcp_listener_t *lst) 297 412 { … … 299 414 } 300 415 416 /** Wait until connection is either established or connection fails. 417 * 418 * Can be called after calling tcp_conn_create() to block until connection 419 * either completes or fails. If the connection fails, EIO is returned. 420 * In this case the connection still exists, but is in a failed 421 * state. 422 * 423 * @param conn Connection 424 * @return EOK if connection is established, EIO otherwise 425 */ 301 426 int tcp_conn_wait_connected(tcp_conn_t *conn) 302 427 { … … 315 440 } 316 441 442 /** Send data over TCP connection. 443 * 444 * @param conn Connection 445 * @param data Data 446 * @param bytes Data size in bytes 447 * 448 * @return EOK on success or negative error code 449 */ 317 450 int tcp_conn_send(tcp_conn_t *conn, const void *data, size_t bytes) 318 451 { … … 340 473 } 341 474 342 475 /** Send FIN. 476 * 477 * Send FIN, indicating no more data will be send over the connection. 478 * 479 * @param conn Connection 480 * @return EOK on success or negative error code 481 */ 343 482 int tcp_conn_send_fin(tcp_conn_t *conn) 344 483 { … … 352 491 } 353 492 493 /** Push connection. 494 * 495 * @param conn Connection 496 * @return EOK on success or negative error code 497 */ 354 498 int tcp_conn_push(tcp_conn_t *conn) 355 499 { … … 363 507 } 364 508 509 /** Reset connection. 510 * 511 * @param conn Connection 512 * @return EOK on success or negative error code 513 */ 365 514 int tcp_conn_reset(tcp_conn_t *conn) 366 515 { … … 374 523 } 375 524 525 /** Read received data from connection without blocking. 526 * 527 * If any received data is pending on the connection, up to @a bsize bytes 528 * are copied to @a buf and the acutal number is stored in @a *nrecv. 529 * The entire buffer of @a bsize bytes is filled except when less data 530 * is currently available or FIN is received. EOK is returned. 531 * 532 * If no received data is pending, returns EAGAIN. 533 * 534 * @param conn Connection 535 * @param buf Buffer 536 * @param bsize Buffer size 537 * @param nrecv Place to store actual number of received bytes 538 * 539 * @return EOK on success, EAGAIN if no received data is pending, or other 540 * negative error code in case of other error 541 */ 376 542 int tcp_conn_recv(tcp_conn_t *conn, void *buf, size_t bsize, size_t *nrecv) 377 543 { … … 408 574 } 409 575 410 int tcp_conn_recv_wait(tcp_conn_t *conn, void *buf, size_t bsize, size_t *nrecv) 576 /** Read received data from connection with blocking. 577 * 578 * Wait for @a bsize bytes of data to be received and copy them to 579 * @a buf. Less data may be returned if FIN is received on the connection. 580 * The actual If any received data is written to @a *nrecv and EOK 581 * is returned on success. 582 * 583 * @param conn Connection 584 * @param buf Buffer 585 * @param bsize Buffer size 586 * @param nrecv Place to store actual number of received bytes 587 * 588 * @return EOK on success or negative error code 589 */ 590 int tcp_conn_recv_wait(tcp_conn_t *conn, void *buf, size_t bsize, 591 size_t *nrecv) 411 592 { 412 593 async_exch_t *exch; … … 450 631 } 451 632 633 /** Connection established event. 634 * 635 * @param tcp TCP client 636 * @param iid Call ID 637 * @param icall Call data 638 */ 452 639 static void tcp_ev_connected(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 453 640 { … … 472 659 } 473 660 661 /** Connection failed event. 662 * 663 * @param tcp TCP client 664 * @param iid Call ID 665 * @param icall Call data 666 */ 474 667 static void tcp_ev_conn_failed(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 475 668 { … … 494 687 } 495 688 689 /** Connection reset event. 690 * 691 * @param tcp TCP client 692 * @param iid Call ID 693 * @param icall Call data 694 */ 496 695 static void tcp_ev_conn_reset(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 497 696 { … … 516 715 } 517 716 717 /** Data available event. 718 * 719 * @param tcp TCP client 720 * @param iid Call ID 721 * @param icall Call data 722 */ 518 723 static void tcp_ev_data(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 519 724 { … … 539 744 } 540 745 746 /** Urgent data event. 747 * 748 * @param tcp TCP client 749 * @param iid Call ID 750 * @param icall Call data 751 */ 541 752 static void tcp_ev_urg_data(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 542 753 { … … 544 755 } 545 756 757 /** New connection event. 758 * 759 * @param tcp TCP client 760 * @param iid Call ID 761 * @param icall Call data 762 */ 546 763 static void tcp_ev_new_conn(tcp_t *tcp, ipc_callid_t iid, ipc_call_t *icall) 547 764 { … … 590 807 } 591 808 809 /** Callback connection handler. 810 * 811 * @param iid Connect call ID 812 * @param icall Connect call data 813 * @param arg Argument, TCP client 814 */ 592 815 static void tcp_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 593 816 { … … 636 859 } 637 860 638 /** Fibril for handling incoming TCP connection in background */ 861 /** Fibril for handling incoming TCP connection in background. 862 * 863 * @param arg Argument, incoming connection information (@c tcp_in_conn_t) 864 */ 639 865 static int tcp_conn_fibril(void *arg) 640 866 { -
uspace/lib/c/generic/inet/udp.c
r3feeab2 rff381a7 43 43 static void udp_cb_conn(ipc_callid_t, ipc_call_t *, void *); 44 44 45 /** Create callback connection from UDP service. 46 * 47 * @param udp UDP service 48 * @return EOK on success or negative error code 49 */ 45 50 static int udp_callback_create(udp_t *udp) 46 51 { … … 48 53 49 54 aid_t req = async_send_0(exch, UDP_CALLBACK_CREATE, NULL); 50 int rc = async_connect_to_me(exch, 0, 0, 0, udp_cb_conn, udp); 55 56 port_id_t port; 57 int rc = async_create_callback_port(exch, INTERFACE_UDP_CB, 0, 0, 58 udp_cb_conn, udp, &port); 59 51 60 async_exchange_end(exch); 52 61 … … 60 69 } 61 70 71 /** Create UDP client instance. 72 * 73 * @param rudp Place to store pointer to new UDP client 74 * @return EOK on success, ENOMEM if out of memory, EIO if service 75 * cannot be contacted 76 */ 62 77 int udp_create(udp_t **rudp) 63 78 { … … 83 98 } 84 99 85 udp->sess = loc_service_connect( EXCHANGE_SERIALIZE, udp_svcid,100 udp->sess = loc_service_connect(udp_svcid, INTERFACE_UDP, 86 101 IPC_FLAG_BLOCKING); 87 102 if (udp->sess == NULL) { … … 103 118 } 104 119 120 /** Destroy UDP client instance. 121 * 122 * @param udp UDP client 123 */ 105 124 void udp_destroy(udp_t *udp) 106 125 { … … 118 137 } 119 138 120 int udp_assoc_create(udp_t *udp, inet_ep2_t *ep2, udp_cb_t *cb, void *arg, 139 /** Create new UDP association. 140 * 141 * Create a UDP association that allows sending and receiving messages. 142 * 143 * @a epp may specify remote address and port, in which case only messages 144 * from that remote endpoint will be received. Also, that remote endpoint 145 * is used as default when @c NULL is passed as destination to 146 * udp_assoc_send_msg. 147 * 148 * @a epp may specify a local link or address. If it does not, the association 149 * will listen on all local links/addresses. If @a epp does not specify 150 * a local port number, a free dynamic port number will be allocated. 151 * 152 * The caller is informed about incoming data by invoking @a cb->recv_msg 153 * 154 * @param udp UDP client 155 * @param epp Internet endpoint pair 156 * @param cb Callbacks 157 * @param arg Argument to callbacks 158 * @param rassoc Place to store pointer to new association 159 * 160 * @return EOK on success or negative error code. 161 */ 162 int udp_assoc_create(udp_t *udp, inet_ep2_t *epp, udp_cb_t *cb, void *arg, 121 163 udp_assoc_t **rassoc) 122 164 { … … 131 173 exch = async_exchange_begin(udp->sess); 132 174 aid_t req = async_send_0(exch, UDP_ASSOC_CREATE, &answer); 133 sysarg_t rc = async_data_write_start(exch, (void *)ep 2,175 sysarg_t rc = async_data_write_start(exch, (void *)epp, 134 176 sizeof(inet_ep2_t)); 135 177 async_exchange_end(exch); … … 161 203 } 162 204 205 /** Destroy UDP association. 206 * 207 * Destroy UDP association. The caller should destroy all associations 208 * he created before destroying the UDP client and before terminating. 209 * 210 * @param assoc UDP association 211 */ 163 212 void udp_assoc_destroy(udp_assoc_t *assoc) 164 213 { … … 178 227 } 179 228 229 /** Send message via UDP association. 230 * 231 * @param assoc Association 232 * @param dest Destination endpoint or @c NULL to use association's remote ep. 233 * @param data Message data 234 * @param bytes Message size in bytes 235 * 236 * @return EOK on success or negative error code 237 */ 180 238 int udp_assoc_send_msg(udp_assoc_t *assoc, inet_ep_t *dest, void *data, 181 239 size_t bytes) … … 211 269 } 212 270 271 /** Get the user/callback argument for an association. 272 * 273 * @param assoc UDP association 274 * @return User argument associated with association 275 */ 213 276 void *udp_assoc_userptr(udp_assoc_t *assoc) 214 277 { … … 216 279 } 217 280 281 /** Get size of received message in bytes. 282 * 283 * Assuming jumbo messages can be received, the caller first needs to determine 284 * the size of the received message by calling this function, then they can 285 * read the message piece-wise using udp_rmsg_read(). 286 * 287 * @param rmsg Received message 288 * @return Size of received message in bytes 289 */ 218 290 size_t udp_rmsg_size(udp_rmsg_t *rmsg) 219 291 { … … 221 293 } 222 294 295 /** Read part of received message. 296 * 297 * @param rmsg Received message 298 * @param off Start offset 299 * @param buf Buffer for storing data 300 * @param bsize Buffer size 301 * 302 * @return EOK on success or negative error code. 303 */ 223 304 int udp_rmsg_read(udp_rmsg_t *rmsg, size_t off, void *buf, size_t bsize) 224 305 { … … 245 326 } 246 327 328 /** Get remote endpoint of received message. 329 * 330 * Place the remote endpoint (the one from which the message was supposedly 331 * sent) to @a ep. 332 * 333 * @param rmsg Received message 334 * @param ep Place to store remote endpoint 335 */ 247 336 void udp_rmsg_remote_ep(udp_rmsg_t *rmsg, inet_ep_t *ep) 248 337 { … … 250 339 } 251 340 341 /** Get type of received ICMP error message. 342 * 343 * @param rerr Received error message 344 * @return Error message type 345 */ 252 346 uint8_t udp_rerr_type(udp_rerr_t *rerr) 253 347 { … … 255 349 } 256 350 351 /** Get code of received ICMP error message. 352 * 353 * @param rerr Received error message 354 * @return Error message code 355 */ 257 356 uint8_t udp_rerr_code(udp_rerr_t *rerr) 258 357 { … … 260 359 } 261 360 361 /** Get information about the next received message from UDP service. 362 * 363 * @param udp UDP client 364 * @param rmsg Place to store message information 365 * 366 * @return EOK on success or negative error code 367 */ 262 368 static int udp_rmsg_info(udp_t *udp, udp_rmsg_t *rmsg) 263 369 { … … 288 394 } 289 395 396 /** Discard next received message in UDP service. 397 * 398 * @param udp UDP client 399 * @return EOK on success or negative error code 400 */ 290 401 static int udp_rmsg_discard(udp_t *udp) 291 402 { … … 299 410 } 300 411 412 /** Get association based on its ID. 413 * 414 * @param udp UDP client 415 * @param id Association ID 416 * @param rassoc Place to store pointer to association 417 * 418 * @return EOK on success, EINVAL if no association with the given ID exists 419 */ 301 420 static int udp_assoc_get(udp_t *udp, sysarg_t id, udp_assoc_t **rassoc) 302 421 { … … 311 430 } 312 431 432 /** Handle 'data' event, i.e. some message(s) arrived. 433 * 434 * For each received message, get information about it, call @c recv_msg 435 * callback and discard it. 436 * 437 * @param udp UDP client 438 * @param iid IPC message ID 439 * @param icall IPC message 440 */ 313 441 static void udp_ev_data(udp_t *udp, ipc_callid_t iid, ipc_call_t *icall) 314 442 { … … 340 468 } 341 469 470 /** UDP service callback connection. 471 * 472 * @param iid Connect message ID 473 * @param icall Connect message 474 * @param arg Argument, UDP client 475 */ 342 476 static void udp_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 343 477 { -
uspace/lib/c/generic/inetcfg.c
r3feeab2 rff381a7 120 120 assert(inetcfg_sess == NULL); 121 121 122 rc = loc_service_get_id(SERVICE_NAME_INET CFG, &inet_svc,122 rc = loc_service_get_id(SERVICE_NAME_INET, &inet_svc, 123 123 IPC_FLAG_BLOCKING); 124 124 if (rc != EOK) 125 125 return ENOENT; 126 126 127 inetcfg_sess = loc_service_connect( EXCHANGE_SERIALIZE, inet_svc,127 inetcfg_sess = loc_service_connect(inet_svc, INTERFACE_INETCFG, 128 128 IPC_FLAG_BLOCKING); 129 129 if (inetcfg_sess == NULL) -
uspace/lib/c/generic/inetping.c
r3feeab2 rff381a7 53 53 inetping_ev_ops = ev_ops; 54 54 55 rc = loc_service_get_id(SERVICE_NAME_INET PING, &inetping_svc,55 rc = loc_service_get_id(SERVICE_NAME_INET, &inetping_svc, 56 56 IPC_FLAG_BLOCKING); 57 57 if (rc != EOK) 58 58 return ENOENT; 59 59 60 inetping_sess = loc_service_connect( EXCHANGE_SERIALIZE, inetping_svc,60 inetping_sess = loc_service_connect(inetping_svc, INTERFACE_INETPING, 61 61 IPC_FLAG_BLOCKING); 62 62 if (inetping_sess == NULL) … … 65 65 async_exch_t *exch = async_exchange_begin(inetping_sess); 66 66 67 rc = async_connect_to_me(exch, 0, 0, 0, inetping_cb_conn, NULL); 67 port_id_t port; 68 rc = async_create_callback_port(exch, INTERFACE_INETPING_CB, 0, 0, 69 inetping_cb_conn, NULL, &port); 70 68 71 async_exchange_end(exch); 69 72 -
uspace/lib/c/generic/io/console.c
r3feeab2 rff381a7 49 49 return NULL; 50 50 51 ctrl->input_sess = fsession(EXCHANGE_SERIALIZE, ifile);51 ctrl->input_sess = vfs_fsession(ifile, INTERFACE_CONSOLE); 52 52 if (!ctrl->input_sess) { 53 53 free(ctrl); … … 55 55 } 56 56 57 ctrl->output_sess = fsession(EXCHANGE_SERIALIZE, ofile);57 ctrl->output_sess = vfs_fsession(ofile, INTERFACE_CONSOLE); 58 58 if (!ctrl->output_sess) { 59 59 free(ctrl); -
uspace/lib/c/generic/io/input.c
r3feeab2 rff381a7 58 58 async_exch_t *exch = async_exchange_begin(sess); 59 59 60 int rc = async_connect_to_me(exch, 0, 0, 0, input_cb_conn, input); 60 port_id_t port; 61 int rc = async_create_callback_port(exch, INTERFACE_INPUT_CB, 0, 0, 62 input_cb_conn, input, &port); 63 61 64 async_exchange_end(exch); 62 65 -
uspace/lib/c/generic/io/io.c
r3feeab2 rff381a7 231 231 if (stream->buf == NULL) { 232 232 errno = ENOMEM; 233 return -1;233 return EOF; 234 234 } 235 235 … … 299 299 } 300 300 301 int fclose(FILE *stream) 301 302 static int _fclose_nofree(FILE *stream) 302 303 { 303 304 int rc = 0; … … 312 313 313 314 list_remove(&stream->link); 315 316 if (rc != 0) { 317 /* errno was set by close() */ 318 return EOF; 319 } 320 321 return 0; 322 } 323 324 int fclose(FILE *stream) 325 { 326 int rc = _fclose_nofree(stream); 314 327 315 328 if ((stream != &stdin_null) … … 318 331 free(stream); 319 332 320 stream = NULL; 321 322 if (rc != 0) { 323 /* errno was set by close() */ 324 return EOF; 325 } 326 327 return 0; 333 return rc; 334 } 335 336 FILE *freopen(const char *path, const char *mode, FILE *stream) 337 { 338 FILE *nstr; 339 340 if (path == NULL) { 341 /* Changing mode is not supported */ 342 return NULL; 343 } 344 345 (void) _fclose_nofree(stream); 346 nstr = fopen(path, mode); 347 if (nstr == NULL) { 348 free(stream); 349 return NULL; 350 } 351 352 list_remove(&nstr->link); 353 *stream = *nstr; 354 list_append(&stream->link, &files); 355 356 free(nstr); 357 358 return stream; 328 359 } 329 360 … … 334 365 * @param nmemb Number of records to read. 335 366 * @param stream Pointer to the stream. 367 * 368 * @return Number of elements successfully read. On error this is less than 369 * nmemb, stream error indicator is set and errno is set. 336 370 */ 337 371 static size_t _fread(void *buf, size_t size, size_t nmemb, FILE *stream) … … 348 382 ssize_t rd = read(stream->fd, buf + done, left); 349 383 350 if (rd < 0) 384 if (rd < 0) { 385 /* errno was set by read() */ 351 386 stream->error = true; 352 else if (rd == 0)387 } else if (rd == 0) { 353 388 stream->eof = true; 354 else {389 } else { 355 390 left -= rd; 356 391 done += rd; … … 367 402 * @param nmemb Number of records to write. 368 403 * @param stream Pointer to the stream. 404 * 405 * @return Number of elements successfully written. On error this is less than 406 * nmemb, stream error indicator is set and errno is set. 369 407 */ 370 408 static size_t _fwrite(const void *buf, size_t size, size_t nmemb, FILE *stream) … … 372 410 size_t left; 373 411 size_t done; 412 int rc; 374 413 375 414 if (size == 0 || nmemb == 0) … … 381 420 while ((left > 0) && (!stream->error)) { 382 421 ssize_t wr; 422 size_t uwr; 383 423 384 if (stream->kio) 385 wr = kio_write(buf + done, left); 386 else 424 if (stream->kio) { 425 uwr = 0; 426 rc = kio_write(buf + done, left, &uwr); 427 if (rc != EOK) 428 errno = rc; 429 } else { 387 430 wr = write(stream->fd, buf + done, left); 431 if (wr >= 0) { 432 uwr = (size_t)wr; 433 rc = EOK; 434 } else { 435 /* errno was set by write */ 436 uwr = 0; 437 rc = errno; 438 } 439 } 388 440 389 if (wr <= 0) 441 if (rc != EOK) { 442 /* errno was set above */ 390 443 stream->error = true; 391 else {392 left -= wr;393 done += wr;444 } else { 445 left -= uwr; 446 done += uwr; 394 447 } 395 448 } … … 401 454 } 402 455 403 /** Read some data in stream buffer. */ 456 /** Read some data in stream buffer. 457 * 458 * On error, stream error indicator is set and errno is set. 459 */ 404 460 static void _ffillbuf(FILE *stream) 405 461 { … … 410 466 rc = read(stream->fd, stream->buf, stream->buf_size); 411 467 if (rc < 0) { 468 /* errno was set by read() */ 412 469 stream->error = true; 413 470 return; … … 434 491 435 492 /* If buffer has prefetched read data, we need to seek back. */ 436 if (bytes_used > 0 && stream->buf_state == _bs_read) 437 lseek(stream->fd, - (ssize_t) bytes_used, SEEK_CUR); 493 if (bytes_used > 0 && stream->buf_state == _bs_read) { 494 off64_t rc; 495 rc = lseek(stream->fd, - (ssize_t) bytes_used, SEEK_CUR); 496 if (rc == (off64_t)-1) { 497 /* errno was set by lseek */ 498 stream->error = 1; 499 return; 500 } 501 } 438 502 439 503 /* If buffer has unwritten data, we need to write them out. */ 440 if (bytes_used > 0 && stream->buf_state == _bs_write) 504 if (bytes_used > 0 && stream->buf_state == _bs_write) { 441 505 (void) _fwrite(stream->buf_tail, 1, bytes_used, stream); 506 /* On error stream error indicator and errno are set by _fwrite */ 507 if (stream->error) 508 return; 509 } 442 510 443 511 stream->buf_head = stream->buf; … … 466 534 return 0; 467 535 536 bytes_left = size * nmemb; 537 total_read = 0; 538 dp = (uint8_t *) dest; 539 540 /* Bytes from ungetc() buffer */ 541 while (stream->ungetc_chars > 0 && bytes_left > 0) { 542 *dp++ = stream->ungetc_buf[--stream->ungetc_chars]; 543 ++total_read; 544 --bytes_left; 545 } 546 468 547 /* If not buffered stream, read in directly. */ 469 548 if (stream->btype == _IONBF) { 470 now = _fread(dest, size, nmemb, stream);471 return now;549 total_read += _fread(dest, 1, bytes_left, stream); 550 return total_read / size; 472 551 } 473 552 … … 482 561 } 483 562 484 bytes_left = size * nmemb;485 total_read = 0;486 dp = (uint8_t *) dest;487 488 563 while ((!stream->error) && (!stream->eof) && (bytes_left > 0)) { 489 564 if (stream->buf_head == stream->buf_tail) 490 565 _ffillbuf(stream); 491 566 492 if (stream->error || stream->eof) 567 if (stream->error || stream->eof) { 568 /* On error errno was set by _ffillbuf() */ 493 569 break; 570 } 494 571 495 572 data_avail = stream->buf_head - stream->buf_tail; … … 546 623 if (stream->buf_state == _bs_read) 547 624 _fflushbuf(stream); 548 549 625 550 626 /* Perform lazy allocation of stream buffer. */ … … 584 660 /* Only need to drain buffer. */ 585 661 _fflushbuf(stream); 586 need_flush = false; 662 if (!stream->error) 663 need_flush = false; 587 664 } 588 665 } … … 618 695 int fputs(const char *str, FILE *stream) 619 696 { 620 return fwrite(str, str_size(str), 1, stream); 697 (void) fwrite(str, str_size(str), 1, stream); 698 if (ferror(stream)) 699 return EOF; 700 return 0; 621 701 } 622 702 … … 674 754 } 675 755 756 int ungetc(int c, FILE *stream) 757 { 758 if (c == EOF) 759 return EOF; 760 761 if (stream->ungetc_chars >= UNGETC_MAX) 762 return EOF; 763 764 stream->ungetc_buf[stream->ungetc_chars++] = 765 (uint8_t)c; 766 767 stream->eof = false; 768 return (uint8_t)c; 769 } 770 676 771 int fseek(FILE *stream, off64_t offset, int whence) 677 772 { 678 773 off64_t rc; 679 774 775 if (stream->error) 776 return EOF; 777 680 778 _fflushbuf(stream); 779 if (stream->error) { 780 /* errno was set by _fflushbuf() */ 781 return EOF; 782 } 783 784 stream->ungetc_chars = 0; 681 785 682 786 rc = lseek(stream->fd, offset, whence); 683 787 if (rc == (off64_t) (-1)) { 684 /* errno has been set by lseek 64.*/685 return -1;788 /* errno has been set by lseek() */ 789 return EOF; 686 790 } 687 791 … … 692 796 off64_t ftell(FILE *stream) 693 797 { 798 off64_t pos; 799 800 if (stream->error) 801 return EOF; 802 694 803 _fflushbuf(stream); 695 return lseek(stream->fd, 0, SEEK_CUR); 804 if (stream->error) { 805 /* errno was set by _fflushbuf() */ 806 return EOF; 807 } 808 809 pos = lseek(stream->fd, 0, SEEK_CUR); 810 if (pos == (off64_t) -1) { 811 /* errno was set by lseek */ 812 return (off64_t) -1; 813 } 814 815 return pos - stream->ungetc_chars; 696 816 } 697 817 … … 703 823 int fflush(FILE *stream) 704 824 { 825 if (stream->error) 826 return EOF; 827 705 828 _fflushbuf(stream); 829 if (stream->error) { 830 /* errno was set by _fflushbuf() */ 831 return EOF; 832 } 706 833 707 834 if (stream->kio) { 708 835 kio_update(); 709 return EOK;836 return 0; 710 837 } 711 838 … … 716 843 */ 717 844 stream->need_sync = false; 718 return fsync(stream->fd); 719 } 720 721 return ENOENT; 845 if (fsync(stream->fd) != 0) { 846 /* errno was set by fsync() */ 847 return EOF; 848 } 849 850 return 0; 851 } 852 853 return 0; 722 854 } 723 855 … … 742 874 if (stream->kio) { 743 875 errno = EBADF; 744 return -1;876 return EOF; 745 877 } 746 878 … … 748 880 } 749 881 750 async_sess_t * fsession(exch_mgmt_t mgmt, FILE *stream)882 async_sess_t *vfs_fsession(FILE *stream, iface_t iface) 751 883 { 752 884 if (stream->fd >= 0) { 753 885 if (stream->sess == NULL) 754 stream->sess = fd_session(mgmt, stream->fd);886 stream->sess = vfs_fd_session(stream->fd, iface); 755 887 756 888 return stream->sess; … … 760 892 } 761 893 762 int fhandle(FILE *stream, int *handle)894 int vfs_fhandle(FILE *stream, int *handle) 763 895 { 764 896 if (stream->fd >= 0) { -
uspace/lib/c/generic/io/kio.c
r3feeab2 rff381a7 43 43 #include <io/printf_core.h> 44 44 45 size_t kio_write(const void *buf, size_t size)45 int kio_write(const void *buf, size_t size, size_t *nwritten) 46 46 { 47 ssize_t ret = (ssize_t) __SYSCALL3(SYS_KIO, KIO_WRITE, (sysarg_t) buf, size);47 int rc = (int) __SYSCALL3(SYS_KIO, KIO_WRITE, (sysarg_t) buf, size); 48 48 49 if (ret >= 0) 50 return (size_t) ret; 51 52 return 0; 49 if (rc == EOK) 50 *nwritten = size; 51 return rc; 53 52 } 54 53 … … 84 83 static int kio_vprintf_str_write(const char *str, size_t size, void *data) 85 84 { 86 size_t wr = kio_write(str, size); 85 size_t wr; 86 87 wr = 0; 88 (void) kio_write(str, size, &wr); 87 89 return str_nlength(str, wr); 88 90 } … … 92 94 size_t offset = 0; 93 95 size_t chars = 0; 96 size_t wr; 94 97 95 98 while (offset < size) { … … 98 101 99 102 if (chr_encode(str[chars], buf, &sz, STR_BOUNDS(1)) == EOK) 100 kio_write(buf, sz );103 kio_write(buf, sz, &wr); 101 104 102 105 chars++; -
uspace/lib/c/generic/io/log.c
r3feeab2 rff381a7 166 166 return ENOMEM; 167 167 168 logger_session = service_connect_blocking(EXCHANGE_SERIALIZE, SERVICE_LOGGER, LOGGER_INTERFACE_WRITER, 0); 168 logger_session = service_connect_blocking(SERVICE_LOGGER, 169 INTERFACE_LOGGER_WRITER, 0); 169 170 if (logger_session == NULL) { 170 171 return ENOMEM; -
uspace/lib/c/generic/io/logctl.c
r3feeab2 rff381a7 48 48 49 49 if (logger_session == NULL) { 50 logger_session = service_connect_blocking( EXCHANGE_SERIALIZE,51 SERVICE_LOGGER, LOGGER_INTERFACE_CONTROL, 0);50 logger_session = service_connect_blocking(SERVICE_LOGGER, 51 INTERFACE_LOGGER_CONTROL, 0); 52 52 if (logger_session == NULL) 53 53 return ENOMEM; -
uspace/lib/c/generic/iplink.c
r3feeab2 rff381a7 59 59 60 60 async_exch_t *exch = async_exchange_begin(sess); 61 62 int rc = async_connect_to_me(exch, 0, 0, 0, iplink_cb_conn, iplink); 61 62 port_id_t port; 63 int rc = async_create_callback_port(exch, INTERFACE_IPLINK_CB, 0, 0, 64 iplink_cb_conn, iplink, &port); 65 63 66 async_exchange_end(exch); 64 67 -
uspace/lib/c/generic/irc.c
r3feeab2 rff381a7 51 51 assert(irc_sess == NULL); 52 52 53 irc_sess = service_connect_blocking(EXCHANGE_SERIALIZE, 54 SERVICE_IRC, 0, 0); 53 irc_sess = service_connect_blocking(SERVICE_IRC, INTERFACE_IRC, 0); 55 54 56 55 if (irc_sess == NULL) -
uspace/lib/c/generic/loader.c
r3feeab2 rff381a7 69 69 70 70 async_sess_t *sess = 71 service_connect_blocking( EXCHANGE_SERIALIZE, SERVICE_LOAD, 0, 0);71 service_connect_blocking(SERVICE_LOADER, INTERFACE_LOADER, 0); 72 72 if (sess == NULL) { 73 73 free(ldr); … … 124 124 return ENOMEM; 125 125 126 if ( !getcwd(cwd, MAX_PATH_LEN + 1))126 if (getcwd(cwd, MAX_PATH_LEN + 1) == NULL) 127 127 str_cpy(cwd, MAX_PATH_LEN + 1, "/"); 128 128 … … 162 162 { 163 163 size_t pa_len; 164 char *pa = absolutize(path, &pa_len);164 char *pa = vfs_absolutize(path, &pa_len); 165 165 if (!pa) 166 166 return ENOMEM; -
uspace/lib/c/generic/loc.c
r3feeab2 rff381a7 107 107 if (!loc_callback_created) { 108 108 async_exch_t *exch = 109 loc_exchange_begin_blocking( LOC_PORT_CONSUMER);109 loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER); 110 110 111 111 ipc_call_t answer; 112 112 aid_t req = async_send_0(exch, LOC_CALLBACK_CREATE, &answer); 113 int rc = async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL); 113 114 port_id_t port; 115 int rc = async_create_callback_port(exch, INTERFACE_LOC_CB, 0, 0, 116 loc_cb_conn, NULL, &port); 117 114 118 loc_exchange_end(exch); 115 119 … … 135 139 * 136 140 */ 137 async_exch_t *loc_exchange_begin_blocking( loc_interface_t iface)141 async_exch_t *loc_exchange_begin_blocking(iface_t iface) 138 142 { 139 143 switch (iface) { 140 case LOC_PORT_SUPPLIER:144 case INTERFACE_LOC_SUPPLIER: 141 145 fibril_mutex_lock(&loc_supp_block_mutex); 142 146 … … 147 151 if (loc_supp_block_sess == NULL) 148 152 loc_supp_block_sess = 149 service_connect_blocking( EXCHANGE_SERIALIZE,150 SERVICE_LOC, LOC_PORT_SUPPLIER, 0);153 service_connect_blocking(SERVICE_LOC, 154 INTERFACE_LOC_SUPPLIER, 0); 151 155 } 152 156 … … 157 161 158 162 return async_exchange_begin(loc_supp_block_sess); 159 case LOC_PORT_CONSUMER:163 case INTERFACE_LOC_CONSUMER: 160 164 fibril_mutex_lock(&loc_cons_block_mutex); 161 165 … … 166 170 if (loc_cons_block_sess == NULL) 167 171 loc_cons_block_sess = 168 service_connect_blocking( EXCHANGE_SERIALIZE,169 SERVICE_LOC, LOC_PORT_CONSUMER, 0);172 service_connect_blocking(SERVICE_LOC, 173 INTERFACE_LOC_CONSUMER, 0); 170 174 } 171 175 … … 188 192 * 189 193 */ 190 async_exch_t *loc_exchange_begin( loc_interface_t iface)194 async_exch_t *loc_exchange_begin(iface_t iface) 191 195 { 192 196 switch (iface) { 193 case LOC_PORT_SUPPLIER:197 case INTERFACE_LOC_SUPPLIER: 194 198 fibril_mutex_lock(&loc_supplier_mutex); 195 199 196 200 if (loc_supplier_sess == NULL) 197 201 loc_supplier_sess = 198 service_connect( EXCHANGE_SERIALIZE,SERVICE_LOC,199 LOC_PORT_SUPPLIER, 0);202 service_connect(SERVICE_LOC, 203 INTERFACE_LOC_SUPPLIER, 0); 200 204 201 205 fibril_mutex_unlock(&loc_supplier_mutex); … … 205 209 206 210 return async_exchange_begin(loc_supplier_sess); 207 case LOC_PORT_CONSUMER:211 case INTERFACE_LOC_CONSUMER: 208 212 fibril_mutex_lock(&loc_consumer_mutex); 209 213 210 214 if (loc_consumer_sess == NULL) 211 215 loc_consumer_sess = 212 service_connect( EXCHANGE_SERIALIZE,SERVICE_LOC,213 LOC_PORT_CONSUMER, 0);216 service_connect(SERVICE_LOC, 217 INTERFACE_LOC_CONSUMER, 0); 214 218 215 219 fibril_mutex_unlock(&loc_consumer_mutex); … … 237 241 int loc_server_register(const char *name) 238 242 { 239 async_exch_t *exch = loc_exchange_begin_blocking( LOC_PORT_SUPPLIER);243 async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_SUPPLIER); 240 244 241 245 ipc_call_t answer; … … 250 254 } 251 255 252 exch = loc_exchange_begin( LOC_PORT_SUPPLIER);253 async_connect_to_me(exch, 0, 0, 0 , NULL, NULL);256 exch = loc_exchange_begin(INTERFACE_LOC_SUPPLIER); 257 async_connect_to_me(exch, 0, 0, 0); 254 258 loc_exchange_end(exch); 255 259 … … 260 264 /** Register new service. 261 265 * 262 * The @p interface is used when forwarding connection to the server. 263 * If not 0, the first argument is the interface and the second argument 264 * is the service ID. 265 * 266 * When the interface is zero (default), the first argument is directly 267 * the handle (to ensure backward compatibility). 268 * 269 * @param fqsn Fully qualified service name 270 * @param[out] sid Service ID of new service 271 * @param interface Interface when forwarding 272 * 273 */ 274 int loc_service_register_with_iface(const char *fqsn, 275 service_id_t *sid, sysarg_t interface) 276 { 277 async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_SUPPLIER); 266 * @param fqsn Fully qualified service name 267 * @param[out] sid Service ID of new service 268 * 269 */ 270 int loc_service_register(const char *fqsn, service_id_t *sid) 271 { 272 async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_SUPPLIER); 278 273 279 274 ipc_call_t answer; 280 aid_t req = async_send_2(exch, LOC_SERVICE_REGISTER, interface, 0, 281 &answer); 275 aid_t req = async_send_0(exch, LOC_SERVICE_REGISTER, &answer); 282 276 sysarg_t retval = async_data_write_start(exch, fqsn, str_size(fqsn)); 283 277 … … 304 298 } 305 299 306 /** Register new service.307 *308 * @param fqsn Fully qualified service name309 * @param sid Output: ID of new service310 *311 */312 int loc_service_register(const char *fqdn, service_id_t *sid)313 {314 return loc_service_register_with_iface(fqdn, sid, 0);315 }316 317 300 /** Unregister service. 318 301 * … … 324 307 sysarg_t retval; 325 308 326 exch = loc_exchange_begin_blocking( LOC_PORT_SUPPLIER);309 exch = loc_exchange_begin_blocking(INTERFACE_LOC_SUPPLIER); 327 310 retval = async_req_1_0(exch, LOC_SERVICE_UNREGISTER, sid); 328 311 loc_exchange_end(exch); … … 337 320 338 321 if (flags & IPC_FLAG_BLOCKING) 339 exch = loc_exchange_begin_blocking( LOC_PORT_CONSUMER);322 exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER); 340 323 else { 341 exch = loc_exchange_begin( LOC_PORT_CONSUMER);324 exch = loc_exchange_begin(INTERFACE_LOC_CONSUMER); 342 325 if (exch == NULL) 343 326 return errno; … … 390 373 391 374 *name = NULL; 392 exch = loc_exchange_begin_blocking( LOC_PORT_CONSUMER);375 exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER); 393 376 394 377 ipc_call_t answer; … … 470 453 471 454 if (flags & IPC_FLAG_BLOCKING) 472 exch = loc_exchange_begin_blocking( LOC_PORT_CONSUMER);455 exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER); 473 456 else { 474 exch = loc_exchange_begin( LOC_PORT_CONSUMER);457 exch = loc_exchange_begin(INTERFACE_LOC_CONSUMER); 475 458 if (exch == NULL) 476 459 return errno; … … 519 502 520 503 if (flags & IPC_FLAG_BLOCKING) 521 exch = loc_exchange_begin_blocking( LOC_PORT_CONSUMER);504 exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER); 522 505 else { 523 exch = loc_exchange_begin( LOC_PORT_CONSUMER);506 exch = loc_exchange_begin(INTERFACE_LOC_CONSUMER); 524 507 if (exch == NULL) 525 508 return errno; … … 556 539 loc_object_type_t loc_id_probe(service_id_t handle) 557 540 { 558 async_exch_t *exch = loc_exchange_begin_blocking( LOC_PORT_CONSUMER);541 async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER); 559 542 560 543 sysarg_t type; … … 569 552 } 570 553 571 async_sess_t *loc_service_connect( exch_mgmt_t mgmt, service_id_t handle,554 async_sess_t *loc_service_connect(service_id_t handle, iface_t iface, 572 555 unsigned int flags) 573 556 { … … 575 558 576 559 if (flags & IPC_FLAG_BLOCKING) 577 sess = service_connect_blocking(mgmt, SERVICE_LOC, 578 LOC_CONNECT_TO_SERVICE, handle); 560 sess = service_connect_blocking(SERVICE_LOC, iface, handle); 579 561 else 580 sess = service_connect(mgmt, SERVICE_LOC, 581 LOC_CONNECT_TO_SERVICE, handle); 562 sess = service_connect(SERVICE_LOC, iface, handle); 582 563 583 564 return sess; … … 586 567 int loc_null_create(void) 587 568 { 588 async_exch_t *exch = loc_exchange_begin_blocking( LOC_PORT_CONSUMER);569 async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER); 589 570 590 571 sysarg_t null_id; … … 601 582 void loc_null_destroy(int null_id) 602 583 { 603 async_exch_t *exch = loc_exchange_begin_blocking( LOC_PORT_CONSUMER);584 async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER); 604 585 async_req_1_0(exch, LOC_NULL_DESTROY, (sysarg_t) null_id); 605 586 loc_exchange_end(exch); … … 627 608 sysarg_t retval; 628 609 629 exch = loc_exchange_begin_blocking( LOC_PORT_SUPPLIER);610 exch = loc_exchange_begin_blocking(INTERFACE_LOC_SUPPLIER); 630 611 retval = async_req_2_0(exch, LOC_SERVICE_ADD_TO_CAT, svc_id, cat_id); 631 612 loc_exchange_end(exch); … … 648 629 size_t loc_count_namespaces(void) 649 630 { 650 async_exch_t *exch = loc_exchange_begin_blocking( LOC_PORT_CONSUMER);631 async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER); 651 632 size_t size = loc_count_namespaces_internal(exch); 652 633 loc_exchange_end(exch); … … 657 638 size_t loc_count_services(service_id_t ns_handle) 658 639 { 659 async_exch_t *exch = loc_exchange_begin_blocking( LOC_PORT_CONSUMER);640 async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER); 660 641 size_t size = loc_count_services_internal(exch, ns_handle); 661 642 loc_exchange_end(exch); … … 668 649 /* Loop until read is succesful */ 669 650 while (true) { 670 async_exch_t *exch = loc_exchange_begin_blocking( LOC_PORT_CONSUMER);651 async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER); 671 652 size_t count = loc_count_namespaces_internal(exch); 672 653 loc_exchange_end(exch); … … 679 660 return 0; 680 661 681 exch = loc_exchange_begin( LOC_PORT_CONSUMER);662 exch = loc_exchange_begin(INTERFACE_LOC_CONSUMER); 682 663 683 664 ipc_call_t answer; … … 717 698 /* Loop until read is succesful */ 718 699 while (true) { 719 async_exch_t *exch = loc_exchange_begin_blocking( LOC_PORT_CONSUMER);700 async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER); 720 701 size_t count = loc_count_services_internal(exch, ns_handle); 721 702 loc_exchange_end(exch); … … 728 709 return 0; 729 710 730 exch = loc_exchange_begin( LOC_PORT_CONSUMER);711 exch = loc_exchange_begin(INTERFACE_LOC_CONSUMER); 731 712 732 713 ipc_call_t answer; … … 765 746 sysarg_t *id_buf, size_t buf_size, size_t *act_size) 766 747 { 767 async_exch_t *exch = loc_exchange_begin_blocking( LOC_PORT_CONSUMER);748 async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER); 768 749 769 750 ipc_call_t answer; -
uspace/lib/c/generic/ns.c
r3feeab2 rff381a7 40 40 #include "private/ns.h" 41 41 42 int service_register(s ysarg_t service)42 int service_register(service_t service) 43 43 { 44 44 async_exch_t *exch = async_exchange_begin(session_ns); 45 int rc = async_connect_to_me(exch, service, 0, 0, NULL, NULL);45 int rc = async_connect_to_me(exch, 0, service, 0); 46 46 async_exchange_end(exch); 47 47 … … 49 49 } 50 50 51 async_sess_t *service_connect(exch_mgmt_t mgmt, services_t service, sysarg_t arg2, 52 51 52 async_sess_t *service_connect(service_t service, iface_t iface, sysarg_t arg3) 53 53 { 54 54 async_exch_t *exch = async_exchange_begin(session_ns); … … 57 57 58 58 async_sess_t *sess = 59 async_connect_me_to (mgmt, exch, service, arg2, arg3);59 async_connect_me_to_iface(exch, iface, service, arg3); 60 60 async_exchange_end(exch); 61 61 … … 68 68 * first argument for non-initial connections. 69 69 */ 70 async_sess_args_set(sess, arg2, arg3, 0);70 async_sess_args_set(sess, iface, arg3, 0); 71 71 72 72 return sess; 73 73 } 74 74 75 async_sess_t *service_connect_blocking( exch_mgmt_t mgmt, services_t service,76 sysarg_t arg 2, sysarg_t arg3)75 async_sess_t *service_connect_blocking(service_t service, iface_t iface, 76 sysarg_t arg3) 77 77 { 78 78 async_exch_t *exch = async_exchange_begin(session_ns); 79 if (!exch)80 return NULL;81 79 async_sess_t *sess = 82 async_connect_me_to_blocking (mgmt, exch, service, arg2, arg3);80 async_connect_me_to_blocking_iface(exch, iface, service, arg3); 83 81 async_exchange_end(exch); 84 82 … … 91 89 * first argument for non-initial connections. 92 90 */ 93 async_sess_args_set(sess, arg2, arg3, 0);91 async_sess_args_set(sess, iface, arg3, 0); 94 92 95 93 return sess; 96 94 } 97 95 98 /** Create bidirectional connection with a service99 *100 * @param[in] service Service.101 * @param[in] arg1 First parameter.102 * @param[in] arg2 Second parameter.103 * @param[in] arg3 Third parameter.104 * @param[in] client_receiver Message receiver.105 *106 * @return Session to the service.107 * @return Other error codes as defined by async_connect_to_me().108 *109 */110 async_sess_t *service_bind(services_t service, sysarg_t arg1, sysarg_t arg2,111 sysarg_t arg3, async_client_conn_t client_receiver)112 {113 /* Connect to the needed service */114 async_sess_t *sess =115 service_connect_blocking(EXCHANGE_SERIALIZE, service, 0, 0);116 if (sess != NULL) {117 /* Request callback connection */118 async_exch_t *exch = async_exchange_begin(sess);119 int rc = async_connect_to_me(exch, arg1, arg2, arg3,120 client_receiver, NULL);121 async_exchange_end(exch);122 123 if (rc != EOK) {124 async_hangup(sess);125 errno = rc;126 return NULL;127 }128 }129 130 return sess;131 }132 96 133 97 int ns_ping(void) -
uspace/lib/c/generic/private/stdio.h
r3feeab2 rff381a7 39 39 #include <stdio.h> 40 40 #include <async.h> 41 42 /** Maximum characters that can be pushed back by ungetc() */ 43 #define UNGETC_MAX 1 41 44 42 45 struct _IO_FILE { … … 82 85 /** Points to end of occupied space when in read mode. */ 83 86 uint8_t *buf_tail; 87 88 /** Pushed back characters */ 89 uint8_t ungetc_buf[UNGETC_MAX]; 90 91 /** Number of pushed back characters */ 92 int ungetc_chars; 84 93 }; 85 94 -
uspace/lib/c/generic/task.c
r3feeab2 rff381a7 112 112 int fd_stderr; 113 113 114 if ((stdin != NULL) && ( fhandle(stdin, &fd_stdin) == EOK))114 if ((stdin != NULL) && (vfs_fhandle(stdin, &fd_stdin) == EOK)) 115 115 files[0] = &fd_stdin; 116 116 else 117 117 files[0] = NULL; 118 118 119 if ((stdout != NULL) && ( fhandle(stdout, &fd_stdout) == EOK))119 if ((stdout != NULL) && (vfs_fhandle(stdout, &fd_stdout) == EOK)) 120 120 files[1] = &fd_stdout; 121 121 else 122 122 files[1] = NULL; 123 123 124 if ((stderr != NULL) && ( fhandle(stderr, &fd_stderr) == EOK))124 if ((stderr != NULL) && (vfs_fhandle(stderr, &fd_stderr) == EOK)) 125 125 files[2] = &fd_stderr; 126 126 else -
uspace/lib/c/generic/time.c
r3feeab2 rff381a7 611 611 goto fallback; 612 612 613 clock_conn = loc_service_connect( EXCHANGE_SERIALIZE,614 svc_id,IPC_FLAG_BLOCKING);613 clock_conn = loc_service_connect(svc_id, INTERFACE_DDF, 614 IPC_FLAG_BLOCKING); 615 615 if (!clock_conn) 616 616 goto fallback; -
uspace/lib/c/generic/vbd.c
r3feeab2 rff381a7 33 33 */ 34 34 35 #include <abi/ipc/interfaces.h> 35 36 #include <errno.h> 36 37 #include <ipc/services.h> … … 65 66 } 66 67 67 vbd->sess = loc_service_connect( EXCHANGE_SERIALIZE, vbd_svcid,68 vbd->sess = loc_service_connect(vbd_svcid, INTERFACE_VBD, 68 69 IPC_FLAG_BLOCKING); 69 70 if (vbd->sess == NULL) { -
uspace/lib/c/generic/vfs/vfs.c
r3feeab2 rff381a7 75 75 76 76 while (vfs_sess == NULL) 77 vfs_sess = service_connect_blocking( EXCHANGE_PARALLEL, SERVICE_VFS,78 0 , 0);77 vfs_sess = service_connect_blocking(SERVICE_VFS, INTERFACE_VFS, 78 0); 79 79 80 80 fibril_mutex_unlock(&vfs_mutex); … … 93 93 } 94 94 95 char * absolutize(const char *path, size_t *retlen)95 char *vfs_absolutize(const char *path, size_t *retlen) 96 96 { 97 97 char *ncwd_path; … … 101 101 size_t size = str_size(path); 102 102 if (*path != '/') { 103 if ( !cwd_path) {103 if (cwd_path == NULL) { 104 104 fibril_mutex_unlock(&cwd_mutex); 105 105 return NULL; 106 106 } 107 107 ncwd_path_nc = malloc(cwd_size + 1 + size + 1); 108 if ( !ncwd_path_nc) {108 if (ncwd_path_nc == NULL) { 109 109 fibril_mutex_unlock(&cwd_mutex); 110 110 return NULL; … … 115 115 } else { 116 116 ncwd_path_nc = malloc(size + 1); 117 if ( !ncwd_path_nc) {117 if (ncwd_path_nc == NULL) { 118 118 fibril_mutex_unlock(&cwd_mutex); 119 119 return NULL; … … 123 123 str_append(ncwd_path_nc, cwd_size + 1 + size + 1, path); 124 124 ncwd_path = canonify(ncwd_path_nc, retlen); 125 if ( !ncwd_path) {125 if (ncwd_path == NULL) { 126 126 fibril_mutex_unlock(&cwd_mutex); 127 127 free(ncwd_path_nc); … … 135 135 ncwd_path = str_dup(ncwd_path); 136 136 free(ncwd_path_nc); 137 if ( !ncwd_path) {137 if (ncwd_path == NULL) { 138 138 fibril_mutex_unlock(&cwd_mutex); 139 139 return NULL; … … 143 143 } 144 144 145 int mount(const char *fs_name, const char *mp, const char *fqsn,145 int vfs_mount(const char *fs_name, const char *mp, const char *fqsn, 146 146 const char *opts, unsigned int flags, unsigned int instance) 147 147 { … … 171 171 172 172 size_t mpa_size; 173 char *mpa = absolutize(mp, &mpa_size);174 if ( !mpa) {173 char *mpa = vfs_absolutize(mp, &mpa_size); 174 if (mpa == NULL) { 175 175 if (null_id != -1) 176 176 loc_null_destroy(null_id); … … 255 255 } 256 256 257 int unmount(const char *mp)257 int vfs_unmount(const char *mp) 258 258 { 259 259 sysarg_t rc; … … 263 263 char *mpa; 264 264 265 mpa = absolutize(mp, &mpa_size);266 if ( !mpa)265 mpa = vfs_absolutize(mp, &mpa_size); 266 if (mpa == NULL) 267 267 return ENOMEM; 268 268 … … 289 289 } 290 290 291 static int open_internal(const char *abs, size_t abs_size, int lflag, int oflag) 291 /** Open file (internal). 292 * 293 * @param abs Absolute path to file 294 * @param abs_size Size of @a abs string 295 * @param lflag L_xxx flags 296 * @param oflag O_xxx flags 297 * @param fd Place to store new file descriptor 298 * 299 * @return EOK on success, non-zero error code on error 300 */ 301 static int open_internal(const char *abs, size_t abs_size, int lflag, int oflag, 302 int *fd) 292 303 { 293 304 async_exch_t *exch = vfs_exchange_begin(); … … 315 326 return (int) rc; 316 327 317 return (int) IPC_GET_ARG1(answer); 318 } 319 328 *fd = (int) IPC_GET_ARG1(answer); 329 return EOK; 330 } 331 332 /** Open file. 333 * 334 * @param path File path 335 * @param oflag O_xxx flags 336 * @param mode File mode (only with O_CREAT) 337 * 338 * @return Nonnegative file descriptor on success. On error -1 is returned 339 * and errno is set. 340 */ 320 341 int open(const char *path, int oflag, ...) 321 342 { 322 343 size_t abs_size; 323 char *abs = absolutize(path, &abs_size); 324 if (!abs) 325 return ENOMEM; 326 327 int ret = open_internal(abs, abs_size, L_FILE, oflag); 344 char *abs = vfs_absolutize(path, &abs_size); 345 int fd = -1; 346 347 if (abs == NULL) { 348 errno = ENOMEM; 349 return -1; 350 } 351 352 int rc = open_internal(abs, abs_size, L_FILE, oflag, &fd); 328 353 free(abs); 329 354 330 return ret; 331 } 332 355 if (rc != EOK) { 356 errno = rc; 357 return -1; 358 } 359 360 return fd; 361 } 362 363 /** Close file. 364 * 365 * @param fildes File descriptor 366 * @return Zero on success. On error -1 is returned and errno is set. 367 */ 333 368 int close(int fildes) 334 369 { … … 339 374 vfs_exchange_end(exch); 340 375 341 return (int) rc; 342 } 343 344 ssize_t read(int fildes, void *buf, size_t nbyte) 376 if (rc != EOK) { 377 errno = rc; 378 return -1; 379 } 380 381 return 0; 382 } 383 384 /** Read bytes from file. 385 * 386 * Read up to @a nbyte bytes from file. The actual number of bytes read 387 * may be lower, but greater than zero if there are any bytes available. 388 * If there are no bytes available for reading, then the function will 389 * return success with zero bytes read. 390 * 391 * @param fildes File descriptor 392 * @param buf Buffer 393 * @param nbyte Maximum number of bytes to read 394 * @param nread Place to store actual number of bytes read (0 or more) 395 * 396 * @return EOK on success, non-zero error code on error. 397 */ 398 static int _read_short(int fildes, void *buf, size_t nbyte, ssize_t *nread) 345 399 { 346 400 sysarg_t rc; … … 357 411 if (rc != EOK) { 358 412 vfs_exchange_end(exch); 359 413 360 414 sysarg_t rc_orig; 361 415 async_wait_for(req, &rc_orig); 362 416 363 417 if (rc_orig == EOK) 364 return (ssize_t)rc;418 return rc; 365 419 else 366 return (ssize_t) rc_orig; 367 } 420 return rc_orig; 421 } 422 368 423 vfs_exchange_end(exch); 369 424 async_wait_for(req, &rc); 370 if (rc == EOK) 371 return (ssize_t) IPC_GET_ARG1(answer); 372 else 425 426 if (rc != EOK) 373 427 return rc; 374 } 375 376 ssize_t write(int fildes, const void *buf, size_t nbyte) 428 429 *nread = (ssize_t) IPC_GET_ARG1(answer); 430 return EOK; 431 } 432 433 /** Write bytes to file. 434 * 435 * Write up to @a nbyte bytes from file. The actual number of bytes written 436 * may be lower, but greater than zero. 437 * 438 * @param fildes File descriptor 439 * @param buf Buffer 440 * @param nbyte Maximum number of bytes to write 441 * @param nread Place to store actual number of bytes written (0 or more) 442 * 443 * @return EOK on success, non-zero error code on error. 444 */ 445 static int _write_short(int fildes, const void *buf, size_t nbyte, 446 ssize_t *nwritten) 377 447 { 378 448 sysarg_t rc; … … 389 459 if (rc != EOK) { 390 460 vfs_exchange_end(exch); 391 461 392 462 sysarg_t rc_orig; 393 463 async_wait_for(req, &rc_orig); 394 464 395 465 if (rc_orig == EOK) 396 return (ssize_t)rc;466 return rc; 397 467 else 398 return (ssize_t) rc_orig; 399 } 468 return rc_orig; 469 } 470 400 471 vfs_exchange_end(exch); 401 472 async_wait_for(req, &rc); 402 if (rc == EOK) 403 return (ssize_t) IPC_GET_ARG1(answer); 404 else 405 return -1; 406 } 407 408 /** Read entire buffer. 409 * 410 * In face of short reads this function continues reading until either 411 * the entire buffer is read or no more data is available (at end of file). 473 474 if (rc != EOK) 475 return rc; 476 477 *nwritten = (ssize_t) IPC_GET_ARG1(answer); 478 return EOK; 479 } 480 481 /** Read data. 482 * 483 * Read up to @a nbytes bytes from file if available. This function always reads 484 * all the available bytes up to @a nbytes. 412 485 * 413 486 * @param fildes File descriptor … … 415 488 * @param nbytes Number of bytes to read 416 489 * 417 * @return On success, positive number of bytes read.418 * On failure, negative error code from read().419 */ 420 ssize_t read _all(int fildes, void *buf, size_t nbyte)490 * @return On success, nonnegative number of bytes read. 491 * On failure, -1 and sets errno. 492 */ 493 ssize_t read(int fildes, void *buf, size_t nbyte) 421 494 { 422 495 ssize_t cnt = 0; 423 496 size_t nread = 0; 424 497 uint8_t *bp = (uint8_t *) buf; 425 498 int rc; 499 426 500 do { 427 501 bp += cnt; 428 502 nread += cnt; 429 cnt = read(fildes, bp, nbyte - nread); 430 } while (cnt > 0 && (nbyte - nread - cnt) > 0); 431 432 if (cnt < 0) 433 return cnt; 434 503 rc = _read_short(fildes, bp, nbyte - nread, &cnt); 504 } while (rc == EOK && cnt > 0 && (nbyte - nread - cnt) > 0); 505 506 if (rc != EOK) { 507 errno = rc; 508 return -1; 509 } 510 435 511 return nread + cnt; 436 512 } 437 513 438 /** Write entire buffer.514 /** Write data. 439 515 * 440 516 * This function fails if it cannot write exactly @a len bytes to the file. … … 444 520 * @param nbytes Number of bytes to write 445 521 * 446 * @return EOK on error, return value from write() if writing447 * failed.448 */ 449 ssize_t write _all(int fildes, const void *buf, size_t nbyte)522 * @return On success, nonnegative number of bytes written. 523 * On failure, -1 and sets errno. 524 */ 525 ssize_t write(int fildes, const void *buf, size_t nbyte) 450 526 { 451 527 ssize_t cnt = 0; 452 528 ssize_t nwritten = 0; 453 529 const uint8_t *bp = (uint8_t *) buf; 530 int rc; 454 531 455 532 do { 456 533 bp += cnt; 457 534 nwritten += cnt; 458 cnt = write(fildes, bp, nbyte - nwritten); 459 } while (cnt > 0 && ((ssize_t )nbyte - nwritten - cnt) > 0); 460 461 if (cnt < 0) 462 return cnt; 463 464 if ((ssize_t)nbyte - nwritten - cnt > 0) 465 return EIO; 535 rc = _write_short(fildes, bp, nbyte - nwritten, &cnt); 536 } while (rc == EOK && ((ssize_t )nbyte - nwritten - cnt) > 0); 537 538 if (rc != EOK) { 539 errno = rc; 540 return -1; 541 } 466 542 467 543 return nbyte; 468 544 } 469 545 546 /** Synchronize file. 547 * 548 * @param fildes File descriptor 549 * @return 0 on success. On error returns -1 and sets errno. 550 */ 470 551 int fsync(int fildes) 471 552 { … … 474 555 vfs_exchange_end(exch); 475 556 476 return (int) rc; 477 } 478 557 if (rc != EOK) { 558 errno = rc; 559 return -1; 560 } 561 562 return 0; 563 } 564 565 /** Seek to a position. 566 * 567 * @param fildes File descriptor 568 * @param offset Offset 569 * @param whence SEEK_SET, SEEK_CUR or SEEK_END 570 * 571 * @return On success the nonnegative offset from start of file. On error 572 * returns (off64_t)-1 and sets errno. 573 */ 479 574 off64_t lseek(int fildes, off64_t offset, int whence) 480 575 { … … 489 584 vfs_exchange_end(exch); 490 585 491 if (rc != EOK) 586 if (rc != EOK) { 587 errno = rc; 492 588 return (off64_t) -1; 589 } 493 590 494 591 return (off64_t) MERGE_LOUP32(newoff_lo, newoff_hi); 495 592 } 496 593 594 /** Truncate file to a specified length. 595 * 596 * Truncate file so that its size is exactly @a length 597 * 598 * @param fildes File descriptor 599 * @param length Length 600 * 601 * @return 0 on success, -1 on error and sets errno. 602 */ 497 603 int ftruncate(int fildes, aoff64_t length) 498 604 { … … 504 610 vfs_exchange_end(exch); 505 611 506 return (int) rc; 507 } 508 612 if (rc != EOK) { 613 errno = rc; 614 return -1; 615 } 616 617 return 0; 618 } 619 620 /** Get file status. 621 * 622 * @param fildes File descriptor 623 * @param stat Place to store file information 624 * 625 * @return 0 on success, -1 on error and sets errno. 626 */ 509 627 int fstat(int fildes, struct stat *stat) 510 628 { … … 518 636 if (rc != EOK) { 519 637 vfs_exchange_end(exch); 520 638 521 639 sysarg_t rc_orig; 522 640 async_wait_for(req, &rc_orig); 523 524 if (rc_orig == EOK) 525 return (ssize_t) rc; 526 else 527 return (ssize_t) rc_orig; 528 } 641 642 if (rc_orig != EOK) 643 rc = rc_orig; 644 if (rc != EOK) { 645 errno = rc; 646 return -1; 647 } 648 649 return 0; 650 } 651 529 652 vfs_exchange_end(exch); 530 653 async_wait_for(req, &rc); 531 532 return rc; 533 } 534 654 655 if (rc != EOK) { 656 errno = rc; 657 return -1; 658 } 659 660 return 0; 661 } 662 663 /** Get file status. 664 * 665 * @param path Path to file 666 * @param stat Place to store file information 667 * 668 * @return 0 on success, -1 on error and sets errno. 669 */ 535 670 int stat(const char *path, struct stat *stat) 536 671 { … … 540 675 541 676 size_t pa_size; 542 char *pa = absolutize(path, &pa_size); 543 if (!pa) 544 return ENOMEM; 677 char *pa = vfs_absolutize(path, &pa_size); 678 if (pa == NULL) { 679 errno = ENOMEM; 680 return -1; 681 } 545 682 546 683 async_exch_t *exch = vfs_exchange_begin(); … … 552 689 free(pa); 553 690 async_wait_for(req, &rc_orig); 691 if (rc_orig != EOK) 692 rc = rc_orig; 693 if (rc != EOK) { 694 errno = rc; 695 return -1; 696 } 697 } 698 rc = async_data_read_start(exch, stat, sizeof(struct stat)); 699 if (rc != EOK) { 700 vfs_exchange_end(exch); 701 free(pa); 702 async_wait_for(req, &rc_orig); 703 if (rc_orig != EOK) 704 rc = rc_orig; 705 if (rc != EOK) { 706 errno = rc; 707 return -1; 708 } 709 } 710 vfs_exchange_end(exch); 711 free(pa); 712 async_wait_for(req, &rc); 713 if (rc != EOK) { 714 errno = rc; 715 return -1; 716 } 717 return 0; 718 } 719 720 /** Open directory. 721 * 722 * @param dirname Directory pathname 723 * 724 * @return Non-NULL pointer on success. On error returns @c NULL and sets errno. 725 */ 726 DIR *opendir(const char *dirname) 727 { 728 DIR *dirp = malloc(sizeof(DIR)); 729 int fd = -1; 730 731 if (dirp == NULL) { 732 errno = ENOMEM; 733 return NULL; 734 } 735 736 size_t abs_size; 737 char *abs = vfs_absolutize(dirname, &abs_size); 738 if (abs == NULL) { 739 free(dirp); 740 errno = ENOMEM; 741 return NULL; 742 } 743 744 int rc = open_internal(abs, abs_size, L_DIRECTORY, 0, &fd); 745 free(abs); 746 747 if (rc != EOK) { 748 free(dirp); 749 errno = rc; 750 return NULL; 751 } 752 753 dirp->fd = fd; 754 return dirp; 755 } 756 757 /** Read directory entry. 758 * 759 * @param dirp Open directory 760 * @return Non-NULL pointer to directory entry on success. On error returns 761 * @c NULL and sets errno. 762 */ 763 struct dirent *readdir(DIR *dirp) 764 { 765 int rc; 766 ssize_t len; 767 768 rc = _read_short(dirp->fd, &dirp->res.d_name[0], NAME_MAX + 1, &len); 769 if (rc != EOK) { 770 errno = rc; 771 return NULL; 772 } 773 774 (void) len; 775 return &dirp->res; 776 } 777 778 /** Rewind directory position to the beginning. 779 * 780 * @param dirp Open directory 781 */ 782 void rewinddir(DIR *dirp) 783 { 784 (void) lseek(dirp->fd, 0, SEEK_SET); 785 } 786 787 /** Close directory. 788 * 789 * @param dirp Open directory 790 * @return 0 on success. On error returns -1 and sets errno. 791 */ 792 int closedir(DIR *dirp) 793 { 794 int rc; 795 796 rc = close(dirp->fd); 797 free(dirp); 798 799 /* On error errno was set by close() */ 800 return rc; 801 } 802 803 /** Create directory. 804 * 805 * @param path Path 806 * @param mode File mode 807 * @return 0 on success. On error returns -1 and sets errno. 808 */ 809 int mkdir(const char *path, mode_t mode) 810 { 811 sysarg_t rc; 812 aid_t req; 813 814 size_t pa_size; 815 char *pa = vfs_absolutize(path, &pa_size); 816 if (pa == NULL) { 817 errno = ENOMEM; 818 return -1; 819 } 820 821 async_exch_t *exch = vfs_exchange_begin(); 822 823 req = async_send_1(exch, VFS_IN_MKDIR, mode, NULL); 824 rc = async_data_write_start(exch, pa, pa_size); 825 if (rc != EOK) { 826 vfs_exchange_end(exch); 827 free(pa); 828 829 sysarg_t rc_orig; 830 async_wait_for(req, &rc_orig); 831 832 if (rc_orig != EOK) 833 rc = rc_orig; 834 835 if (rc != EOK) { 836 errno = rc; 837 return -1; 838 } 839 840 return 0; 841 } 842 843 vfs_exchange_end(exch); 844 free(pa); 845 async_wait_for(req, &rc); 846 847 if (rc != EOK) { 848 errno = rc; 849 return -1; 850 } 851 852 return 0; 853 } 854 855 /** Unlink a file or directory. 856 * 857 * @param path Path to file or empty directory 858 * @param lflag L_xxx flag (L_NONE, L_FILE or L_DIRECTORY) 859 * @return EOK on success, non-zero error code on error 860 */ 861 static int _unlink(const char *path, int lflag) 862 { 863 sysarg_t rc; 864 aid_t req; 865 866 size_t pa_size; 867 char *pa = vfs_absolutize(path, &pa_size); 868 if (pa == NULL) 869 return ENOMEM; 870 871 async_exch_t *exch = vfs_exchange_begin(); 872 873 req = async_send_1(exch, VFS_IN_UNLINK, lflag, NULL); 874 rc = async_data_write_start(exch, pa, pa_size); 875 if (rc != EOK) { 876 vfs_exchange_end(exch); 877 free(pa); 878 879 sysarg_t rc_orig; 880 async_wait_for(req, &rc_orig); 881 554 882 if (rc_orig == EOK) 555 883 return (int) rc; … … 557 885 return (int) rc_orig; 558 886 } 559 rc = async_data_read_start(exch, stat, sizeof(struct stat));560 if (rc != EOK) {561 vfs_exchange_end(exch);562 free(pa);563 async_wait_for(req, &rc_orig);564 if (rc_orig == EOK)565 return (int) rc;566 else567 return (int) rc_orig;568 }569 887 vfs_exchange_end(exch); 570 888 free(pa); … … 573 891 } 574 892 575 DIR *opendir(const char *dirname) 576 { 577 DIR *dirp = malloc(sizeof(DIR)); 578 if (!dirp) 579 return NULL; 580 581 size_t abs_size; 582 char *abs = absolutize(dirname, &abs_size); 583 if (!abs) { 584 free(dirp); 585 return NULL; 586 } 587 588 int ret = open_internal(abs, abs_size, L_DIRECTORY, 0); 589 free(abs); 590 591 if (ret < 0) { 592 free(dirp); 593 return NULL; 594 } 595 596 dirp->fd = ret; 597 return dirp; 598 } 599 600 struct dirent *readdir(DIR *dirp) 601 { 602 ssize_t len = read(dirp->fd, &dirp->res.d_name[0], NAME_MAX + 1); 603 if (len <= 0) 604 return NULL; 605 return &dirp->res; 606 } 607 608 void rewinddir(DIR *dirp) 609 { 610 (void) lseek(dirp->fd, 0, SEEK_SET); 611 } 612 613 int closedir(DIR *dirp) 614 { 615 (void) close(dirp->fd); 616 free(dirp); 893 /** Unlink file or directory. 894 * 895 * @param path Path 896 * @return EOk on success, error code on error 897 */ 898 int unlink(const char *path) 899 { 900 int rc; 901 902 rc = _unlink(path, L_NONE); 903 if (rc != EOK) { 904 errno = rc; 905 return -1; 906 } 907 617 908 return 0; 618 909 } 619 910 620 int mkdir(const char *path, mode_t mode) 621 { 622 sysarg_t rc; 623 aid_t req; 624 625 size_t pa_size; 626 char *pa = absolutize(path, &pa_size); 627 if (!pa) 628 return ENOMEM; 629 630 async_exch_t *exch = vfs_exchange_begin(); 631 632 req = async_send_1(exch, VFS_IN_MKDIR, mode, NULL); 633 rc = async_data_write_start(exch, pa, pa_size); 634 if (rc != EOK) { 635 vfs_exchange_end(exch); 636 free(pa); 637 638 sysarg_t rc_orig; 639 async_wait_for(req, &rc_orig); 640 641 if (rc_orig == EOK) 642 return (int) rc; 643 else 644 return (int) rc_orig; 645 } 646 vfs_exchange_end(exch); 647 free(pa); 648 async_wait_for(req, &rc); 649 return rc; 650 } 651 652 static int _unlink(const char *path, int lflag) 653 { 654 sysarg_t rc; 655 aid_t req; 656 657 size_t pa_size; 658 char *pa = absolutize(path, &pa_size); 659 if (!pa) 660 return ENOMEM; 661 662 async_exch_t *exch = vfs_exchange_begin(); 663 664 req = async_send_1(exch, VFS_IN_UNLINK, lflag, NULL); 665 rc = async_data_write_start(exch, pa, pa_size); 666 if (rc != EOK) { 667 vfs_exchange_end(exch); 668 free(pa); 669 670 sysarg_t rc_orig; 671 async_wait_for(req, &rc_orig); 672 673 if (rc_orig == EOK) 674 return (int) rc; 675 else 676 return (int) rc_orig; 677 } 678 vfs_exchange_end(exch); 679 free(pa); 680 async_wait_for(req, &rc); 681 return rc; 682 } 683 684 int unlink(const char *path) 685 { 686 return _unlink(path, L_NONE); 687 } 688 911 /** Remove empty directory. 912 * 913 * @param path Path 914 * @return 0 on success. On error returns -1 and sets errno. 915 */ 689 916 int rmdir(const char *path) 690 917 { 691 return _unlink(path, L_DIRECTORY); 692 } 693 918 int rc; 919 920 rc = _unlink(path, L_DIRECTORY); 921 if (rc != EOK) { 922 errno = rc; 923 return -1; 924 } 925 926 return 0; 927 } 928 929 /** Rename directory entry. 930 * 931 * @param old Old name 932 * @param new New name 933 * 934 * @return 0 on success. On error returns -1 and sets errno. 935 */ 694 936 int rename(const char *old, const char *new) 695 937 { … … 699 941 700 942 size_t olda_size; 701 char *olda = absolutize(old, &olda_size); 702 if (!olda) 703 return ENOMEM; 943 char *olda = vfs_absolutize(old, &olda_size); 944 if (olda == NULL) { 945 errno = ENOMEM; 946 return -1; 947 } 704 948 705 949 size_t newa_size; 706 char *newa = absolutize(new, &newa_size);707 if ( !newa) {950 char *newa = vfs_absolutize(new, &newa_size); 951 if (newa == NULL) { 708 952 free(olda); 709 return ENOMEM; 953 errno = ENOMEM; 954 return -1; 710 955 } 711 956 … … 719 964 free(newa); 720 965 async_wait_for(req, &rc_orig); 721 if (rc_orig == EOK) 722 return (int) rc; 723 else 724 return (int) rc_orig; 966 if (rc_orig != EOK) 967 rc = rc_orig; 968 if (rc != EOK) { 969 errno = rc; 970 return -1; 971 } 972 return 0; 725 973 } 726 974 rc = async_data_write_start(exch, newa, newa_size); … … 730 978 free(newa); 731 979 async_wait_for(req, &rc_orig); 732 if (rc_orig == EOK) 733 return (int) rc; 734 else 735 return (int) rc_orig; 980 if (rc_orig != EOK) 981 rc = rc_orig; 982 if (rc != EOK) { 983 errno = rc; 984 return -1; 985 } 986 return 0; 736 987 } 737 988 vfs_exchange_end(exch); … … 739 990 free(newa); 740 991 async_wait_for(req, &rc); 741 return rc; 742 } 743 992 993 if (rc != EOK) { 994 errno = rc; 995 return -1; 996 } 997 998 return 0; 999 } 1000 1001 /** Remove directory entry. 1002 * 1003 * @param path Path 1004 * @return 0 on success. On error returns -1 and sets errno. 1005 */ 744 1006 int remove(const char *path) 745 1007 { … … 747 1009 } 748 1010 1011 /** Change working directory. 1012 * 1013 * @param path Path 1014 * @return 0 on success. On error returns -1 and sets errno. 1015 */ 749 1016 int chdir(const char *path) 750 1017 { 751 1018 size_t abs_size; 752 char *abs = absolutize(path, &abs_size); 753 if (!abs) 754 return ENOMEM; 755 756 int fd = open_internal(abs, abs_size, L_DIRECTORY, O_DESC); 757 758 if (fd < 0) { 1019 char *abs = vfs_absolutize(path, &abs_size); 1020 int fd = -1; 1021 1022 if (abs == NULL) { 1023 errno = ENOMEM; 1024 return -1; 1025 } 1026 1027 int rc = open_internal(abs, abs_size, L_DIRECTORY, O_DESC, &fd); 1028 1029 if (rc != EOK) { 759 1030 free(abs); 760 return ENOENT; 1031 errno = rc; 1032 return -1; 761 1033 } 762 1034 … … 765 1037 if (cwd_fd >= 0) 766 1038 close(cwd_fd); 767 768 1039 769 1040 if (cwd_path) … … 775 1046 776 1047 fibril_mutex_unlock(&cwd_mutex); 777 return EOK; 778 } 779 1048 return 0; 1049 } 1050 1051 /** Get current working directory path. 1052 * 1053 * @param buf Buffer 1054 * @param size Size of @a buf 1055 * @return On success returns @a buf. On failure returns @c NULL and sets errno. 1056 */ 780 1057 char *getcwd(char *buf, size_t size) 781 1058 { 782 if (size == 0) 1059 if (size == 0) { 1060 errno = EINVAL; 783 1061 return NULL; 1062 } 784 1063 785 1064 fibril_mutex_lock(&cwd_mutex); … … 787 1066 if ((cwd_size == 0) || (size < cwd_size + 1)) { 788 1067 fibril_mutex_unlock(&cwd_mutex); 1068 errno = ERANGE; 789 1069 return NULL; 790 1070 } … … 796 1076 } 797 1077 798 async_sess_t *fd_session(exch_mgmt_t mgmt, int fildes) 1078 /** Open session to service represented by a special file. 1079 * 1080 * Given that the file referred to by @a fildes represents a service, 1081 * open a session to that service. 1082 * 1083 * @param fildes File descriptor 1084 * @param iface Interface to connect to (XXX Should be automatic) 1085 * @return On success returns session pointer. On error returns @c NULL. 1086 */ 1087 async_sess_t *vfs_fd_session(int fildes, iface_t iface) 799 1088 { 800 1089 struct stat stat; 801 1090 int rc = fstat(fildes, &stat); 802 if (rc != 0) { 803 errno = rc; 1091 if (rc != 0) 804 1092 return NULL; 805 } 806 807 if (!stat.service) { 808 errno = ENOENT; 1093 1094 if (stat.service == 0) 809 1095 return NULL; 810 } 811 812 return loc_service_connect(mgmt, stat.service, 0); 813 } 814 1096 1097 return loc_service_connect(stat.service, iface, 0); 1098 } 1099 1100 /** Duplicate open file. 1101 * 1102 * Duplicate open file under a new file descriptor. 1103 * 1104 * @param oldfd Old file descriptor 1105 * @param newfd New file descriptor 1106 * @return 0 on success. On error -1 is returned and errno is set 1107 */ 815 1108 int dup2(int oldfd, int newfd) 816 1109 { … … 823 1116 824 1117 if (rc == EOK) 825 return (int) ret; 826 827 return (int) rc; 828 } 829 830 int fd_wait(void) 1118 rc = ret; 1119 1120 if (rc != EOK) { 1121 errno = rc; 1122 return -1; 1123 } 1124 1125 return 0; 1126 } 1127 1128 int vfs_fd_wait(void) 831 1129 { 832 1130 async_exch_t *exch = vfs_exchange_begin(); … … 843 1141 } 844 1142 845 int get_mtab_list(list_t *mtab_list)1143 int vfs_get_mtab_list(list_t *mtab_list) 846 1144 { 847 1145 sysarg_t rc; … … 863 1161 864 1162 mtab_ent = malloc(sizeof(mtab_ent_t)); 865 if ( !mtab_ent) {1163 if (mtab_ent == NULL) { 866 1164 rc = ENOMEM; 867 1165 goto exit; … … 904 1202 } 905 1203 1204 /** Get filesystem statistics. 1205 * 1206 * @param path Mount point path 1207 * @param st Buffer for storing information 1208 * @return 0 on success. On error -1 is returned and errno is set. 1209 */ 906 1210 int statfs(const char *path, struct statfs *st) 907 1211 { … … 910 1214 size_t pa_size; 911 1215 912 char *pa = absolutize(path, &pa_size); 913 if (!pa) 914 return ENOMEM; 1216 char *pa = vfs_absolutize(path, &pa_size); 1217 if (pa == NULL) { 1218 errno = ENOMEM; 1219 return -1; 1220 } 915 1221 916 1222 async_exch_t *exch = vfs_exchange_begin(); … … 927 1233 free(pa); 928 1234 async_wait_for(req, &rc_orig); 929 return (int) (rc_orig != EOK ? rc_orig : rc); 1235 rc = (rc_orig != EOK ? rc_orig : rc); 1236 1237 if (rc != EOK) { 1238 errno = rc; 1239 return -1; 1240 } 1241 1242 return 0; 930 1243 } 931 1244 -
uspace/lib/c/generic/vol.c
r3feeab2 rff381a7 33 33 */ 34 34 35 #include <abi/ipc/interfaces.h> 35 36 #include <errno.h> 36 37 #include <ipc/services.h> … … 60 61 rc = loc_service_get_id(SERVICE_NAME_VOLSRV, &vol_svcid, 0); 61 62 if (rc != EOK) { 62 rc = E IO;63 rc = ENOENT; 63 64 goto error; 64 65 } 65 66 66 vol->sess = loc_service_connect( EXCHANGE_SERIALIZE, vol_svcid, 0);67 vol->sess = loc_service_connect(vol_svcid, INTERFACE_VOL, 0); 67 68 if (vol->sess == NULL) { 68 69 rc = EIO; -
uspace/lib/c/include/adt/list.h
r3feeab2 rff381a7 133 133 134 134 /** Returns true if the link is definitely part of a list. False if not sure. */ 135 static inline intlink_in_use(link_t *link)135 static inline bool link_in_use(link_t *link) 136 136 { 137 137 return link->prev != NULL && link->next != NULL; … … 237 237 * 238 238 */ 239 static inline intlist_empty(const list_t *list)239 static inline bool list_empty(const list_t *list) 240 240 { 241 241 return (list->head.next == &list->head); … … 357 357 * 358 358 */ 359 static inline link_t *list_nth(list_t *list, unsigned intn)360 { 361 unsigned intcnt = 0;359 static inline link_t *list_nth(list_t *list, unsigned long n) 360 { 361 unsigned long cnt = 0; 362 362 363 363 link_t *link = list_first(list); … … 396 396 } 397 397 398 extern intlist_member(const link_t *, const list_t *);398 extern bool list_member(const link_t *, const list_t *); 399 399 extern void list_concat(list_t *, list_t *); 400 extern unsigned intlist_count(const list_t *);400 extern unsigned long list_count(const list_t *); 401 401 402 402 #endif -
uspace/lib/c/include/async.h
r3feeab2 rff381a7 48 48 #include <abi/ddi/irq.h> 49 49 #include <abi/ipc/event.h> 50 #include <abi/ipc/interfaces.h> 50 51 51 52 typedef ipc_callid_t aid_t; 53 typedef sysarg_t port_id_t; 52 54 53 55 typedef void *(*async_client_data_ctor_t)(void); 54 56 typedef void (*async_client_data_dtor_t)(void *); 55 57 56 /** Client connection handler58 /** Port connection handler 57 59 * 58 60 * @param callid ID of incoming call or 0 if connection initiated from 59 * inside using async_c onnect_to_me()61 * inside using async_create_callback_port() 60 62 * @param call Incoming call or 0 if connection initiated from inside 61 * @param arg Local argument passed from async_new_connection() or 62 * async_connect_to_me() 63 */ 64 typedef void (*async_client_conn_t)(ipc_callid_t, ipc_call_t *, void *); 63 * using async_create_callback_port() 64 * @param arg Local argument. 65 * 66 */ 67 typedef void (*async_port_handler_t)(ipc_callid_t, ipc_call_t *, void *); 65 68 66 69 /** Notification handler */ … … 80 83 EXCHANGE_ATOMIC = 0, 81 84 85 /** Exchange management via mutual exclusion 86 * 87 * Suitable for any kind of client/server communication, 88 * but can limit parallelism. 89 * 90 */ 91 EXCHANGE_SERIALIZE = 1, 92 82 93 /** Exchange management via phone cloning 83 94 * … … 87 98 * 88 99 */ 89 EXCHANGE_PARALLEL, 90 91 /** Exchange management via mutual exclusion 92 * 93 * Suitable for any kind of client/server communication, 94 * but can limit parallelism. 95 * 96 */ 97 EXCHANGE_SERIALIZE 100 EXCHANGE_PARALLEL = 2 98 101 } exch_mgmt_t; 99 102 … … 147 150 extern void async_forget(aid_t); 148 151 149 extern fid_t async_new_connection(task_id_t, sysarg_t, ipc_callid_t,150 ipc_call_t *, async_client_conn_t, void *);151 152 152 extern void async_usleep(suseconds_t); 153 153 extern void async_create_manager(void); … … 160 160 extern void async_put_client_data_by_id(task_id_t); 161 161 162 extern void async_set_client_connection(async_client_conn_t); 162 extern int async_create_port(iface_t, async_port_handler_t, void *, 163 port_id_t *); 164 extern void async_set_fallback_port_handler(async_port_handler_t, void *); 165 extern int async_create_callback_port(async_exch_t *, iface_t, sysarg_t, 166 sysarg_t, async_port_handler_t, void *, port_id_t *); 167 163 168 extern void async_set_notification_handler_stack_size(size_t); 164 169 … … 343 348 extern async_sess_t *async_connect_me_to(exch_mgmt_t, async_exch_t *, sysarg_t, 344 349 sysarg_t, sysarg_t); 350 extern async_sess_t *async_connect_me_to_iface(async_exch_t *, iface_t, 351 sysarg_t, sysarg_t); 345 352 extern async_sess_t *async_connect_me_to_blocking(exch_mgmt_t, async_exch_t *, 346 353 sysarg_t, sysarg_t, sysarg_t); 354 extern async_sess_t *async_connect_me_to_blocking_iface(async_exch_t *, iface_t, 355 sysarg_t, sysarg_t); 347 356 extern async_sess_t *async_connect_kbox(task_id_t); 348 357 349 extern int async_connect_to_me(async_exch_t *, sysarg_t, sysarg_t, sysarg_t, 350 async_client_conn_t, void *); 358 extern int async_connect_to_me(async_exch_t *, sysarg_t, sysarg_t, sysarg_t); 351 359 352 360 extern int async_hangup(async_sess_t *); -
uspace/lib/c/include/devman.h
r3feeab2 rff381a7 42 42 #include <stdbool.h> 43 43 44 extern async_exch_t *devman_exchange_begin_blocking( devman_interface_t);45 extern async_exch_t *devman_exchange_begin( devman_interface_t);44 extern async_exch_t *devman_exchange_begin_blocking(iface_t); 45 extern async_exch_t *devman_exchange_begin(iface_t); 46 46 extern void devman_exchange_end(async_exch_t *); 47 47 … … 53 53 extern int devman_drv_fun_offline(devman_handle_t); 54 54 55 extern async_sess_t *devman_device_connect(exch_mgmt_t, devman_handle_t, 56 unsigned int); 57 extern async_sess_t *devman_parent_device_connect(exch_mgmt_t, devman_handle_t, 55 extern async_sess_t *devman_device_connect(devman_handle_t, unsigned int); 56 extern async_sess_t *devman_parent_device_connect(devman_handle_t, 58 57 unsigned int); 59 58 -
uspace/lib/c/include/errno.h
r3feeab2 rff381a7 47 47 #define ENOTDIR (-258) 48 48 #define ENOSPC (-259) 49 #define EEXIST (-260)50 49 #define ENOTEMPTY (-261) 51 50 #define EBADF (-262) 52 #define ERANGE (-263) 53 #define EXDEV (-264) 54 #define EIO (-265) 55 #define EMLINK (-266) 56 #define ENXIO (-267) 51 #define EDOM (-263) 52 #define ERANGE (-264) 53 #define EXDEV (-265) 54 #define EIO (-266) 55 #define EMLINK (-267) 56 #define ENXIO (-268) 57 57 58 58 /** Bad checksum. */ -
uspace/lib/c/include/io/kio.h
r3feeab2 rff381a7 40 40 #include <io/verify.h> 41 41 42 extern size_t kio_write(const void *, size_t);42 extern int kio_write(const void *, size_t, size_t *); 43 43 extern void kio_update(void); 44 44 extern void kio_command(const void *, size_t); -
uspace/lib/c/include/ipc/devman.h
r3feeab2 rff381a7 141 141 142 142 typedef enum { 143 DEVMAN_DRIVER = 1,144 DEVMAN_CLIENT,145 DEVMAN_CONNECT_TO_DEVICE,146 DEVMAN_CONNECT_FROM_LOC,147 DEVMAN_CONNECT_TO_PARENTS_DEVICE148 } devman_interface_t;149 150 typedef enum {151 143 DEVMAN_DRIVER_REGISTER = IPC_FIRST_USER_METHOD, 152 144 DEVMAN_ADD_FUNCTION, -
uspace/lib/c/include/ipc/inet.h
r3feeab2 rff381a7 37 37 38 38 #include <ipc/common.h> 39 40 /** Inet ports */41 typedef enum {42 /** Default port */43 INET_PORT_DEFAULT = 1,44 /** Configuration port */45 INET_PORT_CFG,46 /** Ping service port */47 INET_PORT_PING,48 /** Ping6 service port */49 INET_PORT_PING650 } inet_port_t;51 39 52 40 /** Requests on Inet default port */ -
uspace/lib/c/include/ipc/loc.h
r3feeab2 rff381a7 76 76 } loc_event_t; 77 77 78 /** Ports provided by location service.79 *80 * Every process that connects to loc must ask one of following81 * ports, otherwise connection will be refused.82 *83 */84 typedef enum {85 /** Service supplier (server) port */86 LOC_PORT_SUPPLIER = 1,87 /** Service consumer (client) port */88 LOC_PORT_CONSUMER,89 /** Create new connection to instance of device that90 is specified by second argument of call. */91 LOC_CONNECT_TO_SERVICE92 } loc_interface_t;93 94 78 typedef struct { 95 79 service_id_t id; -
uspace/lib/c/include/ipc/logger.h
r3feeab2 rff381a7 69 69 } logger_writer_request_t; 70 70 71 typedef enum {72 /** Interface for controlling logger behavior. */73 LOGGER_INTERFACE_CONTROL,74 /** Interface for servers writing to the log. */75 LOGGER_INTERFACE_WRITER76 } logger_interface_t;77 78 71 #endif 79 72 -
uspace/lib/c/include/ipc/services.h
r3feeab2 rff381a7 38 38 #define LIBC_SERVICES_H_ 39 39 40 #include <fourcc.h> 40 #include <sys/types.h> 41 #include <abi/fourcc.h> 41 42 42 43 typedef enum { 43 44 SERVICE_NONE = 0, 44 SERVICE_LOAD 45 SERVICE_LOADER = FOURCC('l', 'o', 'a', 'd'), 45 46 SERVICE_VFS = FOURCC('v', 'f', 's', ' '), 46 47 SERVICE_LOC = FOURCC('l', 'o', 'c', ' '), … … 49 50 SERVICE_IRC = FOURCC('i', 'r', 'c', ' '), 50 51 SERVICE_CLIPBOARD = FOURCC('c', 'l', 'i', 'p'), 51 } service s_t;52 } service_t; 52 53 53 #define SERVICE_NAME_CORECFG "corecfg" 54 #define SERVICE_NAME_DHCP "net/dhcp" 55 #define SERVICE_NAME_DNSR "net/dnsr" 56 #define SERVICE_NAME_INET "net/inet" 57 #define SERVICE_NAME_INETCFG "net/inetcfg" 58 #define SERVICE_NAME_INETPING "net/inetping" 59 #define SERVICE_NAME_INETPING6 "net/inetping6" 60 #define SERVICE_NAME_NETCONF "net/netconf" 61 #define SERVICE_NAME_UDP "net/udp" 62 #define SERVICE_NAME_TCP "net/tcp" 63 #define SERVICE_NAME_VBD "vbd" 64 #define SERVICE_NAME_VOLSRV "volsrv" 54 #define SERVICE_NAME_CORECFG "corecfg" 55 #define SERVICE_NAME_DHCP "net/dhcp" 56 #define SERVICE_NAME_DNSR "net/dnsr" 57 #define SERVICE_NAME_INET "net/inet" 58 #define SERVICE_NAME_NETCONF "net/netconf" 59 #define SERVICE_NAME_UDP "net/udp" 60 #define SERVICE_NAME_TCP "net/tcp" 61 #define SERVICE_NAME_VBD "vbd" 62 #define SERVICE_NAME_VOLSRV "volsrv" 65 63 66 64 #endif -
uspace/lib/c/include/loc.h
r3feeab2 rff381a7 42 42 typedef void (*loc_cat_change_cb_t)(void); 43 43 44 extern async_exch_t *loc_exchange_begin_blocking( loc_interface_t);45 extern async_exch_t *loc_exchange_begin( loc_interface_t);44 extern async_exch_t *loc_exchange_begin_blocking(iface_t); 45 extern async_exch_t *loc_exchange_begin(iface_t); 46 46 extern void loc_exchange_end(async_exch_t *); 47 47 48 48 extern int loc_server_register(const char *); 49 49 extern int loc_service_register(const char *, service_id_t *); 50 extern int loc_service_register_with_iface(const char *, service_id_t *,51 sysarg_t);52 50 extern int loc_service_unregister(service_id_t); 53 51 extern int loc_service_add_to_cat(service_id_t, category_id_t); … … 65 63 extern loc_object_type_t loc_id_probe(service_id_t); 66 64 67 extern async_sess_t *loc_service_connect( exch_mgmt_t, service_id_t,65 extern async_sess_t *loc_service_connect(service_id_t, iface_t, 68 66 unsigned int); 69 67 -
uspace/lib/c/include/ns.h
r3feeab2 rff381a7 41 41 #include <async.h> 42 42 43 extern int service_register(sysarg_t); 44 extern async_sess_t *service_connect(exch_mgmt_t, services_t, sysarg_t, sysarg_t); 45 extern async_sess_t *service_connect_blocking(exch_mgmt_t, services_t, sysarg_t, 46 sysarg_t); 47 extern async_sess_t *service_bind(services_t, sysarg_t, sysarg_t, sysarg_t, 48 async_client_conn_t); 43 extern int service_register(service_t); 44 extern async_sess_t *service_connect(service_t, iface_t, sysarg_t); 45 extern async_sess_t *service_connect_blocking(service_t, iface_t, sysarg_t); 49 46 50 47 extern int ns_ping(void); -
uspace/lib/c/include/stdint.h
r3feeab2 rff381a7 60 60 #define UINT64_MAX UINT64_C(0xFFFFFFFFFFFFFFFF) 61 61 62 #include <libarch/ types.h>62 #include <libarch/stdint.h> 63 63 64 64 /* off64_t */ -
uspace/lib/c/include/stdio.h
r3feeab2 rff381a7 109 109 extern int puts(const char *); 110 110 111 extern int ungetc(int, FILE *); 112 111 113 /* Formatted string output functions */ 112 114 extern int fprintf(FILE *, const char*, ...) … … 132 134 extern FILE *fopen(const char *, const char *); 133 135 extern FILE *fdopen(int, const char *); 136 extern FILE *freopen(const char *, const char *, FILE *); 134 137 extern int fclose(FILE *); 135 138 -
uspace/lib/c/include/sys/statfs.h
r3feeab2 rff381a7 46 46 47 47 extern int statfs(const char *, struct statfs *); 48 48 49 #endif 49 50 -
uspace/lib/c/include/sys/types.h
r3feeab2 rff381a7 46 46 typedef uint64_t aoff64_t; 47 47 48 typedef uint32_t fourcc_t; 49 48 50 typedef volatile uint8_t ioport8_t; 49 51 typedef volatile uint16_t ioport16_t; -
uspace/lib/c/include/unistd.h
r3feeab2 rff381a7 63 63 extern ssize_t read(int, void *, size_t); 64 64 65 extern ssize_t read_all(int, void *, size_t);66 extern ssize_t write_all(int, const void *, size_t);67 68 65 extern off64_t lseek(int, off64_t, int); 69 66 extern int ftruncate(int, aoff64_t); -
uspace/lib/c/include/vfs/vfs.h
r3feeab2 rff381a7 50 50 51 51 52 extern char * absolutize(const char *, size_t *);52 extern char *vfs_absolutize(const char *, size_t *); 53 53 54 extern int mount(const char *, const char *, const char *, const char *,54 extern int vfs_mount(const char *, const char *, const char *, const char *, 55 55 unsigned int, unsigned int); 56 extern int unmount(const char *);56 extern int vfs_unmount(const char *); 57 57 58 extern int fhandle(FILE *, int *);58 extern int vfs_fhandle(FILE *, int *); 59 59 60 extern int fd_wait(void);61 extern int get_mtab_list(list_t *mtab_list);60 extern int vfs_fd_wait(void); 61 extern int vfs_get_mtab_list(list_t *mtab_list); 62 62 63 63 extern async_exch_t *vfs_exchange_begin(void); 64 64 extern void vfs_exchange_end(async_exch_t *); 65 65 66 #endif 66 67 -
uspace/lib/c/include/vfs/vfs_sess.h
r3feeab2 rff381a7 39 39 #include <stdio.h> 40 40 41 extern async_sess_t * fd_session(exch_mgmt_t, int);42 extern async_sess_t * fsession(exch_mgmt_t, FILE *);41 extern async_sess_t *vfs_fd_session(int, iface_t); 42 extern async_sess_t *vfs_fsession(FILE *, iface_t); 43 43 44 44 #endif
Note:
See TracChangeset
for help on using the changeset viewer.