Changeset 21c5d41 in mainline
- Timestamp:
- 2008-06-03T15:07:52Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bd80465
- Parents:
- 6c89f20
- Location:
- uspace/srv/devmap
- Files:
-
- 1 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devmap/devmap.c
r6c89f20 r21c5d41 45 45 #include <stdlib.h> 46 46 #include <string.h> 47 48 #include "devmap.h" 47 #include <ipc/devmap.h> 48 49 #define NAME "devmap" 49 50 50 51 … … 113 114 } 114 115 115 if (item == &devices_list) { 116 printf("DEVMAP: no device named %s.\n", name); 116 if (item == &devices_list) 117 117 return NULL; 118 }119 118 120 119 device = list_get_instance(item, devmap_device_t, devices); … … 204 203 */ 205 204 if (!ipc_data_write_receive(&callid, &name_size)) { 206 printf("Unexpected request.\n");207 205 free(driver); 208 206 ipc_answer_0(callid, EREFUSED); … … 212 210 213 211 if (name_size > DEVMAP_NAME_MAXLEN) { 214 printf("Too logn name: %u: maximum is %u.\n", name_size,215 DEVMAP_NAME_MAXLEN);216 212 free(driver); 217 213 ipc_answer_0(callid, EINVAL); … … 224 220 */ 225 221 if (NULL == (driver->name = (char *)malloc(name_size + 1))) { 226 printf("Cannot allocate space for driver name.\n");227 222 free(driver); 228 223 ipc_answer_0(callid, ENOMEM); … … 235 230 */ 236 231 if (EOK != ipc_data_write_finalize(callid, driver->name, name_size)) { 237 printf("Cannot read driver name.\n");238 232 free(driver->name); 239 233 free(driver); … … 244 238 driver->name[name_size] = 0; 245 239 246 printf("Read driver name: '%s'.\n", driver->name);247 248 240 /* Initialize futex for list of devices owned by this driver */ 249 241 futex_initialize(&(driver->devices_futex), 1); … … 260 252 261 253 if (IPC_M_CONNECT_TO_ME != IPC_GET_METHOD(call)) { 262 printf("DEVMAP: Unexpected method: %u.\n",263 IPC_GET_METHOD(call));264 254 ipc_answer_0(callid, ENOTSUP); 265 255 … … 289 279 290 280 ipc_answer_0(iid, EOK); 291 printf("Driver registered.\n");292 281 293 282 *odriver = driver; 294 return;295 283 } 296 284 … … 302 290 devmap_device_t *device; 303 291 304 if (NULL == driver) { 305 printf("Error: driver == NULL.\n"); 292 if (NULL == driver) 306 293 return EEXISTS; 307 } 308 309 printf("Unregister driver '%s'.\n", driver->name); 294 310 295 futex_down(&drivers_list_futex); 311 296 … … 323 308 device = list_get_instance(driver->devices.next, 324 309 devmap_device_t, driver_devices); 325 printf("Unregister device '%s'.\n", device->name);326 310 devmap_device_unregister_core(device); 327 311 } … … 338 322 free(driver); 339 323 340 printf("Driver unregistered.\n");341 342 324 return EOK; 343 325 } … … 355 337 356 338 if (NULL == driver) { 357 printf("Invalid driver registration.\n");358 339 ipc_answer_0(iid, EREFUSED); 359 340 return; … … 362 343 /* Create new device entry */ 363 344 if (NULL == 364 (device = (devmap_device_t *)malloc(sizeof(devmap_device_t)))) { 365 printf("Cannot allocate new device.\n"); 345 (device = (devmap_device_t *) malloc(sizeof(devmap_device_t)))) { 366 346 ipc_answer_0(iid, ENOMEM); 367 347 return; … … 371 351 if (!ipc_data_write_receive(&callid, &size)) { 372 352 free(device); 373 printf("Cannot read device name.\n");374 353 ipc_answer_0(iid, EREFUSED); 375 354 return; … … 377 356 378 357 if (size > DEVMAP_NAME_MAXLEN) { 379 printf("Too long device name: %u.\n", size);380 358 free(device); 381 359 ipc_answer_0(callid, EINVAL); … … 383 361 return; 384 362 } 385 386 387 device->name = (char *) malloc(size + 1);363 364 /* +1 for terminating \0 */ 365 device->name = (char *) malloc(size + 1); 388 366 389 367 if (NULL == device->name) { 390 printf("Cannot read device name.\n");391 368 free(device); 392 369 ipc_answer_0(callid, ENOMEM); … … 405 382 /* Check that device with such name is not already registered */ 406 383 if (NULL != devmap_device_find_name(device->name)) { 407 printf( "Device '%s' already registered.\n", device->name);384 printf(NAME ": Device '%s' already registered\n", device->name); 408 385 futex_up(&devices_list_futex); 409 386 free(device->name); … … 429 406 futex_up(&devices_list_futex); 430 407 431 printf("Device '%s' registered.\n", device->name);432 408 ipc_answer_1(iid, EOK, device->handle); 433 434 return;435 409 } 436 410 … … 462 436 463 437 if (NULL == dev) { 464 printf("DEVMAP: No registered device with handle %d.\n",465 handle);466 438 ipc_answer_0(callid, ENOENT); 467 439 return; … … 470 442 ipc_forward_fast(callid, dev->driver->phone, (ipcarg_t)(dev->handle), 471 443 IPC_GET_ARG3(*call), 0, IPC_FF_NONE); 472 return;473 444 } 474 445 … … 485 456 ipcarg_t retval; 486 457 487 488 458 /* 489 459 * Wait for incoming message with device name (but do not … … 529 499 */ 530 500 if (NULL == dev) { 531 printf("DEVMAP: device %s has not been registered.\n", name);532 501 ipc_answer_0(iid, ENOENT); 533 502 return; 534 503 } 535 504 536 printf("DEVMAP: device %s has handler %d.\n", name, dev->handle);537 538 505 ipc_answer_1(iid, EOK, dev->handle); 539 540 return;541 506 } 542 507 … … 575 540 */ 576 541 /* TODO: send name in response */ 577 578 return;579 542 } 580 543 … … 582 545 * 583 546 */ 584 static void 585 devmap_connection_driver(ipc_callid_t iid, ipc_call_t *icall) 547 static void devmap_connection_driver(ipc_callid_t iid, ipc_call_t *icall) 586 548 { 587 549 ipc_callid_t callid; … … 594 556 devmap_driver_register(&driver); 595 557 596 if (NULL == driver) { 597 printf("DEVMAP: driver registration failed.\n"); 598 return; 599 } 558 if (NULL == driver) 559 return; 600 560 601 561 while (cont) { … … 604 564 switch (IPC_GET_METHOD(call)) { 605 565 case IPC_M_PHONE_HUNGUP: 606 printf("DEVMAP: connection hung up.\n");607 566 cont = false; 608 567 continue; /* Exit thread */ 609 568 case DEVMAP_DRIVER_UNREGISTER: 610 printf("DEVMAP: unregister driver.\n");611 569 if (NULL == driver) { 612 printf("DEVMAP: driver was not registered!\n");613 570 ipc_answer_0(callid, ENOENT); 614 571 } else { … … 650 607 * 651 608 */ 652 static void 653 devmap_connection_client(ipc_callid_t iid, ipc_call_t *icall) 609 static void devmap_connection_client(ipc_callid_t iid, ipc_call_t *icall) 654 610 { 655 611 ipc_callid_t callid; … … 664 620 switch (IPC_GET_METHOD(call)) { 665 621 case IPC_M_PHONE_HUNGUP: 666 printf("DEVMAP: connection hung up.\n");667 622 cont = false; 668 623 continue; /* Exit thread */ … … 687 642 * 688 643 */ 689 static void 690 devmap_connection(ipc_callid_t iid, ipc_call_t *icall) 691 { 692 693 printf("DEVMAP: new connection.\n"); 694 695 /* Select interface */ 696 switch ((ipcarg_t)(IPC_GET_ARG1(*icall))) { 644 static void devmap_connection(ipc_callid_t iid, ipc_call_t *icall) 645 { 646 /* Select interface */ 647 switch ((ipcarg_t) (IPC_GET_ARG1(*icall))) { 697 648 case DEVMAP_DRIVER: 698 649 devmap_connection_driver(iid, icall); … … 702 653 break; 703 654 case DEVMAP_CONNECT_TO_DEVICE: 704 /* Connect client to selected device */ 705 printf("DEVMAP: connect to device %d.\n", 706 IPC_GET_ARG2(*icall)); 655 /* Connect client to selected device */ 707 656 devmap_forward(iid, icall); 708 657 break; 709 658 default: 710 659 ipc_answer_0(iid, ENOENT); /* No such interface */ 711 printf("DEVMAP: Unknown interface %u.\n",712 (ipcarg_t)(IPC_GET_ARG1(*icall)));713 660 } 714 661 715 662 /* Cleanup */ 716 717 printf("DEVMAP: connection closed.\n");718 return;719 663 } 720 664 … … 724 668 int main(int argc, char *argv[]) 725 669 { 670 printf(NAME ": HelenOS Device Mapper\n"); 671 726 672 ipcarg_t phonead; 727 673 728 printf("DEVMAP: HelenOS device mapper.\n");729 730 674 if (devmap_init() != 0) { 731 printf( "Error while initializing DEVMAP service.\n");675 printf(NAME ": Error while initializing service\n"); 732 676 return -1; 733 677 } 734 735 678 679 /* Set a handler of incomming connections */ 736 680 async_set_client_connection(devmap_connection); 737 681 … … 740 684 return -1; 741 685 686 printf(NAME ": Accepting connections\n"); 742 687 async_manager(); 743 688 /* Never reached */ … … 748 693 * @} 749 694 */ 750
Note:
See TracChangeset
for help on using the changeset viewer.