linux vfs 解析 之 inode

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

inode


相关的数据结构为:


struct inode {
 struct hlist_node i_hash;
 struct list_head i_list;
 struct list_head i_sb_list;
 struct list_head i_dentry;
 unsigned long  i_ino;
 atomic_t  i_count;
 umode_t   i_mode;
 unsigned int  i_nlink;
 uid_t   i_uid;
 gid_t   i_gid;
 dev_t   i_rdev;
 loff_t   i_size;
 struct timespec  i_atime;
 struct timespec  i_mtime;
 struct timespec  i_ctime;
 unsigned int  i_blkbits;
 unsigned long  i_blksize;
 unsigned long  i_version;
 unsigned long  i_blocks;
 unsigned short          i_bytes;
 spinlock_t  i_lock; 
 struct semaphore i_sem;
 struct rw_semaphore i_alloc_sem;
 struct inode_operations *i_op;
 struct file_operations *i_fop; 
 struct super_block *i_sb;
 struct file_lock *i_flock;
 struct address_space *i_mapping;
 struct address_space i_data;
#ifdef CONFIG_QUOTA
 struct dquot  *i_dquot[MAXQUOTAS];
#endif
 
 struct list_head i_devices;
 struct pipe_inode_info *i_pipe;
 struct block_device *i_bdev;
 struct cdev  *i_cdev;
 int   i_cindex;

 __u32   i_generation;

#ifdef CONFIG_DNOTIFY
 unsigned long  i_dnotify_mask;
 struct dnotify_struct *i_dnotify;
#endif

 unsigned long  i_state;
 unsigned long  dirtied_when; 

 unsigned int  i_flags;

 atomic_t  i_writecount;
 void   *i_security;
 union {
  void  *generic_ip;
 } u;
#ifdef __NEED_I_SIZE_ORDERED
 seqcount_t  i_size_seqcount;
#endif
};

 

inode存在于两个双向链表中:
一个是inode所在文件系统的super block的 s_inodes 链表中

一个是根据inode的使用状态存在于以下三个链表中的某个链表中:
1. 未用的: inode_unused 链表
2. 正在使用的: inode_in_use 链表
3. 脏的: super block中的s_dirty 链表


另外,还有一个重要的链表: inode_hashtable(这个暂不介绍).
                                                                            
                                                                            
            /------------\                                                  
 /----------|super_blocks|----     ..........       ---------------------\  
          \------------/                                               |  
                                                                       |  
       super_block            super_block             super_block      |  
      +-----------+           +-----------+           +-----------+    |  
 \----->|  s_list   |<--------->|  s_list   |<--------->|  s_list   |<---/  
        +-----------+           +-----------+           +-----------+       
  ----->|  s_inodes |<---\      |  s_inodes |           |  s_inodes |       
      +-----------+    |      +-----------+           +-----------+       
      |  s_files  |    |      |  s_files  |           |  s_files  |       
      +-----------+    |      +-----------+           +-----------+       
      |           |    |      |           |      /--->|  s_dirty  |<-----\
      +-----------+    |      +-----------+      |    +-----------+      |
      |           |    |      |           |      |    |           |      |
                       |                         |                       |
                       |                         |                       |
                       |                         |                       |
                       |                         |                       |
                       |                         |                       |
                       |                         \-------------------\   |
                       |                                             |   |
                       \----- ...... ---------\                      |   |
        inode                  inode          |        inode         |   |
     +-----------+          +-----------+     |    +-----------+     |   |
     |           |          |           |     |    |           |     |   |
     +-----------+          +-----------+     |    +-----------+     |   |
 \---->| i_sb_list |<-------->| i_sb_list |<----/    | i_sb_list |     |   |
       +-----------+          +-----------+          +-----------+     |   |
       |  i_hash   |          |  i_hash   |          |  i_hash   |     |   |
       +-----------+          +-----------+          +-----------+     |   |
 /---->|  i_list   |<--\  /-->|  i_list   |<---\  /->|  i_list   |<----/   |
     +-----------+   |  |   +-----------+    |  |  +-----------+         |
     |           |   |  |   |           |    |  |  |           |         |
                     |  |                    |  |                        |
                     |  |                    |  |                        |
                     |  |                    |  |                        |
                     |  |                    |  |                        |
                                             |  \------  ......  --------/
                                             |                            
                     .  .                    |                            
                     .  .                    |                            
  /------------\     .  .                    |                            
 \->|inode_unused|-\   .  .                    |   /------------\           
    \------------/ |   .  .                    \-->|inode_in_use|<---\      
                   |   .  .                        \------------/    |      
                   |                                                 |      
  /------------- --/                                                 |      
  |                    |  |                                          |      
  |                    |  |                                          |      
  |      inode         |  |               inode                      |      
  |   +-----------+    |  |            +-----------+                 |      
  |   | /         |    |  |            |           |                 |      
  |   +-----------+    |  |            +-----------+                 |      
  |   | i_sb_list |    |  |            | i_sb_list |                 |      
  |   +-----------+    |  |            +-----------+                 |      
  |   | |i_hash   |    |  |            |  i_hash   |                 |      
  |   +-----------+    |  |            +-----------+                 |      
  \-->|  i_list   |<---/  \----------->|  i_list   |<----------------/      
      +-----------+                    +-----------+                        
      |           |                    |           |                        
     

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值