#include<linux/init.h>
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/slab.h>
#include<linux/fs.h>
#include<linux/errno.h>
#include<linux/types.h>
#include<linux/aio.h>
#include<linux/cdev.h>
#include<linux/wait.h>
#include<linux/sched.h>
MODULE_LICENCE("Dual BSD/GPL");
struct cdev hello_cdev;
dev_t hello_dev;
wait_queue_head_t hello_wait_queue;
int hello_open(struct inode *inode,struct file *filp){
return 0;
}
int hello_release(struct inode *inode,struct file *filp){
return 0;
}
ssize_t hello_read(struct file *filp,char *data,size_t count,loff_t *lop ){
interruptible_sleep_on(&hello_wait_queue);
return 0;
}
ssize_t hello_write(struct file *filp,const char *data,size_t count,loff_t *lop){
wake_up_interruptible(&hello_wait_queue);
return 0;
}
struct file_operations hello_ops={
.open=hello_open;
.release=hello_release;
.write=hello_write;
.read=hello_read;
};
static int helloworld_init(void){
int ret;
hello_dev=MKDEV(223,0);
if((ret=register_chrdev_region(hello_dev,1,"hello"))<0){
printk("module register error/n");
return -1;
}
cdev_init(&hello_cdev,&hello_ops);
if((ret=cdev_add(&hello_cdev,hello_dev,1))<0){
printk("cdev_add error/n");
unregister_chrdev_region(hello_dev,1);
return -1;
}
init_wait_queue_head(&hello_wait_queue);
printk("<0>hello init/n");
retyrn 0;
}
static void helloworld_exit(void){
cdev_del(&hello_cdev);
unregister_chrdev_region(hello_dev,1);
printk("<0>hello exit/n");
}
module_init(helloworld_init);
module_exit(helloworld_exit);