source: mainline/uspace/srv/vfs/vfs.c@ 44451ee

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

Synchronize VFS handle acceptor with VFS.

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