linux vfs 解析 之 dentry

来源:互联网 发布:南方舆情数据研究院 编辑:程序博客网 时间:2024/07/24 01:19

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     |<-----/     
            +--------------+                      +--------------+