文件系统中的位于内存中所有inode存放在一个名为inode_hashtable
的全局哈希表中(如果inode还在磁盘,尚未读到内存中,则不会加入到全局哈希表中)。另一方面,所有的inode还存放在超级块中的s_inode链表中。
inode_hashtable
哈希表加快了对索引节点对象的搜索。
前提是必须知道索引节点号和文件所在文件系统对应的超级块对象。
该inode_table
位于fs/inode.c
中:
static unsigned int i_hash_mask __read_mostly;
static unsigned int i_hash_shift __read_mostly;
static struct hlist_head *inode_hashtable __read_mostly; //哈希表定义
static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock);
/*
* Empty aops. Can be used for the cases where the user does not
* define any of the address_space operations.
*/
const struct address_space_operations empty_aops = {
};
EXPORT_SYMBOL(empty_aops);
————————————————————————————————————————————————————————
下面以f2fs文件系统查找inode为例:
f2fs_iget
依据索引节点号ino,查找对应的inode;
/*
依据节点号ino,获得对应的inode;
若没有,则创建一个新的inode,读取磁盘上的inode所在的block,生成f2