| 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 vfs
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 |
|
|---|
| 33 | /**
|
|---|
| 34 | * @file vfs.c
|
|---|
| 35 | * @brief VFS service for HelenOS.
|
|---|
| 36 | */
|
|---|
| 37 |
|
|---|
| 38 | #include <vfs/vfs.h>
|
|---|
| 39 | #include <stdlib.h>
|
|---|
| 40 | #include <ipc/services.h>
|
|---|
| 41 | #include <abi/ipc/methods.h>
|
|---|
| 42 | #include <libarch/config.h>
|
|---|
| 43 | #include <ns.h>
|
|---|
| 44 | #include <async.h>
|
|---|
| 45 | #include <errno.h>
|
|---|
| 46 | #include <str_error.h>
|
|---|
| 47 | #include <stdio.h>
|
|---|
| 48 | #include <stdbool.h>
|
|---|
| 49 | #include <str.h>
|
|---|
| 50 | #include <as.h>
|
|---|
| 51 | #include <macros.h>
|
|---|
| 52 | #include "vfs.h"
|
|---|
| 53 |
|
|---|
| 54 | #define NAME "vfs"
|
|---|
| 55 |
|
|---|
| 56 | static void vfs_pager(ipc_call_t *icall, void *arg)
|
|---|
| 57 | {
|
|---|
| 58 | async_accept_0(icall);
|
|---|
| 59 |
|
|---|
| 60 | while (true) {
|
|---|
| 61 | ipc_call_t call;
|
|---|
| 62 | async_get_call(&call);
|
|---|
| 63 |
|
|---|
| 64 | if (!ipc_get_imethod(&call)) {
|
|---|
| 65 | async_answer_0(&call, EOK);
|
|---|
| 66 | break;
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | switch (ipc_get_imethod(&call)) {
|
|---|
| 70 | case IPC_M_PAGE_IN:
|
|---|
| 71 | vfs_page_in(&call);
|
|---|
| 72 | break;
|
|---|
| 73 | default:
|
|---|
| 74 | async_answer_0(&call, ENOTSUP);
|
|---|
| 75 | break;
|
|---|
| 76 | }
|
|---|
| 77 | }
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | static void notification_handler(ipc_call_t *call, void *arg)
|
|---|
| 81 | {
|
|---|
| 82 | if (ipc_get_arg1(call) == VFS_PASS_HANDLE)
|
|---|
| 83 | vfs_op_pass_handle(
|
|---|
| 84 | (task_id_t) MERGE_LOUP32(ipc_get_arg4(call),
|
|---|
| 85 | ipc_get_arg5(call)), call->task_id,
|
|---|
| 86 | (int) ipc_get_arg2(call));
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | int main(int argc, char **argv)
|
|---|
| 90 | {
|
|---|
| 91 | printf("%s: HelenOS VFS server\n", NAME);
|
|---|
| 92 |
|
|---|
| 93 | /*
|
|---|
| 94 | * Initialize VFS node hash table.
|
|---|
| 95 | */
|
|---|
| 96 | if (!vfs_nodes_init()) {
|
|---|
| 97 | printf("%s: Failed to initialize VFS node hash table\n",
|
|---|
| 98 | NAME);
|
|---|
| 99 | return ENOMEM;
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | /*
|
|---|
| 103 | * Allocate and initialize the Path Lookup Buffer.
|
|---|
| 104 | */
|
|---|
| 105 | plb = as_area_create(AS_AREA_ANY, PLB_SIZE,
|
|---|
| 106 | AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE, AS_AREA_UNPAGED);
|
|---|
| 107 | if (plb == AS_MAP_FAILED) {
|
|---|
| 108 | printf("%s: Cannot create address space area\n", NAME);
|
|---|
| 109 | return ENOMEM;
|
|---|
| 110 | }
|
|---|
| 111 | memset(plb, 0, PLB_SIZE);
|
|---|
| 112 |
|
|---|
| 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 |
|
|---|
| 119 | /*
|
|---|
| 120 | * Subscribe to notifications.
|
|---|
| 121 | */
|
|---|
| 122 | async_event_task_subscribe(EVENT_TASK_STATE_CHANGE, notification_handler,
|
|---|
| 123 | NULL);
|
|---|
| 124 |
|
|---|
| 125 | /*
|
|---|
| 126 | * Register at the naming service.
|
|---|
| 127 | */
|
|---|
| 128 | errno_t rc = service_register(SERVICE_VFS, INTERFACE_PAGER, vfs_pager, NULL);
|
|---|
| 129 | if (rc != EOK) {
|
|---|
| 130 | printf("%s: Cannot register VFS pager port: %s\n", NAME, str_error(rc));
|
|---|
| 131 | return rc;
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | rc = service_register(SERVICE_VFS, INTERFACE_VFS, vfs_connection, NULL);
|
|---|
| 135 | if (rc != EOK) {
|
|---|
| 136 | printf("%s: Cannot register VFS file system port: %s\n", NAME, str_error(rc));
|
|---|
| 137 | return rc;
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | rc = service_register(SERVICE_VFS, INTERFACE_VFS_DRIVER, vfs_connection, NULL);
|
|---|
| 141 | if (rc != EOK) {
|
|---|
| 142 | printf("%s: Cannot register VFS driver port: %s\n", NAME, str_error(rc));
|
|---|
| 143 | return rc;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | /*
|
|---|
| 147 | * Start accepting connections.
|
|---|
| 148 | */
|
|---|
| 149 | printf("%s: Accepting connections\n", NAME);
|
|---|
| 150 | async_manager();
|
|---|
| 151 | return 0;
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | /**
|
|---|
| 155 | * @}
|
|---|
| 156 | */
|
|---|