我试图了解 Linux 文件系统的工作原理。 struct mount
有 mnt_mountpoint
字段,它指向挂载点目录并用于路径查找。
struct mount {
/*...*/
struct dentry *mnt_mountpoint;
/*...*/
struct mountpoint *mnt_mp;
/*...*/
}
此时我不明白第二个挂载点字段的用途是什么?它指向 mountpoint
结构,而该结构又指向另一个 mountpoint 目录 m_dentry
。
struct mountpoint {
struct hlist_node m_hash;
struct dentry *m_dentry;
struct hlist_head m_list;
int m_count;
};
最佳答案
We also have struct mountpoint in the picture. Once upon a time it used to be a part of struct dentry - the list of all mounts on given mountpoint. Since it doesn't make sense to bloat every dentry for the sake of a very small fraction that will ever be anyone's mountpoints, that thing got separated.
What we have is
- mark in dentry flags (
DCACHE_MOUNTED
) set for dentries that are currently mountpoints- for each of those we have a struct mountpoint instance (exactly one for each of those dentries).
不是 struct dentry
有一个列表指针,所有的挂载点都存储在一个哈希表中。 m_dentry
字段用于区分落入同一哈希桶的不同挂载点。
我想 struct mount
持有对 struct mountpoint
的引用,主要用于清理。 IE。当 struct mount
被销毁时,我们调用 put_mountpoint(mnt_mp)
。 m_count
递减,如果它达到零,挂载点将被销毁。
关于c - 为什么挂载结构有两个挂载点字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57361052/