, int wait);
1571 int (*freeze_fs) (struct super_block *);
1572 int (*unfreeze_fs) (struct super_block *);
1573 int (*statfs) (struct dentry *, struct kstatfs *);
1574 int (*remount_fs) (struct super_block *, int *, char *);
1575 void (*umount_begin) (struct super_block *);
1576
1577 int (*show_options)(struct seq_file *, struct vfsmount *);
1578 int (*show_stats)(struct seq_file *, struct vfsmount *);
1579#ifdef CONFIG_QUOTA
1580 ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
1581 ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
1582#endif
1583 int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
1584};
1>可以看到该结构体中的每一项都是一个指向超级块操作函数的指针,超级块操作函数执行文件系统和索引节点的低层操作。
2>当文件系统需要对超级块执行操作时,要在超级块对象中寻找需要的操作方法
例如:一个文件系统要写自己的超级块,需要调用:
sturct super_block * sb;
sb->s_op->write_super)(sb);
sb是指向文件系统超级块的指针,沿着该指针进入超级块操作函数表,并从表中取得writ_super()函数,该函数执行写入超级块的实际操作。
Tiger-John说明:
尽管writ_super()方法来自超级块,但是在调用时,还是要把超级块作为参数传递给它。
3>.分析其中比较重要的一些数据结构。
a.struct inode * alloc_inode(struct super_block * sb) :创建和初始化一个新的索引结点。
b.void destroy_inode(struct super_block *sb) :释放指定的索引结点 。
c.void dirty_inode(struct inode *inode) :VFS在索引节点被修改时会调用此函数。
d.void write_inode(struct inode *inode, struct writeback_control *wbc) 将指定的inode写回磁盘。
e.void drop_inode( struct inode * inode):删除索引节点。
f.void put_super(struct super_block *sb) :用来释放超级块。
g.void write_super(struct super_block *sb):更新磁盘上的超级块。
h.void sync_fs(struct super_block *sb,in wait):使文件系统的数据元素与磁盘上的文件系统同步,wait参数指定操作是否同步。
i.int statfs(struct super_block *sb,struct statfs *statfs):获取文件系统状态。把文件系统相关的统计信息放在statfs中。
2.VFS的索引节点
1>文件系统处理文件或目录时的所有信息都存放在称为索引节点的数据结构中。
文件名可以随时该,但是索引节点对文件是唯一的(它是随文件的存在而存在)。
2>具体文件系统的索引节点是存放在磁盘上的,是一种静态结构,要使用它,必须将其调入内存,填写 VFS的索引节点。VFS索引节点也称为动态节点。(即索引节点仅当文件被方位时才在内存中创建)
3>我们来深入下来看一下它的内核
它的定义在 /include/linux/fs.h中有这个结构体的定义
725struct inode {
726 struct hlist_node i_hash; //散列表
727 struct list_head i_list; //索引节点链表
728 struct list_head i_sb_list; //链接一个文件系统中所有inode的链表
729 struct list_head i_dentry; //目录项链表
730 unsigned long i_ino; //索引节点号
731 atomic_t i_count; //引用计数
732 unsigned int i_nlink; //硬连接数
733 uid_t i_uid; //使用者的id
734 gid_t i_gid; //使用组id
735 dev_t i_rdev; //实际设备标识符号
736 unsigned int i_blkbits;
737 u64 i_version; //版本号
738 loff_t i_size; //以字节为单位
739#ifdef __NEED_I_SIZE_ORDERED
740 seqcount_t i_size_seqcount;
741#endif
742 struct timespec i_atime; //最后访问时间
743 struct timespec i_mtime; //最后修改时间
744 struct timesp