You've already forked linux-apfs
mirror of
https://github.com/linux-apfs/linux-apfs.git
synced 2026-05-01 15:00:59 -07:00
Merge tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4
Pull ext4 updates from Ted Ts'o: - Convert content from the ext4 wiki to Documentation rst files so it is more likely to be updated as we add new features to ext4. - Add 64-bit timestamp support to ext4's superblock fields. - ... and the usual bug fixes and cleanups, including a Spectre gadget fixup and some hardening against maliciously corrupted file systems. * tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: (34 commits) ext4: remove unneeded variable "err" in ext4_mb_release_inode_pa() ext4: improve code readability in ext4_iget() ext4: fix spectre gadget in ext4_mb_regular_allocator() ext4: check for NUL characters in extended attribute's name ext4: use ext4_warning() for sb_getblk failure ext4: fix race when setting the bitmap corrupted flag ext4: reset error code in ext4_find_entry in fallback ext4: handle layout changes to pinned DAX mappings dax: dax_layout_busy_page() warn on !exceptional docs: fix up the obviously obsolete bits in the new ext4 documentation docs: add new ext4 superblock time extension fields docs: create filesystem internal section ext4: use swap macro in mext_page_double_lock ext4: check allocation failure when duplicating "data" in ext4_remount() ext4: fix warning message in ext4_enable_quotas() ext4: super: extend timestamps to 40 bits jbd2: replace current_kernel_time64 with ktime equivalent ext4: use timespec64 for all inode times ext4: use ktime_get_real_seconds for i_dtime ext4: use 64-bit timestamps for mmp_time ...
This commit is contained in:
@@ -34,7 +34,7 @@ needs_sphinx = '1.3'
|
||||
# Add any Sphinx extension module names here, as strings. They can be
|
||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||
# ones.
|
||||
extensions = ['kerneldoc', 'rstFlatTable', 'kernel_include', 'cdomain', 'kfigure']
|
||||
extensions = ['kerneldoc', 'rstFlatTable', 'kernel_include', 'cdomain', 'kfigure', 'sphinx.ext.ifconfig']
|
||||
|
||||
# The name of the math extension changed on Sphinx 1.4
|
||||
if major == 1 and minor > 3:
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
.. SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
Ext4 Filesystem
|
||||
===============
|
||||
========================
|
||||
General Information
|
||||
========================
|
||||
|
||||
Ext4 is an advanced level of the ext3 filesystem which incorporates
|
||||
scalability and reliability enhancements for supporting large filesystems
|
||||
@@ -11,37 +13,30 @@ Mailing list: linux-ext4@vger.kernel.org
|
||||
Web site: http://ext4.wiki.kernel.org
|
||||
|
||||
|
||||
1. Quick usage instructions:
|
||||
===========================
|
||||
Quick usage instructions
|
||||
========================
|
||||
|
||||
Note: More extensive information for getting started with ext4 can be
|
||||
found at the ext4 wiki site at the URL:
|
||||
http://ext4.wiki.kernel.org/index.php/Ext4_Howto
|
||||
found at the ext4 wiki site at the URL:
|
||||
http://ext4.wiki.kernel.org/index.php/Ext4_Howto
|
||||
|
||||
- Compile and install the latest version of e2fsprogs (as of this
|
||||
writing version 1.41.3) from:
|
||||
|
||||
http://sourceforge.net/project/showfiles.php?group_id=2406
|
||||
|
||||
or
|
||||
- The latest version of e2fsprogs can be found at:
|
||||
|
||||
https://www.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/
|
||||
|
||||
or
|
||||
|
||||
http://sourceforge.net/project/showfiles.php?group_id=2406
|
||||
|
||||
or grab the latest git repository from:
|
||||
|
||||
git://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git
|
||||
|
||||
- Note that it is highly important to install the mke2fs.conf file
|
||||
that comes with the e2fsprogs 1.41.x sources in /etc/mke2fs.conf. If
|
||||
you have edited the /etc/mke2fs.conf file installed on your system,
|
||||
you will need to merge your changes with the version from e2fsprogs
|
||||
1.41.x.
|
||||
https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git
|
||||
|
||||
- Create a new filesystem using the ext4 filesystem type:
|
||||
|
||||
# mke2fs -t ext4 /dev/hda1
|
||||
# mke2fs -t ext4 /dev/hda1
|
||||
|
||||
Or to configure an existing ext3 filesystem to support extents:
|
||||
Or to configure an existing ext3 filesystem to support extents:
|
||||
|
||||
# tune2fs -O extents /dev/hda1
|
||||
|
||||
@@ -50,10 +45,6 @@ Note: More extensive information for getting started with ext4 can be
|
||||
|
||||
# tune2fs -I 256 /dev/hda1
|
||||
|
||||
(Note: we currently do not have tools to convert an ext4
|
||||
filesystem back to ext3; so please do not do try this on production
|
||||
filesystems.)
|
||||
|
||||
- Mounting:
|
||||
|
||||
# mount -t ext4 /dev/hda1 /wherever
|
||||
@@ -75,10 +66,11 @@ Note: More extensive information for getting started with ext4 can be
|
||||
the filesystem with a large journal can also be helpful for
|
||||
metadata-intensive workloads.
|
||||
|
||||
2. Features
|
||||
===========
|
||||
Features
|
||||
========
|
||||
|
||||
2.1 Currently available
|
||||
Currently Available
|
||||
-------------------
|
||||
|
||||
* ability to use filesystems > 16TB (e2fsprogs support not available yet)
|
||||
* extent format reduces metadata overhead (RAM, IO for access, transactions)
|
||||
@@ -103,31 +95,15 @@ Note: More extensive information for getting started with ext4 can be
|
||||
[1] Filesystems with a block size of 1k may see a limit imposed by the
|
||||
directory hash tree having a maximum depth of two.
|
||||
|
||||
2.2 Candidate features for future inclusion
|
||||
|
||||
* online defrag (patches available but not well tested)
|
||||
* reduced mke2fs time via lazy itable initialization in conjunction with
|
||||
the uninit_bg feature (capability to do this is available in e2fsprogs
|
||||
but a kernel thread to do lazy zeroing of unused inode table blocks
|
||||
after filesystem is first mounted is required for safety)
|
||||
|
||||
There are several others under discussion, whether they all make it in is
|
||||
partly a function of how much time everyone has to work on them. Features like
|
||||
metadata checksumming have been discussed and planned for a bit but no patches
|
||||
exist yet so I'm not sure they're in the near-term roadmap.
|
||||
|
||||
The big performance win will come with mballoc, delalloc and flex_bg
|
||||
grouping of bitmaps and inode tables. Some test results available here:
|
||||
|
||||
- http://www.bullopensource.org/ext4/20080818-ffsb/ffsb-write-2.6.27-rc1.html
|
||||
- http://www.bullopensource.org/ext4/20080818-ffsb/ffsb-readwrite-2.6.27-rc1.html
|
||||
|
||||
3. Options
|
||||
==========
|
||||
Options
|
||||
=======
|
||||
|
||||
When mounting an ext4 filesystem, the following option are accepted:
|
||||
(*) == default
|
||||
|
||||
======================= =======================================================
|
||||
Mount Option Description
|
||||
======================= =======================================================
|
||||
ro Mount filesystem read only. Note that ext4 will
|
||||
replay the journal (and thus write to the
|
||||
partition) even when mounted "read only". The
|
||||
@@ -387,33 +363,38 @@ i_version Enable 64-bit inode version support. This option is
|
||||
dax Use direct access (no page cache). See
|
||||
Documentation/filesystems/dax.txt. Note that
|
||||
this option is incompatible with data=journal.
|
||||
======================= =======================================================
|
||||
|
||||
Data Mode
|
||||
=========
|
||||
There are 3 different data modes:
|
||||
|
||||
* writeback mode
|
||||
In data=writeback mode, ext4 does not journal data at all. This mode provides
|
||||
a similar level of journaling as that of XFS, JFS, and ReiserFS in its default
|
||||
mode - metadata journaling. A crash+recovery can cause incorrect data to
|
||||
appear in files which were written shortly before the crash. This mode will
|
||||
typically provide the best ext4 performance.
|
||||
|
||||
In data=writeback mode, ext4 does not journal data at all. This mode provides
|
||||
a similar level of journaling as that of XFS, JFS, and ReiserFS in its default
|
||||
mode - metadata journaling. A crash+recovery can cause incorrect data to
|
||||
appear in files which were written shortly before the crash. This mode will
|
||||
typically provide the best ext4 performance.
|
||||
|
||||
* ordered mode
|
||||
In data=ordered mode, ext4 only officially journals metadata, but it logically
|
||||
groups metadata information related to data changes with the data blocks into a
|
||||
single unit called a transaction. When it's time to write the new metadata
|
||||
out to disk, the associated data blocks are written first. In general,
|
||||
this mode performs slightly slower than writeback but significantly faster than journal mode.
|
||||
|
||||
In data=ordered mode, ext4 only officially journals metadata, but it logically
|
||||
groups metadata information related to data changes with the data blocks into
|
||||
a single unit called a transaction. When it's time to write the new metadata
|
||||
out to disk, the associated data blocks are written first. In general, this
|
||||
mode performs slightly slower than writeback but significantly faster than
|
||||
journal mode.
|
||||
|
||||
* journal mode
|
||||
data=journal mode provides full data and metadata journaling. All new data is
|
||||
written to the journal first, and then to its final location.
|
||||
In the event of a crash, the journal can be replayed, bringing both data and
|
||||
metadata into a consistent state. This mode is the slowest except when data
|
||||
needs to be read from and written to disk at the same time where it
|
||||
outperforms all others modes. Enabling this mode will disable delayed
|
||||
allocation and O_DIRECT support.
|
||||
|
||||
data=journal mode provides full data and metadata journaling. All new data is
|
||||
written to the journal first, and then to its final location. In the event of
|
||||
a crash, the journal can be replayed, bringing both data and metadata into a
|
||||
consistent state. This mode is the slowest except when data needs to be read
|
||||
from and written to disk at the same time where it outperforms all others
|
||||
modes. Enabling this mode will disable delayed allocation and O_DIRECT
|
||||
support.
|
||||
|
||||
/proc entries
|
||||
=============
|
||||
@@ -425,10 +406,12 @@ Information about mounted ext4 file systems can be found in
|
||||
in table below.
|
||||
|
||||
Files in /proc/fs/ext4/<devname>
|
||||
..............................................................................
|
||||
|
||||
================ =======
|
||||
File Content
|
||||
================ =======
|
||||
mb_groups details of multiblock allocator buddy cache of free blocks
|
||||
..............................................................................
|
||||
================ =======
|
||||
|
||||
/sys entries
|
||||
============
|
||||
@@ -439,28 +422,30 @@ Information about mounted ext4 file systems can be found in
|
||||
/sys/fs/ext4/dm-0). The files in each per-device directory are shown
|
||||
in table below.
|
||||
|
||||
Files in /sys/fs/ext4/<devname>
|
||||
(see also Documentation/ABI/testing/sysfs-fs-ext4)
|
||||
..............................................................................
|
||||
File Content
|
||||
Files in /sys/fs/ext4/<devname>:
|
||||
|
||||
(see also Documentation/ABI/testing/sysfs-fs-ext4)
|
||||
|
||||
============================= =================================================
|
||||
File Content
|
||||
============================= =================================================
|
||||
delayed_allocation_blocks This file is read-only and shows the number of
|
||||
blocks that are dirty in the page cache, but
|
||||
which do not have their location in the
|
||||
filesystem allocated yet.
|
||||
|
||||
inode_goal Tuning parameter which (if non-zero) controls
|
||||
inode_goal Tuning parameter which (if non-zero) controls
|
||||
the goal inode used by the inode allocator in
|
||||
preference to all other allocation heuristics.
|
||||
This is intended for debugging use only, and
|
||||
should be 0 on production systems.
|
||||
|
||||
inode_readahead_blks Tuning parameter which controls the maximum
|
||||
inode_readahead_blks Tuning parameter which controls the maximum
|
||||
number of inode table blocks that ext4's inode
|
||||
table readahead algorithm will pre-read into
|
||||
the buffer cache
|
||||
|
||||
lifetime_write_kbytes This file is read-only and shows the number of
|
||||
lifetime_write_kbytes This file is read-only and shows the number of
|
||||
kilobytes of data that have been written to this
|
||||
filesystem since it was created.
|
||||
|
||||
@@ -508,7 +493,7 @@ Files in /sys/fs/ext4/<devname>
|
||||
in the file system. If there is not enough space
|
||||
for the reserved space when mounting the file
|
||||
mount will _not_ fail.
|
||||
..............................................................................
|
||||
============================= =================================================
|
||||
|
||||
Ioctls
|
||||
======
|
||||
@@ -518,8 +503,10 @@ through the system call interfaces. The list of all Ext4 specific ioctls are
|
||||
shown in the table below.
|
||||
|
||||
Table of Ext4 specific ioctls
|
||||
..............................................................................
|
||||
Ioctl Description
|
||||
|
||||
============================= =================================================
|
||||
Ioctl Description
|
||||
============================= =================================================
|
||||
EXT4_IOC_GETFLAGS Get additional attributes associated with inode.
|
||||
The ioctl argument is an integer bitfield, with
|
||||
bit values described in ext4.h. This ioctl is an
|
||||
@@ -610,8 +597,7 @@ Table of Ext4 specific ioctls
|
||||
normal user by accident.
|
||||
The data blocks of the previous boot loader
|
||||
will be associated with the given inode.
|
||||
|
||||
..............................................................................
|
||||
============================= =================================================
|
||||
|
||||
References
|
||||
==========
|
||||
@@ -0,0 +1,17 @@
|
||||
.. SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
===============
|
||||
ext4 Filesystem
|
||||
===============
|
||||
|
||||
General usage and on-disk artifacts writen by ext4. More documentation may
|
||||
be ported from the wiki as time permits. This should be considered the
|
||||
canonical source of information as the details here have been reviewed by
|
||||
the ext4 community.
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 5
|
||||
:numbered:
|
||||
|
||||
ext4
|
||||
ondisk/index
|
||||
@@ -0,0 +1,44 @@
|
||||
.. SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
About this Book
|
||||
===============
|
||||
|
||||
This document attempts to describe the on-disk format for ext4
|
||||
filesystems. The same general ideas should apply to ext2/3 filesystems
|
||||
as well, though they do not support all the features that ext4 supports,
|
||||
and the fields will be shorter.
|
||||
|
||||
**NOTE**: This is a work in progress, based on notes that the author
|
||||
(djwong) made while picking apart a filesystem by hand. The data
|
||||
structure definitions should be current as of Linux 4.18 and
|
||||
e2fsprogs-1.44. All comments and corrections are welcome, since there is
|
||||
undoubtedly plenty of lore that might not be reflected in freshly
|
||||
created demonstration filesystems.
|
||||
|
||||
License
|
||||
-------
|
||||
This book is licensed under the terms of the GNU Public License, v2.
|
||||
|
||||
Terminology
|
||||
-----------
|
||||
|
||||
ext4 divides a storage device into an array of logical blocks both to
|
||||
reduce bookkeeping overhead and to increase throughput by forcing larger
|
||||
transfer sizes. Generally, the block size will be 4KiB (the same size as
|
||||
pages on x86 and the block layer's default block size), though the
|
||||
actual size is calculated as 2 ^ (10 + ``sb.s_log_block_size``) bytes.
|
||||
Throughout this document, disk locations are given in terms of these
|
||||
logical blocks, not raw LBAs, and not 1024-byte blocks. For the sake of
|
||||
convenience, the logical block size will be referred to as
|
||||
``$block_size`` throughout the rest of the document.
|
||||
|
||||
When referenced in ``preformatted text`` blocks, ``sb`` refers to fields
|
||||
in the super block, and ``inode`` refers to fields in an inode table
|
||||
entry.
|
||||
|
||||
Other References
|
||||
----------------
|
||||
|
||||
Also see http://www.nongnu.org/ext2-doc/ for quite a collection of
|
||||
information about ext2/3. Here's another old reference:
|
||||
http://wiki.osdev.org/Ext2
|
||||
@@ -0,0 +1,56 @@
|
||||
.. SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
Block and Inode Allocation Policy
|
||||
---------------------------------
|
||||
|
||||
ext4 recognizes (better than ext3, anyway) that data locality is
|
||||
generally a desirably quality of a filesystem. On a spinning disk,
|
||||
keeping related blocks near each other reduces the amount of movement
|
||||
that the head actuator and disk must perform to access a data block,
|
||||
thus speeding up disk IO. On an SSD there of course are no moving parts,
|
||||
but locality can increase the size of each transfer request while
|
||||
reducing the total number of requests. This locality may also have the
|
||||
effect of concentrating writes on a single erase block, which can speed
|
||||
up file rewrites significantly. Therefore, it is useful to reduce
|
||||
fragmentation whenever possible.
|
||||
|
||||
The first tool that ext4 uses to combat fragmentation is the multi-block
|
||||
allocator. When a file is first created, the block allocator
|
||||
speculatively allocates 8KiB of disk space to the file on the assumption
|
||||
that the space will get written soon. When the file is closed, the
|
||||
unused speculative allocations are of course freed, but if the
|
||||
speculation is correct (typically the case for full writes of small
|
||||
files) then the file data gets written out in a single multi-block
|
||||
extent. A second related trick that ext4 uses is delayed allocation.
|
||||
Under this scheme, when a file needs more blocks to absorb file writes,
|
||||
the filesystem defers deciding the exact placement on the disk until all
|
||||
the dirty buffers are being written out to disk. By not committing to a
|
||||
particular placement until it's absolutely necessary (the commit timeout
|
||||
is hit, or sync() is called, or the kernel runs out of memory), the hope
|
||||
is that the filesystem can make better location decisions.
|
||||
|
||||
The third trick that ext4 (and ext3) uses is that it tries to keep a
|
||||
file's data blocks in the same block group as its inode. This cuts down
|
||||
on the seek penalty when the filesystem first has to read a file's inode
|
||||
to learn where the file's data blocks live and then seek over to the
|
||||
file's data blocks to begin I/O operations.
|
||||
|
||||
The fourth trick is that all the inodes in a directory are placed in the
|
||||
same block group as the directory, when feasible. The working assumption
|
||||
here is that all the files in a directory might be related, therefore it
|
||||
is useful to try to keep them all together.
|
||||
|
||||
The fifth trick is that the disk volume is cut up into 128MB block
|
||||
groups; these mini-containers are used as outlined above to try to
|
||||
maintain data locality. However, there is a deliberate quirk -- when a
|
||||
directory is created in the root directory, the inode allocator scans
|
||||
the block groups and puts that directory into the least heavily loaded
|
||||
block group that it can find. This encourages directories to spread out
|
||||
over a disk; as the top-level directory/file blobs fill up one block
|
||||
group, the allocators simply move on to the next block group. Allegedly
|
||||
this scheme evens out the loading on the block groups, though the author
|
||||
suspects that the directories which are so unlucky as to land towards
|
||||
the end of a spinning drive get a raw deal performance-wise.
|
||||
|
||||
Of course if all of these mechanisms fail, one can always use e4defrag
|
||||
to defragment files.
|
||||
@@ -0,0 +1,191 @@
|
||||
.. SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
Extended Attributes
|
||||
-------------------
|
||||
|
||||
Extended attributes (xattrs) are typically stored in a separate data
|
||||
block on the disk and referenced from inodes via ``inode.i_file_acl*``.
|
||||
The first use of extended attributes seems to have been for storing file
|
||||
ACLs and other security data (selinux). With the ``user_xattr`` mount
|
||||
option it is possible for users to store extended attributes so long as
|
||||
all attribute names begin with “user”; this restriction seems to have
|
||||
disappeared as of Linux 3.0.
|
||||
|
||||
There are two places where extended attributes can be found. The first
|
||||
place is between the end of each inode entry and the beginning of the
|
||||
next inode entry. For example, if inode.i\_extra\_isize = 28 and
|
||||
sb.inode\_size = 256, then there are 256 - (128 + 28) = 100 bytes
|
||||
available for in-inode extended attribute storage. The second place
|
||||
where extended attributes can be found is in the block pointed to by
|
||||
``inode.i_file_acl``. As of Linux 3.11, it is not possible for this
|
||||
block to contain a pointer to a second extended attribute block (or even
|
||||
the remaining blocks of a cluster). In theory it is possible for each
|
||||
attribute's value to be stored in a separate data block, though as of
|
||||
Linux 3.11 the code does not permit this.
|
||||
|
||||
Keys are generally assumed to be ASCIIZ strings, whereas values can be
|
||||
strings or binary data.
|
||||
|
||||
Extended attributes, when stored after the inode, have a header
|
||||
``ext4_xattr_ibody_header`` that is 4 bytes long:
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 1 1 77
|
||||
:header-rows: 1
|
||||
|
||||
* - Offset
|
||||
- Type
|
||||
- Name
|
||||
- Description
|
||||
* - 0x0
|
||||
- \_\_le32
|
||||
- h\_magic
|
||||
- Magic number for identification, 0xEA020000. This value is set by the
|
||||
Linux driver, though e2fsprogs doesn't seem to check it(?)
|
||||
|
||||
The beginning of an extended attribute block is in
|
||||
``struct ext4_xattr_header``, which is 32 bytes long:
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 1 1 77
|
||||
:header-rows: 1
|
||||
|
||||
* - Offset
|
||||
- Type
|
||||
- Name
|
||||
- Description
|
||||
* - 0x0
|
||||
- \_\_le32
|
||||
- h\_magic
|
||||
- Magic number for identification, 0xEA020000.
|
||||
* - 0x4
|
||||
- \_\_le32
|
||||
- h\_refcount
|
||||
- Reference count.
|
||||
* - 0x8
|
||||
- \_\_le32
|
||||
- h\_blocks
|
||||
- Number of disk blocks used.
|
||||
* - 0xC
|
||||
- \_\_le32
|
||||
- h\_hash
|
||||
- Hash value of all attributes.
|
||||
* - 0x10
|
||||
- \_\_le32
|
||||
- h\_checksum
|
||||
- Checksum of the extended attribute block.
|
||||
* - 0x14
|
||||
- \_\_u32
|
||||
- h\_reserved[2]
|
||||
- Zero.
|
||||
|
||||
The checksum is calculated against the FS UUID, the 64-bit block number
|
||||
of the extended attribute block, and the entire block (header +
|
||||
entries).
|
||||
|
||||
Following the ``struct ext4_xattr_header`` or
|
||||
``struct ext4_xattr_ibody_header`` is an array of
|
||||
``struct ext4_xattr_entry``; each of these entries is at least 16 bytes
|
||||
long. When stored in an external block, the ``struct ext4_xattr_entry``
|
||||
entries must be stored in sorted order. The sort order is
|
||||
``e_name_index``, then ``e_name_len``, and finally ``e_name``.
|
||||
Attributes stored inside an inode do not need be stored in sorted order.
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 1 1 77
|
||||
:header-rows: 1
|
||||
|
||||
* - Offset
|
||||
- Type
|
||||
- Name
|
||||
- Description
|
||||
* - 0x0
|
||||
- \_\_u8
|
||||
- e\_name\_len
|
||||
- Length of name.
|
||||
* - 0x1
|
||||
- \_\_u8
|
||||
- e\_name\_index
|
||||
- Attribute name index. There is a discussion of this below.
|
||||
* - 0x2
|
||||
- \_\_le16
|
||||
- e\_value\_offs
|
||||
- Location of this attribute's value on the disk block where it is stored.
|
||||
Multiple attributes can share the same value. For an inode attribute
|
||||
this value is relative to the start of the first entry; for a block this
|
||||
value is relative to the start of the block (i.e. the header).
|
||||
* - 0x4
|
||||
- \_\_le32
|
||||
- e\_value\_inum
|
||||
- The inode where the value is stored. Zero indicates the value is in the
|
||||
same block as this entry. This field is only used if the
|
||||
INCOMPAT\_EA\_INODE feature is enabled.
|
||||
* - 0x8
|
||||
- \_\_le32
|
||||
- e\_value\_size
|
||||
- Length of attribute value.
|
||||
* - 0xC
|
||||
- \_\_le32
|
||||
- e\_hash
|
||||
- Hash value of attribute name and attribute value. The kernel doesn't
|
||||
update the hash for in-inode attributes, so for that case this value
|
||||
must be zero, because e2fsck validates any non-zero hash regardless of
|
||||
where the xattr lives.
|
||||
* - 0x10
|
||||
- char
|
||||
- e\_name[e\_name\_len]
|
||||
- Attribute name. Does not include trailing NULL.
|
||||
|
||||
Attribute values can follow the end of the entry table. There appears to
|
||||
be a requirement that they be aligned to 4-byte boundaries. The values
|
||||
are stored starting at the end of the block and grow towards the
|
||||
xattr\_header/xattr\_entry table. When the two collide, the overflow is
|
||||
put into a separate disk block. If the disk block fills up, the
|
||||
filesystem returns -ENOSPC.
|
||||
|
||||
The first four fields of the ``ext4_xattr_entry`` are set to zero to
|
||||
mark the end of the key list.
|
||||
|
||||
Attribute Name Indices
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Logically speaking, extended attributes are a series of key=value pairs.
|
||||
The keys are assumed to be NULL-terminated strings. To reduce the amount
|
||||
of on-disk space that the keys consume, the beginning of the key string
|
||||
is matched against the attribute name index. If a match is found, the
|
||||
attribute name index field is set, and matching string is removed from
|
||||
the key name. Here is a map of name index values to key prefixes:
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 79
|
||||
:header-rows: 1
|
||||
|
||||
* - Name Index
|
||||
- Key Prefix
|
||||
* - 0
|
||||
- (no prefix)
|
||||
* - 1
|
||||
- “user.”
|
||||
* - 2
|
||||
- “system.posix\_acl\_access”
|
||||
* - 3
|
||||
- “system.posix\_acl\_default”
|
||||
* - 4
|
||||
- “trusted.”
|
||||
* - 6
|
||||
- “security.”
|
||||
* - 7
|
||||
- “system.” (inline\_data only?)
|
||||
* - 8
|
||||
- “system.richacl” (SuSE kernels only?)
|
||||
|
||||
For example, if the attribute key is “user.fubar”, the attribute name
|
||||
index is set to 1 and the “fubar” name is recorded on disk.
|
||||
|
||||
POSIX ACLs
|
||||
~~~~~~~~~~
|
||||
|
||||
POSIX ACLs are stored in a reduced version of the Linux kernel (and
|
||||
libacl's) internal ACL format. The key difference is that the version
|
||||
number is different (1) and the ``e_id`` field is only stored for named
|
||||
user and group ACLs.
|
||||
@@ -0,0 +1,22 @@
|
||||
.. SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
Bigalloc
|
||||
--------
|
||||
|
||||
At the moment, the default size of a block is 4KiB, which is a commonly
|
||||
supported page size on most MMU-capable hardware. This is fortunate, as
|
||||
ext4 code is not prepared to handle the case where the block size
|
||||
exceeds the page size. However, for a filesystem of mostly huge files,
|
||||
it is desirable to be able to allocate disk blocks in units of multiple
|
||||
blocks to reduce both fragmentation and metadata overhead. The
|
||||
`bigalloc <Bigalloc>`__ feature provides exactly this ability. The
|
||||
administrator can set a block cluster size at mkfs time (which is stored
|
||||
in the s\_log\_cluster\_size field in the superblock); from then on, the
|
||||
block bitmaps track clusters, not individual blocks. This means that
|
||||
block groups can be several gigabytes in size (instead of just 128MiB);
|
||||
however, the minimum allocation unit becomes a cluster, not a block,
|
||||
even for directories. TaoBao had a patchset to extend the “use units of
|
||||
clusters instead of blocks” to the extent tree, though it is not clear
|
||||
where those patches went-- they eventually morphed into “extent tree v2”
|
||||
but that code has not landed as of May 2015.
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
.. SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
Block and inode Bitmaps
|
||||
-----------------------
|
||||
|
||||
The data block bitmap tracks the usage of data blocks within the block
|
||||
group.
|
||||
|
||||
The inode bitmap records which entries in the inode table are in use.
|
||||
|
||||
As with most bitmaps, one bit represents the usage status of one data
|
||||
block or inode table entry. This implies a block group size of 8 \*
|
||||
number\_of\_bytes\_in\_a\_logical\_block.
|
||||
|
||||
NOTE: If ``BLOCK_UNINIT`` is set for a given block group, various parts
|
||||
of the kernel and e2fsprogs code pretends that the block bitmap contains
|
||||
zeros (i.e. all blocks in the group are free). However, it is not
|
||||
necessarily the case that no blocks are in use -- if ``meta_bg`` is set,
|
||||
the bitmaps and group descriptor live inside the group. Unfortunately,
|
||||
ext2fs\_test\_block\_bitmap2() will return '0' for those locations,
|
||||
which produces confusing debugfs output.
|
||||
|
||||
Inode Table
|
||||
-----------
|
||||
Inode tables are statically allocated at mkfs time. Each block group
|
||||
descriptor points to the start of the table, and the superblock records
|
||||
the number of inodes per group. See the section on inodes for more
|
||||
information.
|
||||
@@ -0,0 +1,135 @@
|
||||
.. SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
Layout
|
||||
------
|
||||
|
||||
The layout of a standard block group is approximately as follows (each
|
||||
of these fields is discussed in a separate section below):
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 1 1 1 1 1 1 1
|
||||
:header-rows: 1
|
||||
|
||||
* - Group 0 Padding
|
||||
- ext4 Super Block
|
||||
- Group Descriptors
|
||||
- Reserved GDT Blocks
|
||||
- Data Block Bitmap
|
||||
- inode Bitmap
|
||||
- inode Table
|
||||
- Data Blocks
|
||||
* - 1024 bytes
|
||||
- 1 block
|
||||
- many blocks
|
||||
- many blocks
|
||||
- 1 block
|
||||
- 1 block
|
||||
- many blocks
|
||||
- many more blocks
|
||||
|
||||
For the special case of block group 0, the first 1024 bytes are unused,
|
||||
to allow for the installation of x86 boot sectors and other oddities.
|
||||
The superblock will start at offset 1024 bytes, whichever block that
|
||||
happens to be (usually 0). However, if for some reason the block size =
|
||||
1024, then block 0 is marked in use and the superblock goes in block 1.
|
||||
For all other block groups, there is no padding.
|
||||
|
||||
The ext4 driver primarily works with the superblock and the group
|
||||
descriptors that are found in block group 0. Redundant copies of the
|
||||
superblock and group descriptors are written to some of the block groups
|
||||
across the disk in case the beginning of the disk gets trashed, though
|
||||
not all block groups necessarily host a redundant copy (see following
|
||||
paragraph for more details). If the group does not have a redundant
|
||||
copy, the block group begins with the data block bitmap. Note also that
|
||||
when the filesystem is freshly formatted, mkfs will allocate “reserve
|
||||
GDT block” space after the block group descriptors and before the start
|
||||
of the block bitmaps to allow for future expansion of the filesystem. By
|
||||
default, a filesystem is allowed to increase in size by a factor of
|
||||
1024x over the original filesystem size.
|
||||
|
||||
The location of the inode table is given by ``grp.bg_inode_table_*``. It
|
||||
is continuous range of blocks large enough to contain
|
||||
``sb.s_inodes_per_group * sb.s_inode_size`` bytes.
|
||||
|
||||
As for the ordering of items in a block group, it is generally
|
||||
established that the super block and the group descriptor table, if
|
||||
present, will be at the beginning of the block group. The bitmaps and
|
||||
the inode table can be anywhere, and it is quite possible for the
|
||||
bitmaps to come after the inode table, or for both to be in different
|
||||
groups (flex\_bg). Leftover space is used for file data blocks, indirect
|
||||
block maps, extent tree blocks, and extended attributes.
|
||||
|
||||
Flexible Block Groups
|
||||
---------------------
|
||||
|
||||
Starting in ext4, there is a new feature called flexible block groups
|
||||
(flex\_bg). In a flex\_bg, several block groups are tied together as one
|
||||
logical block group; the bitmap spaces and the inode table space in the
|
||||
first block group of the flex\_bg are expanded to include the bitmaps
|
||||
and inode tables of all other block groups in the flex\_bg. For example,
|
||||
if the flex\_bg size is 4, then group 0 will contain (in order) the
|
||||
superblock, group descriptors, data block bitmaps for groups 0-3, inode
|
||||
bitmaps for groups 0-3, inode tables for groups 0-3, and the remaining
|
||||
space in group 0 is for file data. The effect of this is to group the
|
||||
block metadata close together for faster loading, and to enable large
|
||||
files to be continuous on disk. Backup copies of the superblock and
|
||||
group descriptors are always at the beginning of block groups, even if
|
||||
flex\_bg is enabled. The number of block groups that make up a flex\_bg
|
||||
is given by 2 ^ ``sb.s_log_groups_per_flex``.
|
||||
|
||||
Meta Block Groups
|
||||
-----------------
|
||||
|
||||
Without the option META\_BG, for safety concerns, all block group
|
||||
descriptors copies are kept in the first block group. Given the default
|
||||
128MiB(2^27 bytes) block group size and 64-byte group descriptors, ext4
|
||||
can have at most 2^27/64 = 2^21 block groups. This limits the entire
|
||||
filesystem size to 2^21 ∗ 2^27 = 2^48bytes or 256TiB.
|
||||
|
||||
The solution to this problem is to use the metablock group feature
|
||||
(META\_BG), which is already in ext3 for all 2.6 releases. With the
|
||||
META\_BG feature, ext4 filesystems are partitioned into many metablock
|
||||
groups. Each metablock group is a cluster of block groups whose group
|
||||
descriptor structures can be stored in a single disk block. For ext4
|
||||
filesystems with 4 KB block size, a single metablock group partition
|
||||
includes 64 block groups, or 8 GiB of disk space. The metablock group
|
||||
feature moves the location of the group descriptors from the congested
|
||||
first block group of the whole filesystem into the first group of each
|
||||
metablock group itself. The backups are in the second and last group of
|
||||
each metablock group. This increases the 2^21 maximum block groups limit
|
||||
to the hard limit 2^32, allowing support for a 512PiB filesystem.
|
||||
|
||||
The change in the filesystem format replaces the current scheme where
|
||||
the superblock is followed by a variable-length set of block group
|
||||
descriptors. Instead, the superblock and a single block group descriptor
|
||||
block is placed at the beginning of the first, second, and last block
|
||||
groups in a meta-block group. A meta-block group is a collection of
|
||||
block groups which can be described by a single block group descriptor
|
||||
block. Since the size of the block group descriptor structure is 32
|
||||
bytes, a meta-block group contains 32 block groups for filesystems with
|
||||
a 1KB block size, and 128 block groups for filesystems with a 4KB
|
||||
blocksize. Filesystems can either be created using this new block group
|
||||
descriptor layout, or existing filesystems can be resized on-line, and
|
||||
the field s\_first\_meta\_bg in the superblock will indicate the first
|
||||
block group using this new layout.
|
||||
|
||||
Please see an important note about ``BLOCK_UNINIT`` in the section about
|
||||
block and inode bitmaps.
|
||||
|
||||
Lazy Block Group Initialization
|
||||
-------------------------------
|
||||
|
||||
A new feature for ext4 are three block group descriptor flags that
|
||||
enable mkfs to skip initializing other parts of the block group
|
||||
metadata. Specifically, the INODE\_UNINIT and BLOCK\_UNINIT flags mean
|
||||
that the inode and block bitmaps for that group can be calculated and
|
||||
therefore the on-disk bitmap blocks are not initialized. This is
|
||||
generally the case for an empty block group or a block group containing
|
||||
only fixed-location block group metadata. The INODE\_ZEROED flag means
|
||||
that the inode table has been initialized; mkfs will unset this flag and
|
||||
rely on the kernel to initialize the inode tables in the background.
|
||||
|
||||
By not writing zeroes to the bitmaps and inode table, mkfs time is
|
||||
reduced considerably. Note the feature flag is RO\_COMPAT\_GDT\_CSUM,
|
||||
but the dumpe2fs output prints this as “uninit\_bg”. They are the same
|
||||
thing.
|
||||
@@ -0,0 +1,49 @@
|
||||
.. SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| 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) + 12 to (``$block_size`` / 4) ^ 3 + (``$block_size`` / 4) ^ 2 + (``$block_size`` / 4) + 12, or 1049612 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) | | | |
|
||||
| | | | | | +------------------------------+--------------------------------------------------------------------+ | | |
|
||||
| | | | +--------------------------------+---------------------------------------------------------------------------------------------------------+ | |
|
||||
| | +--------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+ |
|
||||
+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
@@ -0,0 +1,142 @@
|
||||
.. SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
Blocks
|
||||
------
|
||||
|
||||
ext4 allocates storage space in units of “blocks”. A block is a group of
|
||||
sectors between 1KiB and 64KiB, and the number of sectors must be an
|
||||
integral power of 2. Blocks are in turn grouped into larger units called
|
||||
block groups. Block size is specified at mkfs time and typically is
|
||||
4KiB. You may experience mounting problems if block size is greater than
|
||||
page size (i.e. 64KiB blocks on a i386 which only has 4KiB memory
|
||||
pages). By default a filesystem can contain 2^32 blocks; if the '64bit'
|
||||
feature is enabled, then a filesystem can have 2^64 blocks.
|
||||
|
||||
For 32-bit filesystems, limits are as follows:
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 1 1 1 1
|
||||
:header-rows: 1
|
||||
|
||||
* - Item
|
||||
- 1KiB
|
||||
- 2KiB
|
||||
- 4KiB
|
||||
- 64KiB
|
||||
* - Blocks
|
||||
- 2^32
|
||||
- 2^32
|
||||
- 2^32
|
||||
- 2^32
|
||||
* - Inodes
|
||||
- 2^32
|
||||
- 2^32
|
||||
- 2^32
|
||||
- 2^32
|
||||
* - File System Size
|
||||
- 4TiB
|
||||
- 8TiB
|
||||
- 16TiB
|
||||
- 256PiB
|
||||
* - Blocks Per Block Group
|
||||
- 8,192
|
||||
- 16,384
|
||||
- 32,768
|
||||
- 524,288
|
||||
* - Inodes Per Block Group
|
||||
- 8,192
|
||||
- 16,384
|
||||
- 32,768
|
||||
- 524,288
|
||||
* - Block Group Size
|
||||
- 8MiB
|
||||
- 32MiB
|
||||
- 128MiB
|
||||
- 32GiB
|
||||
* - Blocks Per File, Extents
|
||||
- 2^32
|
||||
- 2^32
|
||||
- 2^32
|
||||
- 2^32
|
||||
* - Blocks Per File, Block Maps
|
||||
- 16,843,020
|
||||
- 134,480,396
|
||||
- 1,074,791,436
|
||||
- 4,398,314,962,956 (really 2^32 due to field size limitations)
|
||||
* - File Size, Extents
|
||||
- 4TiB
|
||||
- 8TiB
|
||||
- 16TiB
|
||||
- 256TiB
|
||||
* - File Size, Block Maps
|
||||
- 16GiB
|
||||
- 256GiB
|
||||
- 4TiB
|
||||
- 256TiB
|
||||
|
||||
For 64-bit filesystems, limits are as follows:
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 1 1 1 1
|
||||
:header-rows: 1
|
||||
|
||||
* - Item
|
||||
- 1KiB
|
||||
- 2KiB
|
||||
- 4KiB
|
||||
- 64KiB
|
||||
* - Blocks
|
||||
- 2^64
|
||||
- 2^64
|
||||
- 2^64
|
||||
- 2^64
|
||||
* - Inodes
|
||||
- 2^32
|
||||
- 2^32
|
||||
- 2^32
|
||||
- 2^32
|
||||
* - File System Size
|
||||
- 16ZiB
|
||||
- 32ZiB
|
||||
- 64ZiB
|
||||
- 1YiB
|
||||
* - Blocks Per Block Group
|
||||
- 8,192
|
||||
- 16,384
|
||||
- 32,768
|
||||
- 524,288
|
||||
* - Inodes Per Block Group
|
||||
- 8,192
|
||||
- 16,384
|
||||
- 32,768
|
||||
- 524,288
|
||||
* - Block Group Size
|
||||
- 8MiB
|
||||
- 32MiB
|
||||
- 128MiB
|
||||
- 32GiB
|
||||
* - Blocks Per File, Extents
|
||||
- 2^32
|
||||
- 2^32
|
||||
- 2^32
|
||||
- 2^32
|
||||
* - Blocks Per File, Block Maps
|
||||
- 16,843,020
|
||||
- 134,480,396
|
||||
- 1,074,791,436
|
||||
- 4,398,314,962,956 (really 2^32 due to field size limitations)
|
||||
* - File Size, Extents
|
||||
- 4TiB
|
||||
- 8TiB
|
||||
- 16TiB
|
||||
- 256TiB
|
||||
* - File Size, Block Maps
|
||||
- 16GiB
|
||||
- 256GiB
|
||||
- 4TiB
|
||||
- 256TiB
|
||||
|
||||
Note: Files not using extents (i.e. files using block maps) must be
|
||||
placed within the first 2^32 blocks of a filesystem. Files with extents
|
||||
must be placed within the first 2^48 blocks of a filesystem. It's not
|
||||
clear what happens with larger filesystems.
|
||||
@@ -0,0 +1,73 @@
|
||||
.. SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
Checksums
|
||||
---------
|
||||
|
||||
Starting in early 2012, metadata checksums were added to all major ext4
|
||||
and jbd2 data structures. The associated feature flag is metadata\_csum.
|
||||
The desired checksum algorithm is indicated in the superblock, though as
|
||||
of October 2012 the only supported algorithm is crc32c. Some data
|
||||
structures did not have space to fit a full 32-bit checksum, so only the
|
||||
lower 16 bits are stored. Enabling the 64bit feature increases the data
|
||||
structure size so that full 32-bit checksums can be stored for many data
|
||||
structures. However, existing 32-bit filesystems cannot be extended to
|
||||
enable 64bit mode, at least not without the experimental resize2fs
|
||||
patches to do so.
|
||||
|
||||
Existing filesystems can have checksumming added by running
|
||||
``tune2fs -O metadata_csum`` against the underlying device. If tune2fs
|
||||
encounters directory blocks that lack sufficient empty space to add a
|
||||
checksum, it will request that you run ``e2fsck -D`` to have the
|
||||
directories rebuilt with checksums. This has the added benefit of
|
||||
removing slack space from the directory files and rebalancing the htree
|
||||
indexes. If you \_ignore\_ this step, your directories will not be
|
||||
protected by a checksum!
|
||||
|
||||
The following table describes the data elements that go into each type
|
||||
of checksum. The checksum function is whatever the superblock describes
|
||||
(crc32c as of October 2013) unless noted otherwise.
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 1 4
|
||||
:header-rows: 1
|
||||
|
||||
* - Metadata
|
||||
- Length
|
||||
- Ingredients
|
||||
* - Superblock
|
||||
- \_\_le32
|
||||
- The entire superblock up to the checksum field. The UUID lives inside
|
||||
the superblock.
|
||||
* - MMP
|
||||
- \_\_le32
|
||||
- UUID + the entire MMP block up to the checksum field.
|
||||
* - Extended Attributes
|
||||
- \_\_le32
|
||||
- UUID + the entire extended attribute block. The checksum field is set to
|
||||
zero.
|
||||
* - Directory Entries
|
||||
- \_\_le32
|
||||
- UUID + inode number + inode generation + the directory block up to the
|
||||
fake entry enclosing the checksum field.
|
||||
* - HTREE Nodes
|
||||
- \_\_le32
|
||||
- UUID + inode number + inode generation + all valid extents + HTREE tail.
|
||||
The checksum field is set to zero.
|
||||
* - Extents
|
||||
- \_\_le32
|
||||
- UUID + inode number + inode generation + the entire extent block up to
|
||||
the checksum field.
|
||||
* - Bitmaps
|
||||
- \_\_le32 or \_\_le16
|
||||
- UUID + the entire bitmap. Checksums are stored in the group descriptor,
|
||||
and truncated if the group descriptor size is 32 bytes (i.e. ^64bit)
|
||||
* - Inodes
|
||||
- \_\_le32
|
||||
- UUID + inode number + inode generation + the entire inode. The checksum
|
||||
field is set to zero. Each inode has its own checksum.
|
||||
* - Group Descriptors
|
||||
- \_\_le16
|
||||
- If metadata\_csum, then UUID + group number + the entire descriptor;
|
||||
else if gdt\_csum, then crc16(UUID + group number + the entire
|
||||
descriptor). In all cases, only the lower 16 bits are stored.
|
||||
|
||||
@@ -0,0 +1,426 @@
|
||||
.. SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
Directory Entries
|
||||
-----------------
|
||||
|
||||
In an ext4 filesystem, a directory is more or less a flat file that maps
|
||||
an arbitrary byte string (usually ASCII) to an inode number on the
|
||||
filesystem. There can be many directory entries across the filesystem
|
||||
that reference the same inode number--these are known as hard links, and
|
||||
that is why hard links cannot reference files on other filesystems. As
|
||||
such, directory entries are found by reading the data block(s)
|
||||
associated with a directory file for the particular directory entry that
|
||||
is desired.
|
||||
|
||||
Linear (Classic) Directories
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
By default, each directory lists its entries in an “almost-linear”
|
||||
array. I write “almost” because it's not a linear array in the memory
|
||||
sense because directory entries are not split across filesystem blocks.
|
||||
Therefore, it is more accurate to say that a directory is a series of
|
||||
data blocks and that each block contains a linear array of directory
|
||||
entries. The end of each per-block array is signified by reaching the
|
||||
end of the block; the last entry in the block has a record length that
|
||||
takes it all the way to the end of the block. The end of the entire
|
||||
directory is of course signified by reaching the end of the file. Unused
|
||||
directory entries are signified by inode = 0. By default the filesystem
|
||||
uses ``struct ext4_dir_entry_2`` for directory entries unless the
|
||||
“filetype” feature flag is not set, in which case it uses
|
||||
``struct ext4_dir_entry``.
|
||||
|
||||
The original directory entry format is ``struct ext4_dir_entry``, which
|
||||
is at most 263 bytes long, though on disk you'll need to reference
|
||||
``dirent.rec_len`` to know for sure.
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 1 1 77
|
||||
:header-rows: 1
|
||||
|
||||
* - Offset
|
||||
- Size
|
||||
- Name
|
||||
- Description
|
||||
* - 0x0
|
||||
- \_\_le32
|
||||
- inode
|
||||
- Number of the inode that this directory entry points to.
|
||||
* - 0x4
|
||||
- \_\_le16
|
||||
- rec\_len
|
||||
- Length of this directory entry. Must be a multiple of 4.
|
||||
* - 0x6
|
||||
- \_\_le16
|
||||
- name\_len
|
||||
- Length of the file name.
|
||||
* - 0x8
|
||||
- char
|
||||
- name[EXT4\_NAME\_LEN]
|
||||
- File name.
|
||||
|
||||
Since file names cannot be longer than 255 bytes, the new directory
|
||||
entry format shortens the rec\_len field and uses the space for a file
|
||||
type flag, probably to avoid having to load every inode during directory
|
||||
tree traversal. This format is ``ext4_dir_entry_2``, which is at most
|
||||
263 bytes long, though on disk you'll need to reference
|
||||
``dirent.rec_len`` to know for sure.
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 1 1 77
|
||||
:header-rows: 1
|
||||
|
||||
* - Offset
|
||||
- Size
|
||||
- Name
|
||||
- Description
|
||||
* - 0x0
|
||||
- \_\_le32
|
||||
- inode
|
||||
- Number of the inode that this directory entry points to.
|
||||
* - 0x4
|
||||
- \_\_le16
|
||||
- rec\_len
|
||||
- Length of this directory entry.
|
||||
* - 0x6
|
||||
- \_\_u8
|
||||
- name\_len
|
||||
- Length of the file name.
|
||||
* - 0x7
|
||||
- \_\_u8
|
||||
- file\_type
|
||||
- File type code, see ftype_ table below.
|
||||
* - 0x8
|
||||
- char
|
||||
- name[EXT4\_NAME\_LEN]
|
||||
- File name.
|
||||
|
||||
.. _ftype:
|
||||
|
||||
The directory file type is one of the following values:
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 79
|
||||
:header-rows: 1
|
||||
|
||||
* - Value
|
||||
- Description
|
||||
* - 0x0
|
||||
- Unknown.
|
||||
* - 0x1
|
||||
- Regular file.
|
||||
* - 0x2
|
||||
- Directory.
|
||||
* - 0x3
|
||||
- Character device file.
|
||||
* - 0x4
|
||||
- Block device file.
|
||||
* - 0x5
|
||||
- FIFO.
|
||||
* - 0x6
|
||||
- Socket.
|
||||
* - 0x7
|
||||
- Symbolic link.
|
||||
|
||||
In order to add checksums to these classic directory blocks, a phony
|
||||
``struct ext4_dir_entry`` is placed at the end of each leaf block to
|
||||
hold the checksum. The directory entry is 12 bytes long. The inode
|
||||
number and name\_len fields are set to zero to fool old software into
|
||||
ignoring an apparently empty directory entry, and the checksum is stored
|
||||
in the place where the name normally goes. The structure is
|
||||
``struct ext4_dir_entry_tail``:
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 1 1 77
|
||||
:header-rows: 1
|
||||
|
||||
* - Offset
|
||||
- Size
|
||||
- Name
|
||||
- Description
|
||||
* - 0x0
|
||||
- \_\_le32
|
||||
- det\_reserved\_zero1
|
||||
- Inode number, which must be zero.
|
||||
* - 0x4
|
||||
- \_\_le16
|
||||
- det\_rec\_len
|
||||
- Length of this directory entry, which must be 12.
|
||||
* - 0x6
|
||||
- \_\_u8
|
||||
- det\_reserved\_zero2
|
||||
- Length of the file name, which must be zero.
|
||||
* - 0x7
|
||||
- \_\_u8
|
||||
- det\_reserved\_ft
|
||||
- File type, which must be 0xDE.
|
||||
* - 0x8
|
||||
- \_\_le32
|
||||
- det\_checksum
|
||||
- Directory leaf block checksum.
|
||||
|
||||
The leaf directory block checksum is calculated against the FS UUID, the
|
||||
directory's inode number, the directory's inode generation number, and
|
||||
the entire directory entry block up to (but not including) the fake
|
||||
directory entry.
|
||||
|
||||
Hash Tree Directories
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
A linear array of directory entries isn't great for performance, so a
|
||||
new feature was added to ext3 to provide a faster (but peculiar)
|
||||
balanced tree keyed off a hash of the directory entry name. If the
|
||||
EXT4\_INDEX\_FL (0x1000) flag is set in the inode, this directory uses a
|
||||
hashed btree (htree) to organize and find directory entries. For
|
||||
backwards read-only compatibility with ext2, this tree is actually
|
||||
hidden inside the directory file, masquerading as “empty” directory data
|
||||
blocks! It was stated previously that the end of the linear directory
|
||||
entry table was signified with an entry pointing to inode 0; this is
|
||||
(ab)used to fool the old linear-scan algorithm into thinking that the
|
||||
rest of the directory block is empty so that it moves on.
|
||||
|
||||
The root of the tree always lives in the first data block of the
|
||||
directory. By ext2 custom, the '.' and '..' entries must appear at the
|
||||
beginning of this first block, so they are put here as two
|
||||
``struct ext4_dir_entry_2``\ s and not stored in the tree. The rest of
|
||||
the root node contains metadata about the tree and finally a hash->block
|
||||
map to find nodes that are lower in the htree. If
|
||||
``dx_root.info.indirect_levels`` is non-zero then the htree has two
|
||||
levels; the data block pointed to by the root node's map is an interior
|
||||
node, which is indexed by a minor hash. Interior nodes in this tree
|
||||
contains a zeroed out ``struct ext4_dir_entry_2`` followed by a
|
||||
minor\_hash->block map to find leafe nodes. Leaf nodes contain a linear
|
||||
array of all ``struct ext4_dir_entry_2``; all of these entries
|
||||
(presumably) hash to the same value. If there is an overflow, the
|
||||
entries simply overflow into the next leaf node, and the
|
||||
least-significant bit of the hash (in the interior node map) that gets
|
||||
us to this next leaf node is set.
|
||||
|
||||
To traverse the directory as a htree, the code calculates the hash of
|
||||
the desired file name and uses it to find the corresponding block
|
||||
number. If the tree is flat, the block is a linear array of directory
|
||||
entries that can be searched; otherwise, the minor hash of the file name
|
||||
is computed and used against this second block to find the corresponding
|
||||
third block number. That third block number will be a linear array of
|
||||
directory entries.
|
||||
|
||||
To traverse the directory as a linear array (such as the old code does),
|
||||
the code simply reads every data block in the directory. The blocks used
|
||||
for the htree will appear to have no entries (aside from '.' and '..')
|
||||
and so only the leaf nodes will appear to have any interesting content.
|
||||
|
||||
The root of the htree is in ``struct dx_root``, which is the full length
|
||||
of a data block:
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 1 1 77
|
||||
:header-rows: 1
|
||||
|
||||
* - Offset
|
||||
- Type
|
||||
- Name
|
||||
- Description
|
||||
* - 0x0
|
||||
- \_\_le32
|
||||
- dot.inode
|
||||
- inode number of this directory.
|
||||
* - 0x4
|
||||
- \_\_le16
|
||||
- dot.rec\_len
|
||||
- Length of this record, 12.
|
||||
* - 0x6
|
||||
- u8
|
||||
- dot.name\_len
|
||||
- Length of the name, 1.
|
||||
* - 0x7
|
||||
- u8
|
||||
- dot.file\_type
|
||||
- File type of this entry, 0x2 (directory) (if the feature flag is set).
|
||||
* - 0x8
|
||||
- char
|
||||
- dot.name[4]
|
||||
- “.\\0\\0\\0”
|
||||
* - 0xC
|
||||
- \_\_le32
|
||||
- dotdot.inode
|
||||
- inode number of parent directory.
|
||||
* - 0x10
|
||||
- \_\_le16
|
||||
- dotdot.rec\_len
|
||||
- block\_size - 12. The record length is long enough to cover all htree
|
||||
data.
|
||||
* - 0x12
|
||||
- u8
|
||||
- dotdot.name\_len
|
||||
- Length of the name, 2.
|
||||
* - 0x13
|
||||
- u8
|
||||
- dotdot.file\_type
|
||||
- File type of this entry, 0x2 (directory) (if the feature flag is set).
|
||||
* - 0x14
|
||||
- char
|
||||
- dotdot\_name[4]
|
||||
- “..\\0\\0”
|
||||
* - 0x18
|
||||
- \_\_le32
|
||||
- struct dx\_root\_info.reserved\_zero
|
||||
- Zero.
|
||||
* - 0x1C
|
||||
- u8
|
||||
- struct dx\_root\_info.hash\_version
|
||||
- Hash type, see dirhash_ table below.
|
||||
* - 0x1D
|
||||
- u8
|
||||
- struct dx\_root\_info.info\_length
|
||||
- Length of the tree information, 0x8.
|
||||
* - 0x1E
|
||||
- u8
|
||||
- struct dx\_root\_info.indirect\_levels
|
||||
- Depth of the htree. Cannot be larger than 3 if the INCOMPAT\_LARGEDIR
|
||||
feature is set; cannot be larger than 2 otherwise.
|
||||
* - 0x1F
|
||||
- u8
|
||||
- struct dx\_root\_info.unused\_flags
|
||||
-
|
||||
* - 0x20
|
||||
- \_\_le16
|
||||
- limit
|
||||
- Maximum number of dx\_entries that can follow this header, plus 1 for
|
||||
the header itself.
|
||||
* - 0x22
|
||||
- \_\_le16
|
||||
- count
|
||||
- Actual number of dx\_entries that follow this header, plus 1 for the
|
||||
header itself.
|
||||
* - 0x24
|
||||
- \_\_le32
|
||||
- block
|
||||
- The block number (within the directory file) that goes with hash=0.
|
||||
* - 0x28
|
||||
- struct dx\_entry
|
||||
- entries[0]
|
||||
- As many 8-byte ``struct dx_entry`` as fits in the rest of the data block.
|
||||
|
||||
.. _dirhash:
|
||||
|
||||
The directory hash is one of the following values:
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 79
|
||||
:header-rows: 1
|
||||
|
||||
* - Value
|
||||
- Description
|
||||
* - 0x0
|
||||
- Legacy.
|
||||
* - 0x1
|
||||
- Half MD4.
|
||||
* - 0x2
|
||||
- Tea.
|
||||
* - 0x3
|
||||
- Legacy, unsigned.
|
||||
* - 0x4
|
||||
- Half MD4, unsigned.
|
||||
* - 0x5
|
||||
- Tea, unsigned.
|
||||
|
||||
Interior nodes of an htree are recorded as ``struct dx_node``, which is
|
||||
also the full length of a data block:
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 1 1 77
|
||||
:header-rows: 1
|
||||
|
||||
* - Offset
|
||||
- Type
|
||||
- Name
|
||||
- Description
|
||||
* - 0x0
|
||||
- \_\_le32
|
||||
- fake.inode
|
||||
- Zero, to make it look like this entry is not in use.
|
||||
* - 0x4
|
||||
- \_\_le16
|
||||
- fake.rec\_len
|
||||
- The size of the block, in order to hide all of the dx\_node data.
|
||||
* - 0x6
|
||||
- u8
|
||||
- name\_len
|
||||
- Zero. There is no name for this “unused” directory entry.
|
||||
* - 0x7
|
||||
- u8
|
||||
- file\_type
|
||||
- Zero. There is no file type for this “unused” directory entry.
|
||||
* - 0x8
|
||||
- \_\_le16
|
||||
- limit
|
||||
- Maximum number of dx\_entries that can follow this header, plus 1 for
|
||||
the header itself.
|
||||
* - 0xA
|
||||
- \_\_le16
|
||||
- count
|
||||
- Actual number of dx\_entries that follow this header, plus 1 for the
|
||||
header itself.
|
||||
* - 0xE
|
||||
- \_\_le32
|
||||
- block
|
||||
- The block number (within the directory file) that goes with the lowest
|
||||
hash value of this block. This value is stored in the parent block.
|
||||
* - 0x12
|
||||
- struct dx\_entry
|
||||
- entries[0]
|
||||
- As many 8-byte ``struct dx_entry`` as fits in the rest of the data block.
|
||||
|
||||
The hash maps that exist in both ``struct dx_root`` and
|
||||
``struct dx_node`` are recorded as ``struct dx_entry``, which is 8 bytes
|
||||
long:
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 1 1 77
|
||||
:header-rows: 1
|
||||
|
||||
* - Offset
|
||||
- Type
|
||||
- Name
|
||||
- Description
|
||||
* - 0x0
|
||||
- \_\_le32
|
||||
- hash
|
||||
- Hash code.
|
||||
* - 0x4
|
||||
- \_\_le32
|
||||
- block
|
||||
- Block number (within the directory file, not filesystem blocks) of the
|
||||
next node in the htree.
|
||||
|
||||
(If you think this is all quite clever and peculiar, so does the
|
||||
author.)
|
||||
|
||||
If metadata checksums are enabled, the last 8 bytes of the directory
|
||||
block (precisely the length of one dx\_entry) are used to store a
|
||||
``struct dx_tail``, which contains the checksum. The ``limit`` and
|
||||
``count`` entries in the dx\_root/dx\_node structures are adjusted as
|
||||
necessary to fit the dx\_tail into the block. If there is no space for
|
||||
the dx\_tail, the user is notified to run e2fsck -D to rebuild the
|
||||
directory index (which will ensure that there's space for the checksum.
|
||||
The dx\_tail structure is 8 bytes long and looks like this:
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 1 1 77
|
||||
:header-rows: 1
|
||||
|
||||
* - Offset
|
||||
- Type
|
||||
- Name
|
||||
- Description
|
||||
* - 0x0
|
||||
- u32
|
||||
- dt\_reserved
|
||||
- Zero.
|
||||
* - 0x4
|
||||
- \_\_le32
|
||||
- dt\_checksum
|
||||
- Checksum of the htree directory block.
|
||||
|
||||
The checksum is calculated against the FS UUID, the htree index header
|
||||
(dx\_root or dx\_node), all of the htree indices (dx\_entry) that are in
|
||||
use, and the tail block (dx\_tail).
|
||||
@@ -0,0 +1,12 @@
|
||||
.. SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
Dynamic Structures
|
||||
==================
|
||||
|
||||
Dynamic metadata are created on the fly when files and blocks are
|
||||
allocated to files.
|
||||
|
||||
.. include:: inodes.rst
|
||||
.. include:: ifork.rst
|
||||
.. include:: directory.rst
|
||||
.. include:: attributes.rst
|
||||
@@ -0,0 +1,18 @@
|
||||
.. SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
Large Extended Attribute Values
|
||||
-------------------------------
|
||||
|
||||
To enable ext4 to store extended attribute values that do not fit in the
|
||||
inode or in the single extended attribute block attached to an inode,
|
||||
the EA\_INODE feature allows us to store the value in the data blocks of
|
||||
a regular file inode. This “EA inode” is linked only from the extended
|
||||
attribute name index and must not appear in a directory entry. The
|
||||
inode's i\_atime field is used to store a checksum of the xattr value;
|
||||
and i\_ctime/i\_version store a 64-bit reference count, which enables
|
||||
sharing of large xattr values between multiple owning inodes. For
|
||||
backward compatibility with older versions of this feature, the
|
||||
i\_mtime/i\_generation *may* store a back-reference to the inode number
|
||||
and i\_generation of the **one** owning inode (in cases where the EA
|
||||
inode is not referenced by multiple inodes) to verify that the EA inode
|
||||
is the correct one being accessed.
|
||||
@@ -0,0 +1,13 @@
|
||||
.. SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
Global Structures
|
||||
=================
|
||||
|
||||
The filesystem is sharded into a number of block groups, each of which
|
||||
have static metadata at fixed locations.
|
||||
|
||||
.. include:: super.rst
|
||||
.. include:: group_descr.rst
|
||||
.. include:: bitmaps.rst
|
||||
.. include:: mmp.rst
|
||||
.. include:: journal.rst
|
||||
@@ -0,0 +1,170 @@
|
||||
.. SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
Block Group Descriptors
|
||||
-----------------------
|
||||
|
||||
Each block group on the filesystem has one of these descriptors
|
||||
associated with it. As noted in the Layout section above, the group
|
||||
descriptors (if present) are the second item in the block group. The
|
||||
standard configuration is for each block group to contain a full copy of
|
||||
the block group descriptor table unless the sparse\_super feature flag
|
||||
is set.
|
||||
|
||||
Notice how the group descriptor records the location of both bitmaps and
|
||||
the inode table (i.e. they can float). This means that within a block
|
||||
group, the only data structures with fixed locations are the superblock
|
||||
and the group descriptor table. The flex\_bg mechanism uses this
|
||||
property to group several block groups into a flex group and lay out all
|
||||
of the groups' bitmaps and inode tables into one long run in the first
|
||||
group of the flex group.
|
||||
|
||||
If the meta\_bg feature flag is set, then several block groups are
|
||||
grouped together into a meta group. Note that in the meta\_bg case,
|
||||
however, the first and last two block groups within the larger meta
|
||||
group contain only group descriptors for the groups inside the meta
|
||||
group.
|
||||
|
||||
flex\_bg and meta\_bg do not appear to be mutually exclusive features.
|
||||
|
||||
In ext2, ext3, and ext4 (when the 64bit feature is not enabled), the
|
||||
block group descriptor was only 32 bytes long and therefore ends at
|
||||
bg\_checksum. On an ext4 filesystem with the 64bit feature enabled, the
|
||||
block group descriptor expands to at least the 64 bytes described below;
|
||||
the size is stored in the superblock.
|
||||
|
||||
If gdt\_csum is set and metadata\_csum is not set, the block group
|
||||
checksum is the crc16 of the FS UUID, the group number, and the group
|
||||
descriptor structure. If metadata\_csum is set, then the block group
|
||||
checksum is the lower 16 bits of the checksum of the FS UUID, the group
|
||||
number, and the group descriptor structure. Both block and inode bitmap
|
||||
checksums are calculated against the FS UUID, the group number, and the
|
||||
entire bitmap.
|
||||
|
||||
The block group descriptor is laid out in ``struct ext4_group_desc``.
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 1 1 77
|
||||
:header-rows: 1
|
||||
|
||||
* - Offset
|
||||
- Size
|
||||
- Name
|
||||
- Description
|
||||
* - 0x0
|
||||
- \_\_le32
|
||||
- bg\_block\_bitmap\_lo
|
||||
- Lower 32-bits of location of block bitmap.
|
||||
* - 0x4
|
||||
- \_\_le32
|
||||
- bg\_inode\_bitmap\_lo
|
||||
- Lower 32-bits of location of inode bitmap.
|
||||
* - 0x8
|
||||
- \_\_le32
|
||||
- bg\_inode\_table\_lo
|
||||
- Lower 32-bits of location of inode table.
|
||||
* - 0xC
|
||||
- \_\_le16
|
||||
- bg\_free\_blocks\_count\_lo
|
||||
- Lower 16-bits of free block count.
|
||||
* - 0xE
|
||||
- \_\_le16
|
||||
- bg\_free\_inodes\_count\_lo
|
||||
- Lower 16-bits of free inode count.
|
||||
* - 0x10
|
||||
- \_\_le16
|
||||
- bg\_used\_dirs\_count\_lo
|
||||
- Lower 16-bits of directory count.
|
||||
* - 0x12
|
||||
- \_\_le16
|
||||
- bg\_flags
|
||||
- Block group flags. See the bgflags_ table below.
|
||||
* - 0x14
|
||||
- \_\_le32
|
||||
- bg\_exclude\_bitmap\_lo
|
||||
- Lower 32-bits of location of snapshot exclusion bitmap.
|
||||
* - 0x18
|
||||
- \_\_le16
|
||||
- bg\_block\_bitmap\_csum\_lo
|
||||
- Lower 16-bits of the block bitmap checksum.
|
||||
* - 0x1A
|
||||
- \_\_le16
|
||||
- bg\_inode\_bitmap\_csum\_lo
|
||||
- Lower 16-bits of the inode bitmap checksum.
|
||||
* - 0x1C
|
||||
- \_\_le16
|
||||
- bg\_itable\_unused\_lo
|
||||
- Lower 16-bits of unused inode count. If set, we needn't scan past the
|
||||
``(sb.s_inodes_per_group - gdt.bg_itable_unused)``\ th entry in the
|
||||
inode table for this group.
|
||||
* - 0x1E
|
||||
- \_\_le16
|
||||
- bg\_checksum
|
||||
- Group descriptor checksum; crc16(sb\_uuid+group+desc) if the
|
||||
RO\_COMPAT\_GDT\_CSUM feature is set, or crc32c(sb\_uuid+group\_desc) &
|
||||
0xFFFF if the RO\_COMPAT\_METADATA\_CSUM feature is set.
|
||||
* -
|
||||
-
|
||||
-
|
||||
- These fields only exist if the 64bit feature is enabled and s_desc_size
|
||||
> 32.
|
||||
* - 0x20
|
||||
- \_\_le32
|
||||
- bg\_block\_bitmap\_hi
|
||||
- Upper 32-bits of location of block bitmap.
|
||||
* - 0x24
|
||||
- \_\_le32
|
||||
- bg\_inode\_bitmap\_hi
|
||||
- Upper 32-bits of location of inodes bitmap.
|
||||
* - 0x28
|
||||
- \_\_le32
|
||||
- bg\_inode\_table\_hi
|
||||
- Upper 32-bits of location of inodes table.
|
||||
* - 0x2C
|
||||
- \_\_le16
|
||||
- bg\_free\_blocks\_count\_hi
|
||||
- Upper 16-bits of free block count.
|
||||
* - 0x2E
|
||||
- \_\_le16
|
||||
- bg\_free\_inodes\_count\_hi
|
||||
- Upper 16-bits of free inode count.
|
||||
* - 0x30
|
||||
- \_\_le16
|
||||
- bg\_used\_dirs\_count\_hi
|
||||
- Upper 16-bits of directory count.
|
||||
* - 0x32
|
||||
- \_\_le16
|
||||
- bg\_itable\_unused\_hi
|
||||
- Upper 16-bits of unused inode count.
|
||||
* - 0x34
|
||||
- \_\_le32
|
||||
- bg\_exclude\_bitmap\_hi
|
||||
- Upper 32-bits of location of snapshot exclusion bitmap.
|
||||
* - 0x38
|
||||
- \_\_le16
|
||||
- bg\_block\_bitmap\_csum\_hi
|
||||
- Upper 16-bits of the block bitmap checksum.
|
||||
* - 0x3A
|
||||
- \_\_le16
|
||||
- bg\_inode\_bitmap\_csum\_hi
|
||||
- Upper 16-bits of the inode bitmap checksum.
|
||||
* - 0x3C
|
||||
- \_\_u32
|
||||
- bg\_reserved
|
||||
- Padding to 64 bytes.
|
||||
|
||||
.. _bgflags:
|
||||
|
||||
Block group flags can be any combination of the following:
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 79
|
||||
:header-rows: 1
|
||||
|
||||
* - Value
|
||||
- Description
|
||||
* - 0x1
|
||||
- inode table and bitmap are not initialized (EXT4\_BG\_INODE\_UNINIT).
|
||||
* - 0x2
|
||||
- block bitmap is not initialized (EXT4\_BG\_BLOCK\_UNINIT).
|
||||
* - 0x4
|
||||
- inode table is zeroed (EXT4\_BG\_INODE\_ZEROED).
|
||||
@@ -0,0 +1,194 @@
|
||||
.. SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
The Contents of inode.i\_block
|
||||
------------------------------
|
||||
|
||||
Depending on the type of file an inode describes, the 60 bytes of
|
||||
storage in ``inode.i_block`` 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.
|
||||
|
||||
Symbolic Links
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
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.
|
||||
|
||||
Direct/Indirect Block Addressing
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
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.
|
||||
|
||||
.. ifconfig:: builder != 'latex'
|
||||
|
||||
.. include:: blockmap.rst
|
||||
|
||||
.. ifconfig:: builder == 'latex'
|
||||
|
||||
[Table omitted because LaTeX doesn't support nested tables.]
|
||||
|
||||
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.
|
||||
|
||||
Notice also that a file using this mapping scheme cannot be placed
|
||||
higher than 2^32 blocks.
|
||||
|
||||
Extent Tree
|
||||
~~~~~~~~~~~
|
||||
|
||||
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 ``struct ext4_extent`` with
|
||||
``ee_len = 1000``. 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.
|
||||
|
||||
Extents are arranged as a tree. Each node of the tree begins with a
|
||||
``struct ext4_extent_header``. If the node is an interior node
|
||||
(``eh.eh_depth`` > 0), the header is followed by ``eh.eh_entries``
|
||||
instances of ``struct ext4_extent_idx``; each of these index entries
|
||||
points to a block containing more nodes in the extent tree. If the node
|
||||
is a leaf node (``eh.eh_depth == 0``), then the header is followed by
|
||||
``eh.eh_entries`` instances of ``struct ext4_extent``; these instances
|
||||
point to the file's data blocks. The root node of the extent tree is
|
||||
stored in ``inode.i_block``, which allows for the first four extents to
|
||||
be recorded without the use of extra metadata blocks.
|
||||
|
||||
The extent tree header is recorded in ``struct ext4_extent_header``,
|
||||
which is 12 bytes long:
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 1 1 77
|
||||
:header-rows: 1
|
||||
|
||||
* - Offset
|
||||
- Size
|
||||
- Name
|
||||
- Description
|
||||
* - 0x0
|
||||
- \_\_le16
|
||||
- eh\_magic
|
||||
- Magic number, 0xF30A.
|
||||
* - 0x2
|
||||
- \_\_le16
|
||||
- eh\_entries
|
||||
- Number of valid entries following the header.
|
||||
* - 0x4
|
||||
- \_\_le16
|
||||
- eh\_max
|
||||
- Maximum number of entries that could follow the header.
|
||||
* - 0x6
|
||||
- \_\_le16
|
||||
- eh\_depth
|
||||
- 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 ``2^32``, and the smallest ``n`` that
|
||||
satisfies ``4*(((blocksize - 12)/12)^n) >= 2^32`` is 5.
|
||||
* - 0x8
|
||||
- \_\_le32
|
||||
- eh\_generation
|
||||
- Generation of the tree. (Used by Lustre, but not standard ext4).
|
||||
|
||||
Internal nodes of the extent tree, also known as index nodes, are
|
||||
recorded as ``struct ext4_extent_idx``, and are 12 bytes long:
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 1 1 77
|
||||
:header-rows: 1
|
||||
|
||||
* - Offset
|
||||
- Size
|
||||
- Name
|
||||
- Description
|
||||
* - 0x0
|
||||
- \_\_le32
|
||||
- ei\_block
|
||||
- This index node covers file blocks from 'block' onward.
|
||||
* - 0x4
|
||||
- \_\_le32
|
||||
- ei\_leaf\_lo
|
||||
- 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.
|
||||
* - 0x8
|
||||
- \_\_le16
|
||||
- ei\_leaf\_hi
|
||||
- Upper 16-bits of the previous field.
|
||||
* - 0xA
|
||||
- \_\_u16
|
||||
- ei\_unused
|
||||
-
|
||||
|
||||
Leaf nodes of the extent tree are recorded as ``struct ext4_extent``,
|
||||
and are also 12 bytes long:
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 1 1 77
|
||||
:header-rows: 1
|
||||
|
||||
* - Offset
|
||||
- Size
|
||||
- Name
|
||||
- Description
|
||||
* - 0x0
|
||||
- \_\_le32
|
||||
- ee\_block
|
||||
- First file block number that this extent covers.
|
||||
* - 0x4
|
||||
- \_\_le16
|
||||
- ee\_len
|
||||
- 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 ``ee_len`` -
|
||||
32768. Therefore, the maximum length of a initialized extent is 32768
|
||||
blocks, and the maximum length of an uninitialized extent is 32767.
|
||||
* - 0x6
|
||||
- \_\_le16
|
||||
- ee\_start\_hi
|
||||
- Upper 16-bits of the block number to which this extent points.
|
||||
* - 0x8
|
||||
- \_\_le32
|
||||
- ee\_start\_lo
|
||||
- Lower 32-bits of the block number to which this extent points.
|
||||
|
||||
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.
|
||||
|
||||
``struct ext4_extent_tail`` is 4 bytes long:
|
||||
|
||||
.. list-table::
|
||||
:widths: 1 1 1 77
|
||||
:header-rows: 1
|
||||
|
||||
* - Offset
|
||||
- Size
|
||||
- Name
|
||||
- Description
|
||||
* - 0x0
|
||||
- \_\_le32
|
||||
- eb\_checksum
|
||||
- Checksum of the extent block, crc32c(uuid+inum+igeneration+extentblock)
|
||||
|
||||
Inline Data
|
||||
~~~~~~~~~~~
|
||||
|
||||
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.
|
||||
@@ -0,0 +1,9 @@
|
||||
.. SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
==============================
|
||||
Data Structures and Algorithms
|
||||
==============================
|
||||
.. include:: about.rst
|
||||
.. include:: overview.rst
|
||||
.. include:: globals.rst
|
||||
.. include:: dynamic.rst
|
||||
@@ -0,0 +1,37 @@
|
||||
.. SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
Inline Data
|
||||
-----------
|
||||
|
||||
The inline data feature was designed to handle the case that a file's
|
||||
data is so tiny that it readily fits inside the inode, which
|
||||
(theoretically) reduces disk block consumption and reduces seeks. If the
|
||||
file is smaller than 60 bytes, then the data are stored inline in
|
||||
``inode.i_block``. If the rest of the file would fit inside the extended
|
||||
attribute space, then it might be found as an extended attribute
|
||||
“system.data” within the inode body (“ibody EA”). This of course
|
||||
constrains the amount of extended attributes one can attach to an inode.
|
||||
If the data size increases beyond i\_block + ibody EA, a regular block
|
||||
is allocated and the contents moved to that block.
|
||||
|
||||
Pending a change to compact the extended attribute key used to store
|
||||
inline data, one ought to be able to store 160 bytes of data in a
|
||||
256-byte inode (as of June 2015, when i\_extra\_isize is 28). Prior to
|
||||
that, the limit was 156 bytes due to inefficient use of inode space.
|
||||
|
||||
The inline data feature requires the presence of an extended attribute
|
||||
for “system.data”, even if the attribute value is zero length.
|
||||
|
||||
Inline Directories
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The first four bytes of i\_block are the inode number of the parent
|
||||
directory. Following that is a 56-byte space for an array of directory
|
||||
entries; see ``struct ext4_dir_entry``. If there is a “system.data”
|
||||
attribute in the inode body, the EA value is an array of
|
||||
``struct ext4_dir_entry`` as well. Note that for inline directories, the
|
||||
i\_block and EA space are treated as separate dirent blocks; directory
|
||||
entries cannot span the two.
|
||||
|
||||
Inline directory entries are not checksummed, as the inode checksum
|
||||
should protect all inline data contents.
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user