一个超级块对应一个文件系统**(已经安装的文件系统类型如ext2,此处是实际的文件系统哦,不是VFS)。
之前我们已经说了文件系统用于管理这些文件的数据格式和操作之类的,系统文件有系统文件自己的文件系统,同时对于不同的磁盘分区也有可以是不同的文件系统。那么一个超级块对于一个独立的文件系统。保存文件系统的类型、大小、状态等等。
(“文件系统”和“文件系统类型”不一样!一个文件系统类型下可以包括很多文件系统即很多的super_block)
(linux内核2.4.37)
struct super_block {746 struct list_head s_list; /* Keep this first */747 kdev_t s_dev;748 unsigned long s_blocksize;749 unsigned char s_blocksize_bits;750 unsigned char s_dirt;751 unsigned long long s_maxbytes; /* Max file size */752 struct file_system_type *s_type;753 struct super_operations *s_op;754 struct dquot_operations *dq_op;755 struct quotactl_ops *s_qcop;756 unsigned long s_flags;757 unsigned long s_magic;758 struct dentry *s_root;759 struct rw_semaphore s_umount;760 struct semaphore s_lock;761 int s_count;762 atomic_t s_active;763764 struct list_head s_dirty; /* dirty inodes */765 struct list_head s_locked_inodes;/* inodes being synced */766 struct list_head s_files;767768 struct block_device *s_bdev;769 struct list_head s_instances;770 struct quota_info s_dquot; /* Diskquota specific options */771772 union {773 struct minix_sb_info minix_sb;774 struct ext2_sb_info ext2_sb;775 struct ext3_sb_info ext3_sb;776 struct hpfs_sb_info hpfs_sb;777 struct ntfs_sb_info ntfs_sb;778 struct msdos_sb_info msdos_sb;779 struct isofs_sb_info isofs_sb;780 struct nfs_sb_info nfs_sb;781 struct sysv_sb_info sysv_sb;782 struct affs_sb_info affs_sb;783 struct ufs_sb_info ufs_sb;784 struct efs_sb_info efs_sb;785 struct shmem_sb_info shmem_sb;786 struct romfs_sb_info romfs_sb;787 struct smb_sb_info smbfs_sb;788 struct hfs_sb_info hfs_sb;789 struct adfs_sb_info adfs_sb;790 struct qnx4_sb_info qnx4_sb;791 struct reiserfs_sb_info reiserfs_sb;792 struct bfs_sb_info bfs_sb;793 struct udf_sb_info udf_sb;794 struct ncp_sb_info ncpfs_sb;795 struct usbdev_sb_info usbdevfs_sb;796 struct jffs2_sb_info jffs2_sb;797 struct cramfs_sb_info cramfs_sb;798 void *generic_sbp;799 } u;800 /*801 * The next field is for VFS *only*. No filesystems have any business802 * even looking at it. You had been warned.803 */804 struct semaphore s_vfs_rename_sem; /* Kludge */805806 /* The next field is used by knfsd when converting a (inode number based)807 * file handle into a dentry. As it builds a path in the dcache tree from808 * the bottom up, there may for a time be a subpath of dentrys which is not809 * connected to the main tree. This semaphore ensure that there is only ever810 * one such free path per filesystem. Note that unconnected files (or other811 * non-directories) are allowed, but not unconnected diretories.812 */813 struct semaphore s_nfsd_free_path_sem;814 };
解释字段:
s_list:指向超级块链表的指针,这个struct list_head是很熟悉的结构了,里面其实就是用于连接关系的prev和next字段。
内核中的结构处理都是有讲究的(内核协议栈中也说过),内核单独使用一个简单的结构体将所有的super_block都链接起来,但是这个结构不是super_block本身,因为本身数据结构太大,效率不高,所有仅仅使用
struct
{
list_head prev;
list_head next;
}
这样的结构来将super_block中的s_list链接起来,那么遍历到s_list之后,直接读取super_block这么长的一个内存块,就可以将这个super_block直接读进来!这样就很快捷方便!这也是为什么s_list必须放在第一个字段的原因。
s_dev:包含该具体文件系统的块设备标识符。例如,对于 /dev/hda1,其设备标识符为 0x301
s_blocksize:文件系统中数据块大小,以字节单位
s_blocksize_bits:上面的size大小占用位数,例如512字节就是9 bits
s_dirt:脏位,标识是否超级块被修改
s_maxbytes:允许的最大的文件大小(字节数)
struct file_system_type s_type:文件系统类型(也就是当前这个文件系统属于哪个类型?ext2还是fat32)
要区分“文件系统”和“文件系统类型”不一样!一个文件系统类型下可以包括很多文件系统即很多的super_block,后面会说!
struct super_operations s_op:指向某个特定的具体文件系统的用于超级块操作的函数集合
struct dquot_operations dq_op:指向某个特定的具体文件系统用于限额操作的函数集合
struct quotactl_ops s_qcop:用于配置磁盘限额的的方法,处理来自用户空间的请求
s_flags:安装标识
s_magic:区别于其他文件系统的标识
s_root:指向该具体文件系统安装目录的目录项
s_umount:对超级块读写时进行同步
s_lock:锁标志位,若置该位,则其它进程不能对该超级块操作
s_count:对超级块的使用计数
s_active:引用计数
s_dirty:已修改的索引节点inode形成的链表,一个文件系统中有很多的inode,有些inode节点的内容会被修改,那么会先被记录,然后写回磁盘。
s_locked_inodes:要进行同步的索引节点形成的链表
s_files:所有的已经打开文件的链表,这个file和实实在在的进程相关的
s_bdev:指向文件系统被安装的块设备
u:u 联合体域包括属于具体文件系统的超级块信息
s_instances:具体的意义后来会说的!(同一类型的文件系统通过这个子墩将所有的super_block连接起来)
s_dquot:磁盘限额相关选项
