[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>
|
---|
[a481d81] | 39 | #include <stdlib.h>
|
---|
[c952465d] | 40 | #include <ipc/services.h>
|
---|
[a481d81] | 41 | #include <abi/ipc/methods.h>
|
---|
| 42 | #include <libarch/config.h>
|
---|
[79ae36dd] | 43 | #include <ns.h>
|
---|
[c952465d] | 44 | #include <async.h>
|
---|
| 45 | #include <errno.h>
|
---|
[47a776f9] | 46 | #include <stdio.h>
|
---|
[3e6a98c5] | 47 | #include <stdbool.h>
|
---|
[19f857a] | 48 | #include <str.h>
|
---|
[bcf23cf] | 49 | #include <as.h>
|
---|
[7313e7a] | 50 | #include <atomic.h>
|
---|
[e2ab36f1] | 51 | #include <macros.h>
|
---|
[c952465d] | 52 | #include "vfs.h"
|
---|
| 53 |
|
---|
[007e6efa] | 54 | #define NAME "vfs"
|
---|
[6c89f20] | 55 |
|
---|
[519a97d] | 56 | static void vfs_pager(ipc_callid_t iid, ipc_call_t *icall, void *arg)
|
---|
| 57 | {
|
---|
[a481d81] | 58 | async_answer_0(iid, EOK);
|
---|
| 59 |
|
---|
| 60 | while (true) {
|
---|
| 61 | ipc_call_t call;
|
---|
| 62 | ipc_callid_t callid = async_get_call(&call);
|
---|
| 63 |
|
---|
| 64 | if (!IPC_GET_IMETHOD(call))
|
---|
| 65 | break;
|
---|
| 66 |
|
---|
| 67 | switch (IPC_GET_IMETHOD(call)) {
|
---|
| 68 | case IPC_M_PAGE_IN:
|
---|
[c1f7a315] | 69 | vfs_page_in(callid, &call);
|
---|
[a481d81] | 70 | break;
|
---|
| 71 | default:
|
---|
| 72 | async_answer_0(callid, ENOTSUP);
|
---|
| 73 | break;
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
[519a97d] | 76 | }
|
---|
| 77 |
|
---|
[01c3bb4] | 78 | static void notification_handler(ipc_call_t *call, void *arg)
|
---|
[2bc13887] | 79 | {
|
---|
[8820544] | 80 | if (IPC_GET_ARG1(*call) == VFS_PASS_HANDLE)
|
---|
[354b642] | 81 | vfs_op_pass_handle(
|
---|
[8820544] | 82 | (task_id_t) MERGE_LOUP32(IPC_GET_ARG4(*call),
|
---|
| 83 | IPC_GET_ARG5(*call)), call->in_task_id,
|
---|
| 84 | (int) IPC_GET_ARG2(*call));
|
---|
[2bc13887] | 85 | }
|
---|
| 86 |
|
---|
[0f78e74] | 87 | int main(int argc, char **argv)
|
---|
| 88 | {
|
---|
[519a97d] | 89 | int rc;
|
---|
| 90 |
|
---|
[a47f522] | 91 | printf("%s: HelenOS VFS server\n", NAME);
|
---|
[8dc72b64] | 92 |
|
---|
[b818cff] | 93 | /*
|
---|
| 94 | * Initialize VFS node hash table.
|
---|
| 95 | */
|
---|
| 96 | if (!vfs_nodes_init()) {
|
---|
[a47f522] | 97 | printf("%s: Failed to initialize VFS node hash table\n",
|
---|
| 98 | NAME);
|
---|
[b818cff] | 99 | return ENOMEM;
|
---|
| 100 | }
|
---|
[8dc72b64] | 101 |
|
---|
[bcf23cf] | 102 | /*
|
---|
| 103 | * Allocate and initialize the Path Lookup Buffer.
|
---|
| 104 | */
|
---|
[faba839] | 105 | plb = as_area_create(AS_AREA_ANY, PLB_SIZE,
|
---|
[6aeca0d] | 106 | AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE, AS_AREA_UNPAGED);
|
---|
[faba839] | 107 | if (plb == AS_MAP_FAILED) {
|
---|
[a47f522] | 108 | printf("%s: Cannot create address space area\n", NAME);
|
---|
[37e7dc54] | 109 | return ENOMEM;
|
---|
| 110 | }
|
---|
| 111 | memset(plb, 0, PLB_SIZE);
|
---|
[bcf23cf] | 112 |
|
---|
[b75e929] | 113 | /*
|
---|
| 114 | * Set client data constructor and destructor.
|
---|
| 115 | */
|
---|
| 116 | async_set_client_data_constructor(vfs_client_data_create);
|
---|
| 117 | async_set_client_data_destructor(vfs_client_data_destroy);
|
---|
| 118 |
|
---|
[519a97d] | 119 | /*
|
---|
| 120 | * Create a port for the pager.
|
---|
| 121 | */
|
---|
| 122 | port_id_t port;
|
---|
| 123 | rc = async_create_port(INTERFACE_PAGER, vfs_pager, NULL, &port);
|
---|
| 124 | if (rc != EOK)
|
---|
| 125 | return rc;
|
---|
| 126 |
|
---|
[bcf23cf] | 127 | /*
|
---|
[af7383f3] | 128 | * Set a connection handling function/fibril.
|
---|
[bcf23cf] | 129 | */
|
---|
[b688fd8] | 130 | async_set_fallback_port_handler(vfs_connection, NULL);
|
---|
[af7383f3] | 131 |
|
---|
[2bc13887] | 132 | /*
|
---|
[8820544] | 133 | * Subscribe to notifications.
|
---|
[2bc13887] | 134 | */
|
---|
[8820544] | 135 | async_event_task_subscribe(EVENT_TASK_STATE_CHANGE, notification_handler,
|
---|
| 136 | NULL);
|
---|
[a47f522] | 137 |
|
---|
[bcf23cf] | 138 | /*
|
---|
| 139 | * Register at the naming service.
|
---|
| 140 | */
|
---|
[519a97d] | 141 | rc = service_register(SERVICE_VFS);
|
---|
[a47f522] | 142 | if (rc != EOK) {
|
---|
[007e6efa] | 143 | printf("%s: Cannot register VFS service\n", NAME);
|
---|
[a47f522] | 144 | return rc;
|
---|
[007e6efa] | 145 | }
|
---|
[8dc72b64] | 146 |
|
---|
[bcf23cf] | 147 | /*
|
---|
| 148 | * Start accepting connections.
|
---|
| 149 | */
|
---|
[a47f522] | 150 | printf("%s: Accepting connections\n", NAME);
|
---|
[c952465d] | 151 | async_manager();
|
---|
[0f78e74] | 152 | return 0;
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | /**
|
---|
| 156 | * @}
|
---|
[8dc72b64] | 157 | */
|
---|