source: mainline/uspace/srv/vfs/vfs.c@ 7fa8589

Last change on this file since 7fa8589 was 102f641, checked in by Matthieu Riolo <matthieu.riolo@…>, 6 years ago

Correcting syntax according to ccheck

  • Property mode set to 100644
File size: 4.3 KB
RevLine 
[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
[b1834a01]29/** @addtogroup vfs
[0f78e74]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>
[79ae36dd]42#include <ns.h>
[4224ef7]43#include <as.h>
[c952465d]44#include <async.h>
[241f1985]45#include <stdatomic.h>
[c952465d]46#include <errno.h>
[c1694b6b]47#include <str_error.h>
[47a776f9]48#include <stdio.h>
[4224ef7]49#include <ipc/services.h>
50#include <macros.h>
[3e6a98c5]51#include <stdbool.h>
[4224ef7]52#include <stdio.h>
[19f857a]53#include <str.h>
[4224ef7]54#include <sysman/broker.h>
[c952465d]55#include "vfs.h"
56
[007e6efa]57#define NAME "vfs"
[6c89f20d]58
[984a9ba]59static void vfs_pager(ipc_call_t *icall, void *arg)
[519a97d]60{
[beb83c1]61 async_accept_0(icall);
[a481d81]62
63 while (true) {
64 ipc_call_t call;
[984a9ba]65 async_get_call(&call);
[a35b458]66
[fafb8e5]67 if (!ipc_get_imethod(&call)) {
[889cdb1]68 async_answer_0(&call, EOK);
[a481d81]69 break;
[889cdb1]70 }
[a35b458]71
[fafb8e5]72 switch (ipc_get_imethod(&call)) {
[a481d81]73 case IPC_M_PAGE_IN:
[984a9ba]74 vfs_page_in(&call);
[a481d81]75 break;
76 default:
[984a9ba]77 async_answer_0(&call, ENOTSUP);
[a481d81]78 break;
79 }
80 }
[519a97d]81}
82
[01c3bb4]83static void notification_handler(ipc_call_t *call, void *arg)
[2bc13887]84{
[fafb8e5]85 if (ipc_get_arg1(call) == VFS_PASS_HANDLE)
[354b642]86 vfs_op_pass_handle(
[fafb8e5]87 (task_id_t) MERGE_LOUP32(ipc_get_arg4(call),
88 ipc_get_arg5(call)), call->task_id,
89 (int) ipc_get_arg2(call));
[2bc13887]90}
91
[0f78e74]92int main(int argc, char **argv)
93{
[a47f522]94 printf("%s: HelenOS VFS server\n", NAME);
[a35b458]95
[b818cff]96 /*
97 * Initialize VFS node hash table.
98 */
99 if (!vfs_nodes_init()) {
[a47f522]100 printf("%s: Failed to initialize VFS node hash table\n",
101 NAME);
[b818cff]102 return ENOMEM;
103 }
[a35b458]104
[bcf23cf]105 /*
106 * Allocate and initialize the Path Lookup Buffer.
107 */
[faba839]108 plb = as_area_create(AS_AREA_ANY, PLB_SIZE,
[6aeca0d]109 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE, AS_AREA_UNPAGED);
[faba839]110 if (plb == AS_MAP_FAILED) {
[a47f522]111 printf("%s: Cannot create address space area\n", NAME);
[37e7dc54]112 return ENOMEM;
113 }
114 memset(plb, 0, PLB_SIZE);
[a35b458]115
[b75e929]116 /*
117 * Set client data constructor and destructor.
118 */
119 async_set_client_data_constructor(vfs_client_data_create);
120 async_set_client_data_destructor(vfs_client_data_destroy);
121
[2bc13887]122 /*
[8820544]123 * Subscribe to notifications.
[2bc13887]124 */
[8820544]125 async_event_task_subscribe(EVENT_TASK_STATE_CHANGE, notification_handler,
126 NULL);
[a35b458]127
[bcf23cf]128 /*
129 * Register at the naming service.
130 */
[9b1baac]131 errno_t rc = service_register(SERVICE_VFS, INTERFACE_PAGER, vfs_pager, NULL);
132 if (rc != EOK) {
133 printf("%s: Cannot register VFS pager port: %s\n", NAME, str_error(rc));
134 return rc;
135 }
136
137 rc = service_register(SERVICE_VFS, INTERFACE_VFS, vfs_connection, NULL);
138 if (rc != EOK) {
139 printf("%s: Cannot register VFS file system port: %s\n", NAME, str_error(rc));
140 return rc;
141 }
142
143 rc = service_register(SERVICE_VFS, INTERFACE_VFS_DRIVER, vfs_connection, NULL);
[a47f522]144 if (rc != EOK) {
[9b1baac]145 printf("%s: Cannot register VFS driver port: %s\n", NAME, str_error(rc));
[a47f522]146 return rc;
[007e6efa]147 }
[a35b458]148
[4224ef7]149 /*
150 * Let sysman know we are broker
151 */
152 rc = sysman_broker_register();
153 if (rc != EOK) {
154 printf("%s: Error registering at sysman (%i)\n", NAME, rc);
155 return rc;
156 }
[102f641]157
[bcf23cf]158 /*
159 * Start accepting connections.
160 */
[a47f522]161 printf("%s: Accepting connections\n", NAME);
[bb57a00]162 task_retval(0);
[c952465d]163 async_manager();
[0f78e74]164 return 0;
165}
166
167/**
168 * @}
[8dc72b64]169 */
Note: See TracBrowser for help on using the repository browser.