我正在开发一个模块来读取打开时的文件。我已经钩住了xattributes,因此我需要在不打开文件的情况下获取该文件的sys_open。简而言之,我有dentry和绝对路径,但是很难搞清楚,如何从中得到inode。非常感谢大家的评论。

最佳答案

据我所知,在open回调函数期间,您试图从驱动程序模块获取dentry路径。如果是这样,那么在放下我添加访问dentry信息所需的结构列表的方式之前。
include/linux/fs.h

Struct file{
struct path             f_path;
};

include/linux/path.h
struct path {
           struct vfsmount *mnt;
           struct dentry *dentry;
  };

include/linux/dcache.h
struct dentry {
};

所以你可以这样做。
 static int sample_open(struct inode *inode, struct file *file)
    {
    char *path, *dentry,*par_dentry;
    char buff[256];
    dentry = file->f_path.dentry->d_iname;
    pr_info("dentry :%s\n",dentry);
    par_dentry = file->f_path.dentry->d_parent->d_iname;
    pr_info("parent dentry :%s\n",par_dentry);
    path=dentry_path_raw(file->f_path.dentry,buff,256);
    pr_info("Dentry path %s\n",path);
    }

关于linux - 如何从inode/路径名中找到一个dentry?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43235313/

10-11 19:44