ifork.rst 6.4 KB

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