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