fat.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 
00039 #include "fat.h"
00040 #include <ipc/services.h>
00041 #include <ipc/ns.h>
00042 #include <async.h>
00043 #include <errno.h>
00044 #include <unistd.h>
00045 #include <task.h>
00046 #include <stdio.h>
00047 #include <libfs.h>
00048 #include "../../vfs/vfs.h"
00049 
00050 #define NAME    "fat"
00051 
00052 vfs_info_t fat_vfs_info = {
00053         .name = NAME,
00054         .concurrent_read_write = false,
00055         .write_retains_size = false,    
00056 };
00057 
00058 fs_reg_t fat_reg;
00059 
00078 static void fat_connection(ipc_callid_t iid, ipc_call_t *icall)
00079 {
00080         if (iid) {
00081                 /*
00082                  * This only happens for connections opened by
00083                  * IPC_M_CONNECT_ME_TO calls as opposed to callback connections
00084                  * created by IPC_M_CONNECT_TO_ME.
00085                  */
00086                 async_answer_0(iid, EOK);
00087         }
00088         
00089         dprintf(NAME ": connection opened\n");
00090         while (1) {
00091                 ipc_callid_t callid;
00092                 ipc_call_t call;
00093         
00094                 callid = async_get_call(&call);
00095                 switch  (IPC_GET_IMETHOD(call)) {
00096                 case IPC_M_PHONE_HUNGUP:
00097                         return;
00098                 case VFS_OUT_MOUNTED:
00099                         fat_mounted(callid, &call);
00100                         break;
00101                 case VFS_OUT_MOUNT:
00102                         fat_mount(callid, &call);
00103                         break;
00104                 case VFS_OUT_UNMOUNTED:
00105                         fat_unmounted(callid, &call);
00106                         break;
00107                 case VFS_OUT_UNMOUNT:
00108                         fat_unmount(callid, &call);
00109                         break;
00110                 case VFS_OUT_LOOKUP:
00111                         fat_lookup(callid, &call);
00112                         break;
00113                 case VFS_OUT_READ:
00114                         fat_read(callid, &call);
00115                         break;
00116                 case VFS_OUT_WRITE:
00117                         fat_write(callid, &call);
00118                         break;
00119                 case VFS_OUT_TRUNCATE:
00120                         fat_truncate(callid, &call);
00121                         break;
00122                 case VFS_OUT_STAT:
00123                         fat_stat(callid, &call);
00124                         break;
00125                 case VFS_OUT_CLOSE:
00126                         fat_close(callid, &call);
00127                         break;
00128                 case VFS_OUT_DESTROY:
00129                         fat_destroy(callid, &call);
00130                         break;
00131                 case VFS_OUT_OPEN_NODE:
00132                         fat_open_node(callid, &call);
00133                         break;
00134                 case VFS_OUT_SYNC:
00135                         fat_sync(callid, &call);
00136                         break;
00137                 default:
00138                         async_answer_0(callid, ENOTSUP);
00139                         break;
00140                 }
00141         }
00142 }
00143 
00144 int main(int argc, char **argv)
00145 {
00146         int vfs_phone;
00147         int rc;
00148 
00149         printf(NAME ": HelenOS FAT file system server\n");
00150 
00151         rc = fat_idx_init();
00152         if (rc != EOK)
00153                 goto err;
00154 
00155         vfs_phone = service_connect_blocking(SERVICE_VFS, 0, 0);
00156         if (vfs_phone < EOK) {
00157                 printf(NAME ": failed to connect to VFS\n");
00158                 return -1;
00159         }
00160         
00161         rc = fs_register(vfs_phone, &fat_reg, &fat_vfs_info, fat_connection);
00162         if (rc != EOK) {
00163                 fat_idx_fini();
00164                 goto err;
00165         }
00166         
00167         printf(NAME ": Accepting connections\n");
00168         task_retval(0);
00169         async_manager();
00170         /* not reached */
00171         return 0;
00172 
00173 err:
00174         printf(NAME ": Failed to register file system (%d)\n", rc);
00175         return rc;
00176 }
00177 

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