added rb analyzer
[slick.ecio.git] / ecio-proxy / ecio-proxy.c
blob11eebdf8f5150e9d216ae497e7f1390854c56f56
2 /*
3 * Ecio proxy module 2011 (c) Yury Makarevich
5 * We wrap register_chrdev/unregister_chrdev, copy_from_user
6 */
8 /*
9 * Kernel config: disable SMP, disable module versioning.
11 * EcIo.ko config: patch the appropriate symbols, rename per_cpu__current_task to current_task (remove?),
12 * remove spin_lock related code.
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/fs.h>
19 #include <asm/uaccess.h>
22 The following structure was copied from 2.6.22 kernel
25 struct legacy_file_operations {
26 struct module *owner;
27 loff_t (*llseek) (struct file *, loff_t, int);
28 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
29 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
30 ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
31 ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
32 int (*readdir) (struct file *, void *, filldir_t);
33 unsigned int (*poll) (struct file *, struct poll_table_struct *);
34 int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
35 long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
36 long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
37 int (*mmap) (struct file *, struct vm_area_struct *);
38 int (*open) (struct inode *, struct file *);
39 int (*flush) (struct file *, fl_owner_t id);
40 int (*release) (struct inode *, struct file *);
41 int (*fsync) (struct file *, struct dentry *, int datasync);
42 int (*aio_fsync) (struct kiocb *, int datasync);
43 int (*fasync) (int, struct file *, int);
44 int (*lock) (struct file *, int, struct file_lock *);
45 ssize_t (*sendfile) (struct file *, loff_t *, size_t, read_actor_t, void *);
46 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
47 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
48 int (*check_flags)(int);
49 int (*dir_notify)(struct file *filp, unsigned long arg);
50 int (*flock) (struct file *, int, struct file_lock *);
51 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
52 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
55 static long proxy_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
57 static const struct legacy_file_operations *legacy_fops = NULL;
58 static struct file_operations proxy_fops = {
59 .unlocked_ioctl = proxy_ioctl,
63 int register_ecio(unsigned int major, const char *name,
64 const struct legacy_file_operations *lfops)
66 // wrap file_operations here
67 legacy_fops = lfops;
69 proxy_fops.open = legacy_fops->open;
70 proxy_fops.read = legacy_fops->read;
71 proxy_fops.write = legacy_fops->write;
72 proxy_fops.release = legacy_fops->release;
74 return register_chrdev(major, name, &proxy_fops);
77 int unregister_ecio(unsigned int major, const char *name)
79 unregister_chrdev(major, name);
80 return 0;
83 /////////////////////////////////////////////////////////////////
85 static spinlock_t proxy_ioctl_lock;
87 static long proxy_ioctl(struct file *file, unsigned int cmd, unsigned long arg) {
88 long result;
90 printk(KERN_INFO "ecio-proxy ioctl %d\n", cmd);
92 spin_lock(&proxy_ioctl_lock);
93 result = legacy_fops->ioctl(file->f_path.dentry->d_inode, file, cmd, arg);
94 spin_unlock(&proxy_ioctl_lock);
96 return result;
99 unsigned long copy_from_ecio(void *to, const void __user *from, unsigned long n)
101 return copy_from_user(to, from, n);
104 void _spin_ecio(spinlock_t *lock) {
107 /////////////////////////////////////////////////////////////////
109 int init_module (void) {
110 printk(KERN_INFO "ecio-proxy inserted\n");
111 return 0;
114 void cleanup_module (void) {
115 printk(KERN_INFO "ecio-proxy removed\n");
118 EXPORT_SYMBOL(register_ecio);
119 EXPORT_SYMBOL(unregister_ecio);
120 EXPORT_SYMBOL(copy_from_ecio);
121 EXPORT_SYMBOL(_spin_ecio);