source: mainline/uspace/srv/fs/devfs/devfs.c@ 2dfd9fa

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 2dfd9fa was 17fd1d4, checked in by Martin Decky <martin@…>, 16 years ago

devfs rewrite:

  • implement VFS_OPEN_NODE, VFS_DEVICE, VFS_SYNC, VFS_CLOSE
  • connect to underlying device during VFS_LOOKUP (if L_OPEN flag is used) and VFS_OPEN_NODE
  • disconnect from underlying device during VFS_CLOSE
  • forward VFS_READ, VFS_WRITE and VFS_SYNC to the underlying device
  • VFS_DEVICE: return underlying device handle
  • Property mode set to 100644
File size: 3.4 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.c
35 * @brief Devices file system.
36 *
37 * Every device registered to device mapper is represented as a file in this
38 * file system.
39 */
40
41#include <stdio.h>
42#include <ipc/ipc.h>
43#include <ipc/services.h>
44#include <async.h>
45#include <errno.h>
46#include <libfs.h>
47#include "devfs.h"
48#include "devfs_ops.h"
49
50#define NAME "devfs"
51
52static vfs_info_t devfs_vfs_info = {
53 .name = "devfs",
54};
55
56fs_reg_t devfs_reg;
57
58static void devfs_connection(ipc_callid_t iid, ipc_call_t *icall)
59{
60 if (iid)
61 ipc_answer_0(iid, EOK);
62
63 while (true) {
64 ipc_call_t call;
65 ipc_callid_t callid = async_get_call(&call);
66
67 switch (IPC_GET_METHOD(call)) {
68 case VFS_MOUNTED:
69 devfs_mounted(callid, &call);
70 break;
71 case VFS_MOUNT:
72 devfs_mount(callid, &call);
73 break;
74 case VFS_LOOKUP:
75 devfs_lookup(callid, &call);
76 break;
77 case VFS_OPEN_NODE:
78 devfs_open_node(callid, &call);
79 break;
80 case VFS_DEVICE:
81 devfs_device(callid, &call);
82 break;
83 case VFS_READ:
84 devfs_read(callid, &call);
85 break;
86 case VFS_WRITE:
87 devfs_write(callid, &call);
88 break;
89 case VFS_TRUNCATE:
90 devfs_truncate(callid, &call);
91 break;
92 case VFS_CLOSE:
93 devfs_close(callid, &call);
94 break;
95 case VFS_SYNC:
96 devfs_sync(callid, &call);
97 break;
98 case VFS_DESTROY:
99 devfs_destroy(callid, &call);
100 break;
101 default:
102 ipc_answer_0(callid, ENOTSUP);
103 break;
104 }
105 }
106}
107
108int main(int argc, char *argv[])
109{
110 printf(NAME ": HelenOS Device Filesystem\n");
111
112 if (!devfs_init()) {
113 printf(NAME ": failed to initialize devfs\n");
114 return -1;
115 }
116
117 int vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0);
118 if (vfs_phone < EOK) {
119 printf(NAME ": Unable to connect to VFS\n");
120 return -1;
121 }
122
123 int rc = fs_register(vfs_phone, &devfs_reg, &devfs_vfs_info,
124 devfs_connection);
125 if (rc != EOK) {
126 printf(NAME ": Failed to register file system (%d)\n", rc);
127 return rc;
128 }
129
130 printf(NAME ": Accepting connections\n");
131 async_manager();
132
133 /* Not reached */
134 return 0;
135}
136
137/**
138 * @}
139 */
Note: See TracBrowser for help on using the repository browser.