source: mainline/uspace/srv/vfs/vfs.c@ 42d08592

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

Implement simple VFS pager for testing purposes

  • Property mode set to 100644
File size: 5.8 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 char *buf = memalign(PAGE_SIZE, 1);
61 const char hello[] = "Hello world!";
62
63 memcpy(buf, hello, sizeof(hello));
64
65 while (true) {
66 ipc_call_t call;
67 ipc_callid_t callid = async_get_call(&call);
68
69 if (!IPC_GET_IMETHOD(call))
70 break;
71
72 switch (IPC_GET_IMETHOD(call)) {
73 case IPC_M_PAGE_IN:
74 if (buf)
75 async_answer_1(callid, EOK, (sysarg_t) buf);
76 else
77 async_answer_0(callid, ENOMEM);
78 break;
79
80 default:
81 async_answer_0(callid, ENOTSUP);
82 break;
83 }
84 }
85}
86
87static void vfs_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
88{
89 bool cont = true;
90
91 /*
92 * The connection was opened via the IPC_CONNECT_ME_TO call.
93 * This call needs to be answered.
94 */
95 async_answer_0(iid, EOK);
96
97 while (cont) {
98 ipc_call_t call;
99 ipc_callid_t callid = async_get_call(&call);
100
101 if (!IPC_GET_IMETHOD(call))
102 break;
103
104 switch (IPC_GET_IMETHOD(call)) {
105 case VFS_IN_REGISTER:
106 vfs_register(callid, &call);
107 cont = false;
108 break;
109 case VFS_IN_MOUNT:
110 vfs_mount_srv(callid, &call);
111 break;
112 case VFS_IN_UNMOUNT:
113 vfs_unmount_srv(callid, &call);
114 break;
115 case VFS_IN_OPEN:
116 vfs_open(callid, &call);
117 break;
118 case VFS_IN_CLOSE:
119 vfs_close(callid, &call);
120 break;
121 case VFS_IN_READ:
122 vfs_read(callid, &call);
123 break;
124 case VFS_IN_WRITE:
125 vfs_write(callid, &call);
126 break;
127 case VFS_IN_SEEK:
128 vfs_seek(callid, &call);
129 break;
130 case VFS_IN_TRUNCATE:
131 vfs_truncate(callid, &call);
132 break;
133 case VFS_IN_FSTAT:
134 vfs_fstat(callid, &call);
135 break;
136 case VFS_IN_STAT:
137 vfs_stat(callid, &call);
138 break;
139 case VFS_IN_MKDIR:
140 vfs_mkdir(callid, &call);
141 break;
142 case VFS_IN_UNLINK:
143 vfs_unlink(callid, &call);
144 break;
145 case VFS_IN_RENAME:
146 vfs_rename(callid, &call);
147 break;
148 case VFS_IN_SYNC:
149 vfs_sync(callid, &call);
150 break;
151 case VFS_IN_DUP:
152 vfs_dup(callid, &call);
153 break;
154 case VFS_IN_WAIT_HANDLE:
155 vfs_wait_handle(callid, &call);
156 break;
157 case VFS_IN_MTAB_GET:
158 vfs_get_mtab(callid, &call);
159 break;
160 case VFS_IN_STATFS:
161 vfs_statfs(callid, &call);
162 break;
163 default:
164 async_answer_0(callid, ENOTSUP);
165 break;
166 }
167 }
168
169 /*
170 * Open files for this client will be cleaned up when its last
171 * connection fibril terminates.
172 */
173}
174
175static void notification_handler(ipc_callid_t callid, ipc_call_t *call, void *arg)
176{
177 if (IPC_GET_ARG1(*call) == VFS_PASS_HANDLE)
178 vfs_pass_handle(
179 (task_id_t) MERGE_LOUP32(IPC_GET_ARG4(*call),
180 IPC_GET_ARG5(*call)), call->in_task_id,
181 (int) IPC_GET_ARG2(*call));
182}
183
184int main(int argc, char **argv)
185{
186 int rc;
187
188 printf("%s: HelenOS VFS server\n", NAME);
189
190 /*
191 * Initialize VFS node hash table.
192 */
193 if (!vfs_nodes_init()) {
194 printf("%s: Failed to initialize VFS node hash table\n",
195 NAME);
196 return ENOMEM;
197 }
198
199 /*
200 * Allocate and initialize the Path Lookup Buffer.
201 */
202 plb = as_area_create(AS_AREA_ANY, PLB_SIZE,
203 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE, AS_AREA_UNPAGED);
204 if (plb == AS_MAP_FAILED) {
205 printf("%s: Cannot create address space area\n", NAME);
206 return ENOMEM;
207 }
208 memset(plb, 0, PLB_SIZE);
209
210 /*
211 * Set client data constructor and destructor.
212 */
213 async_set_client_data_constructor(vfs_client_data_create);
214 async_set_client_data_destructor(vfs_client_data_destroy);
215
216 /*
217 * Create a port for the pager.
218 */
219 port_id_t port;
220 rc = async_create_port(INTERFACE_PAGER, vfs_pager, NULL, &port);
221 if (rc != EOK)
222 return rc;
223
224 /*
225 * Set a connection handling function/fibril.
226 */
227 async_set_fallback_port_handler(vfs_connection, NULL);
228
229 /*
230 * Subscribe to notifications.
231 */
232 async_event_task_subscribe(EVENT_TASK_STATE_CHANGE, notification_handler,
233 NULL);
234
235 /*
236 * Register at the naming service.
237 */
238 rc = service_register(SERVICE_VFS);
239 if (rc != EOK) {
240 printf("%s: Cannot register VFS service\n", NAME);
241 return rc;
242 }
243
244 /*
245 * Start accepting connections.
246 */
247 printf("%s: Accepting connections\n", NAME);
248 async_manager();
249 return 0;
250}
251
252/**
253 * @}
254 */
Note: See TracBrowser for help on using the repository browser.