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