vfs.c

00001 /*
00002  * Copyright (c) 2008 Jakub Jermar
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 
00038 #include <ipc/services.h>
00039 #include <ipc/ns.h>
00040 #include <async.h>
00041 #include <errno.h>
00042 #include <stdio.h>
00043 #include <bool.h>
00044 #include <str.h>
00045 #include <as.h>
00046 #include <atomic.h>
00047 #include "vfs.h"
00048 
00049 #define NAME  "vfs"
00050 
00051 static void vfs_connection(ipc_callid_t iid, ipc_call_t *icall)
00052 {
00053         bool keep_on_going = true;
00054 
00055         /*
00056          * The connection was opened via the IPC_CONNECT_ME_TO call.
00057          * This call needs to be answered.
00058          */
00059         async_answer_0(iid, EOK);
00060         
00061         while (keep_on_going) {
00062                 ipc_call_t call;
00063                 ipc_callid_t callid = async_get_call(&call);
00064                 
00065                 switch (IPC_GET_IMETHOD(call)) {
00066                 case IPC_M_PHONE_HUNGUP:
00067                         keep_on_going = false;
00068                         break;
00069                 case VFS_IN_REGISTER:
00070                         vfs_register(callid, &call);
00071                         keep_on_going = false;
00072                         break;
00073                 case VFS_IN_MOUNT:
00074                         vfs_mount(callid, &call);
00075                         break;
00076                 case VFS_IN_UNMOUNT:
00077                         vfs_unmount(callid, &call);
00078                         break;
00079                 case VFS_IN_OPEN:
00080                         vfs_open(callid, &call);
00081                         break;
00082                 case VFS_IN_OPEN_NODE:
00083                         vfs_open_node(callid, &call);
00084                         break;
00085                 case VFS_IN_CLOSE:
00086                         vfs_close(callid, &call);
00087                         break;
00088                 case VFS_IN_READ:
00089                         vfs_read(callid, &call);
00090                         break;
00091                 case VFS_IN_WRITE:
00092                         vfs_write(callid, &call);
00093                         break;
00094                 case VFS_IN_SEEK:
00095                         vfs_seek(callid, &call);
00096                         break;
00097                 case VFS_IN_TRUNCATE:
00098                         vfs_truncate(callid, &call);
00099                         break;
00100                 case VFS_IN_FSTAT:
00101                         vfs_fstat(callid, &call);
00102                         break;
00103                 case VFS_IN_STAT:
00104                         vfs_stat(callid, &call);
00105                         break;
00106                 case VFS_IN_MKDIR:
00107                         vfs_mkdir(callid, &call);
00108                         break;
00109                 case VFS_IN_UNLINK:
00110                         vfs_unlink(callid, &call);
00111                         break;
00112                 case VFS_IN_RENAME:
00113                         vfs_rename(callid, &call);
00114                         break;
00115                 case VFS_IN_SYNC:
00116                         vfs_sync(callid, &call);
00117                         break;
00118                 case VFS_IN_DUP:
00119                         vfs_dup(callid, &call);
00120                 default:
00121                         async_answer_0(callid, ENOTSUP);
00122                         break;
00123                 }
00124         }
00125 
00126         /*
00127          * Open files for this client will be cleaned up when its last
00128          * connection fibril terminates.
00129          */
00130 }
00131 
00132 int main(int argc, char **argv)
00133 {
00134         printf(NAME ": HelenOS VFS server\n");
00135         
00136         /*
00137          * Initialize VFS node hash table.
00138          */
00139         if (!vfs_nodes_init()) {
00140                 printf(NAME ": Failed to initialize VFS node hash table\n");
00141                 return ENOMEM;
00142         }
00143         
00144         /*
00145          * Allocate and initialize the Path Lookup Buffer.
00146          */
00147         plb = as_get_mappable_page(PLB_SIZE);
00148         if (!plb) {
00149                 printf(NAME ": Cannot allocate a mappable piece of address space\n");
00150                 return ENOMEM;
00151         }
00152         
00153         if (as_area_create(plb, PLB_SIZE, AS_AREA_READ | AS_AREA_WRITE |
00154             AS_AREA_CACHEABLE) != plb) {
00155                 printf(NAME ": Cannot create address space area\n");
00156                 return ENOMEM;
00157         }
00158         memset(plb, 0, PLB_SIZE);
00159         
00160         /*
00161          * Set client data constructor and destructor.
00162          */
00163         async_set_client_data_constructor(vfs_client_data_create);
00164         async_set_client_data_destructor(vfs_client_data_destroy);
00165 
00166         /*
00167          * Set a connection handling function/fibril.
00168          */
00169         async_set_client_connection(vfs_connection);
00170 
00171         /*
00172          * Register at the naming service.
00173          */
00174         if (service_register(SERVICE_VFS) != EOK) {
00175                 printf("%s: Cannot register VFS service\n", NAME);
00176                 return EINVAL;
00177         }
00178         
00179         /*
00180          * Start accepting connections.
00181          */
00182         printf(NAME ": Accepting connections\n");
00183         async_manager();
00184         return 0;
00185 }
00186 

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