source: mainline/uspace/srv/fs/ext2fs/ext2fs.c@ 6a44ee4

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

Add extra argument to async connection handlers that can be used for passing
information from async_connect_to_me() to the handler.

  • Property mode set to 100644
File size: 5.0 KB
RevLine 
[3bd76491]1/*
2 * Copyright (c) 2006 Martin Decky
3 * Copyright (c) 2008 Jakub Jermar
[868ef40]4 * Copyright (c) 2011 Martin Sucha
[3bd76491]5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * - The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/** @addtogroup fs
32 * @{
33 */
34
35/**
36 * @file ext2.c
37 * @brief EXT2 file system driver for HelenOS.
38 */
39
[796c276]40#include "ext2fs.h"
[3bd76491]41#include <ipc/services.h>
[79ae36dd]42#include <ns.h>
[3bd76491]43#include <async.h>
44#include <errno.h>
45#include <unistd.h>
46#include <task.h>
47#include <stdio.h>
48#include <libfs.h>
49#include "../../vfs/vfs.h"
50
[796c276]51#define NAME "ext2fs"
[3bd76491]52
[163cf12]53vfs_info_t ext2fs_vfs_info = {
[3bd76491]54 .name = NAME,
55};
56
[796c276]57fs_reg_t ext2fs_reg;
[3bd76491]58
59/**
60 * This connection fibril processes VFS requests from VFS.
61 *
62 * In order to support simultaneous VFS requests, our design is as follows.
63 * The connection fibril accepts VFS requests from VFS. If there is only one
64 * instance of the fibril, VFS will need to serialize all VFS requests it sends
[796c276]65 * to EXT2FS. To overcome this bottleneck, VFS can send EXT2FS the IPC_M_CONNECT_ME_TO
[3bd76491]66 * call. In that case, a new connection fibril will be created, which in turn
67 * will accept the call. Thus, a new phone will be opened for VFS.
68 *
69 * There are few issues with this arrangement. First, VFS can run out of
70 * available phones. In that case, VFS can close some other phones or use one
[796c276]71 * phone for more serialized requests. Similarily, EXT2FS can refuse to duplicate
[3bd76491]72 * the connection. VFS should then just make use of already existing phones and
73 * route its requests through them. To avoid paying the fibril creation price
[796c276]74 * upon each request, EXT2FS might want to keep the connections open after the
[3bd76491]75 * request has been completed.
76 */
[9934f7d]77static void ext2fs_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
[3bd76491]78{
79 if (iid) {
80 /*
81 * This only happens for connections opened by
82 * IPC_M_CONNECT_ME_TO calls as opposed to callback connections
83 * created by IPC_M_CONNECT_TO_ME.
84 */
[cf2af94]85 async_answer_0(iid, EOK);
[3bd76491]86 }
87
88 dprintf(NAME ": connection opened\n");
[79ae36dd]89 while (true) {
[3bd76491]90 ipc_call_t call;
[79ae36dd]91 ipc_callid_t callid = async_get_call(&call);
92
93 if (!IPC_GET_IMETHOD(call))
[3bd76491]94 return;
[79ae36dd]95
96 switch (IPC_GET_IMETHOD(call)) {
[3bd76491]97 case VFS_OUT_MOUNTED:
[796c276]98 ext2fs_mounted(callid, &call);
[3bd76491]99 break;
100 case VFS_OUT_MOUNT:
[796c276]101 ext2fs_mount(callid, &call);
[3bd76491]102 break;
103 case VFS_OUT_UNMOUNTED:
[796c276]104 ext2fs_unmounted(callid, &call);
[3bd76491]105 break;
106 case VFS_OUT_UNMOUNT:
[796c276]107 ext2fs_unmount(callid, &call);
[3bd76491]108 break;
109 case VFS_OUT_LOOKUP:
[796c276]110 ext2fs_lookup(callid, &call);
[3bd76491]111 break;
112 case VFS_OUT_READ:
[796c276]113 ext2fs_read(callid, &call);
[3bd76491]114 break;
115 case VFS_OUT_WRITE:
[796c276]116 ext2fs_write(callid, &call);
[3bd76491]117 break;
118 case VFS_OUT_TRUNCATE:
[796c276]119 ext2fs_truncate(callid, &call);
[3bd76491]120 break;
121 case VFS_OUT_STAT:
[796c276]122 ext2fs_stat(callid, &call);
[3bd76491]123 break;
124 case VFS_OUT_CLOSE:
[796c276]125 ext2fs_close(callid, &call);
[3bd76491]126 break;
127 case VFS_OUT_DESTROY:
[796c276]128 ext2fs_destroy(callid, &call);
[3bd76491]129 break;
130 case VFS_OUT_OPEN_NODE:
[796c276]131 ext2fs_open_node(callid, &call);
[3bd76491]132 break;
133 case VFS_OUT_SYNC:
[796c276]134 ext2fs_sync(callid, &call);
[3bd76491]135 break;
136 default:
[cf2af94]137 async_answer_0(callid, ENOTSUP);
[3bd76491]138 break;
139 }
140 }
141}
142
143int main(int argc, char **argv)
144{
145 printf(NAME ": HelenOS EXT2 file system server\n");
[79ae36dd]146
147 async_sess_t *vfs_sess = service_connect_blocking(EXCHANGE_SERIALIZE,
148 SERVICE_VFS, 0, 0);
149 if (!vfs_sess) {
[3bd76491]150 printf(NAME ": failed to connect to VFS\n");
151 return -1;
152 }
[4dc6a32]153
[79ae36dd]154 int rc = ext2fs_global_init();
[4dc6a32]155 if (rc != EOK) {
156 printf(NAME ": Failed global initialization\n");
157 return 1;
158 }
159
[79ae36dd]160 rc = fs_register(vfs_sess, &ext2fs_reg, &ext2fs_vfs_info, ext2fs_connection);
[5bd1ffb]161 if (rc != EOK) {
162 fprintf(stdout, NAME ": Failed to register fs (%d)\n", rc);
163 return 1;
164 }
[3bd76491]165
166 printf(NAME ": Accepting connections\n");
167 task_retval(0);
168 async_manager();
169 /* not reached */
170 return 0;
171}
172
173/**
174 * @}
175 */
Note: See TracBrowser for help on using the repository browser.