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_answer_0(icall, EOK);
|
---|
59 |
|
---|
60 | while (true) {
|
---|
61 | ipc_call_t call;
|
---|
62 | 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:
|
---|
69 | vfs_page_in(&call);
|
---|
70 | break;
|
---|
71 | default:
|
---|
72 | async_answer_0(&call, ENOTSUP);
|
---|
73 | break;
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | static void notification_handler(ipc_call_t *call, void *arg)
|
---|
79 | {
|
---|
80 | if (IPC_GET_ARG1(*call) == VFS_PASS_HANDLE)
|
---|
81 | vfs_op_pass_handle(
|
---|
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));
|
---|
85 | }
|
---|
86 |
|
---|
87 | int main(int argc, char **argv)
|
---|
88 | {
|
---|
89 | printf("%s: HelenOS VFS server\n", NAME);
|
---|
90 |
|
---|
91 | /*
|
---|
92 | * Initialize VFS node hash table.
|
---|
93 | */
|
---|
94 | if (!vfs_nodes_init()) {
|
---|
95 | printf("%s: Failed to initialize VFS node hash table\n",
|
---|
96 | NAME);
|
---|
97 | return ENOMEM;
|
---|
98 | }
|
---|
99 |
|
---|
100 | /*
|
---|
101 | * Allocate and initialize the Path Lookup Buffer.
|
---|
102 | */
|
---|
103 | plb = as_area_create(AS_AREA_ANY, PLB_SIZE,
|
---|
104 | AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE, AS_AREA_UNPAGED);
|
---|
105 | if (plb == AS_MAP_FAILED) {
|
---|
106 | printf("%s: Cannot create address space area\n", NAME);
|
---|
107 | return ENOMEM;
|
---|
108 | }
|
---|
109 | memset(plb, 0, PLB_SIZE);
|
---|
110 |
|
---|
111 | /*
|
---|
112 | * Set client data constructor and destructor.
|
---|
113 | */
|
---|
114 | async_set_client_data_constructor(vfs_client_data_create);
|
---|
115 | async_set_client_data_destructor(vfs_client_data_destroy);
|
---|
116 |
|
---|
117 | /*
|
---|
118 | * Subscribe to notifications.
|
---|
119 | */
|
---|
120 | async_event_task_subscribe(EVENT_TASK_STATE_CHANGE, notification_handler,
|
---|
121 | NULL);
|
---|
122 |
|
---|
123 | /*
|
---|
124 | * Register at the naming service.
|
---|
125 | */
|
---|
126 | errno_t rc = service_register(SERVICE_VFS, INTERFACE_PAGER, vfs_pager, NULL);
|
---|
127 | if (rc != EOK) {
|
---|
128 | printf("%s: Cannot register VFS pager port: %s\n", NAME, str_error(rc));
|
---|
129 | return rc;
|
---|
130 | }
|
---|
131 |
|
---|
132 | rc = service_register(SERVICE_VFS, INTERFACE_VFS, vfs_connection, NULL);
|
---|
133 | if (rc != EOK) {
|
---|
134 | printf("%s: Cannot register VFS file system port: %s\n", NAME, str_error(rc));
|
---|
135 | return rc;
|
---|
136 | }
|
---|
137 |
|
---|
138 | rc = service_register(SERVICE_VFS, INTERFACE_VFS_DRIVER, vfs_connection, NULL);
|
---|
139 | if (rc != EOK) {
|
---|
140 | printf("%s: Cannot register VFS driver port: %s\n", NAME, str_error(rc));
|
---|
141 | return rc;
|
---|
142 | }
|
---|
143 |
|
---|
144 | /*
|
---|
145 | * Start accepting connections.
|
---|
146 | */
|
---|
147 | printf("%s: Accepting connections\n", NAME);
|
---|
148 | async_manager();
|
---|
149 | return 0;
|
---|
150 | }
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * @}
|
---|
154 | */
|
---|