<!DOCTYPE html>
<html lang="en" data-content_root="../../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>4.2. The Contents of inode.i_block — The Linux Kernel documentation</title>
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=fa44fd50" />
<link rel="stylesheet" type="text/css" href="../../_static/alabaster.css?v=3918102e" />
<script src="../../_static/documentation_options.js?v=5929fcd5"></script>
<script src="../../_static/doctools.js?v=9bcbadda"></script>
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
<link rel="next" title="4.3. Directory Entries" href="directory.html" />
<link rel="prev" title="4.1. Index Nodes" href="inodes.html" />
<link rel="stylesheet" href="../../_static/custom.css" type="text/css" />
</head><body>
<div class="document">
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="../../index.html">
<img class="logo" src="../../_static/logo.svg" alt="Logo of The Linux Kernel"/>
</a></p>
<h1 class="logo"><a href="../../index.html">The Linux Kernel</a></h1>
<p class="blurb">6.18.50</p>
<search id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
<input type="submit" value="Go" />
</form>
</div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>
<p>
<h3 class="kernel-toc-contents">Contents</h3>
<input type="checkbox" class="kernel-toc-toggle" id = "kernel-toc-toggle" checked>
<label class="kernel-toc-title" for="kernel-toc-toggle"></label>
<div class="kerneltoc" id="kerneltoc">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../process/development-process.html">Development process</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../process/submitting-patches.html">Submitting patches</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../process/code-of-conduct.html">Code of conduct</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../maintainer/index.html">Maintainer handbook</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../process/index.html">All development-process docs</a></li>
</ul>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../core-api/index.html">Core API</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../driver-api/index.html">Driver APIs</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../../subsystem-apis.html">Subsystems</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../../subsystem-apis.html#core-subsystems">Core subsystems</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../subsystem-apis.html#human-interfaces">Human interfaces</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../subsystem-apis.html#networking-interfaces">Networking interfaces</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../../subsystem-apis.html#storage-interfaces">Storage interfaces</a><ul class="current">
<li class="toctree-l3 current"><a class="reference internal" href="../index.html">Filesystems in the Linux kernel</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../block/index.html">Block</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../cdrom/index.html">CD-ROM</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../scsi/index.html">SCSI Subsystem</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../target/index.html">TCM Virtual Device</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../nvme/index.html">NVMe Subsystem</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../subsystem-apis.html#other-subsystems">Other subsystems</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../locking/index.html">Locking</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../process/license-rules.html">Licensing rules</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../doc-guide/index.html">Writing documentation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev-tools/index.html">Development tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev-tools/testing-overview.html">Testing guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../kernel-hacking/index.html">Hacking guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../trace/index.html">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../fault-injection/index.html">Fault injection</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livepatch/index.html">Livepatching</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../rust/index.html">Rust</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../admin-guide/index.html">Administration</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../kbuild/index.html">Build system</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../admin-guide/reporting-issues.html">Reporting issues</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../tools/index.html">Userspace tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../userspace-api/index.html">Userspace API</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../firmware-guide/index.html">Firmware</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../devicetree/index.html">Firmware and Devicetree</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../arch/index.html">CPU architectures</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../staging/index.html">Unsorted documentation</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../translations/index.html">Translations</a></li>
</ul>
</div>
<script type="text/javascript"> <!--
var sbar = document.getElementsByClassName("sphinxsidebar")[0];
let currents = document.getElementsByClassName("current")
if (currents.length) {
sbar.scrollTop = currents[currents.length - 1].offsetTop;
}
--> </script>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../../_sources/filesystems/ext4/ifork.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
</div>
</div>
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="the-contents-of-inode-i-block">
<h1><span class="section-number">4.2. </span>The Contents of inode.i_block<a class="headerlink" href="#the-contents-of-inode-i-block" title="Link to this heading">¶</a></h1>
<p>Depending on the type of file an inode describes, the 60 bytes of
storage in <code class="docutils literal notranslate"><span class="pre">inode.i_block</span></code> can be used in different ways. In general,
regular files and directories will use it for file block indexing
information, and special files will use it for special purposes.</p>
<section id="symbolic-links">
<h2><span class="section-number">4.2.1. </span>Symbolic Links<a class="headerlink" href="#symbolic-links" title="Link to this heading">¶</a></h2>
<p>The target of a symbolic link will be stored in this field if the target
string is less than 60 bytes long. Otherwise, either extents or block
maps will be used to allocate data blocks to store the link target.</p>
</section>
<section id="direct-indirect-block-addressing">
<h2><span class="section-number">4.2.2. </span>Direct/Indirect Block Addressing<a class="headerlink" href="#direct-indirect-block-addressing" title="Link to this heading">¶</a></h2>
<p>In ext2/3, file block numbers were mapped to logical block numbers by
means of an (up to) three level 1-1 block map. To find the logical block
that stores a particular file block, the code would navigate through
this increasingly complicated structure. Notice that there is neither a
magic number nor a checksum to provide any level of confidence that the
block isn’t full of garbage.</p>
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>i.i_block Offset</p></th>
<th class="head"><p>Where It Points</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>0 to 11</p></td>
<td><p>Direct map to file blocks 0 to 11.</p></td>
</tr>
<tr class="row-odd"><td><p>12</p></td>
<td><p>Indirect block: (file blocks 12 to (<code class="docutils literal notranslate"><span class="pre">$block_size</span></code> / 4) + 11, or 12 to 1035 if 4KiB blocks)</p>
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Indirect Block Offset</p></th>
<th class="head"><p>Where It Points</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>0 to (<code class="docutils literal notranslate"><span class="pre">$block_size</span></code> / 4)</p></td>
<td><p>Direct map to (<code class="docutils literal notranslate"><span class="pre">$block_size</span></code> / 4) blocks (1024 if 4KiB blocks)</p></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr class="row-even"><td><p>13</p></td>
<td><p>Double-indirect block: (file blocks <code class="docutils literal notranslate"><span class="pre">$block_size</span></code>/4 + 12 to (<code class="docutils literal notranslate"><span class="pre">$block_size</span></code> / 4) ^ 2 + (<code class="docutils literal notranslate"><span class="pre">$block_size</span></code> / 4) + 11, or 1036 to 1049611 if 4KiB blocks)</p>
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Double Indirect Block Offset</p></th>
<th class="head"><p>Where It Points</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>0 to (<code class="docutils literal notranslate"><span class="pre">$block_size</span></code> / 4)</p></td>
<td><p>Map to (<code class="docutils literal notranslate"><span class="pre">$block_size</span></code> / 4) indirect blocks (1024 if 4KiB blocks)</p>
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Indirect Block Offset</p></th>
<th class="head"><p>Where It Points</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>0 to (<code class="docutils literal notranslate"><span class="pre">$block_size</span></code> / 4)</p></td>
<td><p>Direct map to (<code class="docutils literal notranslate"><span class="pre">$block_size</span></code> / 4) blocks (1024 if 4KiB blocks)</p></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr class="row-odd"><td><p>14</p></td>
<td><p>Triple-indirect block: (file blocks (<code class="docutils literal notranslate"><span class="pre">$block_size</span></code> / 4) ^ 2 + (<code class="docutils literal notranslate"><span class="pre">$block_size</span></code> / 4) + 12 to (<code class="docutils literal notranslate"><span class="pre">$block_size</span></code> / 4) ^ 3 + (<code class="docutils literal notranslate"><span class="pre">$block_size</span></code> / 4) ^ 2 + (<code class="docutils literal notranslate"><span class="pre">$block_size</span></code> / 4) + 12, or 1049612 to 1074791436 if 4KiB blocks)</p>
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Triple Indirect Block Offset</p></th>
<th class="head"><p>Where It Points</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>0 to (<code class="docutils literal notranslate"><span class="pre">$block_size</span></code> / 4)</p></td>
<td><p>Map to (<code class="docutils literal notranslate"><span class="pre">$block_size</span></code> / 4) double indirect blocks (1024 if 4KiB blocks)</p>
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Double Indirect Block Offset</p></th>
<th class="head"><p>Where It Points</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>0 to (<code class="docutils literal notranslate"><span class="pre">$block_size</span></code> / 4)</p></td>
<td><p>Map to (<code class="docutils literal notranslate"><span class="pre">$block_size</span></code> / 4) indirect blocks (1024 if 4KiB blocks)</p>
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Indirect Block Offset</p></th>
<th class="head"><p>Where It Points</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>0 to (<code class="docutils literal notranslate"><span class="pre">$block_size</span></code> / 4)</p></td>
<td><p>Direct map to (<code class="docutils literal notranslate"><span class="pre">$block_size</span></code> / 4) blocks (1024 if 4KiB blocks)</p></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>Note that with this block mapping scheme, it is necessary to fill out a
lot of mapping data even for a large contiguous file! This inefficiency
led to the creation of the extent mapping scheme, discussed below.</p>
<p>Notice also that a file using this mapping scheme cannot be placed
higher than 2^32 blocks.</p>
</section>
<section id="extent-tree">
<h2><span class="section-number">4.2.3. </span>Extent Tree<a class="headerlink" href="#extent-tree" title="Link to this heading">¶</a></h2>
<p>In ext4, the file to logical block map has been replaced with an extent
tree. Under the old scheme, allocating a contiguous run of 1,000 blocks
requires an indirect block to map all 1,000 entries; with extents, the
mapping is reduced to a single <code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">ext4_extent</span></code> with
<code class="docutils literal notranslate"><span class="pre">ee_len</span> <span class="pre">=</span> <span class="pre">1000</span></code>. If flex_bg is enabled, it is possible to allocate
very large files with a single extent, at a considerable reduction in
metadata block use, and some improvement in disk efficiency. The inode
must have the extents flag (0x80000) flag set for this feature to be in
use.</p>
<p>Extents are arranged as a tree. Each node of the tree begins with a
<code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">ext4_extent_header</span></code>. If the node is an interior node
(<code class="docutils literal notranslate"><span class="pre">eh.eh_depth</span></code> > 0), the header is followed by <code class="docutils literal notranslate"><span class="pre">eh.eh_entries</span></code>
instances of <code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">ext4_extent_idx</span></code>; each of these index entries
points to a block containing more nodes in the extent tree. If the node
is a leaf node (<code class="docutils literal notranslate"><span class="pre">eh.eh_depth</span> <span class="pre">==</span> <span class="pre">0</span></code>), then the header is followed by
<code class="docutils literal notranslate"><span class="pre">eh.eh_entries</span></code> instances of <code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">ext4_extent</span></code>; these instances
point to the file’s data blocks. The root node of the extent tree is
stored in <code class="docutils literal notranslate"><span class="pre">inode.i_block</span></code>, which allows for the first four extents to
be recorded without the use of extra metadata blocks.</p>
<p>The extent tree header is recorded in <code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">ext4_extent_header</span></code>,
which is 12 bytes long:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 10.0%" />
<col style="width: 10.0%" />
<col style="width: 30.0%" />
<col style="width: 50.0%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Offset</p></th>
<th class="head"><p>Size</p></th>
<th class="head"><p>Name</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>0x0</p></td>
<td><p>__le16</p></td>
<td><p>eh_magic</p></td>
<td><p>Magic number, 0xF30A.</p></td>
</tr>
<tr class="row-odd"><td><p>0x2</p></td>
<td><p>__le16</p></td>
<td><p>eh_entries</p></td>
<td><p>Number of valid entries following the header.</p></td>
</tr>
<tr class="row-even"><td><p>0x4</p></td>
<td><p>__le16</p></td>
<td><p>eh_max</p></td>
<td><p>Maximum number of entries that could follow the header.</p></td>
</tr>
<tr class="row-odd"><td><p>0x6</p></td>
<td><p>__le16</p></td>
<td><p>eh_depth</p></td>
<td><p>Depth of this extent node in the extent tree. 0 = this extent node
points to data blocks; otherwise, this extent node points to other
extent nodes. The extent tree can be at most 5 levels deep: a logical
block number can be at most <code class="docutils literal notranslate"><span class="pre">2^32</span></code>, and the smallest <code class="docutils literal notranslate"><span class="pre">n</span></code> that
satisfies <code class="docutils literal notranslate"><span class="pre">4*(((blocksize</span> <span class="pre">-</span> <span class="pre">12)/12)^n)</span> <span class="pre">>=</span> <span class="pre">2^32</span></code> is 5.</p></td>
</tr>
<tr class="row-even"><td><p>0x8</p></td>
<td><p>__le32</p></td>
<td><p>eh_generation</p></td>
<td><p>Generation of the tree. (Used by Lustre, but not standard ext4).</p></td>
</tr>
</tbody>
</table>
<p>Internal nodes of the extent tree, also known as index nodes, are
recorded as <code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">ext4_extent_idx</span></code>, and are 12 bytes long:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 10.0%" />
<col style="width: 10.0%" />
<col style="width: 30.0%" />
<col style="width: 50.0%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Offset</p></th>
<th class="head"><p>Size</p></th>
<th class="head"><p>Name</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>0x0</p></td>
<td><p>__le32</p></td>
<td><p>ei_block</p></td>
<td><p>This index node covers file blocks from ‘block’ onward.</p></td>
</tr>
<tr class="row-odd"><td><p>0x4</p></td>
<td><p>__le32</p></td>
<td><p>ei_leaf_lo</p></td>
<td><p>Lower 32-bits of the block number of the extent node that is the next
level lower in the tree. The tree node pointed to can be either another
internal node or a leaf node, described below.</p></td>
</tr>
<tr class="row-even"><td><p>0x8</p></td>
<td><p>__le16</p></td>
<td><p>ei_leaf_hi</p></td>
<td><p>Upper 16-bits of the previous field.</p></td>
</tr>
<tr class="row-odd"><td><p>0xA</p></td>
<td><p>__u16</p></td>
<td><p>ei_unused</p></td>
<td></td>
</tr>
</tbody>
</table>
<p>Leaf nodes of the extent tree are recorded as <code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">ext4_extent</span></code>,
and are also 12 bytes long:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 10.0%" />
<col style="width: 10.0%" />
<col style="width: 30.0%" />
<col style="width: 50.0%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Offset</p></th>
<th class="head"><p>Size</p></th>
<th class="head"><p>Name</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>0x0</p></td>
<td><p>__le32</p></td>
<td><p>ee_block</p></td>
<td><p>First file block number that this extent covers.</p></td>
</tr>
<tr class="row-odd"><td><p>0x4</p></td>
<td><p>__le16</p></td>
<td><p>ee_len</p></td>
<td><p>Number of blocks covered by extent. If the value of this field is <=
32768, the extent is initialized. If the value of the field is > 32768,
the extent is uninitialized and the actual extent length is <code class="docutils literal notranslate"><span class="pre">ee_len</span></code> -
32768. Therefore, the maximum length of a initialized extent is 32768
blocks, and the maximum length of an uninitialized extent is 32767.</p></td>
</tr>
<tr class="row-even"><td><p>0x6</p></td>
<td><p>__le16</p></td>
<td><p>ee_start_hi</p></td>
<td><p>Upper 16-bits of the block number to which this extent points.</p></td>
</tr>
<tr class="row-odd"><td><p>0x8</p></td>
<td><p>__le32</p></td>
<td><p>ee_start_lo</p></td>
<td><p>Lower 32-bits of the block number to which this extent points.</p></td>
</tr>
</tbody>
</table>
<p>Prior to the introduction of metadata checksums, the extent header +
extent entries always left at least 4 bytes of unallocated space at the
end of each extent tree data block (because (2^x % 12) >= 4). Therefore,
the 32-bit checksum is inserted into this space. The 4 extents in the
inode do not need checksumming, since the inode is already checksummed.
The checksum is calculated against the FS UUID, the inode number, the
inode generation, and the entire extent block leading up to (but not
including) the checksum itself.</p>
<p><code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">ext4_extent_tail</span></code> is 4 bytes long:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 10.0%" />
<col style="width: 10.0%" />
<col style="width: 30.0%" />
<col style="width: 50.0%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Offset</p></th>
<th class="head"><p>Size</p></th>
<th class="head"><p>Name</p></th>
<th class="head"><p>Description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>0x0</p></td>
<td><p>__le32</p></td>
<td><p>eb_checksum</p></td>
<td><p>Checksum of the extent block, crc32c(uuid+inum+igeneration+extentblock)</p></td>
</tr>
</tbody>
</table>
</section>
<section id="inline-data">
<h2><span class="section-number">4.2.4. </span>Inline Data<a class="headerlink" href="#inline-data" title="Link to this heading">¶</a></h2>
<p>If the inline data feature is enabled for the filesystem and the flag is
set for the inode, it is possible that the first 60 bytes of the file
data are stored here.</p>
</section>
</section>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
©The kernel development community.
|
Powered by <a href="https://www.sphinx-doc.org/">Sphinx 8.1.3</a>
& <a href="https://alabaster.readthedocs.io">Alabaster 0.7.16</a>
|
<a href="../../_sources/filesystems/ext4/ifork.rst.txt"
rel="nofollow">Page source</a>
</div>
</body>
</html>