devfs.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2009 Martin Decky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00041 #include <stdio.h>
00042 #include <ipc/services.h>
00043 #include <ipc/ns.h>
00044 #include <async.h>
00045 #include <errno.h>
00046 #include <task.h>
00047 #include <libfs.h>
00048 #include "devfs.h"
00049 #include "devfs_ops.h"
00050 
00051 #define NAME  "devfs"
00052 
00053 static vfs_info_t devfs_vfs_info = {
00054         .name = NAME,
00055         .concurrent_read_write = false,
00056         .write_retains_size = false,
00057 };
00058 
00059 fs_reg_t devfs_reg;
00060 
00061 static void devfs_connection(ipc_callid_t iid, ipc_call_t *icall)
00062 {
00063         if (iid)
00064                 async_answer_0(iid, EOK);
00065         
00066         while (true) {
00067                 ipc_call_t call;
00068                 ipc_callid_t callid = async_get_call(&call);
00069                 
00070                 switch  (IPC_GET_IMETHOD(call)) {
00071                 case IPC_M_PHONE_HUNGUP:
00072                         return;
00073                 case VFS_OUT_MOUNTED:
00074                         devfs_mounted(callid, &call);
00075                         break;
00076                 case VFS_OUT_MOUNT:
00077                         devfs_mount(callid, &call);
00078                         break;
00079                 case VFS_OUT_UNMOUNTED:
00080                         devfs_unmounted(callid, &call);
00081                         break;
00082                 case VFS_OUT_UNMOUNT:
00083                         devfs_unmount(callid, &call);
00084                         break;
00085                 case VFS_OUT_LOOKUP:
00086                         devfs_lookup(callid, &call);
00087                         break;
00088                 case VFS_OUT_OPEN_NODE:
00089                         devfs_open_node(callid, &call);
00090                         break;
00091                 case VFS_OUT_STAT:
00092                         devfs_stat(callid, &call);
00093                         break;
00094                 case VFS_OUT_READ:
00095                         devfs_read(callid, &call);
00096                         break;
00097                 case VFS_OUT_WRITE:
00098                         devfs_write(callid, &call);
00099                         break;
00100                 case VFS_OUT_TRUNCATE:
00101                         devfs_truncate(callid, &call);
00102                         break;
00103                 case VFS_OUT_CLOSE:
00104                         devfs_close(callid, &call);
00105                         break;
00106                 case VFS_OUT_SYNC:
00107                         devfs_sync(callid, &call);
00108                         break;
00109                 case VFS_OUT_DESTROY:
00110                         devfs_destroy(callid, &call);
00111                         break;
00112                 default:
00113                         async_answer_0(callid, ENOTSUP);
00114                         break;
00115                 }
00116         }
00117 }
00118 
00119 int main(int argc, char *argv[])
00120 {
00121         printf(NAME ": HelenOS Device Filesystem\n");
00122         
00123         if (!devfs_init()) {
00124                 printf(NAME ": failed to initialize devfs\n");
00125                 return -1;
00126         }
00127         
00128         int vfs_phone = service_connect_blocking(SERVICE_VFS, 0, 0);
00129         if (vfs_phone < EOK) {
00130                 printf(NAME ": Unable to connect to VFS\n");
00131                 return -1;
00132         }
00133         
00134         int rc = fs_register(vfs_phone, &devfs_reg, &devfs_vfs_info,
00135             devfs_connection);
00136         if (rc != EOK) {
00137                 printf(NAME ": Failed to register file system (%d)\n", rc);
00138                 return rc;
00139         }
00140         
00141         printf(NAME ": Accepting connections\n");
00142         task_retval(0);
00143         async_manager();
00144         
00145         /* Not reached */
00146         return 0;
00147 }
00148 

Generated on Thu Jun 2 07:45:49 2011 for HelenOS/USB by  doxygen 1.4.7