Advertisement
Guest User

Untitled

a guest
Dec 17th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | None | 0 0
  1. #include <linux/init.h>
  2. #include <linux/module.h>
  3. #include <linux/fs.h>
  4. #include <linux/slab.h>
  5. #include <linux/uaccess.h>
  6.  
  7. char* kbuf = 0;
  8. int wSize;
  9.  
  10. static int mpp_open(struct inode *inode, struct file *filp)
  11. {
  12.     printk ("MPP device opened.\n");
  13.     return 0;
  14. }
  15. static int mpp_release(struct inode *inode, struct file *f)
  16. {
  17.     printk ("MPP device closed.\n");
  18.     return 0;
  19. }
  20. static int mpp_read(struct file *f, char *buf, size_t size, loff_t *offset)
  21. {
  22.     if (!kbuf)
  23.     {
  24.        printk ("MPP reading... nothing to read\n");
  25.        return 1;
  26.     }
  27.     printk ("MPP reading... %s\n",kbuf);
  28.     return 0;
  29. }
  30. static int mpp_write(struct file *f, const char *buf, size_t size, loff_t *offset)
  31. {
  32.     kfree(kbuf);
  33.     kbuf = kmalloc(size, GFP_KERNEL);
  34.     copy_from_user (kbuf, buf, size);
  35.     printk ("MPP writing... %s\n",kbuf);
  36.     wSize = size;
  37.     return 0;
  38. }
  39. static long mpp_ioctl (struct file * f, unsigned int request, unsigned long param)
  40. {
  41.     printk ("MPP ioctl... %d %d\n", request, param);
  42.     return 0;
  43. }
  44.  
  45.  struct file_operations mpp_fops = {
  46.     .owner = THIS_MODULE,
  47.     .llseek = NULL,
  48.     .read = mpp_read,
  49.     .write = mpp_write,
  50.         .aio_read = NULL,
  51.         .aio_write = NULL,
  52.         .readdir = NULL,
  53.         .poll = NULL,
  54.         .unlocked_ioctl = mpp_ioctl,
  55.     .compat_ioctl = NULL,
  56.         .mmap = NULL,
  57.     .open = mpp_open,
  58.         .flush = NULL,
  59.     .release = mpp_release,
  60.         .fsync = NULL,
  61.         .aio_fsync = NULL,
  62.         .fasync = NULL,
  63.         .lock = NULL,
  64.         .sendpage = NULL,
  65.         .get_unmapped_area = NULL,
  66.         .check_flags = NULL,
  67.         .flock = NULL,
  68.         .splice_write = NULL,
  69.         .splice_read = NULL,
  70.         .setlease = NULL,
  71.         .fallocate = NULL
  72. };
  73.  
  74. int major;
  75. static int __init mpp_module_init(void)
  76. {
  77.     printk ("MPP module is loaded\n");
  78.     major = register_chrdev(0, "mpp", &mpp_fops);
  79.     return 0;
  80. }
  81.  
  82. static void __exit mpp_module_exit(void)
  83. {
  84.     printk ("MPP module is unloaded\n");
  85.     unregister_chrdev(major, "mpp");
  86.     return;
  87. }
  88.  
  89. module_init(mpp_module_init);
  90. module_exit(mpp_module_exit);
  91.  
  92. MODULE_LICENSE("GPL");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement