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

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

Do not hold the devices_mutex while connecting to the device in
devfs_node_open().

  • 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 <ipc/ipc.h>
39#include <macros.h>
40#include <bool.h>
41#include <errno.h>
42#include <malloc.h>
43#include <str.h>
44#include <libfs.h>
45#include <fibril_synch.h>
46#include <adt/hash_table.h>
47#include <ipc/devmap.h>
48#include <sys/stat.h>
49#include <libfs.h>
50#include <assert.h>
51#include "devfs.h"
52#include "devfs_ops.h"
53
54typedef struct {
55 devmap_handle_type_t type;
56 devmap_handle_t handle;
57} devfs_node_t;
58
59/** Opened devices structure */
60typedef struct {
61 devmap_handle_t handle;
62 int phone; /**< When < 0, the structure is incomplete. */
63 size_t refcount;
64 link_t link;
65 fibril_condvar_t cv; /**< Broadcast when completed. */
66} device_t;
67
68/** Hash table of opened devices */
69static hash_table_t devices;
70
71/** Hash table mutex */
72static FIBRIL_MUTEX_INITIALIZE(devices_mutex);
73
74#define DEVICES_KEYS 1
75#define DEVICES_KEY_HANDLE 0
76#define DEVICES_BUCKETS 256
77
78/* Implementation of hash table interface for the nodes hash table. */
79static hash_index_t devices_hash(unsigned long key[])
80{
81 return key[DEVICES_KEY_HANDLE] % DEVICES_BUCKETS;
82}
83
84static int devices_compare(unsigned long key[], hash_count_t keys, link_t *item)
85{
86 device_t *dev = hash_table_get_instance(item, device_t, link);
87 return (dev->handle == (devmap_handle_t) key[DEVICES_KEY_HANDLE]);
88}
89
90static void devices_remove_callback(link_t *item)
91{
92 free(hash_table_get_instance(item, device_t, link));
93}
94
95static hash_table_operations_t devices_ops = {
96 .hash = devices_hash,
97 .compare = devices_compare,
98 .remove_callback = devices_remove_callback
99};
100
101static int devfs_node_get_internal(fs_node_t **rfn, devmap_handle_type_t type,
102 devmap_handle_t handle)
103{
104 devfs_node_t *node = (devfs_node_t *) malloc(sizeof(devfs_node_t));
105 if (node == NULL) {
106 *rfn = NULL;
107 return ENOMEM;
108 }
109
110 *rfn = (fs_node_t *) malloc(sizeof(fs_node_t));
111 if (*rfn == NULL) {
112 free(node);
113 *rfn = NULL;
114 return ENOMEM;
115 }
116
117 fs_node_initialize(*rfn);
118 node->type = type;
119 node->handle = handle;
120
121 (*rfn)->data = node;
122 return EOK;
123}
124
125static int devfs_root_get(fs_node_t **rfn, devmap_handle_t devmap_handle)
126{
127 return devfs_node_get_internal(rfn, DEV_HANDLE_NONE, 0);
128}
129
130static int devfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component)
131{
132 devfs_node_t *node = (devfs_node_t *) pfn->data;
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 free(devs);
149 return devfs_node_get_internal(rfn, DEV_HANDLE_NAMESPACE, devs[pos].handle);
150 }
151 }
152
153 free(devs);
154 }
155
156 /* Search root namespace */
157 devmap_handle_t namespace;
158 if (devmap_namespace_get_handle("", &namespace, 0) == EOK) {
159 count = devmap_get_devices(namespace, &devs);
160
161 if (count > 0) {
162 size_t pos;
163 for (pos = 0; pos < count; pos++) {
164 if (str_cmp(devs[pos].name, component) == 0) {
165 free(devs);
166 return devfs_node_get_internal(rfn, DEV_HANDLE_DEVICE, devs[pos].handle);
167 }
168 }
169
170 free(devs);
171 }
172 }
173
174 *rfn = NULL;
175 return EOK;
176 }
177
178 if (node->type == DEV_HANDLE_NAMESPACE) {
179 /* Namespace directory */
180
181 dev_desc_t *devs;
182 size_t count = devmap_get_devices(node->handle, &devs);
183 if (count > 0) {
184 size_t pos;
185 for (pos = 0; pos < count; pos++) {
186 if (str_cmp(devs[pos].name, component) == 0) {
187 free(devs);
188 return devfs_node_get_internal(rfn, DEV_HANDLE_DEVICE, devs[pos].handle);
189 }
190 }
191
192 free(devs);
193 }
194
195 *rfn = NULL;
196 return EOK;
197 }
198
199 *rfn = NULL;
200 return EOK;
201}
202
203static int devfs_node_get(fs_node_t **rfn, devmap_handle_t devmap_handle, fs_index_t index)
204{
205 return devfs_node_get_internal(rfn, devmap_handle_probe(index), index);
206}
207
208static int devfs_node_open(fs_node_t *fn)
209{
210 devfs_node_t *node = (devfs_node_t *) fn->data;
211
212 if (node->handle == 0) {
213 /* Root directory */
214 return EOK;
215 }
216
217 devmap_handle_type_t type = devmap_handle_probe(node->handle);
218
219 if (type == DEV_HANDLE_NAMESPACE) {
220 /* Namespace directory */
221 return EOK;
222 }
223
224 if (type == DEV_HANDLE_DEVICE) {
225 /* Device node */
226
227 unsigned long key[] = {
228 [DEVICES_KEY_HANDLE] = (unsigned long) node->handle
229 };
230 link_t *lnk;
231
232 fibril_mutex_lock(&devices_mutex);
233restart:
234 lnk = hash_table_find(&devices, key);
235 if (lnk == NULL) {
236 device_t *dev = (device_t *) malloc(sizeof(device_t));
237 if (dev == NULL) {
238 fibril_mutex_unlock(&devices_mutex);
239 return ENOMEM;
240 }
241
242 dev->handle = node->handle;
243 dev->phone = -1; /* mark as incomplete */
244 dev->refcount = 1;
245 fibril_condvar_initialize(&dev->cv);
246
247 /*
248 * Insert the incomplete device structure so that other
249 * fibrils will not race with us when we drop the mutex
250 * below.
251 */
252 hash_table_insert(&devices, key, &dev->link);
253
254 /*
255 * Drop the mutex to allow recursive devfs requests.
256 */
257 fibril_mutex_unlock(&devices_mutex);
258
259 int phone = devmap_device_connect(node->handle, 0);
260
261 fibril_mutex_lock(&devices_mutex);
262
263 /*
264 * Notify possible waiters about this device structure
265 * being completed (or destroyed).
266 */
267 fibril_condvar_broadcast(&dev->cv);
268
269 if (phone < 0) {
270 /*
271 * Connecting failed, need to remove the
272 * entry and free the device structure.
273 */
274 hash_table_remove(&devices, key, DEVICES_KEYS);
275 fibril_mutex_unlock(&devices_mutex);
276
277 free(dev);
278 return ENOENT;
279 }
280
281 /* Set the correct phone. */
282 dev->phone = phone;
283 } else {
284 device_t *dev = hash_table_get_instance(lnk, device_t, link);
285
286 if (dev->phone < 0) {
287 /*
288 * Wait until the device structure is completed
289 * and start from the beginning as the device
290 * structure might have entirely disappeared
291 * while we were not holding the mutex in
292 * fibril_condvar_wait().
293 */
294 fibril_condvar_wait(&dev->cv, &devices_mutex);
295 goto restart;
296 }
297
298 dev->refcount++;
299 }
300
301 fibril_mutex_unlock(&devices_mutex);
302
303 return EOK;
304 }
305
306 return ENOENT;
307}
308
309static int devfs_node_put(fs_node_t *fn)
310{
311 free(fn->data);
312 free(fn);
313 return EOK;
314}
315
316static int devfs_create_node(fs_node_t **rfn, devmap_handle_t devmap_handle, int lflag)
317{
318 assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY));
319
320 *rfn = NULL;
321 return ENOTSUP;
322}
323
324static int devfs_destroy_node(fs_node_t *fn)
325{
326 return ENOTSUP;
327}
328
329static int devfs_link_node(fs_node_t *pfn, fs_node_t *cfn, const char *nm)
330{
331 return ENOTSUP;
332}
333
334static int devfs_unlink_node(fs_node_t *pfn, fs_node_t *cfn, const char *nm)
335{
336 return ENOTSUP;
337}
338
339static int devfs_has_children(bool *has_children, fs_node_t *fn)
340{
341 devfs_node_t *node = (devfs_node_t *) fn->data;
342
343 if (node->handle == 0) {
344 size_t count = devmap_count_namespaces();
345 if (count > 0) {
346 *has_children = true;
347 return EOK;
348 }
349
350 /* Root namespace */
351 devmap_handle_t namespace;
352 if (devmap_namespace_get_handle("", &namespace, 0) == EOK) {
353 count = devmap_count_devices(namespace);
354 if (count > 0) {
355 *has_children = true;
356 return EOK;
357 }
358 }
359
360 *has_children = false;
361 return EOK;
362 }
363
364 if (node->type == DEV_HANDLE_NAMESPACE) {
365 size_t count = devmap_count_devices(node->handle);
366 if (count > 0) {
367 *has_children = true;
368 return EOK;
369 }
370
371 *has_children = false;
372 return EOK;
373 }
374
375 *has_children = false;
376 return EOK;
377}
378
379static fs_index_t devfs_index_get(fs_node_t *fn)
380{
381 devfs_node_t *node = (devfs_node_t *) fn->data;
382 return node->handle;
383}
384
385static aoff64_t devfs_size_get(fs_node_t *fn)
386{
387 return 0;
388}
389
390static unsigned int devfs_lnkcnt_get(fs_node_t *fn)
391{
392 devfs_node_t *node = (devfs_node_t *) fn->data;
393
394 if (node->handle == 0)
395 return 0;
396
397 return 1;
398}
399
400static char devfs_plb_get_char(unsigned pos)
401{
402 return devfs_reg.plb_ro[pos % PLB_SIZE];
403}
404
405static bool devfs_is_directory(fs_node_t *fn)
406{
407 devfs_node_t *node = (devfs_node_t *) fn->data;
408
409 return ((node->type == DEV_HANDLE_NONE) || (node->type == DEV_HANDLE_NAMESPACE));
410}
411
412static bool devfs_is_file(fs_node_t *fn)
413{
414 devfs_node_t *node = (devfs_node_t *) fn->data;
415
416 return (node->type == DEV_HANDLE_DEVICE);
417}
418
419static devmap_handle_t devfs_device_get(fs_node_t *fn)
420{
421 devfs_node_t *node = (devfs_node_t *) fn->data;
422
423 if (node->type == DEV_HANDLE_DEVICE)
424 return node->handle;
425
426 return 0;
427}
428
429/** libfs operations */
430libfs_ops_t devfs_libfs_ops = {
431 .root_get = devfs_root_get,
432 .match = devfs_match,
433 .node_get = devfs_node_get,
434 .node_open = devfs_node_open,
435 .node_put = devfs_node_put,
436 .create = devfs_create_node,
437 .destroy = devfs_destroy_node,
438 .link = devfs_link_node,
439 .unlink = devfs_unlink_node,
440 .has_children = devfs_has_children,
441 .index_get = devfs_index_get,
442 .size_get = devfs_size_get,
443 .lnkcnt_get = devfs_lnkcnt_get,
444 .plb_get_char = devfs_plb_get_char,
445 .is_directory = devfs_is_directory,
446 .is_file = devfs_is_file,
447 .device_get = devfs_device_get
448};
449
450bool devfs_init(void)
451{
452 if (!hash_table_create(&devices, DEVICES_BUCKETS,
453 DEVICES_KEYS, &devices_ops))
454 return false;
455
456 if (devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING) < 0)
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 ipc_answer_0(rid, retval);
471 return;
472 }
473
474 free(opts);
475 ipc_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 ipc_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 ipc_answer_0(callid, EINVAL);
519 ipc_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 ipc_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 ipc_answer_1(rid, EOK, 1);
556 return;
557 }
558
559 free(desc);
560 }
561
562 ipc_answer_0(callid, ENOENT);
563 ipc_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 ipc_answer_0(callid, EINVAL);
575 ipc_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 ipc_answer_1(rid, EOK, 1);
586 return;
587 }
588
589 free(desc);
590 ipc_answer_0(callid, ENOENT);
591 ipc_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 ipc_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 ipc_answer_0(callid, EINVAL);
617 ipc_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 ipc_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 ipc_answer_1(rid, rc, bytes);
638 return;
639 }
640
641 ipc_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 ipc_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 ipc_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 ipc_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 ipc_answer_0(callid, EINVAL);
681 ipc_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 ipc_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 ipc_answer_1(rid, rc, bytes);
703 return;
704 }
705
706 ipc_answer_0(rid, ENOENT);
707}
708
709void devfs_truncate(ipc_callid_t rid, ipc_call_t *request)
710{
711 ipc_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 ipc_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 ipc_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 ipc_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 ipc_hangup(dev->phone);
750 hash_table_remove(&devices, key, DEVICES_KEYS);
751 }
752
753 fibril_mutex_unlock(&devices_mutex);
754
755 ipc_answer_0(rid, EOK);
756 return;
757 }
758
759 ipc_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 ipc_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 ipc_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 ipc_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 ipc_answer_0(rid, rc);
808 return;
809 }
810
811 ipc_answer_0(rid, ENOENT);
812}
813
814void devfs_destroy(ipc_callid_t rid, ipc_call_t *request)
815{
816 ipc_answer_0(rid, ENOTSUP);
817}
818
819/**
820 * @}
821 */
Note: See TracBrowser for help on using the repository browser.