问题描述
我需要知道如何从给定的inode获取路径名或dentry
或struct file
.
I need to know how to obtain a pathname or dentry
or struct file
from a given inode.
我正在使用file_open
从路径名获取struct file
,但是总是引起内核恐慌.我需要一种方法来比较我的索引节点列表中的索引节点与路径名中的索引节点,或者比较磁盘中的所有索引节点以找到相应的路径名,然后与索引节点列表进行比较.
I was using file_open
to obtain struct file
from a pathname but but always gave kernel panic. I need a way to compare an inode from my list of inodes with a inode from a pathname or compare all inodes in the disk to find corresponding pathnames, and then compare with my list of inodes.
推荐答案
此示例代码将在Linux内核2.6.xx版中很好地工作
This sample code will work well in Linux kernel version 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);
}
如果该文件具有硬链接,则每个inode对象将具有一个或多个dentries对象.
Each inode object will have one or more dentries object in case this file have a hard link.
这篇关于如何从给定的inode获取路径名或dentry或struct文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!