Linux驱动程序中文件操作结构体file_operations中定义的底层操作函数常用到的参数struct inode *node、struct file *file是怎么回事儿?

问题引入

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 *nodestruct file *file究竟是怎么回事儿?

关于这两个参数我在下面这篇博文中已经详细叙述,这里就不再赘述了。
Linux打开一个文件并读取内容的详细流程【inode结构体、fd文件描述符、struct file结构体、一个打开普通文件和一个打开设备文件的详细流程分析】

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值