我需要知道如何获取路径名或 dentry
或 struct file
从给定的inode。
我正在使用 file_open
获取struct file
从路径名,但总是给内核 panic 。我需要一种方法来将我的 inode 列表中的一个 inode 与路径名中的一个 inode 进行比较,或者比较磁盘中的所有 inode 以找到相应的路径名,然后与我的 inode 列表进行比较。
最佳答案
此示例代码在 Linux 内核版本 2.6.xx 中运行良好
struct dentry *sample_dentry = NULL;
struct inode *tmp_inode = &inode_need_to_get;
struct list_head *tmp_list = NULL;
list_for_each(tmp_list, &(tmp_inode->i_dentry))
{
sample_dentry = list_entry(tmp_list, struct dentry, d_alias);
printk(KERN_EMERG, "name of file is %s\n", sample_dentry->d_iname);
}
如果此文件有硬链接(hard link),每个 inode 对象将有一个或多个 dentries 对象。
关于linux-kernel - 如何从给定的 inode 获取路径名、dentry 或 struct 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8556461/