source: mainline/uspace/srv/vfs/vfs.c@ 2bc13887

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

Add vfs_pass_handle().

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