天天看点

ext4 笔记一(与ext3比较)一、磁盘布局对比二、节点表对比

E文详细介绍:https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout

整体来讲,是在ext3的基础上做了些改进。

下面来看看ext3与ext4的对比:

一、磁盘布局对比

ext4 笔记一(与ext3比较)一、磁盘布局对比二、节点表对比

ext4 中采用了元块组(metablock group)的概念。所谓元块组就是指块组描述符可以存储在一个数据块中的一些连续块组。仍然以 128MB 的块组(数据块为 4KB)为例,ext4 中每个元块组可以包括 4096 / 64 = 64 个块组,即每个元块组的大小是 64 * 128 MB = 8 GB。

二、节点表对比

索引节点结构并没有发生太大变化,不同之处在于最后添加了 5 个与时间有关的字段,这是为了提高时间戳的精度。

索引节点中的 i_block 字段保持不变,但是由于 extent 概念的引入,对于这个数组的使用方式已经改变了,其前 3 个元素一定是一个ext4_extent_header 结构,后续每 3 个元素可能是一个ext4_extent 或ext4_extent_idx 结构,这取决于所表示的文件的大小。这种设计可以有效地表示连续存放的大文件,

1、ext3中i_block字段使用

ext4 笔记一(与ext3比较)一、磁盘布局对比二、节点表对比
i.i_block Offset Where It Points
0 to 11 Direct map to file blocks 0 to 11.
12 Indirect block: (file blocks 12 to ($block_size / 4) + 11, or 12 to 1035 if 4KiB blocks)
Indirect Block Offset Where It Points
0 to ($block_size / 4) Direct map to ($block_size / 4) blocks (1024 if 4KiB blocks)
13 Double-indirect block: (file blocks $block_size/4 + 12 to ($block_size / 4) ^ 2 + ($block_size / 4) + 11, or 1036 to 1049611 if 4KiB blocks)
Double Indirect Block Offset Where It Points
0 to ($block_size / 4) Map to ($block_size / 4) indirect blocks (1024 if 4KiB blocks)
Indirect Block Offset Where It Points
0 to ($block_size / 4) Direct map to ($block_size / 4) blocks (1024 if 4KiB blocks)
14 Triple-indirect block: (file blocks ($block_size / 4) ^ 2 + ($block_size / 4) + 11 to ($block_size / 4) ^ 3 + $block_size / 4) ^ 2 + ($block_size / 4) + 12, or 1049611 to 1074791436 if 4KiB blocks)
Triple Indirect Block Offset Where It Points
0 to ($block_size / 4) Map to ($block_size / 4) double indirect blocks (1024 if 4KiB blocks)
Double Indirect Block Offset Where It Points
0 to ($block_size / 4) Map to ($block_size / 4) indirect blocks (1024 if 4KiB blocks)
Indirect Block Offset Where It Points
0 to ($block_size / 4) Direct map to ($block_size / 4) blocks (1024 if 4KiB blocks)

2、ext4中i_block字段使用

Ext4在ext3的基础上增加了extern取代了ext3的直接、间接、二级间接和三级间接块的形式来定位磁盘中的数据块

ext4 笔记一(与ext3比较)一、磁盘布局对比二、节点表对比

其中相关结构体如下:

/*
  * This is the extent on-disk structure.
  * It's used at the bottom of the tree.
  */
 struct ext4_extent {
         __le32  ee_block;       /* first logical block extent covers */
         __le16  ee_len;         /* number of blocks covered by extent */
         __le16  ee_start_hi;    /* high 16 bits of physical block */
         __le32  ee_start;       /* low 32 bits of physical block */
 };
 
 /*
  * This is index on-disk structure.
  * It's used at all the levels except the bottom.
  */
 struct ext4_extent_idx {
         __le32  ei_block;       /* index covers logical blocks from 'block' */
         __le32  ei_leaf;        /* pointer to the physical block of the next *
                                  * level. leaf or next index could be there */
         __le16  ei_leaf_hi;     /* high 16 bits of physical block */
         __u16   ei_unused;
 };
 
 /*
  * Each block (leaves and indexes), even inode-stored has header.
  */
 struct ext4_extent_header {
         __le16  eh_magic;       /* probably will support different formats */
         __le16  eh_entries;     /* number of valid entries */
         __le16  eh_max;         /* capacity of store in entries */
         __le16  eh_depth;       /* has tree real underlying blocks? */
         __le32  eh_generation;  /* generation of the tree */
};