#define DP_MAJOR 252 /*the major number of the chardev*/ #define DP_MINOR 0 /*the minor number of the chardev*/ static int char_read(struct file *filp,char __user *buffer,size_t,loff_t *); /*the read operation of the chardev----read the data from kernel*/ static int char_open(struct inode *,struct file *); /*open the chardev*/ static int char_write(struct file *filp,const char __user *buffer,size_t ,loff_t*); /*write data to kernel*/ static int char_release(struct inode *,struct file *); /*release the chardev*/ static char *arr,*p; static int chropen; /*the chardev open or not*/ struct cdev *chardev; /*define a char device*/ static int len;
cdev_init(chardev,&char_ops); if(cdev_add(chardev,dev,1)<0) { printk(KERN_ALERT"Add char dev error\n"); }
return 0; }
static int char_open(struct inode *inode,struct file *file) { if(chropen==0) chropen++; else{ printk(KERN_ALERT"Another process open the char device\n"); return -1; }