source: mainline/uspace/srv/fs/devfs/devfs_ops.c@ cf2af94

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since cf2af94 was b366a1bc, checked in by Jakub Jermar <jakub@…>, 14 years ago

Do not use memory after free.

  • Property mode set to 100644
File size: 18.6 KB
Line 
1/*
2 * Copyright (c) 2009 Martin Decky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup fs
30 * @{
31 */
32
33/**
34 * @file devfs_ops.c
35 * @brief Implementation of VFS operations for the devfs file system server.
36 */
37
38#include <macros.h>
39#include <bool.h>
40#include <errno.h>
41#include <malloc.h>
42#include <str.h>
43#include <libfs.h>
44#include <fibril_synch.h>
45#include <adt/hash_table.h>
46#include <ipc/devmap.h>
47#include <sys/stat.h>
48#include <libfs.h>
49#include <assert.h>
50#include "devfs.h"
51#include "devfs_ops.h"
52
53typedef struct {
54 devmap_handle_type_t type;
55 devmap_handle_t handle;
56} devfs_node_t;
57
58/** Opened devices structure */
59typedef struct {
60 devmap_handle_t handle;
61 int phone; /**< When < 0, the structure is incomplete. */
62 size_t refcount;
63 link_t link;
64 fibril_condvar_t cv; /**< Broadcast when completed. */
65} device_t;
66
67/** Hash table of opened devices */
68static hash_table_t devices;
69
70/** Hash table mutex */
71static FIBRIL_MUTEX_INITIALIZE(devices_mutex);
72
73#define DEVICES_KEYS 1
74#define DEVICES_KEY_HANDLE 0
75#define DEVICES_BUCKETS 256
76
77/* Implementation of hash table interface for the nodes hash table. */
78static hash_index_t devices_hash(unsigned long key[])
79{
80 return key[DEVICES_KEY_HANDLE] % DEVICES_BUCKETS;
81}
82
83static int devices_compare(unsigned long key[], hash_count_t keys, link_t *item)
84{
85 device_t *dev = hash_table_get_instance(item, device_t, link);
86 return (dev->handle == (devmap_handle_t) key[DEVICES_KEY_HANDLE]);
87}
88
89static void devices_remove_callback(link_t *item)
90{
91 free(hash_table_get_instance(item, device_t, link));
92}
93
94static hash_table_operations_t devices_ops = {
95 .hash = devices_hash,
96 .compare = devices_compare,
97 .remove_callback = devices_remove_callback
98};
99
100static int devfs_node_get_internal(fs_node_t **rfn, devmap_handle_type_t type,
101 devmap_handle_t handle)
102{
103 devfs_node_t *node = (devfs_node_t *) malloc(sizeof(devfs_node_t));
104 if (node == NULL) {
105 *rfn = NULL;
106 return ENOMEM;
107 }
108
109 *rfn = (fs_node_t *) malloc(sizeof(fs_node_t));
110 if (*rfn == NULL) {
111 free(node);
112 *rfn = NULL;
113 return ENOMEM;
114 }
115
116 fs_node_initialize(*rfn);
117 node->type = type;
118 node->handle = handle;
119
120 (*rfn)->data = node;
121 return EOK;
122}
123
124static int devfs_root_get(fs_node_t **rfn, devmap_handle_t devmap_handle)
125{
126 return devfs_node_get_internal(rfn, DEV_HANDLE_NONE, 0);
127}
128
129static int devfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component)
130{
131 devfs_node_t *node = (devfs_node_t *) pfn->data;
132 int ret;
133
134 if (node->handle == 0) {
135 /* Root directory */
136
137 dev_desc_t *devs;
138 size_t count = devmap_get_namespaces(&devs);
139
140 if (count > 0) {
141 size_t pos;
142 for (pos = 0; pos < count; pos++) {
143 /* Ignore root namespace */
144 if (str_cmp(devs[pos].name, "") == 0)
145 continue;
146
147 if (str_cmp(devs[pos].name, component) == 0) {
148 ret = devfs_node_get_internal(rfn, DEV_HANDLE_NAMESPACE, devs[pos].handle);
149 free(devs);
150 return ret;
151 }
152 }
153
154 free(devs);
155 }
156
157 /* Search root namespace */
158 devmap_handle_t namespace;
159 if (devmap_namespace_get_handle("", &namespace, 0) == EOK) {
160 count = devmap_get_devices(namespace, &devs);
161
162 if (count > 0) {
163 size_t pos;
164 for (pos = 0; pos < count; pos++) {
165 if (str_cmp(devs[pos].name, component) == 0) {
166 ret = devfs_node_get_internal(rfn, DEV_HANDLE_DEVICE, devs[pos].handle);
167 free(devs);
168 return ret;
169 }
170 }
171
172 free(devs);
173 }
174 }
175
176 *rfn = NULL;
177 return EOK;
178 }
179
180 if (node->type == DEV_HANDLE_NAMESPACE) {
181 /* Namespace directory */
182
183 dev_desc_t *devs;
184 size_t count = devmap_get_devices(node->handle, &devs);
185 if (count > 0) {
186 size_t pos;
187 for (pos = 0; pos < count; pos++) {
188 if (str_cmp(devs[pos].name, component) == 0) {
189 ret = devfs_node_get_internal(rfn, DEV_HANDLE_DEVICE, devs[pos].handle);
190 free(devs);
191 return ret;
192 }
193 }
194
195 free(devs);
196 }
197
198 *rfn = NULL;
199 return EOK;
200 }
201
202 *rfn = NULL;
203 return EOK;
204}
205
206static int devfs_node_get(fs_node_t **rfn, devmap_handle_t devmap_handle, fs_index_t index)
207{
208 return devfs_node_get_internal(rfn, devmap_handle_probe(index), index);
209}
210
211static int devfs_node_open(fs_node_t *fn)
212{
213 devfs_node_t *node = (devfs_node_t *) fn->data;
214
215 if (node->handle == 0) {
216 /* Root directory */
217 return EOK;
218 }
219
220 devmap_handle_type_t type = devmap_handle_probe(node->handle);
221
222 if (type == DEV_HANDLE_NAMESPACE) {
223 /* Namespace directory */
224 return EOK;
225 }
226
227 if (type == DEV_HANDLE_DEVICE) {
228 /* Device node */
229
230 unsigned long key[] = {
231 [DEVICES_KEY_HANDLE] = (unsigned long) node->handle
232 };
233 link_t *lnk;
234
235 fibril_mutex_lock(&devices_mutex);
236restart:
237 lnk = hash_table_find(&devices, key);
238 if (lnk == NULL) {
239 device_t *dev = (device_t *) malloc(sizeof(device_t));
240 if (dev == NULL) {
241 fibril_mutex_unlock(&devices_mutex);
242 return ENOMEM;
243 }
244
245 dev->handle = node->handle;
246 dev->phone = -1; /* mark as incomplete */
247 dev->refcount = 1;
248 fibril_condvar_initialize(&dev->cv);
249
250 /*
251 * Insert the incomplete device structure so that other
252 * fibrils will not race with us when we drop the mutex
253 * below.
254 */
255 hash_table_insert(&devices, key, &dev->link);
256
257 /*
258 * Drop the mutex to allow recursive devfs requests.
259 */
260 fibril_mutex_unlock(&devices_mutex);
261
262 int phone = devmap_device_connect(node->handle, 0);
263
264 fibril_mutex_lock(&devices_mutex);
265
266 /*
267 * Notify possible waiters about this device structure
268 * being completed (or destroyed).
269 */
270 fibril_condvar_broadcast(&dev->cv);
271
272 if (phone < 0) {
273 /*
274 * Connecting failed, need to remove the
275 * entry and free the device structure.
276 */
277 hash_table_remove(&devices, key, DEVICES_KEYS);
278 fibril_mutex_unlock(&devices_mutex);
279
280 free(dev);
281 return ENOENT;
282 }
283
284 /* Set the correct phone. */
285 dev->phone = phone;
286 } else {
287 device_t *dev = hash_table_get_instance(lnk, device_t, link);
288
289 if (dev->phone < 0) {
290 /*
291 * Wait until the device structure is completed
292 * and start from the beginning as the device
293 * structure might have entirely disappeared
294 * while we were not holding the mutex in
295 * fibril_condvar_wait().
296 */
297 fibril_condvar_wait(&dev->cv, &devices_mutex);
298 goto restart;
299 }
300
301 dev->refcount++;
302 }
303
304 fibril_mutex_unlock(&devices_mutex);
305
306 return EOK;
307 }
308
309 return ENOENT;
310}
311
312static int devfs_node_put(fs_node_t *fn)
313{
314 free(fn->data);
315 free(fn);
316 return EOK;
317}
318
319static int devfs_create_node(fs_node_t **rfn, devmap_handle_t devmap_handle, int lflag)
320{
321 assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY));
322
323 *rfn = NULL;
324 return ENOTSUP;
325}
326
327static int devfs_destroy_node(fs_node_t *fn)
328{
329 return ENOTSUP;
330}
331
332static int devfs_link_node(fs_node_t *pfn, fs_node_t *cfn, const char *nm)
333{
334 return ENOTSUP;
335}
336
337static int devfs_unlink_node(fs_node_t *pfn, fs_node_t *cfn, const char *nm)
338{
339 return ENOTSUP;
340}
341
342static int devfs_has_children(bool *has_children, fs_node_t *fn)
343{
344 devfs_node_t *node = (devfs_node_t *) fn->data;
345
346 if (node->handle == 0) {
347 size_t count = devmap_count_namespaces();
348 if (count > 0) {
349 *has_children = true;
350 return EOK;
351 }
352
353 /* Root namespace */
354 devmap_handle_t namespace;
355 if (devmap_namespace_get_handle("", &namespace, 0) == EOK) {
356 count = devmap_count_devices(namespace);
357 if (count > 0) {
358 *has_children = true;
359 return EOK;
360 }
361 }
362
363 *has_children = false;
364 return EOK;
365 }
366
367 if (node->type == DEV_HANDLE_NAMESPACE) {
368 size_t count = devmap_count_devices(node->handle);
369 if (count > 0) {
370 *has_children = true;
371 return EOK;
372 }
373
374 *has_children = false;
375 return EOK;
376 }
377
378 *has_children = false;
379 return EOK;
380}
381
382static fs_index_t devfs_index_get(fs_node_t *fn)
383{
384 devfs_node_t *node = (devfs_node_t *) fn->data;
385 return node->handle;
386}
387
388static aoff64_t devfs_size_get(fs_node_t *fn)
389{
390 return 0;
391}
392
393static unsigned int devfs_lnkcnt_get(fs_node_t *fn)
394{
395 devfs_node_t *node = (devfs_node_t *) fn->data;
396
397 if (node->handle == 0)
398 return 0;
399
400 return 1;
401}
402
403static char devfs_plb_get_char(unsigned pos)
404{
405 return devfs_reg.plb_ro[pos % PLB_SIZE];
406}
407
408static bool devfs_is_directory(fs_node_t *fn)
409{
410 devfs_node_t *node = (devfs_node_t *) fn->data;
411
412 return ((node->type == DEV_HANDLE_NONE) || (node->type == DEV_HANDLE_NAMESPACE));
413}
414
415static bool devfs_is_file(fs_node_t *fn)
416{
417 devfs_node_t *node = (devfs_node_t *) fn->data;
418
419 return (node->type == DEV_HANDLE_DEVICE);
420}
421
422static devmap_handle_t devfs_device_get(fs_node_t *fn)
423{
424 devfs_node_t *node = (devfs_node_t *) fn->data;
425
426 if (node->type == DEV_HANDLE_DEVICE)
427 return node->handle;
428
429 return 0;
430}
431
432/** libfs operations */
433libfs_ops_t devfs_libfs_ops = {
434 .root_get = devfs_root_get,
435 .match = devfs_match,
436 .node_get = devfs_node_get,
437 .node_open = devfs_node_open,
438 .node_put = devfs_node_put,
439 .create = devfs_create_node,
440 .destroy = devfs_destroy_node,
441 .link = devfs_link_node,
442 .unlink = devfs_unlink_node,
443 .has_children = devfs_has_children,
444 .index_get = devfs_index_get,
445 .size_get = devfs_size_get,
446 .lnkcnt_get = devfs_lnkcnt_get,
447 .plb_get_char = devfs_plb_get_char,
448 .is_directory = devfs_is_directory,
449 .is_file = devfs_is_file,
450 .device_get = devfs_device_get
451};
452
453bool devfs_init(void)
454{
455 if (!hash_table_create(&devices, DEVICES_BUCKETS,
456 DEVICES_KEYS, &devices_ops))
457 return false;
458
459 return true;
460}
461
462void devfs_mounted(ipc_callid_t rid, ipc_call_t *request)
463{
464 char *opts;
465
466 /* Accept the mount options */
467 sysarg_t retval = async_data_write_accept((void **) &opts, true, 0, 0,
468 0, NULL);
469 if (retval != EOK) {
470 async_answer_0(rid, retval);
471 return;
472 }
473
474 free(opts);
475 async_answer_3(rid, EOK, 0, 0, 0);
476}
477
478void devfs_mount(ipc_callid_t rid, ipc_call_t *request)
479{
480 libfs_mount(&devfs_libfs_ops, devfs_reg.fs_handle, rid, request);
481}
482
483void devfs_unmounted(ipc_callid_t rid, ipc_call_t *request)
484{
485 async_answer_0(rid, ENOTSUP);
486}
487
488void devfs_unmount(ipc_callid_t rid, ipc_call_t *request)
489{
490 libfs_unmount(&devfs_libfs_ops, rid, request);
491}
492
493void devfs_lookup(ipc_callid_t rid, ipc_call_t *request)
494{
495 libfs_lookup(&devfs_libfs_ops, devfs_reg.fs_handle, rid, request);
496}
497
498void devfs_open_node(ipc_callid_t rid, ipc_call_t *request)
499{
500 libfs_open_node(&devfs_libfs_ops, devfs_reg.fs_handle, rid, request);
501}
502
503void devfs_stat(ipc_callid_t rid, ipc_call_t *request)
504{
505 libfs_stat(&devfs_libfs_ops, devfs_reg.fs_handle, rid, request);
506}
507
508void devfs_read(ipc_callid_t rid, ipc_call_t *request)
509{
510 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
511 aoff64_t pos =
512 (aoff64_t) MERGE_LOUP32(IPC_GET_ARG3(*request), IPC_GET_ARG4(*request));
513
514 if (index == 0) {
515 ipc_callid_t callid;
516 size_t size;
517 if (!async_data_read_receive(&callid, &size)) {
518 async_answer_0(callid, EINVAL);
519 async_answer_0(rid, EINVAL);
520 return;
521 }
522
523 dev_desc_t *desc;
524 size_t count = devmap_get_namespaces(&desc);
525
526 /* Get rid of root namespace */
527 size_t i;
528 for (i = 0; i < count; i++) {
529 if (str_cmp(desc[i].name, "") == 0) {
530 if (pos >= i)
531 pos++;
532
533 break;
534 }
535 }
536
537 if (pos < count) {
538 async_data_read_finalize(callid, desc[pos].name, str_size(desc[pos].name) + 1);
539 free(desc);
540 async_answer_1(rid, EOK, 1);
541 return;
542 }
543
544 free(desc);
545 pos -= count;
546
547 /* Search root namespace */
548 devmap_handle_t namespace;
549 if (devmap_namespace_get_handle("", &namespace, 0) == EOK) {
550 count = devmap_get_devices(namespace, &desc);
551
552 if (pos < count) {
553 async_data_read_finalize(callid, desc[pos].name, str_size(desc[pos].name) + 1);
554 free(desc);
555 async_answer_1(rid, EOK, 1);
556 return;
557 }
558
559 free(desc);
560 }
561
562 async_answer_0(callid, ENOENT);
563 async_answer_1(rid, ENOENT, 0);
564 return;
565 }
566
567 devmap_handle_type_t type = devmap_handle_probe(index);
568
569 if (type == DEV_HANDLE_NAMESPACE) {
570 /* Namespace directory */
571 ipc_callid_t callid;
572 size_t size;
573 if (!async_data_read_receive(&callid, &size)) {
574 async_answer_0(callid, EINVAL);
575 async_answer_0(rid, EINVAL);
576 return;
577 }
578
579 dev_desc_t *desc;
580 size_t count = devmap_get_devices(index, &desc);
581
582 if (pos < count) {
583 async_data_read_finalize(callid, desc[pos].name, str_size(desc[pos].name) + 1);
584 free(desc);
585 async_answer_1(rid, EOK, 1);
586 return;
587 }
588
589 free(desc);
590 async_answer_0(callid, ENOENT);
591 async_answer_1(rid, ENOENT, 0);
592 return;
593 }
594
595 if (type == DEV_HANDLE_DEVICE) {
596 /* Device node */
597
598 unsigned long key[] = {
599 [DEVICES_KEY_HANDLE] = (unsigned long) index
600 };
601
602 fibril_mutex_lock(&devices_mutex);
603 link_t *lnk = hash_table_find(&devices, key);
604 if (lnk == NULL) {
605 fibril_mutex_unlock(&devices_mutex);
606 async_answer_0(rid, ENOENT);
607 return;
608 }
609
610 device_t *dev = hash_table_get_instance(lnk, device_t, link);
611 assert(dev->phone >= 0);
612
613 ipc_callid_t callid;
614 if (!async_data_read_receive(&callid, NULL)) {
615 fibril_mutex_unlock(&devices_mutex);
616 async_answer_0(callid, EINVAL);
617 async_answer_0(rid, EINVAL);
618 return;
619 }
620
621 /* Make a request at the driver */
622 ipc_call_t answer;
623 aid_t msg = async_send_3(dev->phone, IPC_GET_IMETHOD(*request),
624 IPC_GET_ARG1(*request), IPC_GET_ARG2(*request),
625 IPC_GET_ARG3(*request), &answer);
626
627 /* Forward the IPC_M_DATA_READ request to the driver */
628 async_forward_fast(callid, dev->phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);
629 fibril_mutex_unlock(&devices_mutex);
630
631 /* Wait for reply from the driver. */
632 sysarg_t rc;
633 async_wait_for(msg, &rc);
634 size_t bytes = IPC_GET_ARG1(answer);
635
636 /* Driver reply is the final result of the whole operation */
637 async_answer_1(rid, rc, bytes);
638 return;
639 }
640
641 async_answer_0(rid, ENOENT);
642}
643
644void devfs_write(ipc_callid_t rid, ipc_call_t *request)
645{
646 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
647 if (index == 0) {
648 async_answer_0(rid, ENOTSUP);
649 return;
650 }
651
652 devmap_handle_type_t type = devmap_handle_probe(index);
653
654 if (type == DEV_HANDLE_NAMESPACE) {
655 /* Namespace directory */
656 async_answer_0(rid, ENOTSUP);
657 return;
658 }
659
660 if (type == DEV_HANDLE_DEVICE) {
661 /* Device node */
662 unsigned long key[] = {
663 [DEVICES_KEY_HANDLE] = (unsigned long) index
664 };
665
666 fibril_mutex_lock(&devices_mutex);
667 link_t *lnk = hash_table_find(&devices, key);
668 if (lnk == NULL) {
669 fibril_mutex_unlock(&devices_mutex);
670 async_answer_0(rid, ENOENT);
671 return;
672 }
673
674 device_t *dev = hash_table_get_instance(lnk, device_t, link);
675 assert(dev->phone >= 0);
676
677 ipc_callid_t callid;
678 if (!async_data_write_receive(&callid, NULL)) {
679 fibril_mutex_unlock(&devices_mutex);
680 async_answer_0(callid, EINVAL);
681 async_answer_0(rid, EINVAL);
682 return;
683 }
684
685 /* Make a request at the driver */
686 ipc_call_t answer;
687 aid_t msg = async_send_3(dev->phone, IPC_GET_IMETHOD(*request),
688 IPC_GET_ARG1(*request), IPC_GET_ARG2(*request),
689 IPC_GET_ARG3(*request), &answer);
690
691 /* Forward the IPC_M_DATA_WRITE request to the driver */
692 async_forward_fast(callid, dev->phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);
693
694 fibril_mutex_unlock(&devices_mutex);
695
696 /* Wait for reply from the driver. */
697 sysarg_t rc;
698 async_wait_for(msg, &rc);
699 size_t bytes = IPC_GET_ARG1(answer);
700
701 /* Driver reply is the final result of the whole operation */
702 async_answer_1(rid, rc, bytes);
703 return;
704 }
705
706 async_answer_0(rid, ENOENT);
707}
708
709void devfs_truncate(ipc_callid_t rid, ipc_call_t *request)
710{
711 async_answer_0(rid, ENOTSUP);
712}
713
714void devfs_close(ipc_callid_t rid, ipc_call_t *request)
715{
716 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
717
718 if (index == 0) {
719 async_answer_0(rid, EOK);
720 return;
721 }
722
723 devmap_handle_type_t type = devmap_handle_probe(index);
724
725 if (type == DEV_HANDLE_NAMESPACE) {
726 /* Namespace directory */
727 async_answer_0(rid, EOK);
728 return;
729 }
730
731 if (type == DEV_HANDLE_DEVICE) {
732 unsigned long key[] = {
733 [DEVICES_KEY_HANDLE] = (unsigned long) index
734 };
735
736 fibril_mutex_lock(&devices_mutex);
737 link_t *lnk = hash_table_find(&devices, key);
738 if (lnk == NULL) {
739 fibril_mutex_unlock(&devices_mutex);
740 async_answer_0(rid, ENOENT);
741 return;
742 }
743
744 device_t *dev = hash_table_get_instance(lnk, device_t, link);
745 assert(dev->phone >= 0);
746 dev->refcount--;
747
748 if (dev->refcount == 0) {
749 async_hangup(dev->phone);
750 hash_table_remove(&devices, key, DEVICES_KEYS);
751 }
752
753 fibril_mutex_unlock(&devices_mutex);
754
755 async_answer_0(rid, EOK);
756 return;
757 }
758
759 async_answer_0(rid, ENOENT);
760}
761
762void devfs_sync(ipc_callid_t rid, ipc_call_t *request)
763{
764 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
765
766 if (index == 0) {
767 async_answer_0(rid, EOK);
768 return;
769 }
770
771 devmap_handle_type_t type = devmap_handle_probe(index);
772
773 if (type == DEV_HANDLE_NAMESPACE) {
774 /* Namespace directory */
775 async_answer_0(rid, EOK);
776 return;
777 }
778
779 if (type == DEV_HANDLE_DEVICE) {
780 unsigned long key[] = {
781 [DEVICES_KEY_HANDLE] = (unsigned long) index
782 };
783
784 fibril_mutex_lock(&devices_mutex);
785 link_t *lnk = hash_table_find(&devices, key);
786 if (lnk == NULL) {
787 fibril_mutex_unlock(&devices_mutex);
788 async_answer_0(rid, ENOENT);
789 return;
790 }
791
792 device_t *dev = hash_table_get_instance(lnk, device_t, link);
793 assert(dev->phone >= 0);
794
795 /* Make a request at the driver */
796 ipc_call_t answer;
797 aid_t msg = async_send_2(dev->phone, IPC_GET_IMETHOD(*request),
798 IPC_GET_ARG1(*request), IPC_GET_ARG2(*request), &answer);
799
800 fibril_mutex_unlock(&devices_mutex);
801
802 /* Wait for reply from the driver */
803 sysarg_t rc;
804 async_wait_for(msg, &rc);
805
806 /* Driver reply is the final result of the whole operation */
807 async_answer_0(rid, rc);
808 return;
809 }
810
811 async_answer_0(rid, ENOENT);
812}
813
814void devfs_destroy(ipc_callid_t rid, ipc_call_t *request)
815{
816 async_answer_0(rid, ENOTSUP);
817}
818
819/**
820 * @}
821 */
Note: See TracBrowser for help on using the repository browser.