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

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux VFS(Virtual File System)是Linux操作系统中的一个重要组件,用于处理文件系统的访问操作。VFS提供了一个抽象层,使用户和应用程序可以以一致的方式访问不同类型的文件系统,如ext4、NTFS等。VFS的开发是为了增强Linux系统的可移植性和灵活性,使其能够在不同的文件系统上运行,并提供统一的API接口。 在Linux VFS的开发中,主要涉及如下几个方面: 1. 文件系统注册和管理:VFS通过注册文件系统的方式,将具体的文件系统和VFS绑定起来。开发者需要实现相应的文件系统操作函数,并注册到VFS中,以便VFS调用。同时,VFS还负责管理已注册的文件系统,并按照一定的规则进行调度和访问。 2. VFS数据结构设计:VFS中涉及到的数据结构设计非常重要,需要考虑到不同文件系统的特点和实现要求。常见的数据结构有inode、dentry、super_block等,它们之间的关系和作用需要合理设计和管理,以保证文件系统的正常运行。 3. 文件系统操作函数的实现:开发者需要根据具体的文件系统类型和需求,实现一系列文件系统操作函数,包括文件的创建、删除、读写等。这些函数需要按照VFS定义的接口规范来进行实现,以保证跨文件系统的通用性和可移植性。 4. 错误处理和异常情况处理:在VFS开发中,需要考虑到各种可能的错误和异常情况,如磁盘空间不足、文件不存在等。开发者需要合理处理这些异常情况,给用户提供友好的错误提示和处理方式,以保证系统的稳定性和可靠性。 总之,Linux VFS的开发是一个复杂而庞大的工作,需要对文件系统的原理和实现有深入的了解,同时具备良好的编程技巧和设计能力。通过开发和完善VFS,可以增强Linux系统的文件系统支持和扩展性,提高系统的性能和可靠性。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值