Changeset cb41a5e in mainline
- Timestamp:
- 2009-05-21T07:03:38Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a095d20
- Parents:
- 2246de6
- Location:
- uspace
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tester/devmap/devmap1.c
r2246de6 rcb41a5e 120 120 char * test_devmap1(bool quiet) 121 121 { 122 int driver_phone; 123 int dev1_handle; 124 int dev2_handle; 125 int dev3_handle; 126 int handle; 127 int rc; 128 122 const char *retval = NULL; 123 129 124 /* Register new driver */ 130 driver_phone = devmap_driver_register("TestDriver", 131 driver_client_connection); 132 133 if (driver_phone < 0) { 134 return "Error: Cannot register driver.\n"; 135 } 136 125 int rc = devmap_driver_register("TestDriver", driver_client_connection); 126 if (rc < 0) { 127 retval = "Error: Cannot register driver.\n"; 128 goto out; 129 } 130 137 131 /* Register new device dev1. */ 138 rc = devmap_device_register(driver_phone, TEST_DEVICE1, &dev1_handle); 132 dev_handle_t dev1_handle; 133 rc = devmap_device_register(TEST_DEVICE1, &dev1_handle); 139 134 if (rc != EOK) { 140 ipc_hangup(driver_phone);141 return "Error: cannot register device.\n";142 } 143 135 retval = "Error: cannot register device.\n"; 136 goto out; 137 } 138 144 139 /* 145 140 * Get handle for dev2 (Should fail unless device is already registered 146 141 * by someone else). 147 142 */ 143 dev_handle_t handle; 148 144 rc = devmap_device_get_handle(TEST_DEVICE2, &handle, 0); 149 145 if (rc == EOK) { 150 ipc_hangup(driver_phone);151 return "Error: got handle for dev2 before it was registered.\n";152 } 153 146 retval = "Error: got handle for dev2 before it was registered.\n"; 147 goto out; 148 } 149 154 150 /* Register new device dev2. */ 155 rc = devmap_device_register(driver_phone, TEST_DEVICE2, &dev2_handle); 151 dev_handle_t dev2_handle; 152 rc = devmap_device_register(TEST_DEVICE2, &dev2_handle); 156 153 if (rc != EOK) { 157 ipc_hangup(driver_phone);158 return "Error: cannot register device dev2.\n";159 } 160 154 retval = "Error: cannot register device dev2.\n"; 155 goto out; 156 } 157 161 158 /* Register device dev1 again. */ 162 rc = devmap_device_register(driver_phone, TEST_DEVICE1, &dev3_handle); 159 dev_handle_t dev3_handle; 160 rc = devmap_device_register(TEST_DEVICE1, &dev3_handle); 163 161 if (rc == EOK) { 164 return "Error: dev1 registered twice.\n"; 165 } 166 162 retval = "Error: dev1 registered twice.\n"; 163 goto out; 164 } 165 167 166 /* Get handle for dev1. */ 168 167 rc = devmap_device_get_handle(TEST_DEVICE1, &handle, 0); 169 168 if (rc != EOK) { 170 ipc_hangup(driver_phone);171 return "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n";172 } 173 169 retval = "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n"; 170 goto out; 171 } 172 174 173 if (handle != dev1_handle) { 175 ipc_hangup(driver_phone);176 return "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n";177 } 178 174 retval = "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n"; 175 goto out; 176 } 177 179 178 if (device_client(dev1_handle) != EOK) { 180 ipc_hangup(driver_phone);181 return "Error: failed client test for 'DEVMAP_DEVICE1'.\n";182 } 183 184 /* TODO: */ 185 186 ipc_hangup(driver_phone);187 179 retval = "Error: failed client test for 'DEVMAP_DEVICE1'.\n"; 180 goto out; 181 } 182 183 out: 184 devmap_hangup_phone(DEVMAP_DRIVER); 185 devmap_hangup_phone(DEVMAP_CLIENT); 186 188 187 return NULL; 189 188 } -
uspace/lib/libc/generic/devmap.c
r2246de6 rcb41a5e 36 36 #include <errno.h> 37 37 38 static int devmap_phone = -1; 38 static int devmap_phone_driver = -1; 39 static int devmap_phone_client = -1; 39 40 40 41 /** Get phone to device mapper task. */ 41 static int devmap_get_phone(unsigned int flags) 42 { 43 int phone; 44 45 if (devmap_phone >= 0) 46 return devmap_phone; 47 48 if (flags & IPC_FLAG_BLOCKING) { 49 phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAP, 50 DEVMAP_CLIENT, 0); 51 } else { 52 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, 53 DEVMAP_CLIENT, 0); 54 } 55 56 if (phone < 0) 57 return phone; 58 59 devmap_phone = phone; 60 return phone; 42 int devmap_get_phone(devmap_interface_t iface, unsigned int flags) 43 { 44 switch (iface) { 45 case DEVMAP_DRIVER: 46 if (devmap_phone_driver >= 0) 47 return devmap_phone_driver; 48 49 if (flags & IPC_FLAG_BLOCKING) 50 devmap_phone_driver = ipc_connect_me_to_blocking(PHONE_NS, 51 SERVICE_DEVMAP, DEVMAP_DRIVER, 0); 52 else 53 devmap_phone_driver = ipc_connect_me_to(PHONE_NS, 54 SERVICE_DEVMAP, DEVMAP_DRIVER, 0); 55 56 return devmap_phone_driver; 57 case DEVMAP_CLIENT: 58 if (devmap_phone_client >= 0) 59 return devmap_phone_client; 60 61 if (flags & IPC_FLAG_BLOCKING) 62 devmap_phone_client = ipc_connect_me_to_blocking(PHONE_NS, 63 SERVICE_DEVMAP, DEVMAP_CLIENT, 0); 64 else 65 devmap_phone_client = ipc_connect_me_to(PHONE_NS, 66 SERVICE_DEVMAP, DEVMAP_CLIENT, 0); 67 68 return devmap_phone_client; 69 default: 70 return -1; 71 } 72 } 73 74 void devmap_hangup_phone(devmap_interface_t iface) 75 { 76 switch (iface) { 77 case DEVMAP_DRIVER: 78 if (devmap_phone_driver >= 0) { 79 ipc_hangup(devmap_phone_driver); 80 devmap_phone_driver = -1; 81 } 82 break; 83 case DEVMAP_CLIENT: 84 if (devmap_phone_client >= 0) { 85 ipc_hangup(devmap_phone_client); 86 devmap_phone_client = -1; 87 } 88 break; 89 default: 90 break; 91 } 61 92 } 62 93 … … 64 95 int devmap_driver_register(const char *name, async_client_conn_t conn) 65 96 { 66 ipcarg_t retval; 67 aid_t req; 68 ipc_call_t answer; 69 int phone; 97 int phone = devmap_get_phone(DEVMAP_DRIVER, IPC_FLAG_BLOCKING); 98 99 if (phone < 0) 100 return phone; 101 102 ipc_call_t answer; 103 aid_t req = async_send_2(phone, DEVMAP_DRIVER_REGISTER, 0, 0, &answer); 104 105 ipcarg_t retval = ipc_data_write_start(phone, name, str_size(name) + 1); 106 107 if (retval != EOK) { 108 async_wait_for(req, NULL); 109 return -1; 110 } 111 112 async_set_client_connection(conn); 113 70 114 ipcarg_t callback_phonehash; 71 72 phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAP, 73 DEVMAP_DRIVER, 0); 74 75 if (phone < 0) { 115 ipc_connect_to_me(phone, 0, 0, 0, &callback_phonehash); 116 async_wait_for(req, &retval); 117 118 return retval; 119 } 120 121 /** Register new device. 122 * 123 * @param name Device name. 124 * @param handle Output: Handle to the created instance of device. 125 * 126 */ 127 int devmap_device_register(const char *name, dev_handle_t *handle) 128 { 129 int phone = devmap_get_phone(DEVMAP_DRIVER, IPC_FLAG_BLOCKING); 130 131 if (phone < 0) 76 132 return phone; 77 } 78 79 req = async_send_2(phone, DEVMAP_DRIVER_REGISTER, 0, 0, &answer); 80 retval = ipc_data_write_start(phone, name, str_size(name) + 1); 81 82 if (retval != EOK) { 83 async_wait_for(req, NULL); 84 ipc_hangup(phone); 85 return -1; 86 } 87 88 async_set_client_connection(conn); 89 90 ipc_connect_to_me(phone, 0, 0, 0, &callback_phonehash); 91 async_wait_for(req, &retval); 92 93 return phone; 94 } 95 96 int devmap_device_get_handle(const char *name, dev_handle_t *handle, 97 unsigned int flags) 98 { 99 ipcarg_t retval; 100 aid_t req; 101 ipc_call_t answer; 102 int phone; 103 104 phone = devmap_get_phone(flags); 105 if (phone < 0) 106 return phone; 107 108 req = async_send_2(phone, DEVMAP_DEVICE_GET_HANDLE, flags, 0, 133 134 ipc_call_t answer; 135 aid_t req = async_send_2(phone, DEVMAP_DEVICE_REGISTER, 0, 0, 109 136 &answer); 110 111 retval = ipc_data_write_start(phone, name, str_size(name) + 1);112 113 if (retval != EOK) { 114 async_wait_for(req, NULL); 115 return retval; 116 } 117 118 async_wait_for(req, &retval); 119 137 138 ipcarg_t retval = ipc_data_write_start(phone, name, str_size(name) + 1); 139 140 if (retval != EOK) { 141 async_wait_for(req, NULL); 142 return retval; 143 } 144 145 async_wait_for(req, &retval); 146 120 147 if (retval != EOK) { 121 148 if (handle != NULL) … … 123 150 return retval; 124 151 } 125 152 126 153 if (handle != NULL) 127 *handle = ( int) IPC_GET_ARG1(answer);128 154 *handle = (dev_handle_t) IPC_GET_ARG1(answer); 155 129 156 return retval; 130 157 } 131 158 159 int devmap_device_get_handle(const char *name, dev_handle_t *handle, unsigned int flags) 160 { 161 int phone = devmap_get_phone(DEVMAP_CLIENT, flags); 162 163 if (phone < 0) 164 return phone; 165 166 ipc_call_t answer; 167 aid_t req = async_send_2(phone, DEVMAP_DEVICE_GET_HANDLE, flags, 0, 168 &answer); 169 170 ipcarg_t retval = ipc_data_write_start(phone, name, str_size(name) + 1); 171 172 if (retval != EOK) { 173 async_wait_for(req, NULL); 174 return retval; 175 } 176 177 async_wait_for(req, &retval); 178 179 if (retval != EOK) { 180 if (handle != NULL) 181 *handle = -1; 182 return retval; 183 } 184 185 if (handle != NULL) 186 *handle = (dev_handle_t) IPC_GET_ARG1(answer); 187 188 return retval; 189 } 190 132 191 int devmap_device_connect(dev_handle_t handle, unsigned int flags) 133 192 { 134 193 int phone; 135 194 136 195 if (flags & IPC_FLAG_BLOCKING) { 137 196 phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAP, … … 141 200 DEVMAP_CONNECT_TO_DEVICE, handle); 142 201 } 143 202 144 203 return phone; 145 204 } 146 205 147 /** Register new device. 148 * 149 * @param driver_phone 150 * @param name Device name. 151 * @param handle Output: Handle to the created instance of device. 152 */ 153 int devmap_device_register(int driver_phone, const char *name, int *handle) 154 { 155 ipcarg_t retval; 156 aid_t req; 157 ipc_call_t answer; 158 159 req = async_send_2(driver_phone, DEVMAP_DEVICE_REGISTER, 0, 0, 160 &answer); 161 162 retval = ipc_data_write_start(driver_phone, name, str_size(name) + 1); 163 164 if (retval != EOK) { 165 async_wait_for(req, NULL); 166 return retval; 167 } 168 169 async_wait_for(req, &retval); 170 171 if (retval != EOK) { 172 if (handle != NULL) 173 *handle = -1; 174 return retval; 175 } 176 177 *handle = (int) IPC_GET_ARG1(answer); 178 return retval; 179 } 206 ipcarg_t devmap_device_get_count(void) 207 { 208 int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING); 209 210 if (phone < 0) 211 return 0; 212 213 ipcarg_t count; 214 int retval = ipc_call_sync_0_1(phone, DEVMAP_DEVICE_GET_COUNT, &count); 215 if (retval != EOK) 216 return 0; 217 218 return count; 219 } 220 221 ipcarg_t devmap_device_get_devices(ipcarg_t count, dev_desc_t *data) 222 { 223 int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING); 224 225 if (phone < 0) 226 return 0; 227 228 ipc_call_t answer; 229 aid_t req = async_send_0(phone, DEVMAP_DEVICE_GET_DEVICES, &answer); 230 231 ipcarg_t retval = ipc_data_read_start(phone, data, count * sizeof(dev_desc_t)); 232 233 if (retval != EOK) { 234 async_wait_for(req, NULL); 235 return 0; 236 } 237 238 async_wait_for(req, &retval); 239 240 if (retval != EOK) 241 return 0; 242 243 return IPC_GET_ARG1(answer); 244 } -
uspace/lib/libc/include/devmap.h
r2246de6 rcb41a5e 39 39 #include <async.h> 40 40 41 typedef int dev_handle_t; 41 extern int devmap_get_phone(devmap_interface_t, unsigned int); 42 extern void devmap_hangup_phone(devmap_interface_t iface); 42 43 43 44 extern int devmap_driver_register(const char *, async_client_conn_t); 44 extern int devmap_device_get_handle(const char *, dev_handle_t *, 45 unsigned int); 45 extern int devmap_device_register(const char *, dev_handle_t *); 46 47 extern int devmap_device_get_handle(const char *, dev_handle_t *, unsigned int); 46 48 extern int devmap_device_connect(dev_handle_t, unsigned int); 47 extern int devmap_device_register(int, const char *, int *); 49 50 extern ipcarg_t devmap_device_get_count(void); 51 extern ipcarg_t devmap_device_get_devices(ipcarg_t, dev_desc_t *); 48 52 49 53 #endif -
uspace/lib/libc/include/ipc/devmap.h
r2246de6 rcb41a5e 38 38 #include <libadt/list.h> 39 39 40 #define DEVMAP_NAME_MAXLEN 512 40 #define DEVMAP_NAME_MAXLEN 255 41 42 typedef ipcarg_t dev_handle_t; 41 43 42 44 typedef enum { … … 46 48 DEVMAP_DEVICE_UNREGISTER, 47 49 DEVMAP_DEVICE_GET_NAME, 48 DEVMAP_DEVICE_GET_HANDLE 50 DEVMAP_DEVICE_GET_HANDLE, 51 DEVMAP_DEVICE_GET_COUNT, 52 DEVMAP_DEVICE_GET_DEVICES 49 53 } devmap_request_t; 50 54 51 /** Representation of device driver. 52 * Each driver is responsible for a set of devices. 53 */ 54 typedef struct { 55 /** Pointers to previous and next drivers in linked list */ 56 link_t drivers; 57 /** Pointer to the linked list of devices controlled by 58 * this driver */ 59 link_t devices; 60 /** Phone asociated with this driver */ 61 ipcarg_t phone; 62 /** Device driver name */ 63 char *name; 64 /** Futex for list of devices owned by this driver */ 65 atomic_t devices_futex; 66 } devmap_driver_t; 67 68 /** Info about registered device 55 /** Interface provided by devmap. 56 * 57 * Every process that connects to devmap must ask one of following 58 * interfaces otherwise connection will be refused. 69 59 * 70 60 */ 71 typedef struct {72 /** Pointer to the previous and next device in the list of all devices */73 link_t devices;74 /** Pointer to the previous and next device in the list of devices75 owned by one driver */76 link_t driver_devices;77 /** Unique device identifier */78 int handle;79 /** Device name */80 char *name;81 /** Device driver handling this device */82 devmap_driver_t *driver;83 } devmap_device_t;84 85 /** Interface provided by devmap.86 * Every process that connects to devmap must ask one of following87 * interfaces otherwise connection will be refused.88 */89 61 typedef enum { 90 91 DEVMAP_DRIVER = 1, 92 62 /** Connect as device driver */ 63 DEVMAP_DRIVER = 1, 64 /** Connect as client */ 93 65 DEVMAP_CLIENT, 94 95 *is specified by second argument of call. */66 /** Create new connection to instance of device that 67 is specified by second argument of call. */ 96 68 DEVMAP_CONNECT_TO_DEVICE 97 69 } devmap_interface_t; 98 70 71 typedef struct { 72 dev_handle_t handle; 73 char name[DEVMAP_NAME_MAXLEN + 1]; 74 } dev_desc_t; 75 99 76 #endif 100 -
uspace/srv/bd/gxe_bd/gxe_bd.c
r2246de6 rcb41a5e 116 116 static int gxe_bd_init(void) 117 117 { 118 int driver_phone;119 118 dev_handle_t dev_handle; 120 119 void *vaddr; … … 126 125 return rc; 127 126 } 128 driver_phone = rc;129 127 130 128 rc = pio_enable((void *) dev_physical, sizeof(gxe_bd_t), &vaddr); … … 144 142 devbuf = vaddr; 145 143 146 rc = devmap_device_register( driver_phone,"disk0", &dev_handle);144 rc = devmap_device_register("disk0", &dev_handle); 147 145 if (rc != EOK) { 148 ipc_hangup(driver_phone);146 devmap_hangup_phone(DEVMAP_DRIVER); 149 147 printf(NAME ": Unable to register device.\n"); 150 148 return rc; -
uspace/srv/devmap/devmap.c
r2246de6 rcb41a5e 49 49 #define NAME "devmap" 50 50 51 /** Representation of device driver. 52 * 53 * Each driver is responsible for a set of devices. 54 * 55 */ 56 typedef struct { 57 /** Pointers to previous and next drivers in linked list */ 58 link_t drivers; 59 /** Pointer to the linked list of devices controlled by this driver */ 60 link_t devices; 61 /** Phone asociated with this driver */ 62 ipcarg_t phone; 63 /** Device driver name */ 64 char *name; 65 /** Futex for list of devices owned by this driver */ 66 atomic_t devices_futex; 67 } devmap_driver_t; 68 69 /** Info about registered device 70 * 71 */ 72 typedef struct { 73 /** Pointer to the previous and next device in the list of all devices */ 74 link_t devices; 75 /** Pointer to the previous and next device in the list of devices 76 owned by one driver */ 77 link_t driver_devices; 78 /** Unique device identifier */ 79 dev_handle_t handle; 80 /** Device name */ 81 char *name; 82 /** Device driver handling this device */ 83 devmap_driver_t *driver; 84 } devmap_device_t; 85 51 86 /** Pending lookup structure. */ 52 87 typedef struct { … … 71 106 static atomic_t create_handle_futex = FUTEX_INITIALIZER; 72 107 73 static int devmap_create_handle(void) 74 { 75 static int last_handle = 0; 76 int handle; 77 108 static dev_handle_t last_handle = 0; 109 110 static dev_handle_t devmap_create_handle(void) 111 { 78 112 /* TODO: allow reusing old handles after their unregistration 79 113 * and implement some version of LRU algorithm … … 82 116 /* FIXME: overflow */ 83 117 futex_down(&create_handle_futex); 84 85 last_handle += 1; 86 handle = last_handle; 87 118 last_handle++; 88 119 futex_up(&create_handle_futex); 89 120 90 return handle; 91 } 92 93 94 /** Initialize device mapper. 95 * 96 * 97 */ 98 static int devmap_init() 99 { 100 /* TODO: */ 101 102 return EOK; 121 return last_handle; 103 122 } 104 123 … … 130 149 * 131 150 */ 132 static devmap_device_t *devmap_device_find_handle( int handle)151 static devmap_device_t *devmap_device_find_handle(dev_handle_t handle) 133 152 { 134 153 futex_down(&devices_list_futex); … … 298 317 futex_down(&drivers_list_futex); 299 318 300 ipc_hangup(driver->phone); 301 302 /* remove it from list of drivers */ 319 if (driver->phone != 0) 320 ipc_hangup(driver->phone); 321 322 /* Remove it from list of drivers */ 303 323 list_remove(&(driver->drivers)); 304 324 305 /* unregister all its devices */ 306 325 /* Unregister all its devices */ 307 326 futex_down(&devices_list_futex); 308 327 futex_down(&(driver->devices_futex)); … … 319 338 320 339 /* free name and driver */ 321 if ( NULL != driver->name)340 if (driver->name != NULL) 322 341 free(driver->name); 323 342 … … 455 474 * Get handle from request 456 475 */ 457 int handle = IPC_GET_ARG2(*call);476 dev_handle_t handle = IPC_GET_ARG2(*call); 458 477 devmap_device_t *dev = devmap_device_find_handle(handle); 459 478 460 if ( NULL == dev) {479 if ((dev == NULL) || (dev->driver == NULL) || (dev->driver->phone == 0)) { 461 480 ipc_answer_0(callid, ENOENT); 462 481 return; 463 482 } 464 483 465 ipc_forward_fast(callid, dev->driver->phone, (ipcarg_t)(dev->handle),484 ipc_forward_fast(callid, dev->driver->phone, dev->handle, 466 485 IPC_GET_ARG3(*call), 0, IPC_FF_NONE); 467 486 } … … 496 515 * Allocate buffer for device name. 497 516 */ 498 char *name = (char *) malloc(size );517 char *name = (char *) malloc(size + 1); 499 518 if (name == NULL) { 500 519 ipc_answer_0(callid, ENOMEM); … … 550 569 * 551 570 */ 552 static void devmap_get_name(ipc_callid_t iid, ipc_call_t *icall) 571 static void devmap_get_name(ipc_callid_t iid, ipc_call_t *icall) 553 572 { 554 573 const devmap_device_t *device = devmap_device_find_handle(IPC_GET_ARG1(*icall)); … … 578 597 579 598 /* TODO: send name in response */ 599 } 600 601 static void devmap_get_count(ipc_callid_t iid, ipc_call_t *icall) 602 { 603 futex_down(&devices_list_futex); 604 ipc_answer_1(iid, EOK, list_count(&devices_list)); 605 futex_up(&devices_list_futex); 606 } 607 608 static void devmap_get_devices(ipc_callid_t iid, ipc_call_t *icall) 609 { 610 futex_down(&devices_list_futex); 611 612 ipc_callid_t callid; 613 size_t size; 614 if (!ipc_data_read_receive(&callid, &size)) { 615 ipc_answer_0(callid, EREFUSED); 616 ipc_answer_0(iid, EREFUSED); 617 return; 618 } 619 620 if ((size % sizeof(dev_desc_t)) != 0) { 621 ipc_answer_0(callid, EINVAL); 622 ipc_answer_0(iid, EREFUSED); 623 return; 624 } 625 626 count_t count = size / sizeof(dev_desc_t); 627 dev_desc_t *desc = (dev_desc_t *) malloc(size); 628 if (desc == NULL) { 629 ipc_answer_0(callid, ENOMEM); 630 ipc_answer_0(iid, EREFUSED); 631 return; 632 } 633 634 count_t pos = 0; 635 link_t *item = devices_list.next; 636 637 while ((item != &devices_list) && (pos < count)) { 638 devmap_device_t *device = list_get_instance(item, devmap_device_t, devices); 639 640 desc[pos].handle = device->handle; 641 str_cpy(desc[pos].name, DEVMAP_NAME_MAXLEN, device->name); 642 pos++; 643 item = item->next; 644 } 645 646 ipcarg_t retval = ipc_data_read_finalize(callid, desc, pos * sizeof(dev_desc_t)); 647 if (retval != EOK) { 648 ipc_answer_0(iid, EREFUSED); 649 free(desc); 650 return; 651 } 652 653 free(desc); 654 655 futex_up(&devices_list_futex); 656 657 ipc_answer_1(iid, EOK, pos); 658 } 659 660 /** Initialize device mapper. 661 * 662 * 663 */ 664 static bool devmap_init() 665 { 666 /* Create NULL device entry */ 667 devmap_device_t *device = (devmap_device_t *) malloc(sizeof(devmap_device_t)); 668 if (device == NULL) 669 return false; 670 671 device->name = str_dup("null"); 672 if (device->name == NULL) { 673 free(device); 674 return false; 675 } 676 677 list_initialize(&(device->devices)); 678 list_initialize(&(device->driver_devices)); 679 680 futex_down(&devices_list_futex); 681 682 /* Get unique device handle */ 683 device->handle = devmap_create_handle(); 684 device->driver = NULL; 685 686 /* Insert device into list of all devices */ 687 list_append(&device->devices, &devices_list); 688 689 futex_up(&devices_list_futex); 690 691 return true; 580 692 } 581 693 … … 622 734 break; 623 735 case DEVMAP_DEVICE_GET_NAME: 624 devmap_get_ handle(callid, &call);736 devmap_get_name(callid, &call); 625 737 break; 626 738 default: … … 661 773 break; 662 774 case DEVMAP_DEVICE_GET_NAME: 663 /* TODO */664 775 devmap_get_name(callid, &call); 776 break; 777 case DEVMAP_DEVICE_GET_COUNT: 778 devmap_get_count(callid, &call); 779 break; 780 case DEVMAP_DEVICE_GET_DEVICES: 781 devmap_get_devices(callid, &call); 665 782 break; 666 783 default: … … 701 818 printf(NAME ": HelenOS Device Mapper\n"); 702 819 703 if ( devmap_init() != 0) {820 if (!devmap_init()) { 704 821 printf(NAME ": Error while initializing service\n"); 705 822 return -1; -
uspace/srv/rd/rd.c
r2246de6 rcb41a5e 113 113 } 114 114 115 while ( 1) {115 while (true) { 116 116 callid = async_get_call(&call); 117 117 switch (IPC_GET_METHOD(call)) { … … 205 205 printf(NAME ": Found RAM disk at %p, %d bytes\n", rd_ph_addr, rd_size); 206 206 207 int driver_phone= devmap_driver_register(NAME, rd_connection);208 if ( driver_phone< 0) {209 printf(NAME ": Unable to register driver \n");207 int rc = devmap_driver_register(NAME, rd_connection); 208 if (rc < 0) { 209 printf(NAME ": Unable to register driver (%d)\n", rc); 210 210 return false; 211 211 } 212 212 213 213 dev_handle_t dev_handle; 214 if (devmap_device_register(driver_phone, "initrd", &dev_handle) != EOK) { 215 ipc_hangup(driver_phone); 216 printf(NAME ": Unable to register device\n"); 217 return false; 218 } 219 220 /* 221 * Create the second device. 222 * We need at least two devices for the sake of testing of non-root 223 * mounts. Of course it would be better to allow the second device 224 * be created dynamically... 225 */ 226 if (devmap_device_register(driver_phone, "spared", &dev_handle) != EOK) { 227 ipc_hangup(driver_phone); 214 if (devmap_device_register("initrd", &dev_handle) != EOK) { 215 devmap_hangup_phone(DEVMAP_DRIVER); 228 216 printf(NAME ": Unable to register device\n"); 229 217 return false; … … 249 237 /** 250 238 * @} 251 */ 239 */
Note:
See TracChangeset
for help on using the changeset viewer.