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
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
00089
00090
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
00176 return 0;
00177 }
00178