source: mainline/uspace/srv/vfs/vfs.c@ f787c8e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since f787c8e was 9b1baac, checked in by Martin Decky <martin@…>, 7 years ago

ns: register service interfaces individually

Each service interface is now registered individually with the naming
service. This adds a degree of type safety, potentially allows the
individual interfaces to be implemented by independent tasks and moves
the code slightly closer to the full-fledged ports design.

Broker services (e.g. the location service) can still register a
fallback port for receiving connections to all interface types
explicitly using service_register_broker().

  • Property mode set to 100644
File size: 4.0 KB
Line 
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 <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 <atomic.h>
52#include <macros.h>
53#include "vfs.h"
54
55#define NAME "vfs"
56
57static void vfs_pager(ipc_call_t *icall, void *arg)
58{
59 async_answer_0(icall, EOK);
60
61 while (true) {
62 ipc_call_t call;
63 async_get_call(&call);
64
65 if (!IPC_GET_IMETHOD(call))
66 break;
67
68 switch (IPC_GET_IMETHOD(call)) {
69 case IPC_M_PAGE_IN:
70 vfs_page_in(&call);
71 break;
72 default:
73 async_answer_0(&call, ENOTSUP);
74 break;
75 }
76 }
77}
78
79static void notification_handler(ipc_call_t *call, void *arg)
80{
81 if (IPC_GET_ARG1(*call) == VFS_PASS_HANDLE)
82 vfs_op_pass_handle(
83 (task_id_t) MERGE_LOUP32(IPC_GET_ARG4(*call),
84 IPC_GET_ARG5(*call)), call->in_task_id,
85 (int) IPC_GET_ARG2(*call));
86}
87
88int main(int argc, char **argv)
89{
90 printf("%s: HelenOS VFS server\n", NAME);
91
92 /*
93 * Initialize VFS node hash table.
94 */
95 if (!vfs_nodes_init()) {
96 printf("%s: Failed to initialize VFS node hash table\n",
97 NAME);
98 return ENOMEM;
99 }
100
101 /*
102 * Allocate and initialize the Path Lookup Buffer.
103 */
104 plb = as_area_create(AS_AREA_ANY, PLB_SIZE,
105 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE, AS_AREA_UNPAGED);
106 if (plb == AS_MAP_FAILED) {
107 printf("%s: Cannot create address space area\n", NAME);
108 return ENOMEM;
109 }
110 memset(plb, 0, PLB_SIZE);
111
112 /*
113 * Set client data constructor and destructor.
114 */
115 async_set_client_data_constructor(vfs_client_data_create);
116 async_set_client_data_destructor(vfs_client_data_destroy);
117
118 /*
119 * Subscribe to notifications.
120 */
121 async_event_task_subscribe(EVENT_TASK_STATE_CHANGE, notification_handler,
122 NULL);
123
124 /*
125 * Register at the naming service.
126 */
127 errno_t rc = service_register(SERVICE_VFS, INTERFACE_PAGER, vfs_pager, NULL);
128 if (rc != EOK) {
129 printf("%s: Cannot register VFS pager port: %s\n", NAME, str_error(rc));
130 return rc;
131 }
132
133 rc = service_register(SERVICE_VFS, INTERFACE_VFS, vfs_connection, NULL);
134 if (rc != EOK) {
135 printf("%s: Cannot register VFS file system port: %s\n", NAME, str_error(rc));
136 return rc;
137 }
138
139 rc = service_register(SERVICE_VFS, INTERFACE_VFS_DRIVER, vfs_connection, NULL);
140 if (rc != EOK) {
141 printf("%s: Cannot register VFS driver port: %s\n", NAME, str_error(rc));
142 return rc;
143 }
144
145 /*
146 * Start accepting connections.
147 */
148 printf("%s: Accepting connections\n", NAME);
149 async_manager();
150 return 0;
151}
152
153/**
154 * @}
155 */
Note: See TracBrowser for help on using the repository browser.