On-disk Format 磁盘格式
This document describes the Btrfs on‐disk format.
本文档描述了 Btrfs 的磁盘格式。
Note 注意
This document contains outdated and incomplete information and has been
copied from the original btrfs.wiki.kernel.org with little review.
本文档包含过时和不完整的信息,并且是从原始的 btrfs.wiki.kernel.org 复制而来,经过了很少的审查。
Overview 概述
Aside from the superblock, Btrfs consists entirely of several trees. The trees
use copy-on-write. Trees are stored in nodes, each of with belong to a level
in the b-tree structure. Internal nodes contain references to other internal
nodes on the next level, or to leaf nodes then the level reaches zero. Leaf
nodes contain various types of data structures, depending on the tree.
除了超级块外,Btrfs 完全由几棵树组成。这些树使用写时复制。树存储在节点中,每个节点都属于 B 树结构中的一个级别。内部节点包含对下一级别的其他内部节点的引用,或者在级别达到零时对叶节点的引用。叶节点包含各种类型的数据结构,取决于树的类型。
Btrfs makes a distinction between logical and physical addresses. Logical
addresses are used in the filesystem structures, while physical addresses are
simply byte offsets on a disk. One logical address may correspond to physical
addresses on any number of disks, depending on RAID settings. The chunk tree is
used to convert from logical addresses to physical addresses; the dev tree can
be used for the reverse.
Btrfs 在逻辑地址和物理地址之间进行区分。逻辑地址用于文件系统结构,而物理地址仅是磁盘上的字节偏移量。一个逻辑地址可能对应于任意数量的磁盘上的物理地址,这取决于 RAID 设置。块树用于将逻辑地址转换为物理地址;dev 树可用于反向操作。
For bootstrapping purposes, the superblock contains a subset of the chunk tree,
specifically it contains “chunk items” for all system chunks. The superblock
also contains a logical reference to root nodes in the root and chunk trees,
which can then be used to locate all the other trees and data stored.
为引导目的,超级块包含块树的子集,具体来说,它包含所有系统块的“块项”。超级块还包含对根节点在根和块树中的逻辑引用,然后可以用于定位所有其他树和存储的数据。
TODO Subvolumes and snapshots.
待办事项:子卷和快照。
Basic Structures 基本结构
Note that the fields are unsigned, so object ID −1 will be treated as
0xffffffffffffffff and sorted to the end of the tree. Since Btrfs uses
little‐endian, a simple byte‐by‐byte comparison of KEYs will not work.
请注意,字段是无符号的,因此对象 ID -1 将被视为 0xffffffffffffffff 并排序到树的末尾。由于 Btrfs 使用小端序,对 KEY 的简单逐字节比较将不起作用。
Off
Size
Type
Description
0
8
UINT
Object ID. Each tree has its own set of Object IDs.
对象 ID。每个树都有自己的对象 ID 集合。8
1
UINT
Item type. 项目类型。
9
8
UINT
Offset. The meaning depends on the item type.
偏移。其含义取决于项目类型。11
Btrfs uses Unix time. Btrfs 使用 Unix 时间。
Off
Size
Type
Description
0
8
SINT
Number of seconds since 1970-01-01T00:00:00Z.
从 1970-01-01T00:00:00Z 开始的秒数。8
4
UINT
Number of nanoseconds since the beginning of the second.
从秒开始的纳秒数。c
Superblock 超级块
The primary superblock is located at 0x10000 (64KiB). Mirror copies of the
superblock are located at physical addresses 0x4000000 (64 MiB) and
0x4000000000 (256GiB), if these locations are valid. Superblock copies are
updated simultaneously. During mount btrfs’ kernel module reads only the first
super block (at 64KiB), if an error is detected mounting fails.
主超级块位于 0x10000(64KiB)处。如果这些位置有效,则超级块的镜像副本位于物理地址 0x4000000(64 MiB)和 0x4000000000(256GiB)处。超级块副本同时更新。在挂载 btrfs 时,内核模块只读取第一个超级块(在 64KiB 处),如果检测到错误,则挂载失败。
Note that btrfs only recognizes disks with a valid 0x1 0000 superblock;
otherwise, there would be confusion with other filesystems.
请注意,btrfs 仅识别具有有效 0x1 0000 超级块的磁盘;否则,将与其他文件系统混淆。
TODO 待办事项
Off
Size
Type
Description
0
20
CSUM
Checksum of everything past this field (from 20 to 1000)
从此字段开始的所有内容的校验和(从 20 到 1000)20
10
UUID
FS UUID
30
8
UINT
physical address of this block (different for mirrors)
该块的物理地址(镜像不同)38
8
flags
40
8
ASCII
magic (“_BHRfS_M”) 魔法(“_BHRfS_M”)
48
8
generation
50
8
logical address of the root tree root
根树根的逻辑地址58
8
logical address of the chunk tree root
块树根的逻辑地址60
8
logical address of the log tree root
日志树根的逻辑地址68
8
log_root_transid
70
8
total_bytes
78
8
bytes_used
80
8
root_dir_objectid (usually 6)
root_dir_objectid(通常为 6)88
8
num_devices
90
4
sectorsize
94
4
nodesize
98
4
leafsize
9c
4
stripesize
a0
4
sys_chunk_array_size
a4
8
chunk_root_generation
ac
8
compat_flags
b4
8
compat_ro_flags - only implementations that support the flags can write to the filesystem
compat_ro_flags - 只有支持这些标志的实现才能写入文件系统bc
8
incompat_flags - only implementations that support the flags can use the filesystem
incompat_flags - 只有支持这些标志的实现才能使用文件系统c4
2
csum_type - Btrfs currently uses the CRC32c little-endian hash function with seed -1.
csum_type - Btrfs 目前使用 CRC32c 小端哈希函数,种子为 -1。c6
1
root_level
c7
1
chunk_root_level
c8
1
log_root_level
c9
62
DEV_ITEM data for this device
此设备的 DEV_ITEM 数据12b
100
label (may not contain ‘/’ or ‘\\’)
标签(可能不包含 '/' 或 '\\')22b
8
cache_generation
233
8
uuid_tree_generation
23b
f0
reserved /* future expansion */
保留 /* 未来扩展 */32b
800
sys_chunk_array:(n bytes valid) Contains (KEY, CHUNK_ITEM) pairs for all SYSTEM chunks. This is needed to bootstrap the mapping from logical addresses to physical.
sys_chunk_array:(n 字节有效) 包含所有系统块的 (KEY, CHUNK_ITEM) 对。这对于引导从逻辑地址到物理地址的映射是必要的。b2b
2a0
Contain super_roots (4 btrfs_root_backup)
包含 super_roots(4 个 btrfs_root_backup)dcb
235
current unused 当前未使用
1000
Header 头部
This is the data stored at the start of every node. The data following it
depends on whether it is an internal or leaf node, both of which are described
below.
这是存储在每个节点开头的数据。其后的数据取决于它是内部节点还是叶节点,两者都在下面描述。
Off
Size
Type
Description
0
20
CSUM
Checksum of everything after this field (from 20 to the end of the node)
此字段之后所有内容的校验和(从 20 到节点末尾)20
10
UUID
FS UUID
30
8
UINT
Logical address of this node
该节点的逻辑地址38
7
FIELD
Flags
3f
1
UINT
Backref. Rev.: always 1 (MIXED) for new filesystems; 0 (OLD) indicates an old filesystem.
反向引用。Rev.:对于新文件系统始终为 1(混合);0(旧)表示旧文件系统。40
10
UUID
Chunk tree UUID 块树 UUID
50
8
UINT
Generation
58
8
UINT
The ID of the tree that contains this node
包含此节点的树的 ID60
4
UINT
Number of items 项目数量
64
1
UINT
Level (0 for leaf nodes)
等级(叶节点为 0)65
Internal Node 内部节点
In internal nodes, the node header is followed by a number of key pointers.
在内部节点中,节点头部后面跟着一些键指针。
Off
Size
Type
Description
0
11
KEY
key
11
8
UINT
block number 块编号
19
8
UINT
generation
21
header
key ptr 键指针
key ptr 键指针
key ptr 键指针
…
free space 空闲空间
Leaf Node 叶节点
In leaf nodes, the node header is followed by a number of items. The items’
data is stored at the end of the node, and the contents of the item data
depends on the item type stored in the key.
在叶节点中,节点头部后面跟着一些项目。项目的数据存储在节点的末尾,项目数据的内容取决于键中存储的项目类型。
Off
Size
Type
Description
0
11
KEY
key
11
4
UINT
data offset relative to end of header (65)
相对于标头末尾的数据偏移量(65)15
4
UINT
data size 数据大小
19
header
item 0 项目 0
item 1 项目 1
…
item N 项目 N
free space 空闲空间
data N 数据 N
…
data 1 数据 1
data 0 数据 0
Object Types 对象类型
TODO 待办事项
Objects 对象
ROOT_TREE (1)
The root tree holds ROOT_ITEMs, ROOT_REFs, and ROOT_BACKREFs for every tree other than itself. It is
used to find the other trees and to determine the subvolume structure. It also holds the items for
the root tree directory. The logical address of the root tree is stored
in the superblock.
根树包含 ROOT_ITEMs、ROOT_REFs 和 ROOT_BACKREFs,用于存储除自身以外的每棵树。它用于查找其他树并确定子卷结构。它还保存了根树目录的项目。根树的逻辑地址存储在超级块中。
Reserved objectids 保留的对象 ID。
There are several well-known objectids that refer to internal trees.
有几个众所周知的 objectids 指的是内部树。
All root objectids between
BTRFS_FIRST_FREE_OBJECTID = 256ULL
and
BTRFS_LAST_FREE_OBJECTID = -256ULL
refer to file trees.
所有根 objectids 在 BTRFS_FIRST_FREE_OBJECTID = 256ULL
和 BTRFS_LAST_FREE_OBJECTID = -256ULL
之间指的是文件树。
Otherwise, the objectid should be considered reserved for internal use.
否则,该 objectid 应被视为内部使用保留。
BTRFS_ROOT_TREE_OBJECTID = 1
The object id that refers to the
ROOT_TREE
itself.
指向ROOT_TREE
本身的对象 ID。BTRFS_EXTENT_TREE_OBJECTID = 2
The objectid that refers to the
EXTENT_TREE
指向EXTENT_TREE
的 objectidBTRFS_CHUNK_TREE_OBJECTID = 3
The objectid that refers to the root of the
CHUNK_TREE
指向CHUNK_TREE
根目录的 objectidBTRFS_DEV_TREE_OBJECTID = 4
The objectid that refers to the root of the
DEV_TREE
指向DEV_TREE
根目录的 objectidBTRFS_FS_TREE_OBJECTID = 5
The objectid that refers to the global
FS_TREE
root.
指向全局FS_TREE
根的 objectid。BTRFS_CSUM_TREE_OBJECTID = 7
The objectid that refers to the
CSUM_TREE
指向CSUM_TREE
的 objectidBTRFS_QUOTA_TREE_OBJECTID = 8
The objectid that refers to the
QUOTA_TREE
指向QUOTA_TREE
的 objectidBTRFS_UUID_TREE_OBJECTID = 9
The objectid that refers to the
UUID_TREE
.
指向UUID_TREE
的 objectid。BTRFS_FREE_SPACE_TREE_OBJECTID = 10
The objectid that refers to the
FREE_SPACE_TREE
.
指向FREE_SPACE_TREE
的 objectid。BTRFS_TREE_LOG_OBJECTID = -7ULL
The objectid that refers to the
TREE_LOG
tree.
指向TREE_LOG
树的 objectid。BTRFS_TREE_RELOC_OBJECTID = -8ULL
The objectid that refers to the
TREE_RELOC
tree.
指向TREE_RELOC
树的 objectid。BTRFS_DATA_RELOC_TREE_OBJECTID = -9ULL
The objectid that refers to the
DATA_RELOC
tree.
指向DATA_RELOC
树的 objectid。
The following are well-known objectids within the ROOT_TREE
that do not
refer to other trees.
以下是 ROOT_TREE
中众所周知的 objectids,它们不指向其他树。
BTRFS_ROOT_TREE_DIR_OBJECTID = 6
The objectid that refers to the directory within the root tree. If it exists, it will have the usual items used to implement a directory associated with it. There will only be a single entry called
default
that points to a key to be used as the root directory on the file system instead of theFS_TREE
.
指向根树中目录的 objectid。如果存在,它将具有用于实现与之关联的目录的常用项目。只会有一个名为default
的条目,指向一个用作文件系统根目录而不是FS_TREE
的密钥。BTRFS_ORPHAN_OBJECTID = -5ULL
The objectid used for orphan root tracking.
用于孤立根跟踪的 objectid。
Developer note: If implementing a feature that requires a new objectid in the
reserved range, you must reserve the objectid via the mailing list before
posting your code for general use. This is a disk format change.
开发者注意:如果要实现需要在保留范围内使用新 objectid 的功能,您必须通过邮件列表预留 objectid,然后再发布您的代码供一般使用。这是磁盘格式更改。
Orphans 孤儿
Removing a root is a multi-step process that may involve many transactions.
References to every extent used by the tree must be decremented and, if they
hit zero, the extents must be released. It is possible that the system crashes,
loses power, or otherwise encounters an error during root removal. Without
additional information, the file system could ultimately contain partially
removed roots, which would make it inconsistent. When a root is removed, it
performs several small operations in a single transaction in preparation for
removal. This process should be familiar to those with an understanding of how
orphans work when an inode is unlinked on any UNIX-style file system.
删除根是一个多步骤过程,可能涉及许多事务。必须递减树使用的每个范围的引用,并且如果它们达到零,则必须释放这些范围。在删除根时,系统可能会崩溃、断电或在其他情况下遇到错误。如果没有额外信息,文件系统最终可能包含部分删除的根,这将使其不一致。当删除根时,它会在准备删除的单个事务中执行几个小操作。对于了解当在任何 UNIX 风格文件系统上取消链接 inode 时孤儿如何工作的人来说,这个过程应该很熟悉。
Unlink the root from the directory that contains it.
从包含它的目录中取消链接根。Initialize the
drop_progress
anddrop_level
fields and set therefs
field to0
in theROOT_ITEM
.
在ROOT_ITEM
中初始化drop_progress
和drop_level
字段,并将refs
字段设置为0
。If an orphan key for this root has not already been inserted into the tree, insert one.
如果此根节点的孤立键尚未插入树中,请插入一个。Remove the UUID entries for this root and any associated received root from the
UUID_TREE
.
从UUID_TREE
中删除此根节点的 UUID 条目以及任何相关的接收根节点。
Ultimately, the cleaner thread handles the reference count adjustments and,
once that is complete, the root has been successfully removed and it removes
the orphan key for that root. As the cleaner progresses, the drop_progress
and drop_level
fields are updated to reflect the most recently processed
item.
最终,清理线程处理引用计数调整,一旦完成,根已成功移除,并移除该根的孤立键。随着清理的进行, drop_progress
和 drop_level
字段将更新以反映最近处理的项目。
This process may be interrupted at any time and it must be recoverable. The
orphan key is how btrfs avoids inconsistencies when that occurs. The orphan key
is located in the ROOT_TREE
and is of the following form.
此过程可能随时中断,必须是可恢复的。孤立键是 btrfs 在发生中断时避免不一致性的方式。孤立键位于 ROOT_TREE
中,其形式如下。
struct btrfs_key 结构 btrfs_key |
---|
|
|
There is no item body associated with this key. All required information is contained within the key itself and the
ROOT_ITEM
associated with the objectid contained inoffset
与此键关联的项目主体不存在。所有必需信息都包含在键本身和offset
中包含的 objectid 相关联的ROOT_ITEM
中。
When the file system is mounted again after failure, the ROOT_TREE
is
searched for all orphan keys and the process is resumed for each one using the
drop_progress
and drop_level
fields in the ROOT_ITEM
.
当文件系统在故障后再次挂载时,将搜索 ROOT_TREE
以查找所有孤立键,并使用 ROOT_ITEM
中的 drop_progress
和 drop_level
字段为每个键恢复进程。
EXTENT tree (2) EXTENT 树(2)
TODO 待办事项
Holds EXTENT_ITEMs, BLOCK_GROUP_ITEMs
持有 EXTENT_ITEMs,BLOCK_GROUP_ITEMsPointed to by ROOT 被 ROOT 指向
EMPTY_SUBVOL dir (2) 空的子卷目录 (2)
TODO 待办事项
CHUNK_TREE (3) 块树 (3)
The chunk tree holds all DEV_ITEMs and CHUNK_ITEMs, making it possible to
determine the device(s) and physical address(es) corresponding to a given
logical address. It is therefore crucial for access to the contents of the
filesystem.
块树包含所有的 DEV_ITEM 和 CHUNK_ITEM,从而可以确定与给定逻辑地址对应的设备和物理地址。因此,对于访问文件系统内容至关重要。
The chunk tree resides entirely in SYSTEM block groups, and will therefore be
accessible from the CHUNK_ITEM array in the Superblock. It also has an entry in
the ROOT tree.
块树完全驻留在系统块组中,因此可以从超级块中的 CHUNK_ITEM 数组中访问。它还在 ROOT 树中有一个条目。
Reserved objectids 保留的对象 ID。
BTRFS_FIRST_CHUNK_TREE_OBJECTID = 256
This objectid indicates the first available objectid in this
CHUNK_TREE
. In practice, it is the only objectid used in the tree. Theoffset
field of the key is the only component used to distinguish separate`CHUNK_ITEM
<#CHUNK_ITEM>`__ items.
此 objectid 指示此CHUNK_TREE
中第一个可用的 objectid。实际上,它是树中唯一使用的 objectid。键的offset
字段是用于区分单独的`CHUNK_ITEM
<#CHUNK_ITEM>`__ 项的唯一组件。
Dev tree (4) Dev 树 (4)
The dev tree holds all DEV_EXTENTs, making it possible to determine the logical
address corresponding to a given physical address. This is necessary when
shrinking or removing devices. The dev tree has an entry in the root tree.
dev 树保存所有 DEV_EXTENT,从而可以确定给定物理地址对应的逻辑地址。在缩小或删除设备时,这是必要的。dev 树在根树中有一个条目。
FS_TREE (5) FS_TREE(5)
TODO 待办事项
Holds
INODE_ITEM
,INODE_REF
,DIR_ITEM
, DIR_INDEXen, XATTR_ITEMs,EXTENT_DATA
for a filesystem
为文件系统保存INODE_ITEM
,INODE_REF
,DIR_ITEM
,DIR_INDEXen,XATTR_ITEMs,EXTENT_DATA
Pointed to by ROOT 被 ROOT 指向
TODO: “..” 待办事项: “..”
Root tree directory 根树目录
The root tree directory is stored in the root tree. It has an INODE_ITEM and a
DIR_ITEM with name “default” pointing to the FS tree. There is also a
corresponding INODE_REF, but no DIR_INDEX. The objectid of the root tree
directory is stored in the superblock, but is currently always 6.
根树目录存储在根树中。它具有一个名为“default”的 INODE_ITEM 和 DIR_ITEM,指向 FS 树。还有一个相应的 INODE_REF,但没有 DIR_INDEX。根树目录的 objectid 存储在超级块中,但目前始终为 6。
Checksum tree (7) 校验树(7)
The checksum tree contains all the EXTENT_CSUMs. It has an entry in the root
tree.
校验和树包含所有的 EXTENT_CSUMs。它在根树中有一个条目。
ORPHAN (-5) 孤立块 (-5)
TODO 待办事项
TREE_LOG (-6) 树木日志 (-6)
TODO 待办事项
TREE_LOG_FIXUP (-7) 树木日志修正 (-7)
TODO 待办事项
TREE_RELOC (-8)
TODO 待办事项
Just a copy of another tree
只是另一棵树的副本
DATA_RELOC tree (-9) DATA_RELOC 树 (-9)
TODO 待办事项
Holds 100 INODE_ITEM 0 拥有 100 个 INODE_ITEM 0
Holds 100 INODE_REF 100 0:’..’
拥有 100 个 INODE_REF 100 0:’..’Pointed to by ROOT 被 ROOT 指向
EXTENT_CSUM (-a)
TODO 待办事项
MULTIPLE_OBJECTIDS (-100)
多个对象 ID (-100)
TODO 待办事项
Item Types 项目类型
INODE_ITEM (01) INODE_ITEM (01)
Location 位置
INODE_ITEM
items are located primarily in file trees but are also found in the
ROOT_TREE to implement the free space cache (v1).
INODE_ITEM
项主要位于文件树中,但也可以在 ROOT_TREE 中找到,以实现空闲空间缓存(v1)。
Usage 用法
struct btrfs_key 结构 btrfs_key |
---|
objectid |
objectid (Used as inode number) |
Description 描述
Contains the stat information for an inode; see stat(2).
包含 i 节点的 stat 信息;请参阅 stat(2)。
Item Contents 项目内容
INODE_ITEM
items contain a single btrfs_inode_item
structure.
INODE_ITEM
项包含一个单一的 btrfs_inode_item
结构。
INODE_REF (0c)
(inode_id, directory_id) TODO
(inode_id, directory_id) 待办事项
From an inode to a name in a directory.
从一个 inode 到目录中的名称。
Off |
Size |
Type |
Description |
---|---|---|---|
0 |
8 |
UINT |
index in the directory 目录中的索引 |
8 |
2 |
UINT |
(n) |
a |
n |
ASCII |
name in the directory 目录中的名称 |
a+n |
This structure can be repeated…?
这个结构可以重复吗?
INODE_EXTREF (0d)
(inode_id, hash of name [using directory object ID as seed]) TODO
(inode_id, 使用目录对象 ID 作为种子的名称哈希) 待办事项
From an inode to a name in a directory. Used if the regarding INODE_REF array
ran out of space. This item requires the EXTENDED_IREF feature.
从一个 inode 到目录中的名称。如果相关的 INODE_REF 数组空间不足,则使用。此项需要 EXTENDED_IREF 功能。
Off |
Size |
Type |
Description |
---|---|---|---|
0 |
8 |
UINT |
directory object ID 目录对象标识符 |
8 |
8 |
UINT |
index in the directory 目录中的索引 |
10 |
2 |
UINT |
(n) |
12 |
n |
ASCII |
name in the directory 目录中的名称 |
12+n |
This structure can be repeated…?
这个结构可以重复吗?
XATTR_ITEM (18)
Location 位置
XATTR_ITEM
items are only located in file trees.
XATTR_ITEM
项仅位于文件树中。
Usage 用法
|
---|
objectid |
|
Description 描述
XATTR_ITEM
items contain extended attributes. Each name is hashed using the
name hash and that value is used in the key for locating the entry quickly.
Each XATTR_ITEM
item contains one or more extended attributes with names
represented by the same hash. All extended attributes that share the same name
hash must fit in a single leaf.
XATTR_ITEM
项包含扩展属性。每个名称都使用名称哈希进行哈希处理,该值用于在定位条目时快速查找键。每个 XATTR_ITEM
项包含一个或多个由相同哈希表示的名称的扩展属性。所有共享相同名称哈希的扩展属性必须适合单个叶子。
Item Contents 项目内容
XATTR_ITEM
items consist of a series of one or more extended attribute
entries with names that share a hash value. Each entry consists of a
btrfs_dir_item
structure immediately followed by the name and the attribute
data. The length of each name is contained in btrfs_dir_item.name_len
. The
data payload begins immediately after the name. The data payload length is
contained in btrfs_dir_item.data_len
btrfs_dir_item.data_len.location
is unused and must be zeroed. btrfs_dir_item.type
contains a shorthand
value referring to the type of item to which an entry refers it must always be
be BTRFS_FT_XATTR
when used to describe an extended attribute.
XATTR_ITEM
项由一系列一个或多个具有共享哈希值的名称的扩展属性条目组成。每个条目由一个 btrfs_dir_item
结构紧随其后,然后是名称和属性数据。每个名称的长度包含在 btrfs_dir_item.name_len
中。数据有效载荷紧随名称之后开始。数据有效载荷长度包含在 btrfs_dir_item.data_len
中。 btrfs_dir_item.data_len.location
未使用,必须清零。 btrfs_dir_item.type
包含一个简写值,指示条目所指的项目类型,用于描述扩展属性时必须始终为 BTRFS_FT_XATTR
。
When there is more than one entry for a single hash value, the offset of each
entry must be calculating using the lengths of the preceding entries including
names and data.
当一个哈希值有多个条目时,每个条目的偏移量必须使用前面条目的长度(包括名称和数据)进行计算。
For more details, please see: struct btrfs_dir_item
and `DIR_ITEM
.
更多详情,请参阅: struct btrfs_dir_item
和 `DIR_ITEM
。
VERITY_DESC (24)
Location 位置
VERITY_DESC
items are located in the FS_TREE. TODO
VERITY_DESC
项位于 FS_TREE 中。待办事项
VERITY_MERKLE (25)
Location 位置
VERITY_MERKLE
items are located in the FS_TREE. TODO
VERITY_MERKLE
项位于 FS_TREE 中。待办事项
ORPHAN_ITEM (30) 孤立项 (30)
(-5, objid of orphan inode) TODO
(-5,孤立索引节点的 objid) 待办事项
`` Empty.`` `` 空的。``
DIR_LOG_ITEM (3c)
(directory_id, first offset) TODO
(目录 ID,第一个偏移) 待办事项
`` 日志被认为是([第一个偏移量,结束偏移量)]的权威来源``
`` 0 8 UINT 结束偏移``
DIR_LOG_INDEX (48)
(directory_id, first offset) TODO
(目录 ID,第一个偏移) 待办事项
`` Same as DIR_LOG_ITEM.``
``与 DIR_LOG_ITEM 相同。``
DIR_ITEM (54) DIR_ITEM(54)
Location 位置
DIR_ITEM
items are only located in file trees.
DIR_ITEM
项仅位于文件树中。
Usage 用法
|
---|
objectid |
|
Description 描述
DIR_ITEM
items contain directory entries. Each name is hashed using the
name hash and that value is used in the key for locating the entry quickly.
Each DIR_ITEM
item contains one or more directory entries with names
represented by the same hash. All directory entries that share the same name
hash must fit in a single leaf.
DIR_ITEM
项包含目录条目。每个名称都使用名称哈希进行哈希处理,该值用于快速定位条目的键。每个 DIR_ITEM
项包含一个或多个由相同哈希表示的名称的目录条目。所有共享相同名称哈希的目录条目必须适合单个叶子。
Item Contents 项目内容
DIR_ITEM
items consist of a series of one or more directory entries with
names that share a hash value. Each entry consists of a btrfs_dir_item
structure immediately followed by the name. The length of each name is
contained in btrfs_dir_item.name_len
. The location of the item to which
this entry refers is contained in btrfs_dir_item.location
and must refer to
a valid item in the same file tree. btrfs_dir_item.type
contains a
shorthand value referring to the type of item to which an entry refers. It will
never be BTRFS_FT_XATTR
when used in a standard directory.
btrfs_dir_item.data_len
is unused and must be 0
.
DIR_ITEM
项由一系列共享哈希值的一个或多个目录条目组成。每个条目由紧随其后的名称组成的 btrfs_dir_item
结构组成。每个名称的长度包含在 btrfs_dir_item.name_len
中。此条目引用的项目的位置包含在 btrfs_dir_item.location
中,必须引用同一文件树中的有效项目。 btrfs_dir_item.type
包含一个简写值,指示条目引用的项目类型。在标准目录中使用时,它永远不会是 BTRFS_FT_XATTR
。 btrfs_dir_item.data_len
未使用,必须是 0
。
When there is more than one entry for a single hash value, the offset of each
entry must be calculating using the lengths of the preceding entries including
names.
当一个哈希值对应多个条目时,每个条目的偏移量必须使用前面条目的长度(包括名称)进行计算。
For more details, please see: struct btrfs_dir_item
.
更多详情,请参阅: struct btrfs_dir_item
。
DIR_INDEX (60)
(parent objectid, 60, index in parent)
(父对象 id,60,父对象中的索引)
Allows looking up an item in a directory by index. Indices start at 2 (because
of “.” and “..”); removed files can cause “holes” in the index space.
DIR_INDEXen have the same contents as DIR_ITEM, but may contain only one entry.
允许通过索引在目录中查找项目。索引从 2 开始(因为“.”和“..”);已删除的文件可能会在索引空间中造成“空洞”。DIR_INDEXen 与 DIR_ITEM 具有相同的内容,但可能只包含一个条目。
EXTENT_DATA (6c) EXTENT_DATA(6c)
(inode id, 6c, offset in file) TODO
(inode id, 6c, 文件中的偏移) 待办事项
The contents of a file.
文件的内容
Off |
Size |
Type |
Description |
---|---|---|---|
0 |
8 |
UINT |
generation |
8 |
8 |
UINT |
(n) size of decoded extent |
10 |
1 |
UINT |
compression (0=none, 1=zlib, 2=LZO) |
11 |
1 |
UINT |
encryption (0=none) 加密 (0=无) |
12 |
2 |
UINT |
other encoding (0=none) 其他编码 (0=无) |
14 |
1 |
UINT |
type (0=inline, 1=regular, 2=prealloc) |
15 |
If the extent is inline, the remaining item bytes are the data bytes (n bytes
in case no compression/encryption/other encoding is used).
如果范围是内联的,则剩余的项目字节是数据字节(如果没有使用压缩/加密/其他编码,则为 n 字节)。
Otherwise, the structure continues:
否则,结构继续:
Off |
Size |
Type |
Description |
---|---|---|---|
15 |
8 |
UINT |
(ea) logical address of extent. If this is zero, the extent is sparse
and consists of all zeroes. |
1d |
8 |
UINT |
(es) size of extent (es) 扩展的大小 |
25 |
8 |
UINT |
(o) offset within the extent |
2d |
8 |
UINT |
(s) logical number of bytes in file |
35 |
ea and es must exactly match an EXTENT_ITEM. If the es bytes of data at
logical address ea are decoded, n bytes will result. The file’s data
contains the s bytes at offset o within the decoded bytes. In the simplest,
uncompressed case, o=0 and n=es=s, so the file’s data simply
contains the n bytes at logical address ea.
ea 和 es 必须与 EXTENT_ITEM 完全匹配。如果在逻辑地址 ea 处的 es 字节数据被解码,将得到 n 字节。文件的数据包含解码字节中偏移量为 o 处的 s 字节。在最简单的、未压缩的情况下,o=0 且 n=es=s,因此文件的数据简单地包含逻辑地址 ea 处的 n 字节。
EXTENT_CSUM (80)
(-a, logical address?) TODO
(-a,逻辑地址?) 待办事项
`` 包含相邻块从逻辑地址(块大小)开始的超级块中类型的一个或多个校验和``
`` 块``
ROOT_ITEM (84) 根项目 (84)
Location 位置
ROOT_ITEM
items are only located in the ROOT_TREE.
仅有 ROOT_ITEM
个项目位于根树中。
Usage 用法
|
---|
objectid |
|
Description 描述
A fundamental component of btrfs is the btree. ROOT_ITEM
items define the
location and parameters of the root of a btree.
btrfs 的一个基本组件是 btree。 ROOT_ITEM
项定义了 btree 根的位置和参数。
Item Contents 项目内容
ROOT_ITEM
items contain a single btrfs_root_item
structure.
ROOT_ITEM
项包含一个单一的 btrfs_root_item
结构。
ROOT_BACKREF (90)
(subtree id, 90, tree id) TODO
(子树 id, 90, 树 id) 待办事项
Same content as ROOT_REF.
与 ROOT_REF 相同的内容。
ROOT_REF (9c)
Location 位置
ROOT_REF
items are only located in the `ROOT_TREE
<#ROOT_TREE>`__.
仅有 ROOT_REF
项位于 `ROOT_TREE
<#ROOT_TREE>`__。
(tree id, subtree id) TODO
(树 ID,子树 ID) 待办事项
`` 0 8 UINT 包含子树的[树 ID]中目录的 ID``
`` 8 8 UINT 序列(树中的索引)(偶数,从 2 开始?)``
`` 12 n ASCII 名称``
EXTENT_ITEM (a8)
Location 位置
EXTENT_ITEM
items are only located in the `EXTENT_TREE
<#EXTENT_TREE>`__.
EXTENT_ITEM
项仅位于 `EXTENT_TREE
<#EXTENT_TREE>`__。
Usage 用法
|
---|
objectid |
|
Description 描述
EXTENT_ITEM
items describe the space allocated for metadata tree nodes and
leafs as well as data extents. The space is allocated from block groups that
define the appropriate regions. In addition to functioning as basic allocation
records, EXTENT_ITEM
items also contain back references that can be used to
repair the file system or resolve extent ownership back to a set of one or more
file trees. Although EXTENT_ITEM
items can be used to describe both
DATA
and TREE_BLOCK
extents, newer file systems with the skinny
metadata feature enabled at mkfs time use METADATA_ITEM items to represent
metadata instead.
EXTENT_ITEM
项描述了为元数据树节点和叶子以及数据范围分配的空间。该空间是从定义适当区域的块组中分配的。除了作为基本分配记录外, EXTENT_ITEM
项还包含可以用于修复文件系统或将范围所有权解析回一组或多个文件树的反向引用。虽然 EXTENT_ITEM
项可用于描述 DATA
和 TREE_BLOCK
范围,但在 mkfs 时间启用了瘦元数据功能的新文件系统使用 METADATA_ITEM 项来代表元数据。
Item Contents 项目内容
EXTENT_ITEM
items begin with the `btrfs_extent_item
<Data_Structures#btrfs_extent_item>`__ structure and are followed by records
that are defined by the flags
field in that structure.
EXTENT_ITEM
项以 `btrfs_extent_item
`__ 结构开头,后跟由该结构中的 flags
字段定义的记录。
METADATA_ITEM (a9) 元数据项 (a9)
Location 位置
METADATA_ITEM
items are only located in the EXTENT_TREE
.
仅有 METADATA_ITEM
项位于 EXTENT_TREE
。
Usage 用法
|
---|
objectid |
|
Description 描述
METADATA_ITEM
items describe the space allocated for metadata tree nodes
and leafs. The space is allocated from block groups that define metadata
regions. In addition to functioning as basic allocation records,
METADATA_ITEM
items also contain back references that can be used to repair
the file system or resolve extent ownership back to a set of one or more file
trees.
METADATA_ITEM
项描述了为元数据树节点和叶子节点分配的空间。该空间是从定义元数据区域的块组中分配的。除了作为基本分配记录的功能外, METADATA_ITEM
项还包含可以用于修复文件系统或将范围所有权解析回一组或多个文件树的反向引用。
Item Contents 项目内容
METADATA_ITEM
items begin with the btrfs_extent_item
structure and are
followed by records that are defined by the flags
field in that structure.
METADATA_ITEM
项以 btrfs_extent_item
结构开头,并由该结构中的 flags
字段定义的记录跟随。
TREE_BLOCK_REF (b0)
(logical address, b0, root object id) TODO
(逻辑地址,b0,根对象 ID) 待办事项
`` 0 8 UINT offset (the object ID of the tree)``
`` 0 8 UINT 偏移量(树的对象 ID)``
EXTENT_DATA_REF (b2) EXTENT_DATA_REF(b2)
(logical address, b2, hash of first three fields) TODO
(逻辑地址,b2,前三个字段的哈希) 待办事项
`` 0 8 UINT 根对象 id(所包含树的 id)``
`` 8 8 UINT 对象 id(所有者)``
`` 10 8 UINT 偏移量(在文件数据中)``
`` 18 4 UINT 计数(始终为 1?)``
EXTENT_REF_V0 (b4) EXTENT_REF_V0(b4)
TODO 待办事项
BLOCK_GROUP_ITEM (c0) 区块组项目 (c0)
Location 位置
BLOCK_GROUP_ITEM
items are only found in the EXTENT_TREE
.
仅在 EXTENT_TREE
中找到 BLOCK_GROUP_ITEM
项。
Usage 用法
|
---|
objectid |
Starting offset in the space defined by the |
Description 描述
While the EXTENT_TREE
defines the address space used for extent allocations
for the entire file system, block groups allocate and define the parameters
within that space. Every EXTENT_ITEM
or METADATA_ITEM
that describes an
extent in use by the file system is apportioned from allocated block groups.
Each block group can represent space used for SYSTEM
objects (e.g. the
CHUNK_TREE
and primary super block), METADATA
trees and items, or
DATA
extents. It is possible to combine METADATA
and DATA
allocations within a single block group, though it is not recommended. This
mixed allocation policy is typically only seen on file systems smaller than
approximately 10 GiB in size.
虽然 EXTENT_TREE
定义了整个文件系统用于范围分配的地址空间,但块组分配并定义了该空间内的参数。描述文件系统中正在使用的范围的每个 EXTENT_ITEM
或 METADATA_ITEM
都是从已分配的块组中分配的。每个块组可以表示用于 SYSTEM
对象(例如 CHUNK_TREE
和主超级块)、 METADATA
树和项目,或 DATA
范围的空间。可以在单个块组中组合 METADATA
和 DATA
分配,但不建议这样做。这种混合分配策略通常仅在大小小于约 10 GiB 的文件系统中看到。
Item Contents 项目内容
BTRFS_BLOCK_GROUP
items contain a single
struct btrfs_block_group_item
.
BTRFS_BLOCK_GROUP
项目包含一个 struct btrfs_block_group_item
。
DEV_EXTENT (cc)
(device id, cc, physical address) TODO
(设备标识符, cc, 物理地址) 待办事项
Maps from physical address to logical.
从物理地址映射到逻辑地址。
Off |
Size |
Type |
Description |
---|---|---|---|
0 |
8 |
UINT |
chunk tree (always 3) 块树(始终为 3) |
8 |
8 |
OBJID |
chunk oid (always 256?) 块 OID(始终为 256?) |
10 |
8 |
UINT |
logical address 逻辑地址 |
18 |
8 |
UINT |
size in bytes 字节大小 |
20 |
10 |
UUID |
chunk tree UUID 块树 UUID |
30 |
DEV_ITEM (d8)
(1, device id) TODO
(1, 设备标识) 待办事项
Contains information about one device.
包含有关一个设备的信息
Off |
Size |
Type |
Description |
---|---|---|---|
0 |
8 |
UINT |
device id 设备标识 |
8 |
8 |
UINT |
number of bytes 字节数 |
10 |
8 |
UINT |
number of bytes used 使用的字节数 |
18 |
4 |
UINT |
optimal I/O align 最佳 I/O 对齐 |
1c |
4 |
UINT |
optimal I/O width 最佳 I/O 宽度 |
20 |
4 |
UINT |
minimal I/O size (sector size) |
24 |
8 |
UINT |
type |
2c |
8 |
UINT |
generation |
34 |
8 |
UINT |
start offset 起始偏移量 |
3c |
4 |
UINT |
dev group 开发组 |
40 |
1 |
UINT |
seek speed 寻找速度 |
41 |
1 |
UINT |
bandwidth |
42 |
10 |
UUID |
device UUID 设备 UUID |
52 |
10 |
UUID |
FS UUID |
62 |
CHUNK_ITEM (e4)
(100, logical address) TODO
(100, 逻辑地址) 待办事项
``将逻辑地址映射到物理地址。``
``0 8 UINT 每个块的大小(字节)``
``8 8 OBJID 引用此块的根(2)``
`` 10 8 UINT 条带长度``
`` 18 8 UINT 类型(与块组标志相同?)``
`` 20 4 UINT 最佳 IO 对齐``
`` 24 4 UINT 最佳 io 宽度``
`` 28 4 UINT 最小 io 大小(扇区大小)``
`` 2c 2 UINT 条带数量``
`` 2e 2 UINT 子条带``
`` 对于每个条带,依次执行以下操作:``
`` 0 8 OBJID 设备标识符``
`` 8 8 UINT 偏移量``
`` 10 10 UUID 设备 UUID``
STRING_ITEM (fd)
(anything, 0) (任何东西,0)
Contains a string; used for testing only.
仅用于测试的字符串。