tmpfs.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2006 Martin Decky
00003  * Copyright (c) 2008 Jakub Jermar
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  *
00010  * - Redistributions of source code must retain the above copyright
00011  *   notice, this list of conditions and the following disclaimer.
00012  * - Redistributions in binary form must reproduce the above copyright
00013  *   notice, this list of conditions and the following disclaimer in the
00014  *   documentation and/or other materials provided with the distribution.
00015  * - The name of the author may not be used to endorse or promote products
00016  *   derived from this software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00019  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00020  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00021  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00022  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00023  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00024  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00025  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00026  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00027  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00043 #include "tmpfs.h"
00044 #include <ipc/services.h>
00045 #include <ipc/ns.h>
00046 #include <async.h>
00047 #include <errno.h>
00048 #include <unistd.h>
00049 #include <stdio.h>
00050 #include <task.h>
00051 #include <libfs.h>
00052 #include "../../vfs/vfs.h"
00053 
00054 #define NAME "tmpfs"
00055 
00056 
00057 vfs_info_t tmpfs_vfs_info = {
00058         .name = NAME,
00059         .concurrent_read_write = false,
00060         .write_retains_size = false,
00061 };
00062 
00063 fs_reg_t tmpfs_reg;
00064 
00084 static void tmpfs_connection(ipc_callid_t iid, ipc_call_t *icall)
00085 {
00086         if (iid) {
00087                 /*
00088                  * This only happens for connections opened by
00089                  * IPC_M_CONNECT_ME_TO calls as opposed to callback connections
00090                  * created by IPC_M_CONNECT_TO_ME.
00091                  */
00092                 async_answer_0(iid, EOK);
00093         }
00094         
00095         dprintf(NAME ": connection opened\n");
00096         while (1) {
00097                 ipc_callid_t callid;
00098                 ipc_call_t call;
00099         
00100                 callid = async_get_call(&call);
00101                 switch  (IPC_GET_IMETHOD(call)) {
00102                 case IPC_M_PHONE_HUNGUP:
00103                         return;
00104                 case VFS_OUT_MOUNTED:
00105                         tmpfs_mounted(callid, &call);
00106                         break;
00107                 case VFS_OUT_MOUNT:
00108                         tmpfs_mount(callid, &call);
00109                         break;
00110                 case VFS_OUT_UNMOUNTED:
00111                         tmpfs_unmounted(callid, &call);
00112                         break;
00113                 case VFS_OUT_UNMOUNT:
00114                         tmpfs_unmount(callid, &call);
00115                         break;
00116                 case VFS_OUT_LOOKUP:
00117                         tmpfs_lookup(callid, &call);
00118                         break;
00119                 case VFS_OUT_READ:
00120                         tmpfs_read(callid, &call);
00121                         break;
00122                 case VFS_OUT_WRITE:
00123                         tmpfs_write(callid, &call);
00124                         break;
00125                 case VFS_OUT_TRUNCATE:
00126                         tmpfs_truncate(callid, &call);
00127                         break;
00128                 case VFS_OUT_CLOSE:
00129                         tmpfs_close(callid, &call);
00130                         break;
00131                 case VFS_OUT_DESTROY:
00132                         tmpfs_destroy(callid, &call);
00133                         break;
00134                 case VFS_OUT_OPEN_NODE:
00135                         tmpfs_open_node(callid, &call);
00136                         break;
00137                 case VFS_OUT_STAT:
00138                         tmpfs_stat(callid, &call);
00139                         break;
00140                 case VFS_OUT_SYNC:
00141                         tmpfs_sync(callid, &call);
00142                         break;
00143                 default:
00144                         async_answer_0(callid, ENOTSUP);
00145                         break;
00146                 }
00147         }
00148 }
00149 
00150 int main(int argc, char **argv)
00151 {
00152         printf(NAME ": HelenOS TMPFS file system server\n");
00153 
00154         if (!tmpfs_init()) {
00155                 printf(NAME ": failed to initialize TMPFS\n");
00156                 return -1;
00157         }
00158 
00159         int vfs_phone = service_connect_blocking(SERVICE_VFS, 0, 0);
00160         if (vfs_phone < EOK) {
00161                 printf(NAME ": Unable to connect to VFS\n");
00162                 return -1;
00163         }
00164 
00165         int rc = fs_register(vfs_phone, &tmpfs_reg, &tmpfs_vfs_info,
00166             tmpfs_connection);
00167         if (rc != EOK) {
00168                 printf(NAME ": Failed to register file system (%d)\n", rc);
00169                 return rc;
00170         }
00171 
00172         printf(NAME ": Accepting connections\n");
00173         task_retval(0);
00174         async_manager();
00175         /* not reached */
00176         return 0;
00177 }
00178 

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