linux vfs 解析 之 dentry

本文详细介绍了 Linux 文件系统中的 dentry 数据结构及其在目录项管理中的作用。dentry 结构用于缓存文件系统的目录项信息,提高文件查找效率。文章通过图示展示了 dentry 如何与其他数据结构如 inode 相关联,并解释了 dentry 在不同链表中的位置及意义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://blog.sina.com.cn/s/blog_5219094a01009a4g.html

dentry


相关的数据结构为:


struct dentry {
 atomic_t d_count;
 unsigned int d_flags;  
 spinlock_t d_lock;  
 struct inode *d_inode;  
 
 struct dentry *d_parent; 
 struct qstr d_name;

 struct list_head d_lru;  
 struct list_head d_child; 
 struct list_head d_subdirs; 
 struct list_head d_alias; 
 unsigned long d_time;  
 struct dentry_operations *d_op;
 struct super_block *d_sb; 
 void *d_fsdata;   
  struct rcu_head d_rcu;
 struct dcookie_struct *d_cookie;
 struct hlist_node d_hash;  
 int d_mounted;
 unsigned char d_iname[DNAME_INLINE_LEN_MIN]; 
};


dentry对象存在于三个双向链表中:
所有未用的目录项: dentry_unused 链表
正在使用的目录项: 对应inode的 i_dentry 链表
表示父子目录结构的链表

另外,还有一个重要的链表: inode_hashtable(这个暂不介绍).

                                                                              
                                                                              
                                                                              
                                    dentry                                    
                               +--------------+                               
                               |              |                               
                               +--------------+                               
   /-------------------------->|  d_subdirs   |<-----------------------------\
   |                           +--------------+                              |
   |                           |              |                              |
   |                           +--------------+                              |
   |                           |              |                              |
   |                           +--------------+                              |
   |                           |              |                              |
   |                       /-->+--------------+<-----\                       |
   |                       |                         |                       |
   |                       |                         |                       |
   |                       |                         |                       |
   |        dentry         |                         |          dentry       |
   |   +--------------+    |                         |    +--------------+   |
   |   |  d_parent    |----/                         \----|  d_parent    |   |
   |   +--------------+                                   +--------------+   |
   |   |  d_subdirs   |                                   |  d_subdirs   |   |
   |   +--------------+                                   +--------------+   |
   \-->|  d_child     |<---------- ......   ------------->|  d_child     |<--/
       +--------------+                                   +--------------+    
       |              |                                   |              |    
       +--------------+                                   +--------------+    
       |              |                                   |              |    
       +--------------+                                   +--------------+    
                                                                              
            dentry                                            dentry          
       +--------------+                                  +--------------+     
       |  d_parent    |                                  |  d_parent    |     
       +--------------+                                  +--------------+     
       |  d_subdirs   |                                  |  d_subdirs   |     
       +--------------+                                  +--------------+     
       |  d_child     |                                  |  d_child     |     
       +--------------+         /---------------\        +--------------+     
 /---->|  d_lru       |<--------| dentry_unused |------->|  d_lru       |<--\ 
     +--------------+         \---------------/        +--------------+   | 
     |              |                                  |              |   | 
     +--------------+                                  +--------------+   | 
                                                                          | 
                                                                          | 
                                                                          | 
                                                                          | 
 \-----------------------------   ......   ---------------------------------/ 
                                                                              
                                                                              
                                   inode                                      
                               +-----------+                                  
                               |           |                                  
                               +-----------+                                  
       /---------------------->|  i_dentry |<---------------------------\     
       |                       +-----------+                            |     
       |                       |           |                            |     
       |                       +-----------+                            |     
       |                       |           |                            |     
       |                       +--,-----,--+                            |     
       |                         /|\   /|\                              |     
       |         dentry           |     |              dentry           |     
       |    +--------------+      |     |         +--------------+      |     
       |    |  d_parent    |      |     |         |  d_parent    |      |     
       |    +--------------+      |     |         +--------------+      |     
       |    |  d_subdirs   |      |     |         |  d_subdirs   |      |     
       |    +--------------+      |     |         +--------------+      |     
       |    |  d_child     |      |     |         |  d_child     |      |     
       |    +--------------+      |     |         +--------------+      |     
       |    |  d_lru       |      |     |         |  d_lru       |      |     
       |    +--------------+      |     |         +--------------+      |     
       |    |  d_inode     |------/     \---------|  d_inode     |      |     
       |    +--------------+                      +--------------+      |     
       \--->|  d_alias     |<-----  ......  ----->|  d_alias     |<-----/     
            +--------------+                      +--------------+            
                                                                              
                                                                              


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值