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

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

Factor out handling of pager requests to vfs_pager.c

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