Changes in uspace/srv/devmap/devmap.c [ab108be4:472c09d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devmap/devmap.c
rab108be4 r472c09d 44 44 #include <fibril_synch.h> 45 45 #include <stdlib.h> 46 #include <str .h>46 #include <string.h> 47 47 #include <ipc/devmap.h> 48 48 … … 172 172 173 173 *name = str_dup(fqdn); 174 if (*name == NULL) { 175 free(*ns_name); 176 return false; 177 } 178 179 if (str_cmp(*name, "") == 0) { 180 free(*name); 174 if ((*name == NULL) || (str_cmp(*name, "") == 0)) { 181 175 free(*ns_name); 182 176 return false; … … 192 186 193 187 *name = str_dup(fqdn + slash_after); 194 if ( *name == NULL) {188 if ((*name == NULL) || (str_cmp(*name, "") == 0)) { 195 189 free(*ns_name); 196 190 return false; 197 191 } 198 192 199 if (str_cmp(*name, "") == 0) {200 free(*name);201 free(*ns_name);202 return false;203 }204 205 193 return true; 206 194 } … … 214 202 static devmap_namespace_t *devmap_namespace_find_name(const char *name) 215 203 { 216 link_t *item ;217 for (item = namespaces_list.next; item != &namespaces_list; item = item->next) {218 devmap_namespace_t *namespace =219 204 link_t *item = namespaces_list.next; 205 206 while (item != &namespaces_list) { 207 devmap_namespace_t *namespace = list_get_instance(item, devmap_namespace_t, namespaces); 220 208 if (str_cmp(namespace->name, name) == 0) 221 209 return namespace; 210 item = item->next; 222 211 } 223 212 … … 235 224 static devmap_namespace_t *devmap_namespace_find_handle(dev_handle_t handle) 236 225 { 237 link_t *item ;238 for (item = namespaces_list.next; item != &namespaces_list; item = item->next) {239 devmap_namespace_t *namespace =240 226 link_t *item = namespaces_list.next; 227 228 while (item != &namespaces_list) { 229 devmap_namespace_t *namespace = list_get_instance(item, devmap_namespace_t, namespaces); 241 230 if (namespace->handle == handle) 242 231 return namespace; 232 233 item = item->next; 243 234 } 244 235 … … 255 246 const char *name) 256 247 { 257 link_t *item; 258 for (item = devices_list.next; item != &devices_list; item = item->next) { 259 devmap_device_t *device = 260 list_get_instance(item, devmap_device_t, devices); 261 if ((str_cmp(device->namespace->name, ns_name) == 0) 262 && (str_cmp(device->name, name) == 0)) 248 link_t *item = devices_list.next; 249 250 while (item != &devices_list) { 251 devmap_device_t *device = list_get_instance(item, devmap_device_t, devices); 252 if ((str_cmp(device->namespace->name, ns_name) == 0) && (str_cmp(device->name, name) == 0)) 263 253 return device; 254 item = item->next; 264 255 } 265 256 … … 277 268 static devmap_device_t *devmap_device_find_handle(dev_handle_t handle) 278 269 { 279 link_t *item ;280 for (item = devices_list.next; item != &devices_list; item = item->next) {281 devmap_device_t *device =282 270 link_t *item = devices_list.next; 271 272 while (item != &devices_list) { 273 devmap_device_t *device = list_get_instance(item, devmap_device_t, devices); 283 274 if (device->handle == handle) 284 275 return device; 276 277 item = item->next; 285 278 } 286 279 … … 374 367 list_remove(&(device->driver_devices)); 375 368 369 free(device->namespace); 376 370 free(device->name); 377 371 free(device); … … 392 386 } 393 387 394 devmap_driver_t *driver = 395 (devmap_driver_t *) malloc(sizeof(devmap_driver_t));388 devmap_driver_t *driver = (devmap_driver_t *) malloc(sizeof(devmap_driver_t)); 389 396 390 if (driver == NULL) { 397 391 ipc_answer_0(iid, ENOMEM); … … 402 396 * Get driver name 403 397 */ 404 int rc = async_data_write_accept((void **) &driver->name, true, 0, 405 DEVMAP_NAME_MAXLEN, 0, NULL); 398 int rc = async_string_receive(&driver->name, DEVMAP_NAME_MAXLEN, NULL); 406 399 if (rc != EOK) { 407 400 free(driver); … … 409 402 return NULL; 410 403 } 404 405 /* Initialize mutex for list of devices owned by this driver */ 406 fibril_mutex_initialize(&driver->devices_mutex); 407 408 /* 409 * Initialize list of asociated devices 410 */ 411 list_initialize(&driver->devices); 411 412 412 413 /* … … 417 418 418 419 if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) { 420 ipc_answer_0(callid, ENOTSUP); 421 419 422 free(driver->name); 420 423 free(driver); 421 ipc_answer_0(callid, ENOTSUP);422 424 ipc_answer_0(iid, ENOTSUP); 423 425 return NULL; … … 425 427 426 428 driver->phone = IPC_GET_ARG5(call); 429 427 430 ipc_answer_0(callid, EOK); 428 431 429 /*430 * Initialize mutex for list of devices431 * owned by this driver432 */433 fibril_mutex_initialize(&driver->devices_mutex);434 435 /*436 * Initialize list of asociated devices437 */438 list_initialize(&driver->devices);439 432 list_initialize(&(driver->drivers)); 440 433 … … 442 435 443 436 /* TODO: 444 * Check that no driver with name equal to 445 * driver->name is registered 437 * check that no driver with name equal to driver->name is registered 446 438 */ 447 439 … … 489 481 fibril_mutex_unlock(&drivers_list_mutex); 490 482 491 /* Free name and driver */483 /* free name and driver */ 492 484 if (driver->name != NULL) 493 485 free(driver->name); … … 510 502 511 503 /* Create new device entry */ 512 devmap_device_t *device = 513 (devmap_device_t *) malloc(sizeof(devmap_device_t)); 504 devmap_device_t *device = (devmap_device_t *) malloc(sizeof(devmap_device_t)); 514 505 if (device == NULL) { 515 506 ipc_answer_0(iid, ENOMEM); … … 519 510 /* Get fqdn */ 520 511 char *fqdn; 521 int rc = async_data_write_accept((void **) &fqdn, true, 0, 522 DEVMAP_NAME_MAXLEN, 0, NULL); 512 int rc = async_string_receive(&fqdn, DEVMAP_NAME_MAXLEN, NULL); 523 513 if (rc != EOK) { 524 514 free(device); … … 541 531 devmap_namespace_t *namespace = devmap_namespace_create(ns_name); 542 532 free(ns_name); 543 if ( namespace == NULL) {533 if (!namespace) { 544 534 fibril_mutex_unlock(&devices_list_mutex); 545 free(device->name);546 535 free(device); 547 536 ipc_answer_0(iid, ENOMEM); … … 554 543 /* Check that device is not already registered */ 555 544 if (devmap_device_find_name(namespace->name, device->name) != NULL) { 556 printf("%s: Device '%s/%s' already registered\n", NAME, 557 device->namespace, device->name); 545 printf(NAME ": Device '%s/%s' already registered\n", device->namespace, device->name); 558 546 devmap_namespace_destroy(namespace); 559 547 fibril_mutex_unlock(&devices_list_mutex); 548 free(device->namespace); 560 549 free(device->name); 561 550 free(device); … … 612 601 613 602 if ((dev == NULL) || (dev->driver == NULL) || (dev->driver->phone == 0)) { 614 fibril_mutex_unlock(&devices_list_mutex);615 603 ipc_answer_0(callid, ENOENT); 616 604 return; … … 634 622 635 623 /* Get fqdn */ 636 int rc = async_data_write_accept((void **) &fqdn, true, 0, 637 DEVMAP_NAME_MAXLEN, 0, NULL); 624 int rc = async_string_receive(&fqdn, DEVMAP_NAME_MAXLEN, NULL); 638 625 if (rc != EOK) { 639 626 ipc_answer_0(iid, rc); … … 678 665 return; 679 666 } 667 fibril_mutex_unlock(&devices_list_mutex); 680 668 681 669 ipc_answer_1(iid, EOK, dev->handle); 682 683 fibril_mutex_unlock(&devices_list_mutex);684 670 free(ns_name); 685 671 free(name); … … 697 683 698 684 /* Get device name */ 699 int rc = async_data_write_accept((void **) &name, true, 0, 700 DEVMAP_NAME_MAXLEN, 0, NULL); 685 int rc = async_string_receive(&name, DEVMAP_NAME_MAXLEN, NULL); 701 686 if (rc != EOK) { 702 687 ipc_answer_0(iid, rc); … … 730 715 return; 731 716 } 717 fibril_mutex_unlock(&devices_list_mutex); 732 718 733 719 ipc_answer_1(iid, EOK, namespace->handle); 734 735 fibril_mutex_unlock(&devices_list_mutex);736 720 free(name); 737 721 } … … 741 725 fibril_mutex_lock(&devices_list_mutex); 742 726 743 devmap_namespace_t *namespace = 744 devmap_namespace_find_handle(IPC_GET_ARG1(*icall)); 727 devmap_namespace_t *namespace = devmap_namespace_find_handle(IPC_GET_ARG1(*icall)); 745 728 if (namespace == NULL) { 746 devmap_device_t *dev = 747 devmap_device_find_handle(IPC_GET_ARG1(*icall)); 729 devmap_device_t *dev = devmap_device_find_handle(IPC_GET_ARG1(*icall)); 748 730 if (dev == NULL) 749 731 ipc_answer_1(iid, EOK, DEV_HANDLE_NONE); … … 767 749 fibril_mutex_lock(&devices_list_mutex); 768 750 769 devmap_namespace_t *namespace = 770 devmap_namespace_find_handle(IPC_GET_ARG1(*icall)); 751 devmap_namespace_t *namespace = devmap_namespace_find_handle(IPC_GET_ARG1(*icall)); 771 752 if (namespace == NULL) 772 753 ipc_answer_0(iid, EEXISTS); … … 797 778 size_t count = size / sizeof(dev_desc_t); 798 779 if (count != list_count(&namespaces_list)) { 799 fibril_mutex_unlock(&devices_list_mutex);800 780 ipc_answer_0(callid, EOVERFLOW); 801 781 ipc_answer_0(iid, EOVERFLOW); … … 805 785 dev_desc_t *desc = (dev_desc_t *) malloc(size); 806 786 if (desc == NULL) { 807 fibril_mutex_unlock(&devices_list_mutex);808 787 ipc_answer_0(callid, ENOMEM); 809 788 ipc_answer_0(iid, ENOMEM); … … 811 790 } 812 791 813 link_t *item ;792 link_t *item = namespaces_list.next; 814 793 size_t pos = 0; 815 for (item = namespaces_list.next; item != &namespaces_list; 816 item = item->next) { 817 devmap_namespace_t *namespace = 818 list_get_instance(item, devmap_namespace_t, namespaces); 794 while (item != &namespaces_list) { 795 devmap_namespace_t *namespace = list_get_instance(item, devmap_namespace_t, namespaces); 819 796 820 797 desc[pos].handle = namespace->handle; 821 798 str_cpy(desc[pos].name, DEVMAP_NAME_MAXLEN, namespace->name); 822 799 pos++; 800 801 item = item->next; 823 802 } 824 803 … … 852 831 fibril_mutex_lock(&devices_list_mutex); 853 832 854 devmap_namespace_t *namespace = 855 devmap_namespace_find_handle(IPC_GET_ARG1(*icall)); 833 devmap_namespace_t *namespace = devmap_namespace_find_handle(IPC_GET_ARG1(*icall)); 856 834 if (namespace == NULL) { 857 835 fibril_mutex_unlock(&devices_list_mutex); … … 863 841 size_t count = size / sizeof(dev_desc_t); 864 842 if (count != namespace->refcnt) { 865 fibril_mutex_unlock(&devices_list_mutex);866 843 ipc_answer_0(callid, EOVERFLOW); 867 844 ipc_answer_0(iid, EOVERFLOW); … … 871 848 dev_desc_t *desc = (dev_desc_t *) malloc(size); 872 849 if (desc == NULL) { 873 fibril_mutex_unlock(&devices_list_mutex);874 850 ipc_answer_0(callid, ENOMEM); 875 851 ipc_answer_0(iid, EREFUSED); … … 877 853 } 878 854 879 link_t *item ;855 link_t *item = devices_list.next; 880 856 size_t pos = 0; 881 for (item = devices_list.next; item != &devices_list; item = item->next) { 882 devmap_device_t *device = 883 list_get_instance(item, devmap_device_t, devices); 857 while (item != &devices_list) { 858 devmap_device_t *device = list_get_instance(item, devmap_device_t, devices); 884 859 885 860 if (device->namespace == namespace) { … … 888 863 pos++; 889 864 } 865 866 item = item->next; 890 867 } 891 868 … … 928 905 } 929 906 930 devmap_device_t *device = 931 (devmap_device_t *) malloc(sizeof(devmap_device_t)); 907 devmap_device_t *device = (devmap_device_t *) malloc(sizeof(devmap_device_t)); 932 908 if (device == NULL) { 933 909 fibril_mutex_unlock(&null_devices_mutex); … … 939 915 940 916 devmap_namespace_t *namespace = devmap_namespace_create("null"); 941 if ( namespace == NULL) {917 if (!namespace) { 942 918 fibril_mutex_lock(&devices_list_mutex); 943 919 fibril_mutex_unlock(&null_devices_mutex); … … 969 945 static void devmap_null_destroy(ipc_callid_t iid, ipc_call_t *icall) 970 946 { 947 fibril_mutex_lock(&null_devices_mutex); 948 971 949 ipcarg_t i = IPC_GET_ARG1(*icall); 972 if (i >= NULL_DEVICES) {973 ipc_answer_0(iid, ELIMIT);974 return;975 }976 977 fibril_mutex_lock(&null_devices_mutex);978 950 979 951 if (null_devices[i] == NULL) { 980 fibril_mutex_unlock(&null_devices_mutex);981 952 ipc_answer_0(iid, ENOENT); 982 953 return; … … 990 961 991 962 fibril_mutex_unlock(&null_devices_mutex); 963 992 964 ipc_answer_0(iid, EOK); 993 965 } … … 1145 1117 int main(int argc, char *argv[]) 1146 1118 { 1147 printf( "%s: HelenOS Device Mapper\n", NAME);1119 printf(NAME ": HelenOS Device Mapper\n"); 1148 1120 1149 1121 if (!devmap_init()) { 1150 printf( "%s: Error while initializing service\n", NAME);1122 printf(NAME ": Error while initializing service\n"); 1151 1123 return -1; 1152 1124 } … … 1160 1132 return -1; 1161 1133 1162 printf( "%s: Accepting connections\n", NAME);1134 printf(NAME ": Accepting connections\n"); 1163 1135 async_manager(); 1164 1136
Note:
See TracChangeset
for help on using the changeset viewer.