source: mainline/uspace/srv/vfs/vfs.c@ 3061bc1

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3061bc1 was b7fd2a0, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

Use errno_t in all uspace and kernel code.

Change type of every variable, parameter and return value that holds an
<errno.h> constant to either errno_t (the usual case), or sys_errno_t
(some places in kernel). This is for the purpose of self-documentation,
as well as for type-checking with a bit of type definition hackery.

Although this is a massive commit, it is a simple text replacement, and thus
is very easy to verify. Simply do the following:

`
git checkout <this commit's hash>
git reset HEAD
git add .
tools/srepl '\berrno_t\b' int
git add .
tools/srepl '\bsys_errno_t\b' sysarg_t
git reset
git diff
`

While this doesn't ensure that the replacements are correct, it does ensure
that the commit doesn't do anything except those replacements. Since errno_t
is typedef'd to int in the usual case (and sys_errno_t to sysarg_t), even if
incorrect, this commit cannot change behavior.

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