1,基本数据结构:
file_system_type
 每种文件系统对应一个文件系统类型结构,注册之后形成单链表,链表表头为file_systems(全局变量).
Superblock
 反应文件系统整体的控制信息,超级块以多种方式存在。(磁盘超级快、内存超级块、VFS超级块)
Inode
 反应了某个文件系统对象的一般元信息(metadata)。(磁盘inode、内存inode、VFS inode)
Dentry
 反应了某个文件系统对象在文件系统树中的位置。
mount
 反映了一个已装载文件系统实例。
 
2,文件系统的注册
 在register_filesystem()函数中来向内核注册文件系统,所有的文件系统都在一个单链表中,各个文件系统的名称存储为字符串,用于描述文件系统结构为file_system_type,内核中用一个名为file_systems 的全局变量来指向该链表的表头。
- struct file_system_type {  
 
-  const char *name;  
 
-  int fs_flags;  
 
-  struct super_block *(*get_sb) (struct file_system_type *, int,)
 
-                  得本文件系统(分区)的super_block,并将之填充到struct vfsmount的mnt_sb成员中。  
 
-  const char *, void *, struct vfsmount *);  
 
-  void (*kill_sb) (struct super_block *);
 
-  struct module *owner;  
 
-  struct file_system_type * next;  
 
-  struct list_head fs_supers;
 
- };  
 
 
在一个系统上,比如smartphone平台,有很多分区,比如/data和/system分区都是ext4文件系统,但是系统中还是只有一个file_system_type的成员,不过每个分区对应的ext4文件系统对应不同的super_block,fs_supers就是将这些相同文件系统不同的super block链接起来形成双向循环链表,fs_supers是链表头,链表元素由super_block结构体的s_instance成员表示。系统中所有的super_block由super_block结构体的s_list链接成双向循环链表,表头是super_blocks变量表示。 
 
3,文件系统的装载和卸载
 使用mount命令可以查询目录树中各种文件系统的装载情况, 在将文件系统装载到一个目录时,装载点的内容被替换为即将装载的文件系统的相对根目录的内容,前一个目录数据消失,直到新文件系统卸载的时候才重新出现。
- struct vfsmount {  
 
-  struct list_head mnt_hash;  
 
-  struct vfsmount *mnt_parent; 
 
-  struct dentry *mnt_mountpoint; 
 
-  struct dentry *mnt_root; 
 
-  struct super_block *mnt_sb; 
 
-  struct list_head mnt_mounts; 
 
-  struct list_head mnt_child; 
 
-  int mnt_flags;  
 
-  char *mnt_devname; 
 
-  struct list_head mnt_list;  
 
-  struct list_head mnt_expire; 
 
-  struct list_head mnt_share; 
 
-  struct list_head mnt_slave_list;
 
-  struct list_head mnt_slave; 
 
-  struct vfsmount *mnt_master; 
 
-  struct mnt_namespace *mnt_ns; 
 
-  atomic_t mnt_count;  
 
-  int mnt_expiry_mark; 
 
- };  
 
 
vfsmount成员mnt_mountpoint表示的是装载点在父文件系统中的dentry,文件系统本身的相对根目录所对应的dentry保存在mnt_root中,两个dentry实例表示同一目录,这意味着在文件系统卸载后不必删除此前的装载点信息。
在新版本的linux内核中,使用了struct mount结构体代替了struct vfsmount结构体。
在装载新的文件系统时,vfsmount并不是唯一需要在内存中创建的结构,装载操作开始于超级块的读取,超级块是整个文件系统的元数据的容器。基于磁盘的文件系统,超级块(磁盘上的)是保存在磁盘设备上固定位置的一个或多个块,在装载该磁盘上的文件系统时,磁盘上的超级块被读入内存,并根据它构造内存中的超级块。
- struct super_block {  
 
-  struct list_head s_list; 
 
-  struct list_head s_io; 
 
-  struct list_head s_more_io; 
 
-  struct list_head s_files; 
 
-  struct block_device *s_bdev;  
 
-  struct list_head s_instances;  
 
-  char s_id[32]; 
 
-  void *s_fs_info; 
 
-  u32 s_time_gran;  
 
- };  
 
 
超级快可以管理系统中inode节点的原因是文件系统内所有的inode要链接到超级快的链表头。
所有超级快对象都以双向循环链表的形式连接在一起,链表第一个元素用super_blocks变量表示,sb_lock自旋锁保护链表免受多处理器系统上的同时访问。s_fs_info指向属于具体文件系统的超级快信息,例如具体文件系统是EXT2,则s_fs_info指向ext2_sb_info,s_dirty表示的修改脏标记,表示内存中的超级快信息是否和硬盘上超级快信息同步,
 对于每个转载的文件系统而言,都有且只有一个超级快实例
 
 
- 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;  
 
-     unsigned int i_nlink;  
 
-     uid_t i_uid;  
 
-     gid_t i_gid;  
 
-     dev_t i_rdev;  
 
-     unsigned long i_version;  
 
-     loff_t i_size;  
 
-     struct timespec i_atime;  
 
-     struct timespec i_mtime;  
 
-     struct timespec i_ctime; 
 
-     unsigned int i_blkbits; 
 
-     blkcnt_t i_blocks;  
 
-     umode_t i_mode; 
 
-     struct inode_operations *i_op; 
 
-     const struct file_operations *i_fop; 
 
-     struct super_block *i_sb;  
 
-     struct address_space *i_mapping; 
 
-     struct address_space i_data; 
 
-     struct dquot *i_dquot[MAXQUOTAS];  
 
-     struct list_head i_devices;  
 
-     union {  
 
-     struct pipe_inode_info *i_pipe;  
 
-     struct block_device *i_bdev;  
 
-     struct cdev *i_cdev;  
 
-     };  
 
-     int i_cindex;  
 
-     __u32 i_generation;  
 
-     unsigned long i_state;  
 
-     unsigned long dirtied_when; 
 
-     unsigned int i_flags;  
 
-     atomic_t i_writecount;  
 
-     void *i_security;  
 
- };  
 
 [文件系统]文件系统学习笔记(四)---常用数据结构
原文:http://www.cnblogs.com/zhiliao112/p/4067838.html