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"
20 #include "../xenbus/xenbus_comms.h"
22 #include <asm/xen/hypervisor.h>
24 MODULE_DESCRIPTION("Xen filesystem");
25 MODULE_LICENSE("GPL");
27 static struct inode *xenfs_make_inode(struct super_block *sb, int mode)
29 struct inode *ret = new_inode(sb);
33 ret->i_uid = GLOBAL_ROOT_UID;
34 ret->i_gid = GLOBAL_ROOT_GID;
36 ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME;
41 static struct dentry *xenfs_create_file(struct super_block *sb,
42 struct dentry *parent,
44 const struct file_operations *fops,
48 struct dentry *dentry;
51 dentry = d_alloc_name(parent, name);
55 inode = xenfs_make_inode(sb, S_IFREG | mode);
62 inode->i_private = data;
68 static ssize_t capabilities_read(struct file *file, char __user *buf,
69 size_t size, loff_t *off)
73 if (xen_initial_domain())
76 return simple_read_from_buffer(buf, size, off, tmp, strlen(tmp));
79 static const struct file_operations capabilities_file_ops = {
80 .read = capabilities_read,
81 .llseek = default_llseek,
84 static int xenfs_fill_super(struct super_block *sb, void *data, int silent)
86 static struct tree_descr xenfs_files[] = {
88 { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR },
89 { "capabilities", &capabilities_file_ops, S_IRUGO },
90 { "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
95 rc = simple_fill_super(sb, XENFS_SUPER_MAGIC, xenfs_files);
99 if (xen_initial_domain()) {
100 xenfs_create_file(sb, sb->s_root, "xsd_kva",
101 &xsd_kva_file_ops, NULL, S_IRUSR|S_IWUSR);
102 xenfs_create_file(sb, sb->s_root, "xsd_port",
103 &xsd_port_file_ops, NULL, S_IRUSR|S_IWUSR);
109 static struct dentry *xenfs_mount(struct file_system_type *fs_type,
110 int flags, const char *dev_name,
113 return mount_single(fs_type, flags, data, xenfs_fill_super);
116 static struct file_system_type xenfs_type = {
117 .owner = THIS_MODULE,
119 .mount = xenfs_mount,
120 .kill_sb = kill_litter_super,
123 static int __init xenfs_init(void)
126 return register_filesystem(&xenfs_type);
128 printk(KERN_INFO "XENFS: not registering filesystem on non-xen platform\n");
132 static void __exit xenfs_exit(void)
135 unregister_filesystem(&xenfs_type);
138 module_init(xenfs_init);
139 module_exit(xenfs_exit);