butterflyfs.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include <linux/module.h>
  2. #include <linux/kernel.h>
  3. #include <linux/slab.h>
  4. #include <linux/init.h>
  5. #include <linux/fs.h>
  6. #include "butterfly.h"
  7. static struct file_system_type butterfly_fs = {
  8. .owner = THIS_MODULE,
  9. .name = "butterflyfs",
  10. .fs_flags = FS_REQUIRES_DEV,
  11. .mount = butterfly_mount,
  12. .kill_sb = butterfly_unmount
  13. };
  14. static struct dentry_operations dirOperations = {
  15. };
  16. static struct file_operations fileOperations = {
  17. };
  18. int butterfly_fill_super(struct super_block *sb, void *data, int silent)
  19. {
  20. struct tree_descr treeDescr[] = {
  21. { }, // Skip
  22. { .name = "", .ops = NULL, .mode = 0 } // End
  23. };
  24. return simple_fill_super(sb, BUTTERFLY_MAGIC, treeDescr);
  25. }
  26. struct dentry *butterfly_mount(
  27. struct file_system_type *fs,
  28. int flags,
  29. const char *devname,
  30. void *data)
  31. {
  32. return mount_bdev(fs, flags, devname, data, butterfly_fill_super);
  33. }
  34. void butterfly_unmount(struct super_block *sb)
  35. {
  36. kill_block_super(sb);
  37. }
  38. static int __init butterfly_init(void)
  39. {
  40. printk(KERN_INFO "INIT");
  41. return register_filesystem(&butterfly_fs);
  42. }
  43. static void __exit butterfly_cleanup(void)
  44. {
  45. unregister_filesystem(&butterfly_fs);
  46. }
  47. module_init(butterfly_init);
  48. module_exit(butterfly_cleanup);