Browse Source

root super block

isundil 9 years ago
parent
commit
2a3927e557
4 changed files with 54 additions and 21 deletions
  1. 0 2
      Makefile
  2. 2 0
      butterfly.h
  3. 52 3
      butterflyfs.c
  4. 0 16
      src/mount.c

+ 0 - 2
Makefile

@@ -1,7 +1,5 @@
 obj-m += butterflyfs.o
 
-butterflyfs-objs := ./src/mount.o
-
 all:
 	make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) modules
 

+ 2 - 0
src/butterfly.h → butterfly.h

@@ -3,6 +3,8 @@
 
 #include <linux/fs.h>
 
+#define BUTTERFLY_MAGIC -638480828
+
 struct dentry   *butterfly_mount(struct file_system_type *fs, int flags, const char *devname, void *data);
 void            butterfly_unmount(struct super_block *sb);
 

+ 52 - 3
butterflyfs.c

@@ -1,7 +1,10 @@
 #include <linux/module.h>
 #include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/init.h>
+#include <linux/fs.h>
 
-#include "src/butterfly.h"
+#include "butterfly.h"
 
 static struct file_system_type butterfly_fs = {
     .owner          = THIS_MODULE,
@@ -12,13 +15,59 @@ static struct file_system_type butterfly_fs = {
     .kill_sb        = butterfly_unmount
 };
 
-int init_module()
+static struct dentry_operations dirOperations = {
+};
+
+static struct file_operations fileOperations = {
+};
+
+int butterfly_fill_super(struct super_block *sb, void *data, int silent)
 {
+    struct tree_descr treeDescr[] = {
+        { }, // Skip
+        { .name = "", .ops = NULL, .mode = 0 } // End
+    };
+
+    return simple_fill_super(sb, BUTTERFLY_MAGIC, treeDescr);
+    /*
+    struct dentry *root = (struct dentry *) kmalloc(sizeof(*root), GFP_KERNEL);
+    struct inode *rootIno = (struct inode *) kmalloc(sizeof(*rootIno), GFP_KERNEL);
+
+    root->d_parent = root;
+    root->d_inode = rootIno;
+    root->d_iname[0] = '\0';
+    root->d_op = &directoryOperations;
+
+    root->d_child.prev = root->d_child.next = &root->d_child;
+    root->d_subdirs.prev = root->d_subdirs.next = &root->d_subdirs;
+    */
+}
+
+struct dentry   *butterfly_mount(
+        struct file_system_type *fs,
+        int flags,
+        const char *devname,
+        void *data)
+{
+    return mount_bdev(fs, flags, devname, data, butterfly_fill_super);
+}
+
+void butterfly_unmount(struct super_block *sb)
+{
+    kill_block_super(sb);
+}
+
+static int __init butterfly_init(void)
+{
+    printk(KERN_INFO "INIT");
     return register_filesystem(&butterfly_fs);
 }
 
-void cleanup_module()
+static void __exit butterfly_cleanup(void)
 {
     unregister_filesystem(&butterfly_fs);
 }
 
+module_init(butterfly_init);
+module_exit(butterfly_cleanup);
+

+ 0 - 16
src/mount.c

@@ -1,16 +0,0 @@
-#include "butterfly.h"
-
-struct dentry   *butterfly_mount(
-        struct file_system_type *fs,
-        int flags,
-        const char *devname,
-        void *data)
-{
-    return NULL;
-}
-
-void butterfly_unmount(struct super_block *sb)
-{
-    kill_block_super(sb);
-}
-