C-如何在内核中获取字符设备的节点名称或路径



我在一个内核驱动程序中有" n" 字符设备。一个读取函数,指的是读取指针。

static struct file_operations fops;
fops.read    = cd_read;

现在,我需要知道读取从用户空间调用的字符设备。

static ssize_t cd_read(struct file *filep, char *buffer, size_t len, loff_t *position)
{
    filep->f_path;
}

我试图通过 filep-> f_path 至少尝试打印它,但是f_path指 fs.h

中的struct路径
struct file {
    ...
    struct path     f_path;
    ...
}

dentry和vfsmount在 path.h 中的路径中的dentry和vfsmount指的是2个未定义的结构。

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

,卡在这里。那么如何在内核中获取字符设备的节点名称或路径?

我找到了解决方案。

filp->f_path.dentry->d_iname

如下所述工作:

在Linux中,如何从" struct File"中获取文件名。结构,在用kgdb?

穿过内核时

最新更新