Changes in uspace/srv/devmap/devmap.c [19f857a:ab108be4] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devmap/devmap.c
r19f857a rab108be4 172 172 173 173 *name = str_dup(fqdn); 174 if ((*name == NULL) || (str_cmp(*name, "") == 0)) { 174 if (*name == NULL) { 175 free(*ns_name); 176 return false; 177 } 178 179 if (str_cmp(*name, "") == 0) { 180 free(*name); 175 181 free(*ns_name); 176 182 return false; … … 186 192 187 193 *name = str_dup(fqdn + slash_after); 188 if ( (*name == NULL) || (str_cmp(*name, "") == 0)) {194 if (*name == NULL) { 189 195 free(*ns_name); 190 196 return false; 191 197 } 192 198 199 if (str_cmp(*name, "") == 0) { 200 free(*name); 201 free(*ns_name); 202 return false; 203 } 204 193 205 return true; 194 206 } … … 202 214 static devmap_namespace_t *devmap_namespace_find_name(const char *name) 203 215 { 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);216 link_t *item; 217 for (item = namespaces_list.next; item != &namespaces_list; item = item->next) { 218 devmap_namespace_t *namespace = 219 list_get_instance(item, devmap_namespace_t, namespaces); 208 220 if (str_cmp(namespace->name, name) == 0) 209 221 return namespace; 210 item = item->next;211 222 } 212 223 … … 224 235 static devmap_namespace_t *devmap_namespace_find_handle(dev_handle_t handle) 225 236 { 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);237 link_t *item; 238 for (item = namespaces_list.next; item != &namespaces_list; item = item->next) { 239 devmap_namespace_t *namespace = 240 list_get_instance(item, devmap_namespace_t, namespaces); 230 241 if (namespace->handle == handle) 231 242 return namespace; 232 233 item = item->next;234 243 } 235 244 … … 246 255 const char *name) 247 256 { 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)) 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)) 253 263 return device; 254 item = item->next;255 264 } 256 265 … … 268 277 static devmap_device_t *devmap_device_find_handle(dev_handle_t handle) 269 278 { 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);279 link_t *item; 280 for (item = devices_list.next; item != &devices_list; item = item->next) { 281 devmap_device_t *device = 282 list_get_instance(item, devmap_device_t, devices); 274 283 if (device->handle == handle) 275 284 return device; 276 277 item = item->next;278 285 } 279 286 … … 367 374 list_remove(&(device->driver_devices)); 368 375 369 free(device->namespace);370 376 free(device->name); 371 377 free(device); … … 386 392 } 387 393 388 devmap_driver_t *driver = (devmap_driver_t *) malloc(sizeof(devmap_driver_t));389 394 devmap_driver_t *driver = 395 (devmap_driver_t *) malloc(sizeof(devmap_driver_t)); 390 396 if (driver == NULL) { 391 397 ipc_answer_0(iid, ENOMEM); … … 404 410 } 405 411 406 /* Initialize mutex for list of devices owned by this driver */ 412 /* 413 * Create connection to the driver 414 */ 415 ipc_call_t call; 416 ipc_callid_t callid = async_get_call(&call); 417 418 if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) { 419 free(driver->name); 420 free(driver); 421 ipc_answer_0(callid, ENOTSUP); 422 ipc_answer_0(iid, ENOTSUP); 423 return NULL; 424 } 425 426 driver->phone = IPC_GET_ARG5(call); 427 ipc_answer_0(callid, EOK); 428 429 /* 430 * Initialize mutex for list of devices 431 * owned by this driver 432 */ 407 433 fibril_mutex_initialize(&driver->devices_mutex); 408 434 … … 411 437 */ 412 438 list_initialize(&driver->devices); 413 414 /*415 * Create connection to the driver416 */417 ipc_call_t call;418 ipc_callid_t callid = async_get_call(&call);419 420 if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) {421 ipc_answer_0(callid, ENOTSUP);422 423 free(driver->name);424 free(driver);425 ipc_answer_0(iid, ENOTSUP);426 return NULL;427 }428 429 driver->phone = IPC_GET_ARG5(call);430 431 ipc_answer_0(callid, EOK);432 433 439 list_initialize(&(driver->drivers)); 434 440 … … 436 442 437 443 /* TODO: 438 * check that no driver with name equal to driver->name is registered 444 * Check that no driver with name equal to 445 * driver->name is registered 439 446 */ 440 447 … … 482 489 fibril_mutex_unlock(&drivers_list_mutex); 483 490 484 /* free name and driver */491 /* Free name and driver */ 485 492 if (driver->name != NULL) 486 493 free(driver->name); … … 503 510 504 511 /* Create new device entry */ 505 devmap_device_t *device = (devmap_device_t *) malloc(sizeof(devmap_device_t)); 512 devmap_device_t *device = 513 (devmap_device_t *) malloc(sizeof(devmap_device_t)); 506 514 if (device == NULL) { 507 515 ipc_answer_0(iid, ENOMEM); … … 533 541 devmap_namespace_t *namespace = devmap_namespace_create(ns_name); 534 542 free(ns_name); 535 if ( !namespace) {543 if (namespace == NULL) { 536 544 fibril_mutex_unlock(&devices_list_mutex); 545 free(device->name); 537 546 free(device); 538 547 ipc_answer_0(iid, ENOMEM); … … 545 554 /* Check that device is not already registered */ 546 555 if (devmap_device_find_name(namespace->name, device->name) != NULL) { 547 printf(NAME ": Device '%s/%s' already registered\n", device->namespace, device->name); 556 printf("%s: Device '%s/%s' already registered\n", NAME, 557 device->namespace, device->name); 548 558 devmap_namespace_destroy(namespace); 549 559 fibril_mutex_unlock(&devices_list_mutex); 550 free(device->namespace);551 560 free(device->name); 552 561 free(device); … … 603 612 604 613 if ((dev == NULL) || (dev->driver == NULL) || (dev->driver->phone == 0)) { 614 fibril_mutex_unlock(&devices_list_mutex); 605 615 ipc_answer_0(callid, ENOENT); 606 616 return; … … 668 678 return; 669 679 } 680 681 ipc_answer_1(iid, EOK, dev->handle); 682 670 683 fibril_mutex_unlock(&devices_list_mutex); 671 672 ipc_answer_1(iid, EOK, dev->handle);673 684 free(ns_name); 674 685 free(name); … … 719 730 return; 720 731 } 732 733 ipc_answer_1(iid, EOK, namespace->handle); 734 721 735 fibril_mutex_unlock(&devices_list_mutex); 722 723 ipc_answer_1(iid, EOK, namespace->handle);724 736 free(name); 725 737 } … … 729 741 fibril_mutex_lock(&devices_list_mutex); 730 742 731 devmap_namespace_t *namespace = devmap_namespace_find_handle(IPC_GET_ARG1(*icall)); 743 devmap_namespace_t *namespace = 744 devmap_namespace_find_handle(IPC_GET_ARG1(*icall)); 732 745 if (namespace == NULL) { 733 devmap_device_t *dev = devmap_device_find_handle(IPC_GET_ARG1(*icall)); 746 devmap_device_t *dev = 747 devmap_device_find_handle(IPC_GET_ARG1(*icall)); 734 748 if (dev == NULL) 735 749 ipc_answer_1(iid, EOK, DEV_HANDLE_NONE); … … 753 767 fibril_mutex_lock(&devices_list_mutex); 754 768 755 devmap_namespace_t *namespace = devmap_namespace_find_handle(IPC_GET_ARG1(*icall)); 769 devmap_namespace_t *namespace = 770 devmap_namespace_find_handle(IPC_GET_ARG1(*icall)); 756 771 if (namespace == NULL) 757 772 ipc_answer_0(iid, EEXISTS); … … 782 797 size_t count = size / sizeof(dev_desc_t); 783 798 if (count != list_count(&namespaces_list)) { 799 fibril_mutex_unlock(&devices_list_mutex); 784 800 ipc_answer_0(callid, EOVERFLOW); 785 801 ipc_answer_0(iid, EOVERFLOW); … … 789 805 dev_desc_t *desc = (dev_desc_t *) malloc(size); 790 806 if (desc == NULL) { 807 fibril_mutex_unlock(&devices_list_mutex); 791 808 ipc_answer_0(callid, ENOMEM); 792 809 ipc_answer_0(iid, ENOMEM); … … 794 811 } 795 812 796 link_t *item = namespaces_list.next;813 link_t *item; 797 814 size_t pos = 0; 798 while (item != &namespaces_list) { 799 devmap_namespace_t *namespace = list_get_instance(item, devmap_namespace_t, namespaces); 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); 800 819 801 820 desc[pos].handle = namespace->handle; 802 821 str_cpy(desc[pos].name, DEVMAP_NAME_MAXLEN, namespace->name); 803 822 pos++; 804 805 item = item->next;806 823 } 807 824 … … 835 852 fibril_mutex_lock(&devices_list_mutex); 836 853 837 devmap_namespace_t *namespace = devmap_namespace_find_handle(IPC_GET_ARG1(*icall)); 854 devmap_namespace_t *namespace = 855 devmap_namespace_find_handle(IPC_GET_ARG1(*icall)); 838 856 if (namespace == NULL) { 839 857 fibril_mutex_unlock(&devices_list_mutex); … … 845 863 size_t count = size / sizeof(dev_desc_t); 846 864 if (count != namespace->refcnt) { 865 fibril_mutex_unlock(&devices_list_mutex); 847 866 ipc_answer_0(callid, EOVERFLOW); 848 867 ipc_answer_0(iid, EOVERFLOW); … … 852 871 dev_desc_t *desc = (dev_desc_t *) malloc(size); 853 872 if (desc == NULL) { 873 fibril_mutex_unlock(&devices_list_mutex); 854 874 ipc_answer_0(callid, ENOMEM); 855 875 ipc_answer_0(iid, EREFUSED); … … 857 877 } 858 878 859 link_t *item = devices_list.next;879 link_t *item; 860 880 size_t pos = 0; 861 while (item != &devices_list) { 862 devmap_device_t *device = list_get_instance(item, devmap_device_t, devices); 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); 863 884 864 885 if (device->namespace == namespace) { … … 867 888 pos++; 868 889 } 869 870 item = item->next;871 890 } 872 891 … … 909 928 } 910 929 911 devmap_device_t *device = (devmap_device_t *) malloc(sizeof(devmap_device_t)); 930 devmap_device_t *device = 931 (devmap_device_t *) malloc(sizeof(devmap_device_t)); 912 932 if (device == NULL) { 913 933 fibril_mutex_unlock(&null_devices_mutex); … … 919 939 920 940 devmap_namespace_t *namespace = devmap_namespace_create("null"); 921 if ( !namespace) {941 if (namespace == NULL) { 922 942 fibril_mutex_lock(&devices_list_mutex); 923 943 fibril_mutex_unlock(&null_devices_mutex); … … 949 969 static void devmap_null_destroy(ipc_callid_t iid, ipc_call_t *icall) 950 970 { 971 ipcarg_t i = IPC_GET_ARG1(*icall); 972 if (i >= NULL_DEVICES) { 973 ipc_answer_0(iid, ELIMIT); 974 return; 975 } 976 951 977 fibril_mutex_lock(&null_devices_mutex); 952 978 953 ipcarg_t i = IPC_GET_ARG1(*icall);954 955 979 if (null_devices[i] == NULL) { 980 fibril_mutex_unlock(&null_devices_mutex); 956 981 ipc_answer_0(iid, ENOENT); 957 982 return; … … 965 990 966 991 fibril_mutex_unlock(&null_devices_mutex); 967 968 992 ipc_answer_0(iid, EOK); 969 993 } … … 1121 1145 int main(int argc, char *argv[]) 1122 1146 { 1123 printf( NAME ": HelenOS Device Mapper\n");1147 printf("%s: HelenOS Device Mapper\n", NAME); 1124 1148 1125 1149 if (!devmap_init()) { 1126 printf( NAME ": Error while initializing service\n");1150 printf("%s: Error while initializing service\n", NAME); 1127 1151 return -1; 1128 1152 } … … 1136 1160 return -1; 1137 1161 1138 printf( NAME ": Accepting connections\n");1162 printf("%s: Accepting connections\n", NAME); 1139 1163 async_manager(); 1140 1164
Note:
See TracChangeset
for help on using the changeset viewer.