2 * xenfs.c - a filesystem for passing info between the a domain and
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.
10 #include <linux/kernel.h>
11 #include <linux/errno.h>
12 #include <linux/module.h>
14 #include <linux/magic.h>
19 #include "../privcmd.h"
21 #include <asm/xen/hypervisor.h>
23 MODULE_DESCRIPTION("Xen filesystem");
24 MODULE_LICENSE("GPL");
26 static struct inode *xenfs_make_inode(struct super_block *sb, int mode)
28 struct inode *ret = new_inode(sb);
32 ret->i_uid = ret->i_gid = 0;
34 ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME;
39 static struct dentry *xenfs_create_file(struct super_block *sb,
40 struct dentry *parent,
42 const struct file_operations *fops,
46 struct dentry *dentry;
49 dentry = d_alloc_name(parent, name);
53 inode = xenfs_make_inode(sb, S_IFREG | mode);
60 inode->i_private = data;
66 static ssize_t capabilities_read(struct file *file, char __user *buf,
67 size_t size, loff_t *off)
71 if (xen_initial_domain())
74 return simple_read_from_buffer(buf, size, off, tmp, strlen(tmp));
77 static const struct file_operations capabilities_file_ops = {
78 .read = capabilities_read,
79 .llseek = default_llseek,
82 static int xenfs_fill_super(struct super_block *sb, void *data, int silent)
84 static struct tree_descr xenfs_files[] = {
86 { "xenbus", &xenbus_file_ops, S_IRUSR|S_IWUSR },
87 { "capabilities", &capabilities_file_ops, S_IRUGO },
88 { "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
93 rc = simple_fill_super(sb, XENFS_SUPER_MAGIC, xenfs_files);
97 if (xen_initial_domain()) {
98 xenfs_create_file(sb, sb->s_root, "xsd_kva",
99 &xsd_kva_file_ops, NULL, S_IRUSR|S_IWUSR);
100 xenfs_create_file(sb, sb->s_root, "xsd_port",
101 &xsd_port_file_ops, NULL, S_IRUSR|S_IWUSR);
107 static struct dentry *xenfs_mount(struct file_system_type *fs_type,
108 int flags, const char *dev_name,
111 return mount_single(fs_type, flags, data, xenfs_fill_super);
114 static struct file_system_type xenfs_type = {
115 .owner = THIS_MODULE,
117 .mount = xenfs_mount,
118 .kill_sb = kill_litter_super,
121 static int __init xenfs_init(void)
124 return register_filesystem(&xenfs_type);
126 printk(KERN_INFO "XENFS: not registering filesystem on non-xen platform\n");
130 static void __exit xenfs_exit(void)
133 unregister_filesystem(&xenfs_type);
136 module_init(xenfs_init);
137 module_exit(xenfs_exit);