super.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * xenfs.c - a filesystem for passing info between the a domain and
  3. * the hypervisor.
  4. *
  5. * 2008-10-07 Alex Zeffertt Replaced /proc/xen/xenbus with xenfs filesystem
  6. * and /proc/xen compatibility mount point.
  7. * Turned xenfs into a loadable module.
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/errno.h>
  11. #include <linux/module.h>
  12. #include <linux/fs.h>
  13. #include <linux/magic.h>
  14. #include "xenfs.h"
  15. #include <asm/xen/hypervisor.h>
  16. MODULE_DESCRIPTION("Xen filesystem");
  17. MODULE_LICENSE("GPL");
  18. static ssize_t capabilities_read(struct file *file, char __user *buf,
  19. size_t size, loff_t *off)
  20. {
  21. char *tmp = "";
  22. if (xen_initial_domain())
  23. tmp = "control_d\n";
  24. return simple_read_from_buffer(buf, size, off, tmp, strlen(tmp));
  25. }
  26. static const struct file_operations capabilities_file_ops = {
  27. .read = capabilities_read,
  28. };
  29. static int xenfs_fill_super(struct super_block *sb, void *data, int silent)
  30. {
  31. static struct tree_descr xenfs_files[] = {
  32. [1] = {},
  33. { "xenbus", &xenbus_file_ops, S_IRUSR|S_IWUSR },
  34. { "capabilities", &capabilities_file_ops, S_IRUGO },
  35. {""},
  36. };
  37. return simple_fill_super(sb, XENFS_SUPER_MAGIC, xenfs_files);
  38. }
  39. static int xenfs_get_sb(struct file_system_type *fs_type,
  40. int flags, const char *dev_name,
  41. void *data, struct vfsmount *mnt)
  42. {
  43. return get_sb_single(fs_type, flags, data, xenfs_fill_super, mnt);
  44. }
  45. static struct file_system_type xenfs_type = {
  46. .owner = THIS_MODULE,
  47. .name = "xenfs",
  48. .get_sb = xenfs_get_sb,
  49. .kill_sb = kill_litter_super,
  50. };
  51. static int __init xenfs_init(void)
  52. {
  53. if (xen_pv_domain())
  54. return register_filesystem(&xenfs_type);
  55. printk(KERN_INFO "XENFS: not registering filesystem on non-xen platform\n");
  56. return 0;
  57. }
  58. static void __exit xenfs_exit(void)
  59. {
  60. if (xen_pv_domain())
  61. unregister_filesystem(&xenfs_type);
  62. }
  63. module_init(xenfs_init);
  64. module_exit(xenfs_exit);