如何从inode/路径名中找到一个dentry? [英] How to find a dentry from an inode/pathname?

查看:512
本文介绍了如何从inode/路径名中找到一个dentry?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个模块,用于在打开时读取文件xattributes.我已经钩住sys_open,因此,我需要在不打开文件的情况下获取文件的dentry.简而言之,我有inode和绝对路径,但是很难弄清楚.如何从中获得dentry.非常感谢所有评论.

I am working on a module to read a files xattributes on open. I have hooked the sys_open and due to this I need to get the dentry of the file without opening the file. In brief I have the inode and the absolute path but having trouble to figure out; how to get a dentry from these. All comments are very much appreciated.

推荐答案

根据我的说法,您正在尝试在打开回调函数中从驱动程序模块获取牙科路径.强>.如果是这样;然后在放下方式之前,我要添加访问牙科信息所需的结构列表.

As per my understating you are trying to get the dentry path from your driver module during the open callback function . If so; then before putting down the way I am adding the structure list which are required to access the the dentry information.

include/linux/fs.h

include/linux/fs.h

Struct file{
struct path             f_path;
};

include/linux/path.h

include/linux/path.h

struct path {
           struct vfsmount *mnt;
           struct dentry *dentry;
  };

include/linux/dcache.h

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);
    }

这篇关于如何从inode/路径名中找到一个dentry?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆