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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 6a7e497 was 5bd1ffb, checked in by Martin Sucha <sucha14@…>, 15 years ago

Print error if ext2fs fails to register

  • 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>
[cf2af94]42#include <ipc/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 */
[4dc6a32]77static void ext2fs_connection(ipc_callid_t iid, ipc_call_t *icall)
[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");
89 while (1) {
90 ipc_callid_t callid;
91 ipc_call_t call;
92
93 callid = async_get_call(&call);
[cf2af94]94 switch (IPC_GET_IMETHOD(call)) {
[3bd76491]95 case IPC_M_PHONE_HUNGUP:
96 return;
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 int vfs_phone;
146 int rc;
147
148 printf(NAME ": HelenOS EXT2 file system server\n");
149
[cf2af94]150 vfs_phone = service_connect_blocking(SERVICE_VFS, 0, 0);
[3bd76491]151 if (vfs_phone < EOK) {
152 printf(NAME ": failed to connect to VFS\n");
153 return -1;
154 }
[4dc6a32]155
156 rc = ext2fs_global_init();
157 if (rc != EOK) {
158 printf(NAME ": Failed global initialization\n");
159 return 1;
160 }
161
162 rc = fs_register(vfs_phone, &ext2fs_reg, &ext2fs_vfs_info, ext2fs_connection);
[5bd1ffb]163 if (rc != EOK) {
164 fprintf(stdout, NAME ": Failed to register fs (%d)\n", rc);
165 return 1;
166 }
[3bd76491]167
168 printf(NAME ": Accepting connections\n");
169 task_retval(0);
170 async_manager();
171 /* not reached */
172 return 0;
173}
174
175/**
176 * @}
177 */
Note: See TracBrowser for help on using the repository browser.