ext4fs

EXT4

ext4 filesystem把磁盘分成一系列block groups,每一个group都有很多blocks.

  • block_size
    superblock中sb.sb.s_log_block_size 记载 (s_log_block_size 0=1K ,1=2K,2=4K)
    sb.sb.s_log_block_size默认值 =2 , 2 ^ (10 + sb.s_log_block_size) =4K

  • blocks_per_group blocks
    superblock中sb.s_blocks_per_group 记载
    默认值是 32,768 ,同时也等于 8 * block_size_in_bytes
    所以一个group = 128MiB

block

ext4 allocates storage space in units of “blocks”.
a block = a group of sectors between 1KiB and 64KiB, 必须是2的整数次幂

mkfs 时指定block的大小,通常是4Kbytes

Blocksize 1KiB 2KiB 4KiB 64KiB
Blocks 2^32 2^32 2^32 2^32
Inodes 2^32 2^32 2^32 2^32
File System Size 4TiB 8TiB 16TiB 256PiB
Blocks Per Block Group 8,192 16,384 32,768 524,288
Inodes Per Block Group 8,192 16,384 32,768 524,288
Block Group Size 8MiB 32MiB 128MiB 32GiB

在这里插入图片描述
group的布局

Group 0 Padding ext4 Super Block Group Descriptors Reserved GDT Blocks Data Block Bitmap inode Bitmap inode Table Data Blocks
1024 bytes 1 block many blocks many blocks 1 block 1 block many blocks many more blocks
group 0

the first 1024 bytes are unused, 可以用作boot。
接下来可能存放supper block

layout

super_block和Group Descriptors 存在与group 0,但是另外一些group 也有备份。
对于没有备份的group就是Data Block Bitmap开头。
Reserve GDT blocks是预留用于将来扩展文件系统, mkfs时产生。

super_block

EXT4 大小1024bytes
如果blocksize 1K , super_block存放在group1
如果blocksize大于1K ,super_block group0 第一个block的1024后面

如果设置sparse_super特性标志,super_block和Group Descriptors的冗余备份仅备份在编号为0或3、5、7的幂次方的块组。
如果没有设置,则每一个group都有super_block。

struct ext4_super_block {
   
		//inode 数目
/*00*/  __le32  s_inodes_count;         /* Inodes count */
		//blocks 数目
        __le32  s_blocks_count_lo;      /* Blocks count */
        //reseverd block数目
        __le32  s_r_blocks_count_lo;    /* Reserved blocks count */
        __le32  s_free_blocks_count_lo; /* Free blocks count */
/*10*/  __le32  s_free_inodes_count;    /* Free inodes count */
        __le32  s_first_data_block;     /* First Data Block */
        //block 大小 2的power
        __le32  s_log_block_size;       /* Block size */
        //for Bigalloc
        __le32  s_log_cluster_size;     /* Allocation cluster size */
        //group里的block数目
/*20*/  __le32  s_blocks_per_group;     /* # Blocks per group */
        __le32  s_clusters_per_group;   /* # Clusters per group */
        __le32  s_inodes_per_group;     /* # Inodes per group */
        __le32  s_mtime;                /* Mount time */
/*30*/  __le32  s_wtime;                /* Write time */
        __le16  s_mnt_count;            /* Mount count */
        //	mount次数,需要  fsck
        __le16  s_max_mnt_count;        /* Maximal mount count */
        //Magic: 0xEF53
        __le16  s_magic;                /* Magic signature */
        //状态: 1: 正常卸载, 2:出错 ,0:其他
        __le16  s_state;                /* File system state */
        //出错后动作,1:Continue 2:Remount read-only 3	:Panic
        __le16  s_errors;               /* Behaviour when detecting errors */
        __le16  s_minor_rev_level;      /* minor revision level */
/*40*/  __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 */
/*50*/  __le16  s_def_resuid;           /* Default uid for reserved blocks */
        __le16  s_def_resgid;           /* Default 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...
         */
        __le32  s_first_ino;            /* First non-reserved inode */
        //inode结构大小
        __le16  s_inode_size;           /* size of inode structure */
        //superblock在的group
        __le16  s_block_group_nr;       /* block group # of this superblock */
        //兼容特性
        __le32  s_feature_compat;       /* compatible feature set */
/*60*/  __le32  s_feature_incompat;     /* incompatible feature set */
        __le32  s_feature_ro_compat;    /* readonly-compatible feature set */
/*68*/  __u8    s_uuid[16];             /* 128-bit uuid for volume */
		//卷名
/*78*/  char    s_volume_name[16];      /* volume name */
	     //上次加载的目录
/*88*/  char    s_last_mounted[64];     /* directory where last mounted */
/*C8*/  __le32  s_algorithm_usage_bitmap; /* For compression */
        /*
         * Performance hints.  Directory preallocation should only
         * happen if the EXT4_FEATURE_COMPAT_DIR_PREALLOC flag is on.
         */
        __u8    s_prealloc_blocks;      /* Nr of blocks to try to preallocate*/
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值