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
00041 #include <stdio.h>
00042 #include <ipc/services.h>
00043 #include <ipc/ns.h>
00044 #include <async.h>
00045 #include <errno.h>
00046 #include <task.h>
00047 #include <libfs.h>
00048 #include "devfs.h"
00049 #include "devfs_ops.h"
00050
00051 #define NAME "devfs"
00052
00053 static vfs_info_t devfs_vfs_info = {
00054 .name = NAME,
00055 .concurrent_read_write = false,
00056 .write_retains_size = false,
00057 };
00058
00059 fs_reg_t devfs_reg;
00060
00061 static void devfs_connection(ipc_callid_t iid, ipc_call_t *icall)
00062 {
00063 if (iid)
00064 async_answer_0(iid, EOK);
00065
00066 while (true) {
00067 ipc_call_t call;
00068 ipc_callid_t callid = async_get_call(&call);
00069
00070 switch (IPC_GET_IMETHOD(call)) {
00071 case IPC_M_PHONE_HUNGUP:
00072 return;
00073 case VFS_OUT_MOUNTED:
00074 devfs_mounted(callid, &call);
00075 break;
00076 case VFS_OUT_MOUNT:
00077 devfs_mount(callid, &call);
00078 break;
00079 case VFS_OUT_UNMOUNTED:
00080 devfs_unmounted(callid, &call);
00081 break;
00082 case VFS_OUT_UNMOUNT:
00083 devfs_unmount(callid, &call);
00084 break;
00085 case VFS_OUT_LOOKUP:
00086 devfs_lookup(callid, &call);
00087 break;
00088 case VFS_OUT_OPEN_NODE:
00089 devfs_open_node(callid, &call);
00090 break;
00091 case VFS_OUT_STAT:
00092 devfs_stat(callid, &call);
00093 break;
00094 case VFS_OUT_READ:
00095 devfs_read(callid, &call);
00096 break;
00097 case VFS_OUT_WRITE:
00098 devfs_write(callid, &call);
00099 break;
00100 case VFS_OUT_TRUNCATE:
00101 devfs_truncate(callid, &call);
00102 break;
00103 case VFS_OUT_CLOSE:
00104 devfs_close(callid, &call);
00105 break;
00106 case VFS_OUT_SYNC:
00107 devfs_sync(callid, &call);
00108 break;
00109 case VFS_OUT_DESTROY:
00110 devfs_destroy(callid, &call);
00111 break;
00112 default:
00113 async_answer_0(callid, ENOTSUP);
00114 break;
00115 }
00116 }
00117 }
00118
00119 int main(int argc, char *argv[])
00120 {
00121 printf(NAME ": HelenOS Device Filesystem\n");
00122
00123 if (!devfs_init()) {
00124 printf(NAME ": failed to initialize devfs\n");
00125 return -1;
00126 }
00127
00128 int vfs_phone = service_connect_blocking(SERVICE_VFS, 0, 0);
00129 if (vfs_phone < EOK) {
00130 printf(NAME ": Unable to connect to VFS\n");
00131 return -1;
00132 }
00133
00134 int rc = fs_register(vfs_phone, &devfs_reg, &devfs_vfs_info,
00135 devfs_connection);
00136 if (rc != EOK) {
00137 printf(NAME ": Failed to register file system (%d)\n", rc);
00138 return rc;
00139 }
00140
00141 printf(NAME ": Accepting connections\n");
00142 task_retval(0);
00143 async_manager();
00144
00145
00146 return 0;
00147 }
00148