| 1 | /*
|
|---|
| 2 | * Copyright (c) 2006 Martin Decky
|
|---|
| 3 | * Copyright (c) 2008 Jakub Jermar
|
|---|
| 4 | * Copyright (c) 2011 Martin Sucha
|
|---|
| 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 |
|
|---|
| 40 | #include "ext2fs.h"
|
|---|
| 41 | #include <ipc/services.h>
|
|---|
| 42 | #include <ns.h>
|
|---|
| 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 |
|
|---|
| 51 | #define NAME "ext2fs"
|
|---|
| 52 |
|
|---|
| 53 | vfs_info_t ext2fs_vfs_info = {
|
|---|
| 54 | .name = NAME,
|
|---|
| 55 | };
|
|---|
| 56 |
|
|---|
| 57 | fs_reg_t ext2fs_reg;
|
|---|
| 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
|
|---|
| 65 | * to EXT2FS. To overcome this bottleneck, VFS can send EXT2FS the IPC_M_CONNECT_ME_TO
|
|---|
| 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
|
|---|
| 71 | * phone for more serialized requests. Similarily, EXT2FS can refuse to duplicate
|
|---|
| 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
|
|---|
| 74 | * upon each request, EXT2FS might want to keep the connections open after the
|
|---|
| 75 | * request has been completed.
|
|---|
| 76 | */
|
|---|
| 77 | static void ext2fs_connection(ipc_callid_t iid, ipc_call_t *icall)
|
|---|
| 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 | */
|
|---|
| 85 | async_answer_0(iid, EOK);
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | dprintf(NAME ": connection opened\n");
|
|---|
| 89 | while (true) {
|
|---|
| 90 | ipc_call_t call;
|
|---|
| 91 | ipc_callid_t callid = async_get_call(&call);
|
|---|
| 92 |
|
|---|
| 93 | if (!IPC_GET_IMETHOD(call))
|
|---|
| 94 | return;
|
|---|
| 95 |
|
|---|
| 96 | switch (IPC_GET_IMETHOD(call)) {
|
|---|
| 97 | case VFS_OUT_MOUNTED:
|
|---|
| 98 | ext2fs_mounted(callid, &call);
|
|---|
| 99 | break;
|
|---|
| 100 | case VFS_OUT_MOUNT:
|
|---|
| 101 | ext2fs_mount(callid, &call);
|
|---|
| 102 | break;
|
|---|
| 103 | case VFS_OUT_UNMOUNTED:
|
|---|
| 104 | ext2fs_unmounted(callid, &call);
|
|---|
| 105 | break;
|
|---|
| 106 | case VFS_OUT_UNMOUNT:
|
|---|
| 107 | ext2fs_unmount(callid, &call);
|
|---|
| 108 | break;
|
|---|
| 109 | case VFS_OUT_LOOKUP:
|
|---|
| 110 | ext2fs_lookup(callid, &call);
|
|---|
| 111 | break;
|
|---|
| 112 | case VFS_OUT_READ:
|
|---|
| 113 | ext2fs_read(callid, &call);
|
|---|
| 114 | break;
|
|---|
| 115 | case VFS_OUT_WRITE:
|
|---|
| 116 | ext2fs_write(callid, &call);
|
|---|
| 117 | break;
|
|---|
| 118 | case VFS_OUT_TRUNCATE:
|
|---|
| 119 | ext2fs_truncate(callid, &call);
|
|---|
| 120 | break;
|
|---|
| 121 | case VFS_OUT_STAT:
|
|---|
| 122 | ext2fs_stat(callid, &call);
|
|---|
| 123 | break;
|
|---|
| 124 | case VFS_OUT_CLOSE:
|
|---|
| 125 | ext2fs_close(callid, &call);
|
|---|
| 126 | break;
|
|---|
| 127 | case VFS_OUT_DESTROY:
|
|---|
| 128 | ext2fs_destroy(callid, &call);
|
|---|
| 129 | break;
|
|---|
| 130 | case VFS_OUT_OPEN_NODE:
|
|---|
| 131 | ext2fs_open_node(callid, &call);
|
|---|
| 132 | break;
|
|---|
| 133 | case VFS_OUT_SYNC:
|
|---|
| 134 | ext2fs_sync(callid, &call);
|
|---|
| 135 | break;
|
|---|
| 136 | default:
|
|---|
| 137 | async_answer_0(callid, ENOTSUP);
|
|---|
| 138 | break;
|
|---|
| 139 | }
|
|---|
| 140 | }
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | int main(int argc, char **argv)
|
|---|
| 144 | {
|
|---|
| 145 | printf(NAME ": HelenOS EXT2 file system server\n");
|
|---|
| 146 |
|
|---|
| 147 | async_sess_t *vfs_sess = service_connect_blocking(EXCHANGE_SERIALIZE,
|
|---|
| 148 | SERVICE_VFS, 0, 0);
|
|---|
| 149 | if (!vfs_sess) {
|
|---|
| 150 | printf(NAME ": failed to connect to VFS\n");
|
|---|
| 151 | return -1;
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | int rc = ext2fs_global_init();
|
|---|
| 155 | if (rc != EOK) {
|
|---|
| 156 | printf(NAME ": Failed global initialization\n");
|
|---|
| 157 | return 1;
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | rc = fs_register(vfs_sess, &ext2fs_reg, &ext2fs_vfs_info, ext2fs_connection);
|
|---|
| 161 | if (rc != EOK) {
|
|---|
| 162 | fprintf(stdout, NAME ": Failed to register fs (%d)\n", rc);
|
|---|
| 163 | return 1;
|
|---|
| 164 | }
|
|---|
| 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 | */
|
|---|