file_operation

来源:互联网 发布:淘宝店铺装修免费图片 编辑:程序博客网 时间:2024/06/06 13:15
struct file_operations ***_ops={
 .owner =  THIS_MODULE,
 .llseek =  ***_llseek,
 .read =  ***_read,
 .write =  ***_write,
 .ioctl =  ***_ioctl,
 .open =  ***_open,
 .release = ***_release, 
};

loff_t (*llseek) (struct file * filp , loff_t  p,  int  orig);
ssize_t (*read) (struct file * filp, char __user * buffer, size_t    size , loff_t *  p);
ssize_t (*write) (struct file *  filp, const char __user *   buffer, size_t  count, loff_t * ppos);
int (*ioctl) (struct file *filp, unsigned int cmd, unsigned long arg);
int (*open) (struct inode * inode , struct file *  filp ) ;
int (*release) (struct inode *, struct file *);

unsigned long copy_to_user(void __user *to, const void *from, unsigned long n);

unsigned long copy_from_user(void * to, const void __user * from, unsigned long n);

void cdev_init(struct cdev *cdev, const struct file_operations *fops)

int alloc_chrdev_region(dev_t *dev,unsigned int firstminor,unsigned int count,char *name);
Firstminor : 通常为0; 
*dev:存放返回的设备号; 

int cdev_add(struct cdev* dev,dev_t num,unsigned int count)
num设备号 count设备数

void cdev_del(struct cdev *p)

引用 void unregister_chrdev_region(dev_t first, unsigned int count);
first为第一个设备号,count为申请的设备数量
0 0
原创粉丝点击