Changes in uspace/srv/devmap/devmap.c [ab108be4:19f857a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devmap/devmap.c
rab108be4 r19f857a 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); … … 410 404 } 411 405 406 /* Initialize mutex for list of devices owned by this driver */ 407 fibril_mutex_initialize(&driver->devices_mutex); 408 409 /* 410 * Initialize list of asociated devices 411 */ 412 list_initialize(&driver->devices); 413 412 414 /* 413 415 * Create connection to the driver … … 417 419 418 420 if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) { 421 ipc_answer_0(callid, ENOTSUP); 422 419 423 free(driver->name); 420 424 free(driver); 421 ipc_answer_0(callid, ENOTSUP);422 425 ipc_answer_0(iid, ENOTSUP); 423 426 return NULL; … … 425 428 426 429 driver->phone = IPC_GET_ARG5(call); 430 427 431 ipc_answer_0(callid, EOK); 428 432 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 433 list_initialize(&(driver->drivers)); 440 434 … … 442 436 443 437 /* TODO: 444 * Check that no driver with name equal to 445 * driver->name is registered 438 * check that no driver with name equal to driver->name is registered 446 439 */ 447 440 … … 489 482 fibril_mutex_unlock(&drivers_list_mutex); 490 483 491 /* Free name and driver */484 /* free name and driver */ 492 485 if (driver->name != NULL) 493 486 free(driver->name); … … 510 503 511 504 /* Create new device entry */ 512 devmap_device_t *device = 513 (devmap_device_t *) malloc(sizeof(devmap_device_t)); 505 devmap_device_t *device = (devmap_device_t *) malloc(sizeof(devmap_device_t)); 514 506 if (device == NULL) { 515 507 ipc_answer_0(iid, ENOMEM); … … 541 533 devmap_namespace_t *namespace = devmap_namespace_create(ns_name); 542 534 free(ns_name); 543 if ( namespace == NULL) {535 if (!namespace) { 544 536 fibril_mutex_unlock(&devices_list_mutex); 545 free(device->name);546 537 free(device); 547 538 ipc_answer_0(iid, ENOMEM); … … 554 545 /* Check that device is not already registered */ 555 546 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); 547 printf(NAME ": Device '%s/%s' already registered\n", device->namespace, device->name); 558 548 devmap_namespace_destroy(namespace); 559 549 fibril_mutex_unlock(&devices_list_mutex); 550 free(device->namespace); 560 551 free(device->name); 561 552 free(device); … … 612 603 613 604 if ((dev == NULL) || (dev->driver == NULL) || (dev->driver->phone == 0)) { 614 fibril_mutex_unlock(&devices_list_mutex);615 605 ipc_answer_0(callid, ENOENT); 616 606 return; … … 678 668 return; 679 669 } 670 fibril_mutex_unlock(&devices_list_mutex); 680 671 681 672 ipc_answer_1(iid, EOK, dev->handle); 682 683 fibril_mutex_unlock(&devices_list_mutex);684 673 free(ns_name); 685 674 free(name); … … 730 719 return; 731 720 } 721 fibril_mutex_unlock(&devices_list_mutex); 732 722 733 723 ipc_answer_1(iid, EOK, namespace->handle); 734 735 fibril_mutex_unlock(&devices_list_mutex);736 724 free(name); 737 725 } … … 741 729 fibril_mutex_lock(&devices_list_mutex); 742 730 743 devmap_namespace_t *namespace = 744 devmap_namespace_find_handle(IPC_GET_ARG1(*icall)); 731 devmap_namespace_t *namespace = devmap_namespace_find_handle(IPC_GET_ARG1(*icall)); 745 732 if (namespace == NULL) { 746 devmap_device_t *dev = 747 devmap_device_find_handle(IPC_GET_ARG1(*icall)); 733 devmap_device_t *dev = devmap_device_find_handle(IPC_GET_ARG1(*icall)); 748 734 if (dev == NULL) 749 735 ipc_answer_1(iid, EOK, DEV_HANDLE_NONE); … … 767 753 fibril_mutex_lock(&devices_list_mutex); 768 754 769 devmap_namespace_t *namespace = 770 devmap_namespace_find_handle(IPC_GET_ARG1(*icall)); 755 devmap_namespace_t *namespace = devmap_namespace_find_handle(IPC_GET_ARG1(*icall)); 771 756 if (namespace == NULL) 772 757 ipc_answer_0(iid, EEXISTS); … … 797 782 size_t count = size / sizeof(dev_desc_t); 798 783 if (count != list_count(&namespaces_list)) { 799 fibril_mutex_unlock(&devices_list_mutex);800 784 ipc_answer_0(callid, EOVERFLOW); 801 785 ipc_answer_0(iid, EOVERFLOW); … … 805 789 dev_desc_t *desc = (dev_desc_t *) malloc(size); 806 790 if (desc == NULL) { 807 fibril_mutex_unlock(&devices_list_mutex);808 791 ipc_answer_0(callid, ENOMEM); 809 792 ipc_answer_0(iid, ENOMEM); … … 811 794 } 812 795 813 link_t *item ;796 link_t *item = namespaces_list.next; 814 797 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); 798 while (item != &namespaces_list) { 799 devmap_namespace_t *namespace = list_get_instance(item, devmap_namespace_t, namespaces); 819 800 820 801 desc[pos].handle = namespace->handle; 821 802 str_cpy(desc[pos].name, DEVMAP_NAME_MAXLEN, namespace->name); 822 803 pos++; 804 805 item = item->next; 823 806 } 824 807 … … 852 835 fibril_mutex_lock(&devices_list_mutex); 853 836 854 devmap_namespace_t *namespace = 855 devmap_namespace_find_handle(IPC_GET_ARG1(*icall)); 837 devmap_namespace_t *namespace = devmap_namespace_find_handle(IPC_GET_ARG1(*icall)); 856 838 if (namespace == NULL) { 857 839 fibril_mutex_unlock(&devices_list_mutex); … … 863 845 size_t count = size / sizeof(dev_desc_t); 864 846 if (count != namespace->refcnt) { 865 fibril_mutex_unlock(&devices_list_mutex);866 847 ipc_answer_0(callid, EOVERFLOW); 867 848 ipc_answer_0(iid, EOVERFLOW); … … 871 852 dev_desc_t *desc = (dev_desc_t *) malloc(size); 872 853 if (desc == NULL) { 873 fibril_mutex_unlock(&devices_list_mutex);874 854 ipc_answer_0(callid, ENOMEM); 875 855 ipc_answer_0(iid, EREFUSED); … … 877 857 } 878 858 879 link_t *item ;859 link_t *item = devices_list.next; 880 860 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); 861 while (item != &devices_list) { 862 devmap_device_t *device = list_get_instance(item, devmap_device_t, devices); 884 863 885 864 if (device->namespace == namespace) { … … 888 867 pos++; 889 868 } 869 870 item = item->next; 890 871 } 891 872 … … 928 909 } 929 910 930 devmap_device_t *device = 931 (devmap_device_t *) malloc(sizeof(devmap_device_t)); 911 devmap_device_t *device = (devmap_device_t *) malloc(sizeof(devmap_device_t)); 932 912 if (device == NULL) { 933 913 fibril_mutex_unlock(&null_devices_mutex); … … 939 919 940 920 devmap_namespace_t *namespace = devmap_namespace_create("null"); 941 if ( namespace == NULL) {921 if (!namespace) { 942 922 fibril_mutex_lock(&devices_list_mutex); 943 923 fibril_mutex_unlock(&null_devices_mutex); … … 969 949 static void devmap_null_destroy(ipc_callid_t iid, ipc_call_t *icall) 970 950 { 951 fibril_mutex_lock(&null_devices_mutex); 952 971 953 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 954 979 955 if (null_devices[i] == NULL) { 980 fibril_mutex_unlock(&null_devices_mutex);981 956 ipc_answer_0(iid, ENOENT); 982 957 return; … … 990 965 991 966 fibril_mutex_unlock(&null_devices_mutex); 967 992 968 ipc_answer_0(iid, EOK); 993 969 } … … 1145 1121 int main(int argc, char *argv[]) 1146 1122 { 1147 printf( "%s: HelenOS Device Mapper\n", NAME);1123 printf(NAME ": HelenOS Device Mapper\n"); 1148 1124 1149 1125 if (!devmap_init()) { 1150 printf( "%s: Error while initializing service\n", NAME);1126 printf(NAME ": Error while initializing service\n"); 1151 1127 return -1; 1152 1128 } … … 1160 1136 return -1; 1161 1137 1162 printf( "%s: Accepting connections\n", NAME);1138 printf(NAME ": Accepting connections\n"); 1163 1139 async_manager(); 1164 1140
Note:
See TracChangeset
for help on using the changeset viewer.