根据file_operations结构成员的原型,这里我们需要实现如下回调:
int (*open) (struct inode *, struct file *); ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); int (*release) (struct inode *, struct file *);open和close函数为了简单起见不做任何处理,只是简单的输出kernel信息:
int simple_open(struct inode * pnode, struct file * pfile) { printk(KERN_INFO "open simple\n"); return 0; } int simple_release(struct inode * pnode, struct file * pfile) { printk(KERN_INFO "close simple\n"); return 0; }