Rev 4562 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4562 | Rev 4584 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2009 Martin Decky |
2 | * Copyright (c) 2009 Martin Decky |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup fs |
29 | /** @addtogroup fs |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** |
33 | /** |
34 | * @file devfs.c |
34 | * @file devfs.c |
35 | * @brief Devices file system. |
35 | * @brief Devices file system. |
36 | * |
36 | * |
37 | * Every device registered to device mapper is represented as a file in this |
37 | * Every device registered to device mapper is represented as a file in this |
38 | * file system. |
38 | * file system. |
39 | */ |
39 | */ |
40 | 40 | ||
41 | #include <stdio.h> |
41 | #include <stdio.h> |
42 | #include <ipc/ipc.h> |
42 | #include <ipc/ipc.h> |
43 | #include <ipc/services.h> |
43 | #include <ipc/services.h> |
44 | #include <async.h> |
44 | #include <async.h> |
45 | #include <errno.h> |
45 | #include <errno.h> |
46 | #include <libfs.h> |
46 | #include <libfs.h> |
47 | #include "devfs.h" |
47 | #include "devfs.h" |
48 | #include "devfs_ops.h" |
48 | #include "devfs_ops.h" |
49 | 49 | ||
50 | #define NAME "devfs" |
50 | #define NAME "devfs" |
51 | 51 | ||
52 | static vfs_info_t devfs_vfs_info = { |
52 | static vfs_info_t devfs_vfs_info = { |
53 | .name = "devfs", |
53 | .name = "devfs", |
54 | }; |
54 | }; |
55 | 55 | ||
56 | fs_reg_t devfs_reg; |
56 | fs_reg_t devfs_reg; |
57 | 57 | ||
58 | static void devfs_connection(ipc_callid_t iid, ipc_call_t *icall) |
58 | static void devfs_connection(ipc_callid_t iid, ipc_call_t *icall) |
59 | { |
59 | { |
60 | if (iid) |
60 | if (iid) |
61 | ipc_answer_0(iid, EOK); |
61 | ipc_answer_0(iid, EOK); |
62 | 62 | ||
63 | while (true) { |
63 | while (true) { |
64 | ipc_call_t call; |
64 | ipc_call_t call; |
65 | ipc_callid_t callid = async_get_call(&call); |
65 | ipc_callid_t callid = async_get_call(&call); |
66 | 66 | ||
67 | switch (IPC_GET_METHOD(call)) { |
67 | switch (IPC_GET_METHOD(call)) { |
68 | case IPC_M_PHONE_HUNGUP: |
68 | case IPC_M_PHONE_HUNGUP: |
69 | return; |
69 | return; |
70 | case VFS_MOUNTED: |
70 | case VFS_OUT_MOUNTED: |
71 | devfs_mounted(callid, &call); |
71 | devfs_mounted(callid, &call); |
72 | break; |
72 | break; |
73 | case VFS_MOUNT: |
73 | case VFS_OUT_MOUNT: |
74 | devfs_mount(callid, &call); |
74 | devfs_mount(callid, &call); |
75 | break; |
75 | break; |
76 | case VFS_LOOKUP: |
76 | case VFS_OUT_LOOKUP: |
77 | devfs_lookup(callid, &call); |
77 | devfs_lookup(callid, &call); |
78 | break; |
78 | break; |
79 | case VFS_OPEN_NODE: |
79 | case VFS_OUT_OPEN_NODE: |
80 | devfs_open_node(callid, &call); |
80 | devfs_open_node(callid, &call); |
81 | break; |
81 | break; |
82 | case VFS_DEVICE: |
82 | case VFS_OUT_DEVICE: |
83 | devfs_device(callid, &call); |
83 | devfs_device(callid, &call); |
84 | break; |
84 | break; |
85 | case VFS_READ: |
85 | case VFS_OUT_READ: |
86 | devfs_read(callid, &call); |
86 | devfs_read(callid, &call); |
87 | break; |
87 | break; |
88 | case VFS_WRITE: |
88 | case VFS_OUT_WRITE: |
89 | devfs_write(callid, &call); |
89 | devfs_write(callid, &call); |
90 | break; |
90 | break; |
91 | case VFS_TRUNCATE: |
91 | case VFS_OUT_TRUNCATE: |
92 | devfs_truncate(callid, &call); |
92 | devfs_truncate(callid, &call); |
93 | break; |
93 | break; |
94 | case VFS_CLOSE: |
94 | case VFS_OUT_CLOSE: |
95 | devfs_close(callid, &call); |
95 | devfs_close(callid, &call); |
96 | break; |
96 | break; |
97 | case VFS_SYNC: |
97 | case VFS_OUT_SYNC: |
98 | devfs_sync(callid, &call); |
98 | devfs_sync(callid, &call); |
99 | break; |
99 | break; |
100 | case VFS_DESTROY: |
100 | case VFS_OUT_DESTROY: |
101 | devfs_destroy(callid, &call); |
101 | devfs_destroy(callid, &call); |
102 | break; |
102 | break; |
103 | default: |
103 | default: |
104 | ipc_answer_0(callid, ENOTSUP); |
104 | ipc_answer_0(callid, ENOTSUP); |
105 | break; |
105 | break; |
106 | } |
106 | } |
107 | } |
107 | } |
108 | } |
108 | } |
109 | 109 | ||
110 | int main(int argc, char *argv[]) |
110 | int main(int argc, char *argv[]) |
111 | { |
111 | { |
112 | printf(NAME ": HelenOS Device Filesystem\n"); |
112 | printf(NAME ": HelenOS Device Filesystem\n"); |
113 | 113 | ||
114 | if (!devfs_init()) { |
114 | if (!devfs_init()) { |
115 | printf(NAME ": failed to initialize devfs\n"); |
115 | printf(NAME ": failed to initialize devfs\n"); |
116 | return -1; |
116 | return -1; |
117 | } |
117 | } |
118 | 118 | ||
119 | int vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0); |
119 | int vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0); |
120 | if (vfs_phone < EOK) { |
120 | if (vfs_phone < EOK) { |
121 | printf(NAME ": Unable to connect to VFS\n"); |
121 | printf(NAME ": Unable to connect to VFS\n"); |
122 | return -1; |
122 | return -1; |
123 | } |
123 | } |
124 | 124 | ||
125 | int rc = fs_register(vfs_phone, &devfs_reg, &devfs_vfs_info, |
125 | int rc = fs_register(vfs_phone, &devfs_reg, &devfs_vfs_info, |
126 | devfs_connection); |
126 | devfs_connection); |
127 | if (rc != EOK) { |
127 | if (rc != EOK) { |
128 | printf(NAME ": Failed to register file system (%d)\n", rc); |
128 | printf(NAME ": Failed to register file system (%d)\n", rc); |
129 | return rc; |
129 | return rc; |
130 | } |
130 | } |
131 | 131 | ||
132 | printf(NAME ": Accepting connections\n"); |
132 | printf(NAME ": Accepting connections\n"); |
133 | async_manager(); |
133 | async_manager(); |
134 | 134 | ||
135 | /* Not reached */ |
135 | /* Not reached */ |
136 | return 0; |
136 | return 0; |
137 | } |
137 | } |
138 | 138 | ||
139 | /** |
139 | /** |
140 | * @} |
140 | * @} |
141 | */ |
141 | */ |
142 | 142 |