source: mainline/uspace/srv/vfs/vfs.c@ df02460

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

Fix includes.

  • Property mode set to 100644
File size: 5.1 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 <ipc/services.h>
39#include <abi/ipc/event.h>
40#include <event.h>
41#include <ns.h>
42#include <async.h>
43#include <errno.h>
44#include <stdio.h>
45#include <bool.h>
46#include <str.h>
47#include <as.h>
48#include <atomic.h>
49#include <vfs/vfs.h>
50#include "vfs.h"
51
52#define NAME "vfs"
53
54static void vfs_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
55{
56 bool cont = true;
57
58 /*
59 * The connection was opened via the IPC_CONNECT_ME_TO call.
60 * This call needs to be answered.
61 */
62 async_answer_0(iid, EOK);
63
64 while (cont) {
65 ipc_call_t call;
66 ipc_callid_t callid = async_get_call(&call);
67
68 if (!IPC_GET_IMETHOD(call))
69 break;
70
71 switch (IPC_GET_IMETHOD(call)) {
72 case VFS_IN_REGISTER:
73 vfs_register(callid, &call);
74 cont = false;
75 break;
76 case VFS_IN_MOUNT:
77 vfs_mount(callid, &call);
78 break;
79 case VFS_IN_UNMOUNT:
80 vfs_unmount(callid, &call);
81 break;
82 case VFS_IN_OPEN:
83 vfs_open(callid, &call);
84 break;
85 case VFS_IN_OPEN_NODE:
86 vfs_open_node(callid, &call);
87 break;
88 case VFS_IN_CLOSE:
89 vfs_close(callid, &call);
90 break;
91 case VFS_IN_READ:
92 vfs_read(callid, &call);
93 break;
94 case VFS_IN_WRITE:
95 vfs_write(callid, &call);
96 break;
97 case VFS_IN_SEEK:
98 vfs_seek(callid, &call);
99 break;
100 case VFS_IN_TRUNCATE:
101 vfs_truncate(callid, &call);
102 break;
103 case VFS_IN_FSTAT:
104 vfs_fstat(callid, &call);
105 break;
106 case VFS_IN_STAT:
107 vfs_stat(callid, &call);
108 break;
109 case VFS_IN_MKDIR:
110 vfs_mkdir(callid, &call);
111 break;
112 case VFS_IN_UNLINK:
113 vfs_unlink(callid, &call);
114 break;
115 case VFS_IN_RENAME:
116 vfs_rename(callid, &call);
117 break;
118 case VFS_IN_SYNC:
119 vfs_sync(callid, &call);
120 break;
121 case VFS_IN_DUP:
122 vfs_dup(callid, &call);
123 default:
124 async_answer_0(callid, ENOTSUP);
125 break;
126 }
127 }
128
129 /*
130 * Open files for this client will be cleaned up when its last
131 * connection fibril terminates.
132 */
133}
134
135enum {
136 VFS_TASK_STATE_CHANGE
137};
138
139static void notification_received(ipc_callid_t callid, ipc_call_t *call)
140{
141 switch (IPC_GET_IMETHOD(*call)) {
142 case VFS_TASK_STATE_CHANGE:
143 if (IPC_GET_ARG1(*call) == VFS_PASS_HANDLE)
144 vfs_pass_handle(IPC_GET_ARG4(*call),
145 IPC_GET_ARG5(*call), (int) IPC_GET_ARG2(*call));
146 break;
147 default:
148 break;
149 }
150}
151
152int main(int argc, char **argv)
153{
154 printf(NAME ": HelenOS VFS server\n");
155
156 /*
157 * Initialize VFS node hash table.
158 */
159 if (!vfs_nodes_init()) {
160 printf(NAME ": Failed to initialize VFS node hash table\n");
161 return ENOMEM;
162 }
163
164 /*
165 * Allocate and initialize the Path Lookup Buffer.
166 */
167 plb = as_get_mappable_page(PLB_SIZE);
168 if (!plb) {
169 printf(NAME ": Cannot allocate a mappable piece of address space\n");
170 return ENOMEM;
171 }
172
173 if (as_area_create(plb, PLB_SIZE, AS_AREA_READ | AS_AREA_WRITE |
174 AS_AREA_CACHEABLE) != plb) {
175 printf(NAME ": Cannot create address space area\n");
176 return ENOMEM;
177 }
178 memset(plb, 0, PLB_SIZE);
179
180 /*
181 * Set client data constructor and destructor.
182 */
183 async_set_client_data_constructor(vfs_client_data_create);
184 async_set_client_data_destructor(vfs_client_data_destroy);
185
186 /*
187 * Set a connection handling function/fibril.
188 */
189 async_set_client_connection(vfs_connection);
190
191 /*
192 * Set notification handler and subscribe to notifications.
193 */
194 async_set_interrupt_received(notification_received);
195 event_task_subscribe(EVENT_TASK_STATE_CHANGE, VFS_TASK_STATE_CHANGE);
196
197 /*
198 * Register at the naming service.
199 */
200 if (service_register(SERVICE_VFS) != EOK) {
201 printf("%s: Cannot register VFS service\n", NAME);
202 return EINVAL;
203 }
204
205 /*
206 * Start accepting connections.
207 */
208 printf(NAME ": Accepting connections\n");
209 async_manager();
210 return 0;
211}
212
213/**
214 * @}
215 */
Note: See TracBrowser for help on using the repository browser.