VFS之super_block

今天在解决工作问题的同时也扩展我的知识面,有一种想深入研究文件系统的冲动,初略的研究了一下。

 

虚拟文件系统:VFS, virtual fiel system.

 

struct super_block {
 struct list_head s_list;  //维护super_blocks全局变量的成员
 dev_t   s_dev;  
 unsigned long  s_blocksize;
 unsigned long  s_old_blocksize;
 unsigned char  s_blocksize_bits;
 unsigned char  s_dirt;
 unsigned long long s_maxbytes; 
 struct file_system_type *s_type;
 struct super_operations *s_op;
 struct dquot_operations *dq_op;
  struct quotactl_ops *s_qcop;
 struct export_operations *s_export_op;
 unsigned long  s_flags;
 unsigned long  s_magic;
 struct dentry  *s_root;
 struct rw_semaphore s_umount;
 struct semaphore s_lock;
 int   s_count;
 int   s_syncing;
 int   s_need_sync_fs;
 atomic_t  s_active;
 void                    *s_security;
 struct xattr_handler **s_xattr;

 struct list_head s_inodes; 
 struct list_head s_dirty; 
 struct list_head s_io;  
 struct hlist_head s_anon;  
 struct list_head s_files;

 struct block_device *s_bdev;
 struct list_head s_instances; //维护特定文件系统全局变量的成员
 struct quota_info s_dquot; 

 int   s_frozen;
 wait_queue_head_t s_wait_unfrozen;

 char s_id[32];    

 void    *s_fs_info; 

 
 struct semaphore s_vfs_rename_sem; 

 
 u32     s_time_gran;
};

 

super_block存在于两个链表中,一个是系统所有super_block的链表, 一个是对于特定的文件系统的super_block链表. 前者是被维护在一个全局变量super_blocks中,这个全局变量定义在文件fs/super.c。后者也是被维护在一个全局变量file_systems中,它被定义在文件fs/filesystems.c中。下图给予形象的展示:

                                                                            
所有的super_block都存在于 super-blocks 链表中:                                                                            
                                                                            
            /------------/                                                  
 /--------->|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  |           |  s_dirty  |           |  s_dirty  |       
        +-----------+           +-----------+           +-----------+       
        |  s_op     |           |  s_op     |           |  s_op     |       
        +-----------+           +-----------+           +-----------+       
        |  s_fs_info|           |  s_fs_info|           |  s_fs_info|       
        +-----------+           +-----------+           +-----------+       
        |           |           |           |           |           |       
                                                                            
                                                                            

对于特定的文件系统, 该文件系统的所有的super block 都存在于file_sytem_type中的fs_supers链表中.
而所有的文件系统,都存在于file_systems链表中.这是通过调用register_filesystem接口来注册文件系统的.
int register_filesystem(struct file_system_type * fs) 

                                                                             
                         file_system_type        file_system_type            
                    /--->+-------------+    /--->+-------------+             
                    |    |    name     |    |    |    name     |             
/--------------/    |    +-------------+    |    +-------------+     /------/
| file_systems |----/    |    next     |----/    |    next     |---->| NULL |
/--------------/         +-------------+         +-------------+     /------/
                         |   get_sb    |         |   get_sb    |             
                         +-------------+         +-------------+             
                         |   kill_sb   |         |   kill_sb   |             
                         +-------------+         +-------------+             
       /---------------->|  fs_supers  |<---/    |  fs_supers  |             
       |                 +-------------+    |    +-------------+             
       |                 |             |    |    |             |             
       |  /------------->+-------------+    |    +-------------+             
       |  |                     //          |                                
       |  |                     ||          /------------.............------/
       |  |                     |/--------------------/                     |
       |  |                     |                     |                     |
       |  |     super_block     |      super_block    |     super_block     |
       |  |   +-------------+   |    +-------------+  |   +-------------+   |
       |  /---|  s_type     |   /----|    s_type   |  /---|   s_type    |   |
       |      +-------------+        +-------------+      +-------------+   |
       /----->| s_instances |<------>| s_instances |<---->| s_instances |---/
              +-------------+        +-------------+      +-------------+    
              |             |        |             |      |             |    
              +-------------+        +-------------+      +-------------+    
              |             |        |             |      |             |    
              +-------------+        +-------------+      +-------------+    
              |             |        |             |      |             |

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值