0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0012
0013 #include <linux/kernel.h>
0014 #include <linux/errno.h>
0015 #include <linux/module.h>
0016 #include <linux/fs.h>
0017 #include <linux/fs_context.h>
0018 #include <linux/magic.h>
0019
0020 #include <xen/xen.h>
0021 #include <xen/xenbus.h>
0022
0023 #include "xenfs.h"
0024 #include "../privcmd.h"
0025
0026 #include <asm/xen/hypervisor.h>
0027
0028 MODULE_DESCRIPTION("Xen filesystem");
0029 MODULE_LICENSE("GPL");
0030
0031 static ssize_t capabilities_read(struct file *file, char __user *buf,
0032 size_t size, loff_t *off)
0033 {
0034 char *tmp = "";
0035
0036 if (xen_initial_domain())
0037 tmp = "control_d\n";
0038
0039 return simple_read_from_buffer(buf, size, off, tmp, strlen(tmp));
0040 }
0041
0042 static const struct file_operations capabilities_file_ops = {
0043 .read = capabilities_read,
0044 .llseek = default_llseek,
0045 };
0046
0047 static int xenfs_fill_super(struct super_block *sb, struct fs_context *fc)
0048 {
0049 static const struct tree_descr xenfs_files[] = {
0050 [2] = { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR },
0051 { "capabilities", &capabilities_file_ops, S_IRUGO },
0052 { "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
0053 {""},
0054 };
0055
0056 static const struct tree_descr xenfs_init_files[] = {
0057 [2] = { "xenbus", &xen_xenbus_fops, S_IRUSR|S_IWUSR },
0058 { "capabilities", &capabilities_file_ops, S_IRUGO },
0059 { "privcmd", &xen_privcmd_fops, S_IRUSR|S_IWUSR },
0060 { "xsd_kva", &xsd_kva_file_ops, S_IRUSR|S_IWUSR},
0061 { "xsd_port", &xsd_port_file_ops, S_IRUSR|S_IWUSR},
0062 #ifdef CONFIG_XEN_SYMS
0063 { "xensyms", &xensyms_ops, S_IRUSR},
0064 #endif
0065 {""},
0066 };
0067
0068 return simple_fill_super(sb, XENFS_SUPER_MAGIC,
0069 xen_initial_domain() ? xenfs_init_files : xenfs_files);
0070 }
0071
0072 static int xenfs_get_tree(struct fs_context *fc)
0073 {
0074 return get_tree_single(fc, xenfs_fill_super);
0075 }
0076
0077 static const struct fs_context_operations xenfs_context_ops = {
0078 .get_tree = xenfs_get_tree,
0079 };
0080
0081 static int xenfs_init_fs_context(struct fs_context *fc)
0082 {
0083 fc->ops = &xenfs_context_ops;
0084 return 0;
0085 }
0086
0087 static struct file_system_type xenfs_type = {
0088 .owner = THIS_MODULE,
0089 .name = "xenfs",
0090 .init_fs_context = xenfs_init_fs_context,
0091 .kill_sb = kill_litter_super,
0092 };
0093 MODULE_ALIAS_FS("xenfs");
0094
0095 static int __init xenfs_init(void)
0096 {
0097 if (xen_domain())
0098 return register_filesystem(&xenfs_type);
0099
0100 return 0;
0101 }
0102
0103 static void __exit xenfs_exit(void)
0104 {
0105 if (xen_domain())
0106 unregister_filesystem(&xenfs_type);
0107 }
0108
0109 module_init(xenfs_init);
0110 module_exit(xenfs_exit);
0111