| 1 | /*
|
|---|
| 2 | * Copyright (c) 2008 Jakub Jermar
|
|---|
| 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 | * @{
|
|---|
| 31 | */
|
|---|
| 32 |
|
|---|
| 33 | /**
|
|---|
| 34 | * @file vfs.c
|
|---|
| 35 | * @brief VFS service for HelenOS.
|
|---|
| 36 | */
|
|---|
| 37 |
|
|---|
| 38 | #include <ipc/services.h>
|
|---|
| 39 | #include <ipc/ns.h>
|
|---|
| 40 | #include <async.h>
|
|---|
| 41 | #include <errno.h>
|
|---|
| 42 | #include <stdio.h>
|
|---|
| 43 | #include <bool.h>
|
|---|
| 44 | #include <str.h>
|
|---|
| 45 | #include <as.h>
|
|---|
| 46 | #include <atomic.h>
|
|---|
| 47 | #include "vfs.h"
|
|---|
| 48 |
|
|---|
| 49 | #define NAME "vfs"
|
|---|
| 50 |
|
|---|
| 51 | static void vfs_connection(ipc_callid_t iid, ipc_call_t *icall)
|
|---|
| 52 | {
|
|---|
| 53 | bool keep_on_going = true;
|
|---|
| 54 |
|
|---|
| 55 | /*
|
|---|
| 56 | * The connection was opened via the IPC_CONNECT_ME_TO call.
|
|---|
| 57 | * This call needs to be answered.
|
|---|
| 58 | */
|
|---|
| 59 | async_answer_0(iid, EOK);
|
|---|
| 60 |
|
|---|
| 61 | while (keep_on_going) {
|
|---|
| 62 | ipc_call_t call;
|
|---|
| 63 | ipc_callid_t callid = async_get_call(&call);
|
|---|
| 64 |
|
|---|
| 65 | switch (IPC_GET_IMETHOD(call)) {
|
|---|
| 66 | case IPC_M_PHONE_HUNGUP:
|
|---|
| 67 | keep_on_going = false;
|
|---|
| 68 | break;
|
|---|
| 69 | case VFS_IN_REGISTER:
|
|---|
| 70 | vfs_register(callid, &call);
|
|---|
| 71 | keep_on_going = false;
|
|---|
| 72 | break;
|
|---|
| 73 | case VFS_IN_MOUNT:
|
|---|
| 74 | vfs_mount(callid, &call);
|
|---|
| 75 | break;
|
|---|
| 76 | case VFS_IN_UNMOUNT:
|
|---|
| 77 | vfs_unmount(callid, &call);
|
|---|
| 78 | break;
|
|---|
| 79 | case VFS_IN_OPEN:
|
|---|
| 80 | vfs_open(callid, &call);
|
|---|
| 81 | break;
|
|---|
| 82 | case VFS_IN_OPEN_NODE:
|
|---|
| 83 | vfs_open_node(callid, &call);
|
|---|
| 84 | break;
|
|---|
| 85 | case VFS_IN_CLOSE:
|
|---|
| 86 | vfs_close(callid, &call);
|
|---|
| 87 | break;
|
|---|
| 88 | case VFS_IN_READ:
|
|---|
| 89 | vfs_read(callid, &call);
|
|---|
| 90 | break;
|
|---|
| 91 | case VFS_IN_WRITE:
|
|---|
| 92 | vfs_write(callid, &call);
|
|---|
| 93 | break;
|
|---|
| 94 | case VFS_IN_SEEK:
|
|---|
| 95 | vfs_seek(callid, &call);
|
|---|
| 96 | break;
|
|---|
| 97 | case VFS_IN_TRUNCATE:
|
|---|
| 98 | vfs_truncate(callid, &call);
|
|---|
| 99 | break;
|
|---|
| 100 | case VFS_IN_FSTAT:
|
|---|
| 101 | vfs_fstat(callid, &call);
|
|---|
| 102 | break;
|
|---|
| 103 | case VFS_IN_STAT:
|
|---|
| 104 | vfs_stat(callid, &call);
|
|---|
| 105 | break;
|
|---|
| 106 | case VFS_IN_MKDIR:
|
|---|
| 107 | vfs_mkdir(callid, &call);
|
|---|
| 108 | break;
|
|---|
| 109 | case VFS_IN_UNLINK:
|
|---|
| 110 | vfs_unlink(callid, &call);
|
|---|
| 111 | break;
|
|---|
| 112 | case VFS_IN_RENAME:
|
|---|
| 113 | vfs_rename(callid, &call);
|
|---|
| 114 | break;
|
|---|
| 115 | case VFS_IN_SYNC:
|
|---|
| 116 | vfs_sync(callid, &call);
|
|---|
| 117 | break;
|
|---|
| 118 | case VFS_IN_DUP:
|
|---|
| 119 | vfs_dup(callid, &call);
|
|---|
| 120 | default:
|
|---|
| 121 | async_answer_0(callid, ENOTSUP);
|
|---|
| 122 | break;
|
|---|
| 123 | }
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | /*
|
|---|
| 127 | * Open files for this client will be cleaned up when its last
|
|---|
| 128 | * connection fibril terminates.
|
|---|
| 129 | */
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | int main(int argc, char **argv)
|
|---|
| 133 | {
|
|---|
| 134 | printf(NAME ": HelenOS VFS server\n");
|
|---|
| 135 |
|
|---|
| 136 | /*
|
|---|
| 137 | * Initialize VFS node hash table.
|
|---|
| 138 | */
|
|---|
| 139 | if (!vfs_nodes_init()) {
|
|---|
| 140 | printf(NAME ": Failed to initialize VFS node hash table\n");
|
|---|
| 141 | return ENOMEM;
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | /*
|
|---|
| 145 | * Allocate and initialize the Path Lookup Buffer.
|
|---|
| 146 | */
|
|---|
| 147 | plb = as_get_mappable_page(PLB_SIZE);
|
|---|
| 148 | if (!plb) {
|
|---|
| 149 | printf(NAME ": Cannot allocate a mappable piece of address space\n");
|
|---|
| 150 | return ENOMEM;
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | if (as_area_create(plb, PLB_SIZE, AS_AREA_READ | AS_AREA_WRITE |
|
|---|
| 154 | AS_AREA_CACHEABLE) != plb) {
|
|---|
| 155 | printf(NAME ": Cannot create address space area\n");
|
|---|
| 156 | return ENOMEM;
|
|---|
| 157 | }
|
|---|
| 158 | memset(plb, 0, PLB_SIZE);
|
|---|
| 159 |
|
|---|
| 160 | /*
|
|---|
| 161 | * Set client data constructor and destructor.
|
|---|
| 162 | */
|
|---|
| 163 | async_set_client_data_constructor(vfs_client_data_create);
|
|---|
| 164 | async_set_client_data_destructor(vfs_client_data_destroy);
|
|---|
| 165 |
|
|---|
| 166 | /*
|
|---|
| 167 | * Set a connection handling function/fibril.
|
|---|
| 168 | */
|
|---|
| 169 | async_set_client_connection(vfs_connection);
|
|---|
| 170 |
|
|---|
| 171 | /*
|
|---|
| 172 | * Register at the naming service.
|
|---|
| 173 | */
|
|---|
| 174 | if (service_register(SERVICE_VFS) != EOK) {
|
|---|
| 175 | printf("%s: Cannot register VFS service\n", NAME);
|
|---|
| 176 | return EINVAL;
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | /*
|
|---|
| 180 | * Start accepting connections.
|
|---|
| 181 | */
|
|---|
| 182 | printf(NAME ": Accepting connections\n");
|
|---|
| 183 | async_manager();
|
|---|
| 184 | return 0;
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | /**
|
|---|
| 188 | * @}
|
|---|
| 189 | */
|
|---|