^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) .. SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) The Contents of inode.i\_block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) ------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) Depending on the type of file an inode describes, the 60 bytes of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) storage in ``inode.i_block`` can be used in different ways. In general,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) regular files and directories will use it for file block indexing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) information, and special files will use it for special purposes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) Symbolic Links
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) ~~~~~~~~~~~~~~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) The target of a symbolic link will be stored in this field if the target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) string is less than 60 bytes long. Otherwise, either extents or block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) maps will be used to allocate data blocks to store the link target.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) Direct/Indirect Block Addressing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) In ext2/3, file block numbers were mapped to logical block numbers by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) means of an (up to) three level 1-1 block map. To find the logical block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) that stores a particular file block, the code would navigate through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) this increasingly complicated structure. Notice that there is neither a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) magic number nor a checksum to provide any level of confidence that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) block isn't full of garbage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) .. ifconfig:: builder != 'latex'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) .. include:: blockmap.rst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) .. ifconfig:: builder == 'latex'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) [Table omitted because LaTeX doesn't support nested tables.]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) Note that with this block mapping scheme, it is necessary to fill out a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) lot of mapping data even for a large contiguous file! This inefficiency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) led to the creation of the extent mapping scheme, discussed below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) Notice also that a file using this mapping scheme cannot be placed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) higher than 2^32 blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) Extent Tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) ~~~~~~~~~~~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) In ext4, the file to logical block map has been replaced with an extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) tree. Under the old scheme, allocating a contiguous run of 1,000 blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) requires an indirect block to map all 1,000 entries; with extents, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) mapping is reduced to a single ``struct ext4_extent`` with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) ``ee_len = 1000``. If flex\_bg is enabled, it is possible to allocate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) very large files with a single extent, at a considerable reduction in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) metadata block use, and some improvement in disk efficiency. The inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) must have the extents flag (0x80000) flag set for this feature to be in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) Extents are arranged as a tree. Each node of the tree begins with a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) ``struct ext4_extent_header``. If the node is an interior node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) (``eh.eh_depth`` > 0), the header is followed by ``eh.eh_entries``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) instances of ``struct ext4_extent_idx``; each of these index entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) points to a block containing more nodes in the extent tree. If the node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) is a leaf node (``eh.eh_depth == 0``), then the header is followed by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ``eh.eh_entries`` instances of ``struct ext4_extent``; these instances
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) point to the file's data blocks. The root node of the extent tree is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) stored in ``inode.i_block``, which allows for the first four extents to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) be recorded without the use of extra metadata blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) The extent tree header is recorded in ``struct ext4_extent_header``,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) which is 12 bytes long:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) .. list-table::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) :widths: 8 8 24 40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) :header-rows: 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * - Offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) - Size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) - Name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) - Description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * - 0x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) - \_\_le16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) - eh\_magic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) - Magic number, 0xF30A.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * - 0x2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) - \_\_le16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) - eh\_entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) - Number of valid entries following the header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * - 0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) - \_\_le16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) - eh\_max
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) - Maximum number of entries that could follow the header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * - 0x6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) - \_\_le16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) - eh\_depth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) - Depth of this extent node in the extent tree. 0 = this extent node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) points to data blocks; otherwise, this extent node points to other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) extent nodes. The extent tree can be at most 5 levels deep: a logical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) block number can be at most ``2^32``, and the smallest ``n`` that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) satisfies ``4*(((blocksize - 12)/12)^n) >= 2^32`` is 5.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * - 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) - \_\_le32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) - eh\_generation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) - Generation of the tree. (Used by Lustre, but not standard ext4).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) Internal nodes of the extent tree, also known as index nodes, are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) recorded as ``struct ext4_extent_idx``, and are 12 bytes long:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) .. list-table::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) :widths: 8 8 24 40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) :header-rows: 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * - Offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) - Size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) - Name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) - Description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * - 0x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) - \_\_le32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) - ei\_block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) - This index node covers file blocks from 'block' onward.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * - 0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) - \_\_le32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) - ei\_leaf\_lo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) - Lower 32-bits of the block number of the extent node that is the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) level lower in the tree. The tree node pointed to can be either another
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) internal node or a leaf node, described below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * - 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) - \_\_le16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) - ei\_leaf\_hi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) - Upper 16-bits of the previous field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * - 0xA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) - \_\_u16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) - ei\_unused
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) Leaf nodes of the extent tree are recorded as ``struct ext4_extent``,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) and are also 12 bytes long:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) .. list-table::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) :widths: 8 8 24 40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) :header-rows: 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * - Offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) - Size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) - Name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) - Description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * - 0x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) - \_\_le32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) - ee\_block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) - First file block number that this extent covers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * - 0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) - \_\_le16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) - ee\_len
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) - Number of blocks covered by extent. If the value of this field is <=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 32768, the extent is initialized. If the value of the field is > 32768,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) the extent is uninitialized and the actual extent length is ``ee_len`` -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 32768. Therefore, the maximum length of a initialized extent is 32768
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) blocks, and the maximum length of an uninitialized extent is 32767.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * - 0x6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) - \_\_le16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) - ee\_start\_hi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) - Upper 16-bits of the block number to which this extent points.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * - 0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) - \_\_le32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) - ee\_start\_lo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) - Lower 32-bits of the block number to which this extent points.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) Prior to the introduction of metadata checksums, the extent header +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) extent entries always left at least 4 bytes of unallocated space at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) end of each extent tree data block (because (2^x % 12) >= 4). Therefore,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) the 32-bit checksum is inserted into this space. The 4 extents in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) inode do not need checksumming, since the inode is already checksummed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) The checksum is calculated against the FS UUID, the inode number, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) inode generation, and the entire extent block leading up to (but not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) including) the checksum itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) ``struct ext4_extent_tail`` is 4 bytes long:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) .. list-table::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) :widths: 8 8 24 40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) :header-rows: 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * - Offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) - Size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) - Name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) - Description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * - 0x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) - \_\_le32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) - eb\_checksum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) - Checksum of the extent block, crc32c(uuid+inum+igeneration+extentblock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) Inline Data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) ~~~~~~~~~~~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) If the inline data feature is enabled for the filesystem and the flag is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) set for the inode, it is possible that the first 60 bytes of the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) data are stored here.