[a095d20] | 1 | /*
|
---|
| 2 | * Copyright (c) 2009 Martin Decky
|
---|
| 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 | * @{
|
---|
[17fd1d4] | 31 | */
|
---|
[a095d20] | 32 |
|
---|
| 33 | /**
|
---|
| 34 | * @file devfs.c
|
---|
| 35 | * @brief Devices file system.
|
---|
| 36 | *
|
---|
| 37 | * Every device registered to device mapper is represented as a file in this
|
---|
| 38 | * file system.
|
---|
| 39 | */
|
---|
| 40 |
|
---|
| 41 | #include <stdio.h>
|
---|
| 42 | #include <ipc/ipc.h>
|
---|
| 43 | #include <ipc/services.h>
|
---|
| 44 | #include <async.h>
|
---|
| 45 | #include <errno.h>
|
---|
[bbddafb] | 46 | #include <task.h>
|
---|
[a095d20] | 47 | #include <libfs.h>
|
---|
| 48 | #include "devfs.h"
|
---|
| 49 | #include "devfs_ops.h"
|
---|
| 50 |
|
---|
| 51 | #define NAME "devfs"
|
---|
| 52 |
|
---|
| 53 | static vfs_info_t devfs_vfs_info = {
|
---|
[5643a04] | 54 | .name = NAME,
|
---|
[a095d20] | 55 | };
|
---|
| 56 |
|
---|
| 57 | fs_reg_t devfs_reg;
|
---|
| 58 |
|
---|
| 59 | static void devfs_connection(ipc_callid_t iid, ipc_call_t *icall)
|
---|
| 60 | {
|
---|
| 61 | if (iid)
|
---|
| 62 | ipc_answer_0(iid, EOK);
|
---|
| 63 |
|
---|
| 64 | while (true) {
|
---|
| 65 | ipc_call_t call;
|
---|
| 66 | ipc_callid_t callid = async_get_call(&call);
|
---|
| 67 |
|
---|
| 68 | switch (IPC_GET_METHOD(call)) {
|
---|
[e2dccb0] | 69 | case IPC_M_PHONE_HUNGUP:
|
---|
| 70 | return;
|
---|
[4198f9c3] | 71 | case VFS_OUT_MOUNTED:
|
---|
[a095d20] | 72 | devfs_mounted(callid, &call);
|
---|
| 73 | break;
|
---|
[4198f9c3] | 74 | case VFS_OUT_MOUNT:
|
---|
[a095d20] | 75 | devfs_mount(callid, &call);
|
---|
| 76 | break;
|
---|
[3c11713] | 77 | case VFS_OUT_UNMOUNTED:
|
---|
| 78 | devfs_unmounted(callid, &call);
|
---|
| 79 | break;
|
---|
| 80 | case VFS_OUT_UNMOUNT:
|
---|
| 81 | devfs_unmount(callid, &call);
|
---|
| 82 | break;
|
---|
[4198f9c3] | 83 | case VFS_OUT_LOOKUP:
|
---|
[a095d20] | 84 | devfs_lookup(callid, &call);
|
---|
| 85 | break;
|
---|
[4198f9c3] | 86 | case VFS_OUT_OPEN_NODE:
|
---|
[17fd1d4] | 87 | devfs_open_node(callid, &call);
|
---|
| 88 | break;
|
---|
[852b801] | 89 | case VFS_OUT_STAT:
|
---|
| 90 | devfs_stat(callid, &call);
|
---|
[17fd1d4] | 91 | break;
|
---|
[4198f9c3] | 92 | case VFS_OUT_READ:
|
---|
[a095d20] | 93 | devfs_read(callid, &call);
|
---|
| 94 | break;
|
---|
[4198f9c3] | 95 | case VFS_OUT_WRITE:
|
---|
[a095d20] | 96 | devfs_write(callid, &call);
|
---|
| 97 | break;
|
---|
[4198f9c3] | 98 | case VFS_OUT_TRUNCATE:
|
---|
[a095d20] | 99 | devfs_truncate(callid, &call);
|
---|
| 100 | break;
|
---|
[4198f9c3] | 101 | case VFS_OUT_CLOSE:
|
---|
[17fd1d4] | 102 | devfs_close(callid, &call);
|
---|
| 103 | break;
|
---|
[4198f9c3] | 104 | case VFS_OUT_SYNC:
|
---|
[17fd1d4] | 105 | devfs_sync(callid, &call);
|
---|
| 106 | break;
|
---|
[4198f9c3] | 107 | case VFS_OUT_DESTROY:
|
---|
[a095d20] | 108 | devfs_destroy(callid, &call);
|
---|
| 109 | break;
|
---|
| 110 | default:
|
---|
| 111 | ipc_answer_0(callid, ENOTSUP);
|
---|
| 112 | break;
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | int main(int argc, char *argv[])
|
---|
| 118 | {
|
---|
| 119 | printf(NAME ": HelenOS Device Filesystem\n");
|
---|
| 120 |
|
---|
| 121 | if (!devfs_init()) {
|
---|
| 122 | printf(NAME ": failed to initialize devfs\n");
|
---|
| 123 | return -1;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | int vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0);
|
---|
| 127 | if (vfs_phone < EOK) {
|
---|
| 128 | printf(NAME ": Unable to connect to VFS\n");
|
---|
| 129 | return -1;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | int rc = fs_register(vfs_phone, &devfs_reg, &devfs_vfs_info,
|
---|
| 133 | devfs_connection);
|
---|
| 134 | if (rc != EOK) {
|
---|
| 135 | printf(NAME ": Failed to register file system (%d)\n", rc);
|
---|
| 136 | return rc;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | printf(NAME ": Accepting connections\n");
|
---|
[bbddafb] | 140 | task_retval(0);
|
---|
[a095d20] | 141 | async_manager();
|
---|
| 142 |
|
---|
| 143 | /* Not reached */
|
---|
| 144 | return 0;
|
---|
| 145 | }
|
---|
| 146 |
|
---|
[17fd1d4] | 147 | /**
|
---|
[a095d20] | 148 | * @}
|
---|
| 149 | */
|
---|