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
    访问您自己的资料


  • 因为内核约定是这样的。更改它们需要大量的代码重写。