00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
00083
00084
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
00171 return 0;
00172
00173 err:
00174 printf(NAME ": Failed to register file system (%d)\n", rc);
00175 return rc;
00176 }
00177