Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <linux/init.h>
- #include <linux/module.h>
- #include <linux/fs.h>
- #include <linux/slab.h>
- #include <linux/uaccess.h>
- char* kbuf = 0;
- int wSize;
- static int mpp_open(struct inode *inode, struct file *filp)
- {
- printk ("MPP device opened.\n");
- return 0;
- }
- static int mpp_release(struct inode *inode, struct file *f)
- {
- printk ("MPP device closed.\n");
- return 0;
- }
- static int mpp_read(struct file *f, char *buf, size_t size, loff_t *offset)
- {
- if (!kbuf)
- {
- printk ("MPP reading... nothing to read\n");
- return 1;
- }
- printk ("MPP reading... %s\n",kbuf);
- return 0;
- }
- static int mpp_write(struct file *f, const char *buf, size_t size, loff_t *offset)
- {
- kfree(kbuf);
- kbuf = kmalloc(size, GFP_KERNEL);
- copy_from_user (kbuf, buf, size);
- printk ("MPP writing... %s\n",kbuf);
- wSize = size;
- return 0;
- }
- static long mpp_ioctl (struct file * f, unsigned int request, unsigned long param)
- {
- printk ("MPP ioctl... %d %d\n", request, param);
- return 0;
- }
- struct file_operations mpp_fops = {
- .owner = THIS_MODULE,
- .llseek = NULL,
- .read = mpp_read,
- .write = mpp_write,
- .aio_read = NULL,
- .aio_write = NULL,
- .readdir = NULL,
- .poll = NULL,
- .unlocked_ioctl = mpp_ioctl,
- .compat_ioctl = NULL,
- .mmap = NULL,
- .open = mpp_open,
- .flush = NULL,
- .release = mpp_release,
- .fsync = NULL,
- .aio_fsync = NULL,
- .fasync = NULL,
- .lock = NULL,
- .sendpage = NULL,
- .get_unmapped_area = NULL,
- .check_flags = NULL,
- .flock = NULL,
- .splice_write = NULL,
- .splice_read = NULL,
- .setlease = NULL,
- .fallocate = NULL
- };
- int major;
- static int __init mpp_module_init(void)
- {
- printk ("MPP module is loaded\n");
- major = register_chrdev(0, "mpp", &mpp_fops);
- return 0;
- }
- static void __exit mpp_module_exit(void)
- {
- printk ("MPP module is unloaded\n");
- unregister_chrdev(major, "mpp");
- return;
- }
- module_init(mpp_module_init);
- module_exit(mpp_module_exit);
- MODULE_LICENSE("GPL");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement