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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 0328987 was 6afc9d7, checked in by Jiri Svoboda <jiri@…>, 10 years ago

UNIX-like I/O functions should use errno to return error code for many reasons.

  • Property mode set to 100644
File size: 5.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>
[c952465d]39#include <ipc/services.h>
[79ae36dd]40#include <ns.h>
[c952465d]41#include <async.h>
42#include <errno.h>
[47a776f9]43#include <stdio.h>
[3e6a98c5]44#include <stdbool.h>
[19f857a]45#include <str.h>
[bcf23cf]46#include <as.h>
[7313e7a]47#include <atomic.h>
[e2ab36f1]48#include <macros.h>
[c952465d]49#include "vfs.h"
50
[007e6efa]51#define NAME "vfs"
[6c89f20d]52
[9934f7d]53static void vfs_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
[c952465d]54{
[79ae36dd]55 bool cont = true;
56
[c952465d]57 /*
58 * The connection was opened via the IPC_CONNECT_ME_TO call.
59 * This call needs to be answered.
60 */
[ffa2c8ef]61 async_answer_0(iid, EOK);
[8dc72b64]62
[79ae36dd]63 while (cont) {
[d79dcdb]64 ipc_call_t call;
[8dc72b64]65 ipc_callid_t callid = async_get_call(&call);
66
[79ae36dd]67 if (!IPC_GET_IMETHOD(call))
[d79dcdb]68 break;
[79ae36dd]69
70 switch (IPC_GET_IMETHOD(call)) {
[4198f9c3]71 case VFS_IN_REGISTER:
[d79dcdb]72 vfs_register(callid, &call);
[79ae36dd]73 cont = false;
[d79dcdb]74 break;
[4198f9c3]75 case VFS_IN_MOUNT:
[6afc9d7]76 vfs_mount_srv(callid, &call);
[828d215]77 break;
[7f5e070]78 case VFS_IN_UNMOUNT:
[6afc9d7]79 vfs_unmount_srv(callid, &call);
[7f5e070]80 break;
[4198f9c3]81 case VFS_IN_OPEN:
[828d215]82 vfs_open(callid, &call);
83 break;
[4198f9c3]84 case VFS_IN_CLOSE:
[e704503]85 vfs_close(callid, &call);
86 break;
[4198f9c3]87 case VFS_IN_READ:
[b3cd9eb]88 vfs_read(callid, &call);
89 break;
[4198f9c3]90 case VFS_IN_WRITE:
[ee1b8ca]91 vfs_write(callid, &call);
92 break;
[4198f9c3]93 case VFS_IN_SEEK:
[222e57c]94 vfs_seek(callid, &call);
95 break;
[4198f9c3]96 case VFS_IN_TRUNCATE:
[0ee4322]97 vfs_truncate(callid, &call);
98 break;
[852b801]99 case VFS_IN_FSTAT:
100 vfs_fstat(callid, &call);
101 break;
102 case VFS_IN_STAT:
103 vfs_stat(callid, &call);
104 break;
[4198f9c3]105 case VFS_IN_MKDIR:
[72bde81]106 vfs_mkdir(callid, &call);
107 break;
[4198f9c3]108 case VFS_IN_UNLINK:
[f15cf1a6]109 vfs_unlink(callid, &call);
110 break;
[4198f9c3]111 case VFS_IN_RENAME:
[a8e9ab8d]112 vfs_rename(callid, &call);
113 break;
[4198f9c3]114 case VFS_IN_SYNC:
[05b9912]115 vfs_sync(callid, &call);
116 break;
[2b88074b]117 case VFS_IN_DUP:
118 vfs_dup(callid, &call);
[27b76ca]119 break;
120 case VFS_IN_WAIT_HANDLE:
121 vfs_wait_handle(callid, &call);
122 break;
[41e9ef7]123 case VFS_IN_MTAB_GET:
[76a67ce]124 vfs_get_mtab(callid, &call);
[10e4cd7]125 break;
[66366470]126 case VFS_IN_STATFS:
127 vfs_statfs(callid, &call);
128 break;
[d79dcdb]129 default:
[ffa2c8ef]130 async_answer_0(callid, ENOTSUP);
[d79dcdb]131 break;
132 }
[c952465d]133 }
[79ae36dd]134
[b75e929]135 /*
136 * Open files for this client will be cleaned up when its last
137 * connection fibril terminates.
138 */
[c952465d]139}
140
[8820544]141static void notification_handler(ipc_callid_t callid, ipc_call_t *call, void *arg)
[2bc13887]142{
[8820544]143 if (IPC_GET_ARG1(*call) == VFS_PASS_HANDLE)
144 vfs_pass_handle(
145 (task_id_t) MERGE_LOUP32(IPC_GET_ARG4(*call),
146 IPC_GET_ARG5(*call)), call->in_task_id,
147 (int) IPC_GET_ARG2(*call));
[2bc13887]148}
149
[0f78e74]150int main(int argc, char **argv)
151{
[a47f522]152 printf("%s: HelenOS VFS server\n", NAME);
[8dc72b64]153
[b818cff]154 /*
155 * Initialize VFS node hash table.
156 */
157 if (!vfs_nodes_init()) {
[a47f522]158 printf("%s: Failed to initialize VFS node hash table\n",
159 NAME);
[b818cff]160 return ENOMEM;
161 }
[8dc72b64]162
[bcf23cf]163 /*
164 * Allocate and initialize the Path Lookup Buffer.
165 */
[faba839]166 plb = as_area_create(AS_AREA_ANY, PLB_SIZE,
[fbcdeb8]167 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
[faba839]168 if (plb == AS_MAP_FAILED) {
[a47f522]169 printf("%s: Cannot create address space area\n", NAME);
[37e7dc54]170 return ENOMEM;
171 }
172 memset(plb, 0, PLB_SIZE);
[bcf23cf]173
[b75e929]174 /*
175 * Set client data constructor and destructor.
176 */
177 async_set_client_data_constructor(vfs_client_data_create);
178 async_set_client_data_destructor(vfs_client_data_destroy);
179
[bcf23cf]180 /*
[af7383f3]181 * Set a connection handling function/fibril.
[bcf23cf]182 */
[b688fd8]183 async_set_fallback_port_handler(vfs_connection, NULL);
[af7383f3]184
[2bc13887]185 /*
[8820544]186 * Subscribe to notifications.
[2bc13887]187 */
[8820544]188 async_event_task_subscribe(EVENT_TASK_STATE_CHANGE, notification_handler,
189 NULL);
[a47f522]190
[bcf23cf]191 /*
192 * Register at the naming service.
193 */
[a47f522]194 int rc = service_register(SERVICE_VFS);
195 if (rc != EOK) {
[007e6efa]196 printf("%s: Cannot register VFS service\n", NAME);
[a47f522]197 return rc;
[007e6efa]198 }
[8dc72b64]199
[bcf23cf]200 /*
201 * Start accepting connections.
202 */
[a47f522]203 printf("%s: Accepting connections\n", NAME);
[c952465d]204 async_manager();
[0f78e74]205 return 0;
206}
207
208/**
209 * @}
[8dc72b64]210 */
Note: See TracBrowser for help on using the repository browser.