ext2文件系统的数据结构,带你走进EXT文件系统族-Ext2文件系统
ext2文件系统的数据结构,带你走进EXT文件系统族-Ext2文件系统超级块超级块:超级块是文件系统的核心结构,保存了文件系统所有的特征数据。内核在装载文件系统时,最先看到的就是超级块的内容。使用ext2_super_block结构定义超级块。
一、学习内容1.Ext2物理结构
2.Ext2数据结构
3.Ext2文件系统操作
Ext2第二代扩展文件系统(Second extended Filesystem),是linux内核使用的文件系统
Ext2文件系统特性:
1.磁盘块分为组
2.支持快速符号链接
3.在启动时支持对文件系统的状态进行自动的一致性检查
4.Ext2索引节点中引入新的字段(块、删除逻辑、日志)
必须建立各种结构(在内核中定义为C语言数据类型),来存放文件系统的数据,包括文件内容、目录层次结构的表示、相关的管理数据(如访问权限与用户和组的关联),以及用于管理文件系统内部信息的元数据。这些对从块设备读取数据进行分析而言,都是必要的。这些结构的持久副本显然需要存储在硬盘上,这样数据再两次会话之间不会丢失。下一次启动重新激活内核时,数据仍然时可用的。因为硬盘和物理内存的需求不同,同一数据结构通常会有两个版本,一个用在磁盘上的持久存储,另一个用在内存中的处理。
Ext2文件系统专注于高性能
1.支持可变块长,使得文件系统能够处理预期的应用;
2.快速符号链接,如果链接目标的路径足够短,则将其存储在inode自身中;
3.将扩展能力集成到设计当中,从旧版本迁移到新版本时,无需重新格式化和重新加载硬盘;
4.Ext2有一个非常大的有点(与现代文件系统相比,Ext2文件系统的代码非常紧凑,使用不到10000行代码就足以实现了)。
块(block)的两个含义
1.有些文件系统存储在面向块的设备上,与设备之间的数据传输都以块为单位进行,不会传输单个字符。
2.Ext2文件系统是一种基于块的文件系统,他将硬盘分为若干块,每个块的长度都相同,按块管理元数据和文件内容。
块组
块组是该文件系统的基本成分,容纳文件系统其他结构,每个文件系统都由大量块组成,直接在硬盘上相继排列。
块组是Ext2文件系统的核心要素。块组是该文件系统的基本成分,容纳了文件系统的其他结构。
为什么Ext2文件系统允许这样浪费空间?有两个原因,可以证明提供额外的空间的做法是正确的。
1.如果系统崩溃破坏的超级块,有关文件系统结构和内容所有信息都会丢失。如果有冗余的副本,该信息是可能恢复的。
2.通过使文件和管理数据尽可能的接近,减少磁头寻道和旋转,这可以提高文件系统的性能。
超级块:用于存储文件系统自身元数据的核心结构,内核只使用第一个块组的超级块读取文件系统的元信息。
块描述符:包含的信息反映文件系统各个块组的状态,比如:块组中空闲块和inode数目,每个块组都包含了文件系统中所有块组的组描述符信息。
indoe表:包含块组中所有的inode,inode用于保存文件系统中与各个文件和目录相关的所有元数据。
数据块:包含文件系统中的文件的有用数据。
更多linux内核视频教程文档资料免费领取后台私信【内核】自行获取.
超级块
超级块:超级块是文件系统的核心结构,保存了文件系统所有的特征数据。内核在装载文件系统时,最先看到的就是超级块的内容。使用ext2_super_block结构定义超级块。
/*
* structure of the super block
*/
struct ext2_super_block {
__le32 s_inodes_count; /* Inodes count (inode数目)*/
__le32 s_blocks_count; /* Blocks count (块数目)*/
__le32 s_r_blocks_count; /* Reserved blocks count(已分配块的数目) */
__le32 s_free_blocks_count; /* Free blocks count (空闲块数目)*/
__le32 s_free_inodes_count; /* Free inodes count(空闲inode数目) */
__le32 s_first_data_block; /* First Data Block (第一个数据块)*/
__le32 s_log_block_size; /* Block size (块长度)*/
__le32 s_log_frag_size; /* Fragment size (碎片长度)*/
__le32 s_blocks_per_group; /* # Blocks per group (每个块组包含的块数)*/
__le32 s_frags_per_group; /* # Fragments per group (每个块包含的碎片)*/
__le32 s_inodes_per_group; /* # Inodes per group (每个块组的inode数目))*/
__le32 s_mtime; /* Mount time (装载时间)*/
__le32 s_wtime; /* Write time (写入时间)*/
__le16 s_mnt_count; /* Mount count (装载计数)*/
__le16 s_max_mnt_count; /* Maximal mount count (最大装载数)*/
__le16 s_magic; /* Magic signature (魔数,标记文件系统类型)*/
__le16 s_state; /* File system state (文件系统状态)*/
__le16 s_errors; /* Behaviour when detecting errors (检测到错误时的行为)*/
__le16 s_minor_rev_level; /* minor revision level (副修订号)*/
__le32 s_lastcheck; /* time of last check (上一次检查的时间)*/
__le32 s_checkinterval; /* max. time between checks (两次检查允许间隔的最长时间)*/
__le32 s_creator_os; /* OS (创建文件系统的操作系统)*/
__le32 s_rev_level; /* Revision level (修订号)*/
__le16 s_def_resuid; /* Default uid for reserved blocks (能够使用的保留块的默认uid)*/
__le16 s_def_resgid; /* Default gid for reserved blocks (能够使用保留块的默认GID)*/
/*
* These fields are for EXT2_DYNAMIC_REV superblocks only.
*
* Note: the difference between the compatible feature set and
* the incompatible feature set is that if there is a bit set
* in the incompatible feature set that the kernel doesn't
* know about it should refuse to mount the filesystem.
*
* e2fsck's requirements are more strict; if it doesn't know
* about a feature in either the compatible or incompatible
* feature set it must abort and not try to meddle with
* things it doesn't understand...
*/
__le32 s_first_ino; /* First non-reserved inode (第一个非保留的inode)*/
__le16 s_inode_size; /* size of inode structure (inode结构的长度)*/
__le16 s_block_group_nr; /* block group # of this superblock (当前超级块所在的块组编号)*/
__le32 s_feature_compat; /* compatible feature set 兼容特性集*/
__le32 s_feature_incompat; /* incompatible feature set 不兼容特性集*/
__le32 s_feature_ro_compat; /* readonly-compatible feature set 只读兼容特性集*/
__u8 s_uuid[16]; /* 128-bit uuid for volume 卷的128位的uuid*/
char s_volume_name[16]; /* volume name 卷名*/
char s_last_mounted[64]; /* directory where last mounted 上次装载的目录*/
__le32 s_algorithm_usage_bitmap; /* For compression 用于压缩*/
/*
* Performance hints. Directory preallocation should only
* happen if the EXT2_COMPAT_PREALLOC flag is on.
*/
__u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate(试图预分配的块数)*/
__u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs 试图为目录预分配的块数*/
__u16 s_padding1;
/*
* Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set.
*/
__u8 s_journal_uuid[16]; /* uuid of journal superblock */
__u32 s_journal_inum; /* inode number of journal file */
__u32 s_journal_dev; /* device number of journal file */
__u32 s_last_orphan; /* start of list of inodes to delete */
__u32 s_hash_seed[4]; /* HTREE hash seed */
__u8 s_def_hash_version; /* Default hash version to use */
__u8 s_reserved_char_pad;
__u16 s_reserved_word_pad;
__le32 s_default_mount_opts;
__le32 s_first_meta_bg; /* First metablock block group */
__u32 s_reserved[190]; /* Padding to the end of the block */
};