xref: /openbmc/linux/Documentation/filesystems/ext4/ifork.rst (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
18a98ec7cSDarrick J. Wong.. SPDX-License-Identifier: GPL-2.0
28a98ec7cSDarrick J. Wong
3*3103084aSWang JianjianThe Contents of inode.i_block
48a98ec7cSDarrick J. Wong------------------------------
58a98ec7cSDarrick J. Wong
68a98ec7cSDarrick J. WongDepending on the type of file an inode describes, the 60 bytes of
78a98ec7cSDarrick J. Wongstorage in ``inode.i_block`` can be used in different ways. In general,
88a98ec7cSDarrick J. Wongregular files and directories will use it for file block indexing
98a98ec7cSDarrick J. Wonginformation, and special files will use it for special purposes.
108a98ec7cSDarrick J. Wong
118a98ec7cSDarrick J. WongSymbolic Links
128a98ec7cSDarrick J. Wong~~~~~~~~~~~~~~
138a98ec7cSDarrick J. Wong
148a98ec7cSDarrick J. WongThe target of a symbolic link will be stored in this field if the target
158a98ec7cSDarrick J. Wongstring is less than 60 bytes long. Otherwise, either extents or block
168a98ec7cSDarrick J. Wongmaps will be used to allocate data blocks to store the link target.
178a98ec7cSDarrick J. Wong
188a98ec7cSDarrick J. WongDirect/Indirect Block Addressing
198a98ec7cSDarrick J. Wong~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
208a98ec7cSDarrick J. Wong
218a98ec7cSDarrick J. WongIn ext2/3, file block numbers were mapped to logical block numbers by
228a98ec7cSDarrick J. Wongmeans of an (up to) three level 1-1 block map. To find the logical block
238a98ec7cSDarrick J. Wongthat stores a particular file block, the code would navigate through
248a98ec7cSDarrick J. Wongthis increasingly complicated structure. Notice that there is neither a
258a98ec7cSDarrick J. Wongmagic number nor a checksum to provide any level of confidence that the
268a98ec7cSDarrick J. Wongblock isn't full of garbage.
278a98ec7cSDarrick J. Wong
288a98ec7cSDarrick J. Wong.. ifconfig:: builder != 'latex'
298a98ec7cSDarrick J. Wong
308a98ec7cSDarrick J. Wong   .. include:: blockmap.rst
318a98ec7cSDarrick J. Wong
328a98ec7cSDarrick J. Wong.. ifconfig:: builder == 'latex'
338a98ec7cSDarrick J. Wong
348a98ec7cSDarrick J. Wong   [Table omitted because LaTeX doesn't support nested tables.]
358a98ec7cSDarrick J. Wong
368a98ec7cSDarrick J. WongNote that with this block mapping scheme, it is necessary to fill out a
378a98ec7cSDarrick J. Wonglot of mapping data even for a large contiguous file! This inefficiency
388a98ec7cSDarrick J. Wongled to the creation of the extent mapping scheme, discussed below.
398a98ec7cSDarrick J. Wong
408a98ec7cSDarrick J. WongNotice also that a file using this mapping scheme cannot be placed
418a98ec7cSDarrick J. Wonghigher than 2^32 blocks.
428a98ec7cSDarrick J. Wong
438a98ec7cSDarrick J. WongExtent Tree
448a98ec7cSDarrick J. Wong~~~~~~~~~~~
458a98ec7cSDarrick J. Wong
468a98ec7cSDarrick J. WongIn ext4, the file to logical block map has been replaced with an extent
478a98ec7cSDarrick J. Wongtree. Under the old scheme, allocating a contiguous run of 1,000 blocks
488a98ec7cSDarrick J. Wongrequires an indirect block to map all 1,000 entries; with extents, the
498a98ec7cSDarrick J. Wongmapping is reduced to a single ``struct ext4_extent`` with
50*3103084aSWang Jianjian``ee_len = 1000``. If flex_bg is enabled, it is possible to allocate
518a98ec7cSDarrick J. Wongvery large files with a single extent, at a considerable reduction in
528a98ec7cSDarrick J. Wongmetadata block use, and some improvement in disk efficiency. The inode
538a98ec7cSDarrick J. Wongmust have the extents flag (0x80000) flag set for this feature to be in
548a98ec7cSDarrick J. Wonguse.
558a98ec7cSDarrick J. Wong
568a98ec7cSDarrick J. WongExtents are arranged as a tree. Each node of the tree begins with a
578a98ec7cSDarrick J. Wong``struct ext4_extent_header``. If the node is an interior node
588a98ec7cSDarrick J. Wong(``eh.eh_depth`` > 0), the header is followed by ``eh.eh_entries``
598a98ec7cSDarrick J. Wonginstances of ``struct ext4_extent_idx``; each of these index entries
608a98ec7cSDarrick J. Wongpoints to a block containing more nodes in the extent tree. If the node
618a98ec7cSDarrick J. Wongis a leaf node (``eh.eh_depth == 0``), then the header is followed by
628a98ec7cSDarrick J. Wong``eh.eh_entries`` instances of ``struct ext4_extent``; these instances
638a98ec7cSDarrick J. Wongpoint to the file's data blocks. The root node of the extent tree is
648a98ec7cSDarrick J. Wongstored in ``inode.i_block``, which allows for the first four extents to
658a98ec7cSDarrick J. Wongbe recorded without the use of extra metadata blocks.
668a98ec7cSDarrick J. Wong
678a98ec7cSDarrick J. WongThe extent tree header is recorded in ``struct ext4_extent_header``,
688a98ec7cSDarrick J. Wongwhich is 12 bytes long:
698a98ec7cSDarrick J. Wong
708a98ec7cSDarrick J. Wong.. list-table::
718a98ec7cSDarrick J. Wong   :widths: 8 8 24 40
728a98ec7cSDarrick J. Wong   :header-rows: 1
738a98ec7cSDarrick J. Wong
748a98ec7cSDarrick J. Wong   * - Offset
758a98ec7cSDarrick J. Wong     - Size
768a98ec7cSDarrick J. Wong     - Name
778a98ec7cSDarrick J. Wong     - Description
788a98ec7cSDarrick J. Wong   * - 0x0
79*3103084aSWang Jianjian     - __le16
80*3103084aSWang Jianjian     - eh_magic
818a98ec7cSDarrick J. Wong     - Magic number, 0xF30A.
828a98ec7cSDarrick J. Wong   * - 0x2
83*3103084aSWang Jianjian     - __le16
84*3103084aSWang Jianjian     - eh_entries
858a98ec7cSDarrick J. Wong     - Number of valid entries following the header.
868a98ec7cSDarrick J. Wong   * - 0x4
87*3103084aSWang Jianjian     - __le16
88*3103084aSWang Jianjian     - eh_max
898a98ec7cSDarrick J. Wong     - Maximum number of entries that could follow the header.
908a98ec7cSDarrick J. Wong   * - 0x6
91*3103084aSWang Jianjian     - __le16
92*3103084aSWang Jianjian     - eh_depth
938a98ec7cSDarrick J. Wong     - Depth of this extent node in the extent tree. 0 = this extent node
948a98ec7cSDarrick J. Wong       points to data blocks; otherwise, this extent node points to other
958a98ec7cSDarrick J. Wong       extent nodes. The extent tree can be at most 5 levels deep: a logical
968a98ec7cSDarrick J. Wong       block number can be at most ``2^32``, and the smallest ``n`` that
978a98ec7cSDarrick J. Wong       satisfies ``4*(((blocksize - 12)/12)^n) >= 2^32`` is 5.
988a98ec7cSDarrick J. Wong   * - 0x8
99*3103084aSWang Jianjian     - __le32
100*3103084aSWang Jianjian     - eh_generation
1018a98ec7cSDarrick J. Wong     - Generation of the tree. (Used by Lustre, but not standard ext4).
1028a98ec7cSDarrick J. Wong
1038a98ec7cSDarrick J. WongInternal nodes of the extent tree, also known as index nodes, are
1048a98ec7cSDarrick J. Wongrecorded as ``struct ext4_extent_idx``, and are 12 bytes long:
1058a98ec7cSDarrick J. Wong
1068a98ec7cSDarrick J. Wong.. list-table::
1078a98ec7cSDarrick J. Wong   :widths: 8 8 24 40
1088a98ec7cSDarrick J. Wong   :header-rows: 1
1098a98ec7cSDarrick J. Wong
1108a98ec7cSDarrick J. Wong   * - Offset
1118a98ec7cSDarrick J. Wong     - Size
1128a98ec7cSDarrick J. Wong     - Name
1138a98ec7cSDarrick J. Wong     - Description
1148a98ec7cSDarrick J. Wong   * - 0x0
115*3103084aSWang Jianjian     - __le32
116*3103084aSWang Jianjian     - ei_block
1178a98ec7cSDarrick J. Wong     - This index node covers file blocks from 'block' onward.
1188a98ec7cSDarrick J. Wong   * - 0x4
119*3103084aSWang Jianjian     - __le32
120*3103084aSWang Jianjian     - ei_leaf_lo
1218a98ec7cSDarrick J. Wong     - Lower 32-bits of the block number of the extent node that is the next
1228a98ec7cSDarrick J. Wong       level lower in the tree. The tree node pointed to can be either another
1238a98ec7cSDarrick J. Wong       internal node or a leaf node, described below.
1248a98ec7cSDarrick J. Wong   * - 0x8
125*3103084aSWang Jianjian     - __le16
126*3103084aSWang Jianjian     - ei_leaf_hi
1278a98ec7cSDarrick J. Wong     - Upper 16-bits of the previous field.
1288a98ec7cSDarrick J. Wong   * - 0xA
129*3103084aSWang Jianjian     - __u16
130*3103084aSWang Jianjian     - ei_unused
1318a98ec7cSDarrick J. Wong     -
1328a98ec7cSDarrick J. Wong
1338a98ec7cSDarrick J. WongLeaf nodes of the extent tree are recorded as ``struct ext4_extent``,
1348a98ec7cSDarrick J. Wongand are also 12 bytes long:
1358a98ec7cSDarrick J. Wong
1368a98ec7cSDarrick J. Wong.. list-table::
1378a98ec7cSDarrick J. Wong   :widths: 8 8 24 40
1388a98ec7cSDarrick J. Wong   :header-rows: 1
1398a98ec7cSDarrick J. Wong
1408a98ec7cSDarrick J. Wong   * - Offset
1418a98ec7cSDarrick J. Wong     - Size
1428a98ec7cSDarrick J. Wong     - Name
1438a98ec7cSDarrick J. Wong     - Description
1448a98ec7cSDarrick J. Wong   * - 0x0
145*3103084aSWang Jianjian     - __le32
146*3103084aSWang Jianjian     - ee_block
1478a98ec7cSDarrick J. Wong     - First file block number that this extent covers.
1488a98ec7cSDarrick J. Wong   * - 0x4
149*3103084aSWang Jianjian     - __le16
150*3103084aSWang Jianjian     - ee_len
1518a98ec7cSDarrick J. Wong     - Number of blocks covered by extent. If the value of this field is <=
1528a98ec7cSDarrick J. Wong       32768, the extent is initialized. If the value of the field is > 32768,
1538a98ec7cSDarrick J. Wong       the extent is uninitialized and the actual extent length is ``ee_len`` -
1548a98ec7cSDarrick J. Wong       32768. Therefore, the maximum length of a initialized extent is 32768
1558a98ec7cSDarrick J. Wong       blocks, and the maximum length of an uninitialized extent is 32767.
1568a98ec7cSDarrick J. Wong   * - 0x6
157*3103084aSWang Jianjian     - __le16
158*3103084aSWang Jianjian     - ee_start_hi
1598a98ec7cSDarrick J. Wong     - Upper 16-bits of the block number to which this extent points.
1608a98ec7cSDarrick J. Wong   * - 0x8
161*3103084aSWang Jianjian     - __le32
162*3103084aSWang Jianjian     - ee_start_lo
1638a98ec7cSDarrick J. Wong     - Lower 32-bits of the block number to which this extent points.
1648a98ec7cSDarrick J. Wong
1658a98ec7cSDarrick J. WongPrior to the introduction of metadata checksums, the extent header +
1668a98ec7cSDarrick J. Wongextent entries always left at least 4 bytes of unallocated space at the
1678a98ec7cSDarrick J. Wongend of each extent tree data block (because (2^x % 12) >= 4). Therefore,
1688a98ec7cSDarrick J. Wongthe 32-bit checksum is inserted into this space. The 4 extents in the
1698a98ec7cSDarrick J. Wonginode do not need checksumming, since the inode is already checksummed.
1708a98ec7cSDarrick J. WongThe checksum is calculated against the FS UUID, the inode number, the
1718a98ec7cSDarrick J. Wonginode generation, and the entire extent block leading up to (but not
1728a98ec7cSDarrick J. Wongincluding) the checksum itself.
1738a98ec7cSDarrick J. Wong
1748a98ec7cSDarrick J. Wong``struct ext4_extent_tail`` is 4 bytes long:
1758a98ec7cSDarrick J. Wong
1768a98ec7cSDarrick J. Wong.. list-table::
1778a98ec7cSDarrick J. Wong   :widths: 8 8 24 40
1788a98ec7cSDarrick J. Wong   :header-rows: 1
1798a98ec7cSDarrick J. Wong
1808a98ec7cSDarrick J. Wong   * - Offset
1818a98ec7cSDarrick J. Wong     - Size
1828a98ec7cSDarrick J. Wong     - Name
1838a98ec7cSDarrick J. Wong     - Description
1848a98ec7cSDarrick J. Wong   * - 0x0
185*3103084aSWang Jianjian     - __le32
186*3103084aSWang Jianjian     - eb_checksum
1878a98ec7cSDarrick J. Wong     - Checksum of the extent block, crc32c(uuid+inum+igeneration+extentblock)
1888a98ec7cSDarrick J. Wong
1898a98ec7cSDarrick J. WongInline Data
1908a98ec7cSDarrick J. Wong~~~~~~~~~~~
1918a98ec7cSDarrick J. Wong
1928a98ec7cSDarrick J. WongIf the inline data feature is enabled for the filesystem and the flag is
1938a98ec7cSDarrick J. Wongset for the inode, it is possible that the first 60 bytes of the file
1948a98ec7cSDarrick J. Wongdata are stored here.
195