Changeset c47e1a8 in mainline for uspace/srv/devmap/devmap.c
- Timestamp:
- 2010-05-21T07:50:04Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d51ee2b
- Parents:
- cf8cc36 (diff), 15b592b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devmap/devmap.c
rcf8cc36 rc47e1a8 44 44 #include <fibril_synch.h> 45 45 #include <stdlib.h> 46 #include <str ing.h>46 #include <str.h> 47 47 #include <ipc/devmap.h> 48 48 … … 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); … … 396 402 * Get driver name 397 403 */ 398 int rc = async_string_receive(&driver->name, DEVMAP_NAME_MAXLEN, NULL); 404 int rc = async_data_write_accept((void **) &driver->name, true, 0, 405 DEVMAP_NAME_MAXLEN, 0, NULL); 399 406 if (rc != EOK) { 400 407 free(driver); … … 403 410 } 404 411 405 /* 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 */ 406 433 fibril_mutex_initialize(&driver->devices_mutex); 407 434 … … 410 437 */ 411 438 list_initialize(&driver->devices); 412 413 /*414 * Create connection to the driver415 */416 ipc_call_t call;417 ipc_callid_t callid = async_get_call(&call);418 419 if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) {420 ipc_answer_0(callid, ENOTSUP);421 422 free(driver->name);423 free(driver);424 ipc_answer_0(iid, ENOTSUP);425 return NULL;426 }427 428 driver->phone = IPC_GET_ARG5(call);429 430 ipc_answer_0(callid, EOK);431 432 439 list_initialize(&(driver->drivers)); 433 440 … … 435 442 436 443 /* TODO: 437 * 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 438 446 */ 439 447 … … 481 489 fibril_mutex_unlock(&drivers_list_mutex); 482 490 483 /* free name and driver */491 /* Free name and driver */ 484 492 if (driver->name != NULL) 485 493 free(driver->name); … … 502 510 503 511 /* Create new device entry */ 504 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)); 505 514 if (device == NULL) { 506 515 ipc_answer_0(iid, ENOMEM); … … 510 519 /* Get fqdn */ 511 520 char *fqdn; 512 int rc = async_string_receive(&fqdn, DEVMAP_NAME_MAXLEN, NULL); 521 int rc = async_data_write_accept((void **) &fqdn, true, 0, 522 DEVMAP_NAME_MAXLEN, 0, NULL); 513 523 if (rc != EOK) { 514 524 free(device); … … 531 541 devmap_namespace_t *namespace = devmap_namespace_create(ns_name); 532 542 free(ns_name); 533 if ( !namespace) {543 if (namespace == NULL) { 534 544 fibril_mutex_unlock(&devices_list_mutex); 545 free(device->name); 535 546 free(device); 536 547 ipc_answer_0(iid, ENOMEM); … … 543 554 /* Check that device is not already registered */ 544 555 if (devmap_device_find_name(namespace->name, device->name) != NULL) { 545 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); 546 558 devmap_namespace_destroy(namespace); 547 559 fibril_mutex_unlock(&devices_list_mutex); 548 free(device->namespace);549 560 free(device->name); 550 561 free(device); … … 601 612 602 613 if ((dev == NULL) || (dev->driver == NULL) || (dev->driver->phone == 0)) { 614 fibril_mutex_unlock(&devices_list_mutex); 603 615 ipc_answer_0(callid, ENOENT); 604 616 return; … … 622 634 623 635 /* Get fqdn */ 624 int rc = async_string_receive(&fqdn, DEVMAP_NAME_MAXLEN, NULL); 636 int rc = async_data_write_accept((void **) &fqdn, true, 0, 637 DEVMAP_NAME_MAXLEN, 0, NULL); 625 638 if (rc != EOK) { 626 639 ipc_answer_0(iid, rc); … … 665 678 return; 666 679 } 680 681 ipc_answer_1(iid, EOK, dev->handle); 682 667 683 fibril_mutex_unlock(&devices_list_mutex); 668 669 ipc_answer_1(iid, EOK, dev->handle);670 684 free(ns_name); 671 685 free(name); … … 683 697 684 698 /* Get device name */ 685 int rc = async_string_receive(&name, DEVMAP_NAME_MAXLEN, NULL); 699 int rc = async_data_write_accept((void **) &name, true, 0, 700 DEVMAP_NAME_MAXLEN, 0, NULL); 686 701 if (rc != EOK) { 687 702 ipc_answer_0(iid, rc); … … 715 730 return; 716 731 } 732 733 ipc_answer_1(iid, EOK, namespace->handle); 734 717 735 fibril_mutex_unlock(&devices_list_mutex); 718 719 ipc_answer_1(iid, EOK, namespace->handle);720 736 free(name); 721 737 } … … 725 741 fibril_mutex_lock(&devices_list_mutex); 726 742 727 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)); 728 745 if (namespace == NULL) { 729 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)); 730 748 if (dev == NULL) 731 749 ipc_answer_1(iid, EOK, DEV_HANDLE_NONE); … … 749 767 fibril_mutex_lock(&devices_list_mutex); 750 768 751 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)); 752 771 if (namespace == NULL) 753 772 ipc_answer_0(iid, EEXISTS); … … 778 797 size_t count = size / sizeof(dev_desc_t); 779 798 if (count != list_count(&namespaces_list)) { 799 fibril_mutex_unlock(&devices_list_mutex); 780 800 ipc_answer_0(callid, EOVERFLOW); 781 801 ipc_answer_0(iid, EOVERFLOW); … … 785 805 dev_desc_t *desc = (dev_desc_t *) malloc(size); 786 806 if (desc == NULL) { 807 fibril_mutex_unlock(&devices_list_mutex); 787 808 ipc_answer_0(callid, ENOMEM); 788 809 ipc_answer_0(iid, ENOMEM); … … 790 811 } 791 812 792 link_t *item = namespaces_list.next;813 link_t *item; 793 814 size_t pos = 0; 794 while (item != &namespaces_list) { 795 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); 796 819 797 820 desc[pos].handle = namespace->handle; 798 821 str_cpy(desc[pos].name, DEVMAP_NAME_MAXLEN, namespace->name); 799 822 pos++; 800 801 item = item->next;802 823 } 803 824 … … 831 852 fibril_mutex_lock(&devices_list_mutex); 832 853 833 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)); 834 856 if (namespace == NULL) { 835 857 fibril_mutex_unlock(&devices_list_mutex); … … 841 863 size_t count = size / sizeof(dev_desc_t); 842 864 if (count != namespace->refcnt) { 865 fibril_mutex_unlock(&devices_list_mutex); 843 866 ipc_answer_0(callid, EOVERFLOW); 844 867 ipc_answer_0(iid, EOVERFLOW); … … 848 871 dev_desc_t *desc = (dev_desc_t *) malloc(size); 849 872 if (desc == NULL) { 873 fibril_mutex_unlock(&devices_list_mutex); 850 874 ipc_answer_0(callid, ENOMEM); 851 875 ipc_answer_0(iid, EREFUSED); … … 853 877 } 854 878 855 link_t *item = devices_list.next;879 link_t *item; 856 880 size_t pos = 0; 857 while (item != &devices_list) { 858 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); 859 884 860 885 if (device->namespace == namespace) { … … 863 888 pos++; 864 889 } 865 866 item = item->next;867 890 } 868 891 … … 905 928 } 906 929 907 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)); 908 932 if (device == NULL) { 909 933 fibril_mutex_unlock(&null_devices_mutex); … … 915 939 916 940 devmap_namespace_t *namespace = devmap_namespace_create("null"); 917 if ( !namespace) {941 if (namespace == NULL) { 918 942 fibril_mutex_lock(&devices_list_mutex); 919 943 fibril_mutex_unlock(&null_devices_mutex); … … 945 969 static void devmap_null_destroy(ipc_callid_t iid, ipc_call_t *icall) 946 970 { 971 ipcarg_t i = IPC_GET_ARG1(*icall); 972 if (i >= NULL_DEVICES) { 973 ipc_answer_0(iid, ELIMIT); 974 return; 975 } 976 947 977 fibril_mutex_lock(&null_devices_mutex); 948 978 949 ipcarg_t i = IPC_GET_ARG1(*icall);950 951 979 if (null_devices[i] == NULL) { 980 fibril_mutex_unlock(&null_devices_mutex); 952 981 ipc_answer_0(iid, ENOENT); 953 982 return; … … 961 990 962 991 fibril_mutex_unlock(&null_devices_mutex); 963 964 992 ipc_answer_0(iid, EOK); 965 993 } … … 1117 1145 int main(int argc, char *argv[]) 1118 1146 { 1119 printf( NAME ": HelenOS Device Mapper\n");1147 printf("%s: HelenOS Device Mapper\n", NAME); 1120 1148 1121 1149 if (!devmap_init()) { 1122 printf( NAME ": Error while initializing service\n");1150 printf("%s: Error while initializing service\n", NAME); 1123 1151 return -1; 1124 1152 } … … 1132 1160 return -1; 1133 1161 1134 printf( NAME ": Accepting connections\n");1162 printf("%s: Accepting connections\n", NAME); 1135 1163 async_manager(); 1136 1164
Note:
See TracChangeset
for help on using the changeset viewer.