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