super.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 <xen/xen.h>
  15. #include "xenfs.h"
  16. #include <asm/xen/hypervisor.h>
  17. MODULE_DESCRIPTION("Xen filesystem");
  18. MODULE_LICENSE("GPL");
  19. static ssize_t capabilities_read(struct file *file, char __user *buf,
  20. size_t size, loff_t *off)
  21. {
  22. char *tmp = "";
  23. if (xen_initial_domain())
  24. tmp = "control_d\n";
  25. return simple_read_from_buffer(buf, size, off, tmp, strlen(tmp));
  26. }
  27. static const struct file_operations capabilities_file_ops = {
  28. .read = capabilities_read,
  29. };
  30. static int xenfs_fill_super(struct super_block *sb, void *data, int silent)
  31. {
  32. static struct tree_descr xenfs_files[] = {
  33. [1] = {},
  34. { "xenbus", &xenbus_file_ops, S_IRUSR|S_IWUSR },
  35. { "capabilities", &capabilities_file_ops, S_IRUGO },
  36. {""},
  37. };
  38. return simple_fill_super(sb, XENFS_SUPER_MAGIC, xenfs_files);
  39. }
  40. static int xenfs_get_sb(struct file_system_type *fs_type,
  41. int flags, const char *dev_name,
  42. void *data, struct vfsmount *mnt)
  43. {
  44. return get_sb_single(fs_type, flags, data, xenfs_fill_super, mnt);
  45. }
  46. static struct file_system_type xenfs_type = {
  47. .owner = THIS_MODULE,
  48. .name = "xenfs",
  49. .get_sb = xenfs_get_sb,
  50. .kill_sb = kill_litter_super,
  51. };
  52. static int __init xenfs_init(void)
  53. {
  54. if (xen_pv_domain())
  55. return register_filesystem(&xenfs_type);
  56. printk(KERN_INFO "XENFS: not registering filesystem on non-xen platform\n");
  57. return 0;
  58. }
  59. static void __exit xenfs_exit(void)
  60. {
  61. if (xen_pv_domain())
  62. unregister_filesystem(&xenfs_type);
  63. }
  64. module_init(xenfs_init);
  65. module_exit(xenfs_exit);