Ext4 超级块详解

转载:http://blog.csdn.net/sunlei0625/article/details/79011946

先上图:




The Super Block 

The superblock records various information about the enclosing filesystem, such as block counts, inode counts, supported features, maintenance information, and more.

If the sparse_super feature flag is set, redundant copies of the superblock and group descriptors are kept only in the groups whose group number is either 0 or a power of 3, 5, or 7. If the flag is not set, redundant copies are kept in all groups.

The superblock checksum is calculated against the superblock structure, which includes the FS UUID.

The ext4 superblock is laid out as follows in struct ext4_super_block:

OffsetSizeNameDescription
0x0__le32s_inodes_countTotal inode count.
0x4__le32s_blocks_count_loTotal block count.
0x8__le32s_r_blocks_count_loThis number of blocks can only be allocated by the super-user.
0xC__le32s_free_blocks_count_loFree block count.
0x10__le32s_free_inodes_countFree inode count.
0x14__le32s_first_data_blockFirst data block. This must be at least 1 for 1k-block filesystems and is typically 0 for all other block sizes.
0x18__le32s_log_block_sizeBlock size is 2 ^ (10 + s_log_block_size).
0x1C__le32s_log_cluster_sizeCluster size is (2 ^ s_log_cluster_size) blocks if bigalloc is enabled, zero otherwise.
0x20__le32s_blocks_per_groupBlocks per group.
0x24__le32s_clusters_per_groupClusters per group, if bigalloc is enabled.
0x28__le32s_inodes_per_groupInodes per group.
0x2C__le32s_mtimeMount time, in seconds since the epoch.
0x30__le32s_wtimeWrite time, in seconds since the epoch.
0x34__le16s_mnt_countNumber of mounts since the last fsck.
0x36__le16s_max_mnt_countNumber of mounts beyond which a fsck is needed.
0x38__le16s_magicMagic signature, 0xEF53
0x3A__le16s_stateFile system state. Valid values are:
0x0001Cleanly umounted
0x0002Errors detected
0x0004Orphans being recovered
0x3C__le16s_errorsBehaviour when detecting errors. One of:
1Continue
2Remount read-only
3Panic
0x3E__le16s_minor_rev_levelMinor revision level.
0x40__le32s_lastcheckTime of last check, in seconds since the epoch.
0x44__le32s_checkintervalMaximum time between checks, in seconds.
0x48__le32s_creator_osOS. One of:
0Linux
1Hurd
2Masix
3FreeBSD
4Lites
0x4C__le32s_rev_levelRevision level. One of:
0Original format
1v2 format w/ dynamic inode sizes
0x50__le16s_def_resuidDefault uid for reserved blocks.
0x52__le16s_def_resgidDefault gid for reserved blocks.
These fields are for EXT4_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...

0x54__le32s_first_inoFirst non-reserved inode.
0x58__le16s_inode_sizeSize of inode structure, in bytes.
0x5A__le16s_block_group_nrBlock group # of this superblock.
0x5C__le32s_feature_compatCompatible feature set flags. Kernel can still read/write this fs even if it doesn't understand a flag; fsck should not do that. Any of:
0x1Directory preallocation (COMPAT_DIR_PREALLOC).
0x2"imagic inodes". Not clear from the code what this does (COMPAT_IMAGIC_INODES).
0x4Has a journal (COMPAT_HAS_JOURNAL).
0x8Supports extended attributes (COMPAT_EXT_ATTR).
0x10Has reserved GDT blocks for filesystem expansion (COMPAT_RESIZE_INODE).
0x20Has directory indices (COMPAT_DIR_INDEX).
0x40"Lazy BG". Not in Linux kernel, seems to have been for uninitialized block groups? (COMPAT_LAZY_BG)
0x80"Exclude inode". Not used. (COMPAT_EXCLUDE_INODE).
0x100"Exclude bitmap". Seems to be used to indicate the presence of snapshot-related exclude bitmaps? Not defined in kernel or used in e2fsprogs (COMPAT_EXCLUDE_BITMAP).
0x200Sparse Super Block, v2. If this flag is set, the SB field s_backup_bgs points to the two block groups that contain backup superblocks (COMPAT_SPARSE_SUPER2).
0x60__le32s_feature_incompatIncompatible feature set. If the kernel or fsck doesn't understand one of these bits, it should stop. Any of:
0x1Compression (INCOMPAT_COMPRESSION).
0x2Directory entries record the file type. See ext4_dir_entry_2 below (INCOMPAT_FILETYPE).
0x4Filesystem needs recovery (INCOMPAT_RECOVER).
0x8Filesystem has a separate journal device (INCOMPAT_JOURNAL_DEV).
0x10Meta block groups. See the earlier discussion of this feature (INCOMPAT_META_BG).
0x40Files in this filesystem use extents (INCOMPAT_EXTENTS).
0x80Enable a filesystem size of 2^64 blocks (INCOMPAT_64BIT).
0x100Multiple mount protection. Not implemented (INCOMPAT_MMP).
0x200Flexible block groups. See the earlier discussion of this feature (INCOMPAT_FLEX_BG).
0x400Inodes can be used to store large extended attribute values (INCOMPAT_EA_INODE).
0x1000Data in directory entry (INCOMPAT_DIRDATA). (Not implemented?)
0x2000Metadata checksum seed is stored in the superblock. This feature enables the administrator to change the UUID of a metadata_csum filesystem while the filesystem is mounted; without it, the checksum definition requires all metadata blocks to be rewritten (INCOMPAT_CSUM_SEED).
0x4000Large directory >2GB or 3-level htree (INCOMPAT_LARGEDIR). Prior to this feature, directories could not be larger than 4GiB and could not have an htree more than 2 levels deep. If this feature is enabled, directories can be larger than 4GiB and have a maximum htree depth of 3.
0x8000Data in inode (INCOMPAT_INLINE_DATA).
0x10000Encrypted inodes are present on the filesystem. (INCOMPAT_ENCRYPT).
0x64__le32s_feature_ro_compatReadonly-compatible feature set. If the kernel doesn't understand one of these bits, it can still mount read-only. Any of:
0x1Sparse superblocks. See the earlier discussion of this feature (RO_COMPAT_SPARSE_SUPER).
0x2This filesystem has been used to store a file greater than 2GiB (RO_COMPAT_LARGE_FILE).
0x4Not used in kernel or e2fsprogs (RO_COMPAT_BTREE_DIR).
0x8This filesystem has files whose sizes are represented in units of logical blocks, not 512-byte sectors. This implies a very large file indeed! (RO_COMPAT_HUGE_FILE)
0x10Group descriptors have checksums. In addition to detecting corruption, this is useful for lazy formatting with uninitialized groups (RO_COMPAT_GDT_CSUM).
0x20Indicates that the old ext3 32,000 subdirectory limit no longer applies (RO_COMPAT_DIR_NLINK). A directory's i_links_count will be set to 1 if it is incremented past 64,999.
0x40Indicates that large inodes exist on this filesystem (RO_COMPAT_EXTRA_ISIZE).
0x80This filesystem has a snapshot (RO_COMPAT_HAS_SNAPSHOT).
0x100Quota (RO_COMPAT_QUOTA).
0x200This filesystem supports "bigalloc", which means that file extents are tracked in units of clusters (of blocks) instead of blocks (RO_COMPAT_BIGALLOC).
0x400This filesystem supports metadata checksumming. (RO_COMPAT_METADATA_CSUM; implies RO_COMPAT_GDT_CSUM, though GDT_CSUM must not be set)
0x800Filesystem supports replicas. This feature is neither in the kernel nor e2fsprogs. (RO_COMPAT_REPLICA)
0x1000Read-only filesystem image; the kernel will not mount this image read-write and most tools will refuse to write to the image. (RO_COMPAT_READONLY)
0x2000Filesystem tracks project quotas. (RO_COMPAT_PROJECT)
0x68__u8s_uuid[16]128-bit UUID for volume.
0x78chars_volume_name[16]Volume label.
0x88chars_last_mounted[64]Directory where filesystem was last mounted.
0xC8__le32s_algorithm_usage_bitmapFor compression (Not used in e2fsprogs/Linux)
Performance hints. Directory preallocation should only happen if the EXT4_FEATURE_COMPAT_DIR_PREALLOC flag is on.
0xCC__u8s_prealloc_blocks# of blocks to try to preallocate for ... files? (Not used in e2fsprogs/Linux)
0xCD__u8s_prealloc_dir_blocks# of blocks to preallocate for directories. (Not used in e2fsprogs/Linux)
0xCE__le16s_reserved_gdt_blocksNumber of reserved GDT entries for future filesystem expansion.
Journaling support valid if EXT4_FEATURE_COMPAT_HAS_JOURNAL set.
0xD0__u8s_journal_uuid[16]UUID of journal superblock
0xE0__le32s_journal_inuminode number of journal file.
0xE4__le32s_journal_devDevice number of journal file, if the external journal feature flag is set.
0xE8__le32s_last_orphanStart of list of orphaned inodes to delete.
0xEC__le32s_hash_seed[4]HTREE hash seed.
0xFC__u8s_def_hash_versionDefault hash algorithm to use for directory hashes. One of:
0x0Legacy.
0x1Half MD4.
0x2Tea.
0x3Legacy, unsigned.
0x4Half MD4, unsigned.
0x5Tea, unsigned.
0xFD__u8s_jnl_backup_typeIf this value is 0 or EXT3_JNL_BACKUP_BLOCKS (1), then the s_jnl_blocks field contains a duplicate copy of the inode's i_block[] array and i_size.
0xFE__le16s_desc_sizeSize of group descriptors, in bytes, if the 64bit incompat feature flag is set.
0x100__le32s_default_mount_optsDefault mount options. Any of:
0x0001Print debugging info upon (re)mount. (EXT4_DEFM_DEBUG)
0x0002New files take the gid of the containing directory (instead of the fsgid of the current process). (EXT4_DEFM_BSDGROUPS)
0x0004Support userspace-provided extended attributes. (EXT4_DEFM_XATTR_USER)
0x0008Support POSIX access control lists (ACLs). (EXT4_DEFM_ACL)
0x0010Do not support 32-bit UIDs. (EXT4_DEFM_UID16)
0x0020All data and metadata are commited to the journal. (EXT4_DEFM_JMODE_DATA)
0x0040All data are flushed to the disk before metadata are committed to the journal. (EXT4_DEFM_JMODE_ORDERED)
0x0060Data ordering is not preserved; data may be written after the metadata has been written. (EXT4_DEFM_JMODE_WBACK)
0x0100Disable write flushes. (EXT4_DEFM_NOBARRIER)
0x0200Track which blocks in a filesystem are metadata and therefore should not be used as data blocks. This option will be enabled by default on 3.18, hopefully. (EXT4_DEFM_BLOCK_VALIDITY)
0x0400Enable DISCARD support, where the storage device is told about blocks becoming unused. (EXT4_DEFM_DISCARD)
0x0800Disable delayed allocation. (EXT4_DEFM_NODELALLOC)
0x104__le32s_first_meta_bgFirst metablock block group, if the meta_bg feature is enabled.
0x108__le32s_mkfs_timeWhen the filesystem was created, in seconds since the epoch.
0x10C__le32s_jnl_blocks[17]Backup copy of the journal inode's i_block[] array in the first 15 elements and i_size_high and i_size in the 16th and 17th elements, respectively.
64bit support valid if EXT4_FEATURE_COMPAT_64BIT
0x150__le32s_blocks_count_hiHigh 32-bits of the block count.
0x154__le32s_r_blocks_count_hiHigh 32-bits of the reserved block count.
0x158__le32s_free_blocks_count_hiHigh 32-bits of the free block count.
0x15C__le16s_min_extra_isizeAll inodes have at least # bytes.
0x15E__le16s_want_extra_isizeNew inodes should reserve # bytes.
0x160__le32s_flagsMiscellaneous flags. Any of:
0x0001Signed directory hash in use.
0x0002Unsigned directory hash in use.
0x0004To test development code.
0x164__le16s_raid_strideRAID stride. This is the number of logical blocks read from or written to the disk before moving to the next disk. This affects the placement of filesystem metadata, which will hopefully make RAID storage faster.
0x166__le16s_mmp_interval# seconds to wait in multi-mount prevention (MMP) checking. In theory, MMP is a mechanism to record in the superblock which host and device have mounted the filesystem, in order to prevent multiple mounts. This feature does not seem to be implemented...
0x168__le64s_mmp_blockBlock # for multi-mount protection data.
0x170__le32s_raid_stripe_widthRAID stripe width. This is the number of logical blocks read from or written to the disk before coming back to the current disk. This is used by the block allocator to try to reduce the number of read-modify-write operations in a RAID5/6.
0x174__u8s_log_groups_per_flexSize of a flexible block group is 2 ^ s_log_groups_per_flex.
0x175__u8s_checksum_typeMetadata checksum algorithm type. The only valid value is 1 (crc32c).
0x176__le16s_reserved_pad 
0x178__le64s_kbytes_writtenNumber of KiB written to this filesystem over its lifetime.
0x180__le32s_snapshot_inuminode number of active snapshot. (Not used in e2fsprogs/Linux.)
0x184__le32s_snapshot_idSequential ID of active snapshot. (Not used in e2fsprogs/Linux.)
0x188__le64s_snapshot_r_blocks_countNumber of blocks reserved for active snapshot's future use. (Not used in e2fsprogs/Linux.)
0x190__le32s_snapshot_listinode number of the head of the on-disk snapshot list. (Not used in e2fsprogs/Linux.)
0x194__le32s_error_countNumber of errors seen.
0x198__le32s_first_error_timeFirst time an error happened, in seconds since the epoch.
0x19C__le32s_first_error_inoinode involved in first error.
0x1A0__le64s_first_error_blockNumber of block involved of first error.
0x1A8__u8s_first_error_func[32]Name of function where the error happened.
0x1C8__le32s_first_error_lineLine number where error happened.
0x1CC__le32s_last_error_timeTime of most recent error, in seconds since the epoch.
0x1D0__le32s_last_error_inoinode involved in most recent error.
0x1D4__le32s_last_error_lineLine number where most recent error happened.
0x1D8__le64s_last_error_blockNumber of block involved in most recent error.
0x1E0__u8s_last_error_func[32]Name of function where the most recent error happened.
0x200__u8s_mount_opts[64]ASCIIZ string of mount options.
0x240__le32s_usr_quota_inumInode number of user quota file.
0x244__le32s_grp_quota_inumInode number of group quota file.
0x248__le32s_overhead_blocksOverhead blocks/clusters in fs. (Huh? This field is always zero, which means that the kernel calculates it dynamically.)
0x24C__le32s_backup_bgs[2]Block groups containing superblock backups (if sparse_super2)
0x254__u8s_encrypt_algos[4]Encryption algorithms in use. There can be up to four algorithms in use at any time; valid algorithm codes are given below:
0Invalid algorithm (ENCRYPTION_MODE_INVALID).
1256-bit AES in XTS mode (ENCRYPTION_MODE_AES_256_XTS).
2256-bit AES in GCM mode (ENCRYPTION_MODE_AES_256_GCM).
3256-bit AES in CBC mode (ENCRYPTION_MODE_AES_256_CBC).
0x258__u8s_encrypt_pw_salt[16]Salt for the string2key algorithm for encryption.
0x268__le32s_lpf_inoInode number of lost+found
0x26C__le32s_prj_quota_inumInode that tracks project quotas.
0x270__le32s_checksum_seedChecksum seed used for metadata_csum calculations. This value is crc32c(~0, $orig_fs_uuid).
0x274__le32s_reserved[98]Padding to the end of the block.
0x3FC__le32s_checksumSuperblock checksum.

Total size is 1024 bytes.


  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值