summaryrefslogtreecommitdiff
path: root/fs/sysfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/sysfs.c')
-rw-r--r--fs/sysfs.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/fs/sysfs.c b/fs/sysfs.c
new file mode 100644
index 0000000..57a56c8
--- /dev/null
+++ b/fs/sysfs.c
@@ -0,0 +1,46 @@
+#include "mount.h"
+#include "sysfs.h"
+
+#include "mem.h"
+#include "kmalloc.h"
+#include "mount.h"
+
+#include "log.h"
+
+#include "lib/string/string.h"
+
+static const char* names[] = {"/mem","/kmalloc","/mount"};
+static uint32_t map[]={mem_sysfs,kmalloc_sysfs,mount_sysfs};
+static uint32_t count=3;
+
+
+/* mount interface */
+
+fd sysfs_file_open(mount *m,char *path)
+{
+ klog("sysfs file open: %s",path);
+ for (int i=0;i<count;i++)
+ {
+ if(!strcmp(path,names[i]))
+ return fd_from_sysfs(map[i]);
+ }
+ return fd_from_sysfs(map[0]);
+}
+
+int sysfs_read_dir(mount *m,char *path, fs_dirent *dirs, uint32_t *pos)
+{
+ if(*pos>=count)return 0;
+ memcpy(dirs->name,names[*pos],strlen(names[*pos])+1);
+ *pos+=1;
+ return 1;
+}
+
+void sysfs_mount(char* path)
+{
+ mount m;
+ m.type=MOUNT_TYPE_SYS;
+ memcpy(m.path,path,strlen(path)+1);
+ m.mount_file_open=sysfs_file_open;
+ m.mount_read_dir=sysfs_read_dir;
+ mount_add(m);
+}