Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394...
[pandora-kernel.git] / drivers / xen / xenfs / super.c
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
10 #include <linux/kernel.h>
11 #include <linux/errno.h>
12 #include <linux/module.h>
13 #include <linux/fs.h>
14 #include <linux/magic.h>
15
16 #include <xen/xen.h>
17
18 #include "xenfs.h"
19
20 #include <asm/xen/hypervisor.h>
21
22 MODULE_DESCRIPTION("Xen filesystem");
23 MODULE_LICENSE("GPL");
24
25 static ssize_t capabilities_read(struct file *file, char __user *buf,
26                                  size_t size, loff_t *off)
27 {
28         char *tmp = "";
29
30         if (xen_initial_domain())
31                 tmp = "control_d\n";
32
33         return simple_read_from_buffer(buf, size, off, tmp, strlen(tmp));
34 }
35
36 static const struct file_operations capabilities_file_ops = {
37         .read = capabilities_read,
38 };
39
40 static int xenfs_fill_super(struct super_block *sb, void *data, int silent)
41 {
42         static struct tree_descr xenfs_files[] = {
43                 [1] = {},
44                 { "xenbus", &xenbus_file_ops, S_IRUSR|S_IWUSR },
45                 { "capabilities", &capabilities_file_ops, S_IRUGO },
46                 {""},
47         };
48
49         return simple_fill_super(sb, XENFS_SUPER_MAGIC, xenfs_files);
50 }
51
52 static int xenfs_get_sb(struct file_system_type *fs_type,
53                         int flags, const char *dev_name,
54                         void *data, struct vfsmount *mnt)
55 {
56         return get_sb_single(fs_type, flags, data, xenfs_fill_super, mnt);
57 }
58
59 static struct file_system_type xenfs_type = {
60         .owner =        THIS_MODULE,
61         .name =         "xenfs",
62         .get_sb =       xenfs_get_sb,
63         .kill_sb =      kill_litter_super,
64 };
65
66 static int __init xenfs_init(void)
67 {
68         if (xen_domain())
69                 return register_filesystem(&xenfs_type);
70
71         printk(KERN_INFO "XENFS: not registering filesystem on non-xen platform\n");
72         return 0;
73 }
74
75 static void __exit xenfs_exit(void)
76 {
77         if (xen_domain())
78                 unregister_filesystem(&xenfs_type);
79 }
80
81 module_init(xenfs_init);
82 module_exit(xenfs_exit);
83