问题引入
Linux驱动开发中file_operations中定义的底层操作函数常用到的参数struct inode *node、struct file *file究竟是怎么回事儿?
比如下面的这个file_operations结构体:
static struct file_operations hello_drv = {
.owner = THIS_MODULE,
.open = hello_drv_open,
.read = hello_drv_read,
.write = hello_drv_write,
.release = hello_drv_close,
};
它里面涉及到的底层操作函数
hello_drv_open
hello_drv_read
hello_drv_write
hello_drv_close
要么都或多或少的用到了这两个参数struct inode *node、struct file *file,它们的原型分别如下:
static int hello_drv_open (struct inode *node, struct file *file)
static ssize_t hello_drv_read (struct file *file, char __user *buf, size_t size, loff_t *offset)
static ssize_t hello_drv_write (struct file *file, const char __user *buf, size_t size, loff_t *offset)
static int hello_drv_close (struct inode *node, struct file *file)
所以我们非常有必要了解下这两个参数struct inode *node
、struct file *file
究竟是怎么回事儿?
关于这两个参数我在下面这篇博文中已经详细叙述,这里就不再赘述了。
Linux打开一个文件并读取内容的详细流程【inode结构体、fd文件描述符、struct file
结构体、一个打开普通文件和一个打开设备文件的详细流程分析】