Changeset b74959bd in mainline for uspace/srv/devmap/devmap.c
- Timestamp:
- 2007-11-20T21:33:32Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8498915
- Parents:
- 3209923
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devmap/devmap.c
r3209923 rb74959bd 114 114 115 115 if (item == &devices_list) { 116 printf("D evMap: no device named %s.\n", name);116 printf("DEVMAP: no device named %s.\n", name); 117 117 return NULL; 118 118 } … … 190 190 191 191 if (IPC_GET_METHOD(icall) != DEVMAP_DRIVER_REGISTER) { 192 ipc_answer_ fast(iid, EREFUSED, 0, 0);192 ipc_answer_0(iid, EREFUSED); 193 193 return; 194 194 } … … 196 196 if (NULL == 197 197 (driver = (devmap_driver_t *)malloc(sizeof(devmap_driver_t)))) { 198 ipc_answer_ fast(iid, ENOMEM, 0, 0);198 ipc_answer_0(iid, ENOMEM); 199 199 return; 200 200 } … … 203 203 * Get driver name 204 204 */ 205 if (!ipc_data_receive(&callid, &call,NULL, &name_size)) {206 printf("Unexpected request : %u.\n", IPC_GET_METHOD(call));205 if (!ipc_data_receive(&callid, NULL, &name_size)) { 206 printf("Unexpected request.\n"); 207 207 free(driver); 208 ipc_answer_ fast(callid, EREFUSED, 0, 0);209 ipc_answer_ fast(iid, EREFUSED, 0, 0);208 ipc_answer_0(callid, EREFUSED); 209 ipc_answer_0(iid, EREFUSED); 210 210 return; 211 211 } … … 215 215 DEVMAP_NAME_MAXLEN); 216 216 free(driver); 217 ipc_answer_ fast(callid, EINVAL, 0, 0);218 ipc_answer_ fast(iid, EREFUSED, 0, 0);217 ipc_answer_0(callid, EINVAL); 218 ipc_answer_0(iid, EREFUSED); 219 219 return; 220 220 } … … 226 226 printf("Cannot allocate space for driver name.\n"); 227 227 free(driver); 228 ipc_answer_ fast(callid, ENOMEM, 0, 0);229 ipc_answer_ fast(iid, EREFUSED, 0, 0);228 ipc_answer_0(callid, ENOMEM); 229 ipc_answer_0(iid, EREFUSED); 230 230 return; 231 231 } … … 234 234 * Send confirmation to sender and get data into buffer. 235 235 */ 236 if (EOK != ipc_data_deliver(callid, &call,driver->name, name_size)) {236 if (EOK != ipc_data_deliver(callid, driver->name, name_size)) { 237 237 printf("Cannot read driver name.\n"); 238 238 free(driver->name); 239 239 free(driver); 240 ipc_answer_ fast(iid, EREFUSED, 0, 0);240 ipc_answer_0(iid, EREFUSED); 241 241 return; 242 242 } … … 251 251 /* 252 252 * Initialize list of asociated devices 253 253 */ 254 254 list_initialize(&(driver->devices)); 255 255 … … 260 260 261 261 if (IPC_M_CONNECT_TO_ME != IPC_GET_METHOD(call)) { 262 printf("D evMap: Unexpected method: %u.\n",262 printf("DEVMAP: Unexpected method: %u.\n", 263 263 IPC_GET_METHOD(call)); 264 ipc_answer_ fast(callid, ENOTSUP, 0, 0);264 ipc_answer_0(callid, ENOTSUP); 265 265 266 266 free(driver->name); 267 267 free(driver); 268 ipc_answer_ fast(iid, ENOTSUP, 0, 0);268 ipc_answer_0(iid, ENOTSUP); 269 269 return; 270 270 } … … 272 272 driver->phone = IPC_GET_ARG3(call); 273 273 274 ipc_answer_ fast(callid, EOK, 0, 0);274 ipc_answer_0(callid, EOK); 275 275 276 276 list_initialize(&(driver->drivers)); … … 288 288 futex_up(&drivers_list_futex); 289 289 290 ipc_answer_ fast(iid, EOK, 0, 0);290 ipc_answer_0(iid, EOK); 291 291 printf("Driver registered.\n"); 292 292 … … 295 295 } 296 296 297 /** Unregister device driver, unregister all its devices and free driver structure.298 * 297 /** Unregister device driver, unregister all its devices and free driver 298 * structure. 299 299 */ 300 300 static int devmap_driver_unregister(devmap_driver_t *driver) … … 348 348 */ 349 349 static void devmap_device_register(ipc_callid_t iid, ipc_call_t *icall, 350 350 devmap_driver_t *driver) 351 351 { 352 352 ipc_callid_t callid; 353 ipc_call_t call;354 353 size_t size; 355 354 devmap_device_t *device; … … 357 356 if (NULL == driver) { 358 357 printf("Invalid driver registration.\n"); 359 ipc_answer_ fast(iid, EREFUSED, 0, 0);358 ipc_answer_0(iid, EREFUSED); 360 359 return; 361 360 } … … 365 364 (device = (devmap_device_t *)malloc(sizeof(devmap_device_t)))) { 366 365 printf("Cannot allocate new device.\n"); 367 ipc_answer_ fast(iid, ENOMEM, 0, 0);366 ipc_answer_0(iid, ENOMEM); 368 367 return; 369 368 } 370 369 371 370 /* Get device name */ 372 if (!ipc_data_receive(&callid, &call,NULL, &size)) {371 if (!ipc_data_receive(&callid, NULL, &size)) { 373 372 free(device); 374 373 printf("Cannot read device name.\n"); 375 ipc_answer_ fast(iid, EREFUSED, 0, 0);374 ipc_answer_0(iid, EREFUSED); 376 375 return; 377 376 } … … 380 379 printf("Too long device name: %u.\n", size); 381 380 free(device); 382 ipc_answer_ fast(callid, EINVAL, 0, 0);383 ipc_answer_ fast(iid, EREFUSED, 0, 0);381 ipc_answer_0(callid, EINVAL); 382 ipc_answer_0(iid, EREFUSED); 384 383 return; 385 384 } … … 391 390 printf("Cannot read device name.\n"); 392 391 free(device); 393 ipc_answer_ fast(callid, ENOMEM, 0, 0);394 ipc_answer_ fast(iid, EREFUSED, 0, 0);395 return; 396 } 397 398 ipc_data_deliver(callid, &call,device->name, size);392 ipc_answer_0(callid, ENOMEM); 393 ipc_answer_0(iid, EREFUSED); 394 return; 395 } 396 397 ipc_data_deliver(callid, device->name, size); 399 398 device->name[size] = 0; 400 399 … … 410 409 free(device->name); 411 410 free(device); 412 ipc_answer_ fast(iid, EEXISTS, 0, 0);411 ipc_answer_0(iid, EEXISTS); 413 412 return; 414 413 } … … 420 419 421 420 /* Insert device into list of all devices */ 422 list_append(& (device->devices), &devices_list);421 list_append(&device->devices, &devices_list); 423 422 424 423 /* Insert device into list of devices that belog to one driver */ 425 futex_down(& (device->driver->devices_futex));426 427 list_append(& (device->driver_devices), &(device->driver->devices));428 429 futex_up(& (device->driver->devices_futex));424 futex_down(&device->driver->devices_futex); 425 426 list_append(&device->driver_devices, &device->driver->devices); 427 428 futex_up(&device->driver->devices_futex); 430 429 futex_up(&devices_list_futex); 431 430 432 431 printf("Device '%s' registered.\n", device->name); 433 ipc_answer_ fast(iid, EOK, device->handle, 0);432 ipc_answer_1(iid, EOK, device->handle); 434 433 435 434 return; … … 440 439 */ 441 440 static int devmap_device_unregister(ipc_callid_t iid, ipc_call_t *icall, 442 441 devmap_driver_t *driver) 443 442 { 444 443 /* TODO */ … … 465 464 466 465 if (NULL == dev) { 467 printf("D evMap: No registered device with handle %d.\n",466 printf("DEVMAP: No registered device with handle %d.\n", 468 467 handle); 469 ipc_answer_ fast(callid, ENOENT, 0, 0);468 ipc_answer_0(callid, ENOENT); 470 469 return; 471 470 } … … 487 486 const devmap_device_t *dev; 488 487 ipc_callid_t callid; 489 ipc_call_t call;490 488 ipcarg_t retval; 491 489 … … 495 493 * read the name itself until the buffer is allocated). 496 494 */ 497 if (!ipc_data_receive(&callid, &call,NULL, &name_size)) {498 ipc_answer_ fast(callid, EREFUSED, 0, 0);499 ipc_answer_ fast(iid, EREFUSED, 0, 0);495 if (!ipc_data_receive(&callid, NULL, &name_size)) { 496 ipc_answer_0(callid, EREFUSED); 497 ipc_answer_0(iid, EREFUSED); 500 498 return; 501 499 } 502 500 503 501 if (name_size > DEVMAP_NAME_MAXLEN) { 504 ipc_answer_ fast(callid, EINVAL, 0, 0);505 ipc_answer_ fast(iid, EREFUSED, 0, 0);502 ipc_answer_0(callid, EINVAL); 503 ipc_answer_0(iid, EREFUSED); 506 504 return; 507 505 } … … 511 509 */ 512 510 if (NULL == (name = (char *)malloc(name_size))) { 513 ipc_answer_ fast(callid, ENOMEM, 0, 0);514 ipc_answer_ fast(iid, EREFUSED, 0, 0);511 ipc_answer_0(callid, ENOMEM); 512 ipc_answer_0(iid, EREFUSED); 515 513 return; 516 514 } … … 519 517 * Send confirmation to sender and get data into buffer. 520 518 */ 521 if (EOK != (retval = ipc_data_deliver(callid, &call, name, 522 name_size))) { 523 ipc_answer_fast(iid, EREFUSED, 0, 0); 519 if (EOK != (retval = ipc_data_deliver(callid, name, name_size))) { 520 ipc_answer_0(iid, EREFUSED); 524 521 return; 525 522 } … … 534 531 */ 535 532 if (NULL == dev) { 536 printf("D evMap: device %s has not been registered.\n", name);537 ipc_answer_ fast(iid, ENOENT, 0, 0);538 return; 539 } 540 541 printf("D evMap: device %s has handler %d.\n", name, dev->handle);533 printf("DEVMAP: device %s has not been registered.\n", name); 534 ipc_answer_0(iid, ENOENT); 535 return; 536 } 537 538 printf("DEVMAP: device %s has handler %d.\n", name, dev->handle); 542 539 543 ipc_answer_ fast(iid, EOK, dev->handle, 0);540 ipc_answer_1(iid, EOK, dev->handle); 544 541 545 542 return; … … 560 557 */ 561 558 if (NULL == device) { 562 ipc_answer_ fast(iid, ENOENT, 0, 0);559 ipc_answer_0(iid, ENOENT); 563 560 return; 564 561 } 565 562 566 ipc_answer_ fast(iid, EOK, 0, 0);563 ipc_answer_0(iid, EOK); 567 564 568 565 name_size = strlen(device->name); … … 570 567 571 568 /* FIXME: 572 we have no channel from D evMapto client ->569 we have no channel from DEVMAP to client -> 573 570 sending must be initiated by client 574 571 … … 595 592 devmap_driver_t *driver = NULL; 596 593 597 ipc_answer_ fast(iid, EOK, 0, 0);594 ipc_answer_0(iid, EOK); 598 595 599 596 devmap_driver_register(&driver); 600 597 601 598 if (NULL == driver) { 602 printf("D evMap: driver registration failed.\n");599 printf("DEVMAP: driver registration failed.\n"); 603 600 return; 604 601 } … … 609 606 switch (IPC_GET_METHOD(call)) { 610 607 case IPC_M_PHONE_HUNGUP: 611 printf("D evMap: connection hung up.\n");608 printf("DEVMAP: connection hung up.\n"); 612 609 cont = false; 613 610 continue; /* Exit thread */ 614 611 case DEVMAP_DRIVER_UNREGISTER: 615 printf("D evMap: unregister driver.\n");612 printf("DEVMAP: unregister driver.\n"); 616 613 if (NULL == driver) { 617 printf("D evMap: driver was not registered!\n");618 ipc_answer_ fast(callid, ENOENT, 0, 0);614 printf("DEVMAP: driver was not registered!\n"); 615 ipc_answer_0(callid, ENOENT); 619 616 } else { 620 ipc_answer_ fast(callid, EOK, 0, 0);617 ipc_answer_0(callid, EOK); 621 618 } 622 619 break; … … 637 634 default: 638 635 if (!(callid & IPC_CALLID_NOTIFICATION)) { 639 ipc_answer_ fast(callid, ENOENT, 0, 0);636 ipc_answer_0(callid, ENOENT); 640 637 } 641 638 } … … 643 640 644 641 if (NULL != driver) { 645 646 647 642 /* 643 * Unregister the device driver and all its devices. 644 */ 648 645 devmap_driver_unregister(driver); 649 646 driver = NULL; … … 662 659 bool cont = true; 663 660 664 ipc_answer_ fast(iid, EOK, 0, 0); /* Accept connection */661 ipc_answer_0(iid, EOK); /* Accept connection */ 665 662 666 663 while (cont) { … … 669 666 switch (IPC_GET_METHOD(call)) { 670 667 case IPC_M_PHONE_HUNGUP: 671 printf("D evMap: connection hung up.\n");668 printf("DEVMAP: connection hung up.\n"); 672 669 cont = false; 673 670 continue; /* Exit thread */ … … 675 672 case DEVMAP_DEVICE_CONNECT_ME_TO: 676 673 /* Connect client to selected device */ 677 printf("D evMap: connect to device %d.\n",674 printf("DEVMAP: connect to device %d.\n", 678 675 IPC_GET_ARG1(call)); 679 676 devmap_forward(callid, &call); … … 690 687 default: 691 688 if (!(callid & IPC_CALLID_NOTIFICATION)) { 692 ipc_answer_ fast(callid, ENOENT, 0, 0);689 ipc_answer_0(callid, ENOENT); 693 690 } 694 691 } … … 703 700 { 704 701 705 printf("D evMap: new connection.\n");702 printf("DEVMAP: new connection.\n"); 706 703 707 704 /* Select interface */ … … 714 711 break; 715 712 default: 716 ipc_answer_ fast(iid, ENOENT, 0, 0); /* No such interface */717 printf("D evMap: Unknown interface %u.\n",713 ipc_answer_0(iid, ENOENT); /* No such interface */ 714 printf("DEVMAP: Unknown interface %u.\n", 718 715 (ipcarg_t)(IPC_GET_ARG1(*icall))); 719 716 } … … 721 718 /* Cleanup */ 722 719 723 printf("D evMap: connection closed.\n");720 printf("DEVMAP: connection closed.\n"); 724 721 return; 725 722 } … … 732 729 ipcarg_t phonead; 733 730 734 printf("D evMap: HelenOS device mapper.\n");731 printf("DEVMAP: HelenOS device mapper.\n"); 735 732 736 733 if (devmap_init() != 0) { 737 printf("Error while initializing D evMapservice.\n");734 printf("Error while initializing DEVMAP service.\n"); 738 735 return -1; 739 736 }
Note:
See TracChangeset
for help on using the changeset viewer.