Linux kernel 对VFS中的不同文件使用相同的文件\u操作

Linux kernel 对VFS中的不同文件使用相同的文件\u操作,linux-kernel,kernel-module,Linux Kernel,Kernel Module,我正在自定义内核模块的securityfs中创建几个dentry对象。我是这样做的: inst->output_file = securityfs_create_file("1", S_IRUSR | S_IRGRP, uprp_dir, NULL, &my_file_ops); inst->output_file = securityfs_create

我正在自定义内核模块的
securityfs
中创建几个
dentry
对象。我是这样做的:

inst->output_file = securityfs_create_file("1",
                               S_IRUSR | S_IRGRP, uprp_dir, NULL,
                               &my_file_ops);
inst->output_file = securityfs_create_file("2",
                               S_IRUSR | S_IRGRP, uprp_dir, NULL,
                               &my_file_ops);
// and so on 
我为
my\u file\u ops
实现了通常的序列操作。但是,问题是,所有
dentry
对象都会调用以下函数:

 static int ct_open(struct inode *inode, struct file *file)
然后继续使用:

 static void *my_seq_ops_start (struct seq_file *m, loff_t *pos)

问题是,如何确定用户想要读取哪个dentry对象(在这些函数中)?--这意味着我想要为文件
1
2
输出不同的内容

当VFS通过
myfile\u ops
结构调用您的
ct\u open()
函数时,它会将打开的文件作为
struct inode*
struct file*
传回。
struct文件
包含一个成员
f\u dentry
,该成员是指向由
securityfs\u create\u file()
返回的dentry的指针。
struct dentry
包含文件名


然而,更清楚的是,
securityfs\u create\u file()
的第四个参数是供您使用的。您可以传入任何指向所需内部结构的指针,并在打开操作期间从inode.i_私有指针检索它。这通常是“正确”的抽象级别,因此您的文件操作不需要知道任何有关文件名的信息。

非常感谢。我更喜欢第二种方法,因为它更容易实现。如果您能推荐这两种选择中的“更好的”,那就太好了,仅供参考。