Linux 为什么打开带有两个参数的调用(struct inode*,struct file*)?
我正在实现一个角色驱动程序。所以我正在注册文件操作。当我注册Linux 为什么打开带有两个参数的调用(struct inode*,struct file*)?,linux,linux-kernel,linux-device-driver,embedded-linux,Linux,Linux Kernel,Linux Device Driver,Embedded Linux,我正在实现一个角色驱动程序。所以我正在注册文件操作。当我注册read函数时,我用这种方法提取了minor数字 myread(struct file * file, char __user * ubuf, size_t lbuf, loff_t *offset) { int minor; minor = MINOR(file->f_path.dentry->d_inode->f_pos->i_rdev);
read
函数时,我用这种方法提取了minor
数字
myread(struct file * file, char __user * ubuf, size_t lbuf, loff_t *offset)
{
int minor;
minor = MINOR(file->f_path.dentry->d_inode->f_pos->i_rdev);
.......
此规则也适用于open
调用
myopen(struct inode * inode, struct file * file)
struct file
定义引用了struct inode
。所以一个参数对于open
调用就足够了
我的问题是:
open
有两个参数?(或)为什么read
没有struct inode*
参数read
call中的次要号码,我使用了上面的指令。为了找到定义和头文件,我花了1小时30分钟。有什么简单的方法可以找到结构的定义吗struct file
找到struct inode
的引用的方法有多少?最好的方法是什么您不能使用该构造来搜索inode;打开文件后,文件甚至目录可能已被删除 内核约定(参见的第3章)是
open
函数中,您可以从inode中查找自己的数据(或分配自己的数据),并设置文件->私有_数据
指针;及read
功能中,然后使用file->private\u data
访问您自己的资料因为内核约定是这样的。更改它们需要大量的代码重写。