source: mainline/uspace/srv/vfs/vfs.c@ 1dff985

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

Merge from lp:~zarevucky-jiri/helenos/vfs-2.5 up to revision 1926

  • Property mode set to 100644
File size: 5.6 KB
Line 
1/*
2 * Copyright (c) 2008 Jakub Jermar
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 vfs.c
35 * @brief VFS service for HelenOS.
36 */
37
38#include <vfs/vfs.h>
39#include <stdlib.h>
40#include <ipc/services.h>
41#include <abi/ipc/methods.h>
42#include <libarch/config.h>
43#include <ns.h>
44#include <async.h>
45#include <errno.h>
46#include <stdio.h>
47#include <stdbool.h>
48#include <str.h>
49#include <as.h>
50#include <atomic.h>
51#include <macros.h>
52#include "vfs.h"
53
54#define NAME "vfs"
55
56static void vfs_pager(ipc_callid_t iid, ipc_call_t *icall, void *arg)
57{
58 async_answer_0(iid, EOK);
59
60 while (true) {
61 ipc_call_t call;
62 ipc_callid_t callid = async_get_call(&call);
63
64 if (!IPC_GET_IMETHOD(call))
65 break;
66
67 switch (IPC_GET_IMETHOD(call)) {
68 case IPC_M_PAGE_IN:
69 vfs_page_in(callid, &call);
70 break;
71 default:
72 async_answer_0(callid, ENOTSUP);
73 break;
74 }
75 }
76}
77
78static void vfs_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
79{
80 bool cont = true;
81
82 /*
83 * The connection was opened via the IPC_CONNECT_ME_TO call.
84 * This call needs to be answered.
85 */
86 async_answer_0(iid, EOK);
87
88 while (cont) {
89 ipc_call_t call;
90 ipc_callid_t callid = async_get_call(&call);
91
92 if (!IPC_GET_IMETHOD(call))
93 break;
94
95 switch (IPC_GET_IMETHOD(call)) {
96 case VFS_IN_REGISTER:
97 vfs_register(callid, &call);
98 cont = false;
99 break;
100 case VFS_IN_MOUNT:
101 vfs_mount_srv(callid, &call);
102 break;
103 case VFS_IN_UNMOUNT:
104 vfs_unmount_srv(callid, &call);
105 break;
106 case VFS_IN_WALK:
107 vfs_walk(callid, &call);
108 break;
109 case VFS_IN_OPEN2:
110 vfs_open2(callid, &call);
111 break;
112 case VFS_IN_CLOSE:
113 vfs_close(callid, &call);
114 break;
115 case VFS_IN_READ:
116 vfs_read(callid, &call);
117 break;
118 case VFS_IN_WRITE:
119 vfs_write(callid, &call);
120 break;
121 case VFS_IN_SEEK:
122 vfs_seek(callid, &call);
123 break;
124 case VFS_IN_TRUNCATE:
125 vfs_truncate(callid, &call);
126 break;
127 case VFS_IN_FSTAT:
128 vfs_fstat(callid, &call);
129 break;
130 case VFS_IN_UNLINK2:
131 vfs_unlink2(callid, &call);
132 break;
133 case VFS_IN_RENAME:
134 vfs_rename(callid, &call);
135 break;
136 case VFS_IN_SYNC:
137 vfs_sync(callid, &call);
138 break;
139 case VFS_IN_DUP:
140 vfs_dup(callid, &call);
141 break;
142 case VFS_IN_WAIT_HANDLE:
143 vfs_wait_handle(callid, &call);
144 break;
145 case VFS_IN_MTAB_GET:
146 vfs_get_mtab(callid, &call);
147 break;
148 case VFS_IN_STATFS:
149 vfs_statfs(callid, &call);
150 break;
151 default:
152 async_answer_0(callid, ENOTSUP);
153 break;
154 }
155 }
156
157 /*
158 * Open files for this client will be cleaned up when its last
159 * connection fibril terminates.
160 */
161}
162
163static void notification_handler(ipc_callid_t callid, ipc_call_t *call, void *arg)
164{
165 if (IPC_GET_ARG1(*call) == VFS_PASS_HANDLE)
166 vfs_pass_handle(
167 (task_id_t) MERGE_LOUP32(IPC_GET_ARG4(*call),
168 IPC_GET_ARG5(*call)), call->in_task_id,
169 (int) IPC_GET_ARG2(*call));
170}
171
172int main(int argc, char **argv)
173{
174 int rc;
175
176 printf("%s: HelenOS VFS server\n", NAME);
177
178 /*
179 * Initialize VFS node hash table.
180 */
181 if (!vfs_nodes_init()) {
182 printf("%s: Failed to initialize VFS node hash table\n",
183 NAME);
184 return ENOMEM;
185 }
186
187 /*
188 * Allocate and initialize the Path Lookup Buffer.
189 */
190 plb = as_area_create(AS_AREA_ANY, PLB_SIZE,
191 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE, AS_AREA_UNPAGED);
192 if (plb == AS_MAP_FAILED) {
193 printf("%s: Cannot create address space area\n", NAME);
194 return ENOMEM;
195 }
196 memset(plb, 0, PLB_SIZE);
197
198 /*
199 * Set client data constructor and destructor.
200 */
201 async_set_client_data_constructor(vfs_client_data_create);
202 async_set_client_data_destructor(vfs_client_data_destroy);
203
204 /*
205 * Create a port for the pager.
206 */
207 port_id_t port;
208 rc = async_create_port(INTERFACE_PAGER, vfs_pager, NULL, &port);
209 if (rc != EOK)
210 return rc;
211
212 /*
213 * Set a connection handling function/fibril.
214 */
215 async_set_fallback_port_handler(vfs_connection, NULL);
216
217 /*
218 * Subscribe to notifications.
219 */
220 async_event_task_subscribe(EVENT_TASK_STATE_CHANGE, notification_handler,
221 NULL);
222
223 /*
224 * Register at the naming service.
225 */
226 rc = service_register(SERVICE_VFS);
227 if (rc != EOK) {
228 printf("%s: Cannot register VFS service\n", NAME);
229 return rc;
230 }
231
232 /*
233 * Start accepting connections.
234 */
235 printf("%s: Accepting connections\n", NAME);
236 async_manager();
237 return 0;
238}
239
240/**
241 * @}
242 */
Note: See TracBrowser for help on using the repository browser.