btrfs-tests.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (C) 2013 Fusion IO. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public
  6. * License v2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public
  14. * License along with this program; if not, write to the
  15. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. * Boston, MA 021110-1307, USA.
  17. */
  18. #include <linux/fs.h>
  19. #include <linux/mount.h>
  20. #include <linux/magic.h>
  21. #include "btrfs-tests.h"
  22. #include "../ctree.h"
  23. static struct vfsmount *test_mnt = NULL;
  24. static struct dentry *btrfs_test_mount(struct file_system_type *fs_type,
  25. int flags, const char *dev_name,
  26. void *data)
  27. {
  28. return mount_pseudo(fs_type, "btrfs_test:", NULL, NULL, BTRFS_TEST_MAGIC);
  29. }
  30. static struct file_system_type test_type = {
  31. .name = "btrfs_test_fs",
  32. .mount = btrfs_test_mount,
  33. .kill_sb = kill_anon_super,
  34. };
  35. struct inode *btrfs_new_test_inode(void)
  36. {
  37. return new_inode(test_mnt->mnt_sb);
  38. }
  39. int btrfs_init_test_fs(void)
  40. {
  41. int ret;
  42. ret = register_filesystem(&test_type);
  43. if (ret) {
  44. printk(KERN_ERR "btrfs: cannot register test file system\n");
  45. return ret;
  46. }
  47. test_mnt = kern_mount(&test_type);
  48. if (IS_ERR(test_mnt)) {
  49. printk(KERN_ERR "btrfs: cannot mount test file system\n");
  50. unregister_filesystem(&test_type);
  51. return ret;
  52. }
  53. return 0;
  54. }
  55. void btrfs_destroy_test_fs(void)
  56. {
  57. kern_unmount(test_mnt);
  58. unregister_filesystem(&test_type);
  59. }