写几个函数和结构体吧~

来源:互联网 发布:淘宝怎么搜原味胖次 编辑:程序博客网 时间:2024/04/29 10:08
1、struct cdev{    struct file_operations*    ops;    dev_t                      dev;    unsigned int               count;    struct kobject             kobj;    struct module              *owner;    struct list_head list      list;    ...    }2、struct file{    struct inode*              f_inode;    const struct file_operations* f_op;    unsigned int               f_flags;    fmode_t                      fmode:    loff_t                       f_pos;    void*                 private_date;    ...    }3、struct inode{    dev_t                         dev;    umode_t                     imode;    struct cdev*               i_cdev;    struct list_head        i_devices;    ...    }4、int xxx_open(struct inode* inode , struct file* filp);5、

ssize_t xxx_read(stuct file* file , char __user * buf , size_t size , loff_t* ppos);
int copy_to_user(buf , (void*)dev.mem+offset , size);
6、
ssize_t xxx_write(struct file* file,const char __user* buf ,size_t size,loff_t* ppos);
int copy_from_user((void*)dev.mem+offset , buf , size);
7、
int ioctl(struct inode*inode,struct file*filp,unsigend int cmd,unsigned long arg);

[注]:1、应用程用了open之后,VFS就会产生inode和file结构体,然后由inode结构体找到cdev,file中的file_operations指针成员指向cdev中的方法集。
2、对于键盘和鼠标这一类的相似的设备虽然不是属于同一类但是我们还是可以不需要写多个cdev结构体。

0 0
原创粉丝点击