18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ciJournal (jbd2) 48c2ecf20Sopenharmony_ci-------------- 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ciIntroduced in ext3, the ext4 filesystem employs a journal to protect the 78c2ecf20Sopenharmony_cifilesystem against corruption in the case of a system crash. A small 88c2ecf20Sopenharmony_cicontinuous region of disk (default 128MiB) is reserved inside the 98c2ecf20Sopenharmony_cifilesystem as a place to land “important” data writes on-disk as quickly 108c2ecf20Sopenharmony_cias possible. Once the important data transaction is fully written to the 118c2ecf20Sopenharmony_cidisk and flushed from the disk write cache, a record of the data being 128c2ecf20Sopenharmony_cicommitted is also written to the journal. At some later point in time, 138c2ecf20Sopenharmony_cithe journal code writes the transactions to their final locations on 148c2ecf20Sopenharmony_cidisk (this could involve a lot of seeking or a lot of small 158c2ecf20Sopenharmony_ciread-write-erases) before erasing the commit record. Should the system 168c2ecf20Sopenharmony_cicrash during the second slow write, the journal can be replayed all the 178c2ecf20Sopenharmony_ciway to the latest commit record, guaranteeing the atomicity of whatever 188c2ecf20Sopenharmony_cigets written through the journal to the disk. The effect of this is to 198c2ecf20Sopenharmony_ciguarantee that the filesystem does not become stuck midway through a 208c2ecf20Sopenharmony_cimetadata update. 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ciFor performance reasons, ext4 by default only writes filesystem metadata 238c2ecf20Sopenharmony_cithrough the journal. This means that file data blocks are /not/ 248c2ecf20Sopenharmony_ciguaranteed to be in any consistent state after a crash. If this default 258c2ecf20Sopenharmony_ciguarantee level (``data=ordered``) is not satisfactory, there is a mount 268c2ecf20Sopenharmony_cioption to control journal behavior. If ``data=journal``, all data and 278c2ecf20Sopenharmony_cimetadata are written to disk through the journal. This is slower but 288c2ecf20Sopenharmony_cisafest. If ``data=writeback``, dirty data blocks are not flushed to the 298c2ecf20Sopenharmony_cidisk before the metadata are written to disk through the journal. 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ciIn case of ``data=ordered`` mode, Ext4 also supports fast commits which 328c2ecf20Sopenharmony_cihelp reduce commit latency significantly. The default ``data=ordered`` 338c2ecf20Sopenharmony_cimode works by logging metadata blocks to the journal. In fast commit 348c2ecf20Sopenharmony_cimode, Ext4 only stores the minimal delta needed to recreate the 358c2ecf20Sopenharmony_ciaffected metadata in fast commit space that is shared with JBD2. 368c2ecf20Sopenharmony_ciOnce the fast commit area fills in or if fast commit is not possible 378c2ecf20Sopenharmony_cior if JBD2 commit timer goes off, Ext4 performs a traditional full commit. 388c2ecf20Sopenharmony_ciA full commit invalidates all the fast commits that happened before 398c2ecf20Sopenharmony_ciit and thus it makes the fast commit area empty for further fast 408c2ecf20Sopenharmony_cicommits. This feature needs to be enabled at mkfs time. 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ciThe journal inode is typically inode 8. The first 68 bytes of the 438c2ecf20Sopenharmony_cijournal inode are replicated in the ext4 superblock. The journal itself 448c2ecf20Sopenharmony_ciis normal (but hidden) file within the filesystem. The file usually 458c2ecf20Sopenharmony_ciconsumes an entire block group, though mke2fs tries to put it in the 468c2ecf20Sopenharmony_cimiddle of the disk. 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ciAll fields in jbd2 are written to disk in big-endian order. This is the 498c2ecf20Sopenharmony_ciopposite of ext4. 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ciNOTE: Both ext4 and ocfs2 use jbd2. 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ciThe maximum size of a journal embedded in an ext4 filesystem is 2^32 548c2ecf20Sopenharmony_ciblocks. jbd2 itself does not seem to care. 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ciLayout 578c2ecf20Sopenharmony_ci~~~~~~ 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ciGenerally speaking, the journal has this format: 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci.. list-table:: 628c2ecf20Sopenharmony_ci :widths: 16 48 16 638c2ecf20Sopenharmony_ci :header-rows: 1 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci * - Superblock 668c2ecf20Sopenharmony_ci - descriptor\_block (data\_blocks or revocation\_block) [more data or 678c2ecf20Sopenharmony_ci revocations] commmit\_block 688c2ecf20Sopenharmony_ci - [more transactions...] 698c2ecf20Sopenharmony_ci * - 708c2ecf20Sopenharmony_ci - One transaction 718c2ecf20Sopenharmony_ci - 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ciNotice that a transaction begins with either a descriptor and some data, 748c2ecf20Sopenharmony_cior a block revocation list. A finished transaction always ends with a 758c2ecf20Sopenharmony_cicommit. If there is no commit record (or the checksums don't match), the 768c2ecf20Sopenharmony_citransaction will be discarded during replay. 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ciExternal Journal 798c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~ 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ciOptionally, an ext4 filesystem can be created with an external journal 828c2ecf20Sopenharmony_cidevice (as opposed to an internal journal, which uses a reserved inode). 838c2ecf20Sopenharmony_ciIn this case, on the filesystem device, ``s_journal_inum`` should be 848c2ecf20Sopenharmony_cizero and ``s_journal_uuid`` should be set. On the journal device there 858c2ecf20Sopenharmony_ciwill be an ext4 super block in the usual place, with a matching UUID. 868c2ecf20Sopenharmony_ciThe journal superblock will be in the next full block after the 878c2ecf20Sopenharmony_cisuperblock. 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci.. list-table:: 908c2ecf20Sopenharmony_ci :widths: 12 12 12 32 12 918c2ecf20Sopenharmony_ci :header-rows: 1 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci * - 1024 bytes of padding 948c2ecf20Sopenharmony_ci - ext4 Superblock 958c2ecf20Sopenharmony_ci - Journal Superblock 968c2ecf20Sopenharmony_ci - descriptor\_block (data\_blocks or revocation\_block) [more data or 978c2ecf20Sopenharmony_ci revocations] commmit\_block 988c2ecf20Sopenharmony_ci - [more transactions...] 998c2ecf20Sopenharmony_ci * - 1008c2ecf20Sopenharmony_ci - 1018c2ecf20Sopenharmony_ci - 1028c2ecf20Sopenharmony_ci - One transaction 1038c2ecf20Sopenharmony_ci - 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ciBlock Header 1068c2ecf20Sopenharmony_ci~~~~~~~~~~~~ 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ciEvery block in the journal starts with a common 12-byte header 1098c2ecf20Sopenharmony_ci``struct journal_header_s``: 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci.. list-table:: 1128c2ecf20Sopenharmony_ci :widths: 8 8 24 40 1138c2ecf20Sopenharmony_ci :header-rows: 1 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci * - Offset 1168c2ecf20Sopenharmony_ci - Type 1178c2ecf20Sopenharmony_ci - Name 1188c2ecf20Sopenharmony_ci - Description 1198c2ecf20Sopenharmony_ci * - 0x0 1208c2ecf20Sopenharmony_ci - \_\_be32 1218c2ecf20Sopenharmony_ci - h\_magic 1228c2ecf20Sopenharmony_ci - jbd2 magic number, 0xC03B3998. 1238c2ecf20Sopenharmony_ci * - 0x4 1248c2ecf20Sopenharmony_ci - \_\_be32 1258c2ecf20Sopenharmony_ci - h\_blocktype 1268c2ecf20Sopenharmony_ci - Description of what this block contains. See the jbd2_blocktype_ table 1278c2ecf20Sopenharmony_ci below. 1288c2ecf20Sopenharmony_ci * - 0x8 1298c2ecf20Sopenharmony_ci - \_\_be32 1308c2ecf20Sopenharmony_ci - h\_sequence 1318c2ecf20Sopenharmony_ci - The transaction ID that goes with this block. 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci.. _jbd2_blocktype: 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ciThe journal block type can be any one of: 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci.. list-table:: 1388c2ecf20Sopenharmony_ci :widths: 16 64 1398c2ecf20Sopenharmony_ci :header-rows: 1 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci * - Value 1428c2ecf20Sopenharmony_ci - Description 1438c2ecf20Sopenharmony_ci * - 1 1448c2ecf20Sopenharmony_ci - Descriptor. This block precedes a series of data blocks that were 1458c2ecf20Sopenharmony_ci written through the journal during a transaction. 1468c2ecf20Sopenharmony_ci * - 2 1478c2ecf20Sopenharmony_ci - Block commit record. This block signifies the completion of a 1488c2ecf20Sopenharmony_ci transaction. 1498c2ecf20Sopenharmony_ci * - 3 1508c2ecf20Sopenharmony_ci - Journal superblock, v1. 1518c2ecf20Sopenharmony_ci * - 4 1528c2ecf20Sopenharmony_ci - Journal superblock, v2. 1538c2ecf20Sopenharmony_ci * - 5 1548c2ecf20Sopenharmony_ci - Block revocation records. This speeds up recovery by enabling the 1558c2ecf20Sopenharmony_ci journal to skip writing blocks that were subsequently rewritten. 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ciSuper Block 1588c2ecf20Sopenharmony_ci~~~~~~~~~~~ 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ciThe super block for the journal is much simpler as compared to ext4's. 1618c2ecf20Sopenharmony_ciThe key data kept within are size of the journal, and where to find the 1628c2ecf20Sopenharmony_cistart of the log of transactions. 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ciThe journal superblock is recorded as ``struct journal_superblock_s``, 1658c2ecf20Sopenharmony_ciwhich is 1024 bytes long: 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci.. list-table:: 1688c2ecf20Sopenharmony_ci :widths: 8 8 24 40 1698c2ecf20Sopenharmony_ci :header-rows: 1 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci * - Offset 1728c2ecf20Sopenharmony_ci - Type 1738c2ecf20Sopenharmony_ci - Name 1748c2ecf20Sopenharmony_ci - Description 1758c2ecf20Sopenharmony_ci * - 1768c2ecf20Sopenharmony_ci - 1778c2ecf20Sopenharmony_ci - 1788c2ecf20Sopenharmony_ci - Static information describing the journal. 1798c2ecf20Sopenharmony_ci * - 0x0 1808c2ecf20Sopenharmony_ci - journal\_header\_t (12 bytes) 1818c2ecf20Sopenharmony_ci - s\_header 1828c2ecf20Sopenharmony_ci - Common header identifying this as a superblock. 1838c2ecf20Sopenharmony_ci * - 0xC 1848c2ecf20Sopenharmony_ci - \_\_be32 1858c2ecf20Sopenharmony_ci - s\_blocksize 1868c2ecf20Sopenharmony_ci - Journal device block size. 1878c2ecf20Sopenharmony_ci * - 0x10 1888c2ecf20Sopenharmony_ci - \_\_be32 1898c2ecf20Sopenharmony_ci - s\_maxlen 1908c2ecf20Sopenharmony_ci - Total number of blocks in this journal. 1918c2ecf20Sopenharmony_ci * - 0x14 1928c2ecf20Sopenharmony_ci - \_\_be32 1938c2ecf20Sopenharmony_ci - s\_first 1948c2ecf20Sopenharmony_ci - First block of log information. 1958c2ecf20Sopenharmony_ci * - 1968c2ecf20Sopenharmony_ci - 1978c2ecf20Sopenharmony_ci - 1988c2ecf20Sopenharmony_ci - Dynamic information describing the current state of the log. 1998c2ecf20Sopenharmony_ci * - 0x18 2008c2ecf20Sopenharmony_ci - \_\_be32 2018c2ecf20Sopenharmony_ci - s\_sequence 2028c2ecf20Sopenharmony_ci - First commit ID expected in log. 2038c2ecf20Sopenharmony_ci * - 0x1C 2048c2ecf20Sopenharmony_ci - \_\_be32 2058c2ecf20Sopenharmony_ci - s\_start 2068c2ecf20Sopenharmony_ci - Block number of the start of log. Contrary to the comments, this field 2078c2ecf20Sopenharmony_ci being zero does not imply that the journal is clean! 2088c2ecf20Sopenharmony_ci * - 0x20 2098c2ecf20Sopenharmony_ci - \_\_be32 2108c2ecf20Sopenharmony_ci - s\_errno 2118c2ecf20Sopenharmony_ci - Error value, as set by jbd2\_journal\_abort(). 2128c2ecf20Sopenharmony_ci * - 2138c2ecf20Sopenharmony_ci - 2148c2ecf20Sopenharmony_ci - 2158c2ecf20Sopenharmony_ci - The remaining fields are only valid in a v2 superblock. 2168c2ecf20Sopenharmony_ci * - 0x24 2178c2ecf20Sopenharmony_ci - \_\_be32 2188c2ecf20Sopenharmony_ci - s\_feature\_compat; 2198c2ecf20Sopenharmony_ci - Compatible feature set. See the table jbd2_compat_ below. 2208c2ecf20Sopenharmony_ci * - 0x28 2218c2ecf20Sopenharmony_ci - \_\_be32 2228c2ecf20Sopenharmony_ci - s\_feature\_incompat 2238c2ecf20Sopenharmony_ci - Incompatible feature set. See the table jbd2_incompat_ below. 2248c2ecf20Sopenharmony_ci * - 0x2C 2258c2ecf20Sopenharmony_ci - \_\_be32 2268c2ecf20Sopenharmony_ci - s\_feature\_ro\_compat 2278c2ecf20Sopenharmony_ci - Read-only compatible feature set. There aren't any of these currently. 2288c2ecf20Sopenharmony_ci * - 0x30 2298c2ecf20Sopenharmony_ci - \_\_u8 2308c2ecf20Sopenharmony_ci - s\_uuid[16] 2318c2ecf20Sopenharmony_ci - 128-bit uuid for journal. This is compared against the copy in the ext4 2328c2ecf20Sopenharmony_ci super block at mount time. 2338c2ecf20Sopenharmony_ci * - 0x40 2348c2ecf20Sopenharmony_ci - \_\_be32 2358c2ecf20Sopenharmony_ci - s\_nr\_users 2368c2ecf20Sopenharmony_ci - Number of file systems sharing this journal. 2378c2ecf20Sopenharmony_ci * - 0x44 2388c2ecf20Sopenharmony_ci - \_\_be32 2398c2ecf20Sopenharmony_ci - s\_dynsuper 2408c2ecf20Sopenharmony_ci - Location of dynamic super block copy. (Not used?) 2418c2ecf20Sopenharmony_ci * - 0x48 2428c2ecf20Sopenharmony_ci - \_\_be32 2438c2ecf20Sopenharmony_ci - s\_max\_transaction 2448c2ecf20Sopenharmony_ci - Limit of journal blocks per transaction. (Not used?) 2458c2ecf20Sopenharmony_ci * - 0x4C 2468c2ecf20Sopenharmony_ci - \_\_be32 2478c2ecf20Sopenharmony_ci - s\_max\_trans\_data 2488c2ecf20Sopenharmony_ci - Limit of data blocks per transaction. (Not used?) 2498c2ecf20Sopenharmony_ci * - 0x50 2508c2ecf20Sopenharmony_ci - \_\_u8 2518c2ecf20Sopenharmony_ci - s\_checksum\_type 2528c2ecf20Sopenharmony_ci - Checksum algorithm used for the journal. See jbd2_checksum_type_ for 2538c2ecf20Sopenharmony_ci more info. 2548c2ecf20Sopenharmony_ci * - 0x51 2558c2ecf20Sopenharmony_ci - \_\_u8[3] 2568c2ecf20Sopenharmony_ci - s\_padding2 2578c2ecf20Sopenharmony_ci - 2588c2ecf20Sopenharmony_ci * - 0x54 2598c2ecf20Sopenharmony_ci - \_\_be32 2608c2ecf20Sopenharmony_ci - s\_num\_fc\_blocks 2618c2ecf20Sopenharmony_ci - Number of fast commit blocks in the journal. 2628c2ecf20Sopenharmony_ci * - 0x58 2638c2ecf20Sopenharmony_ci - \_\_u32 2648c2ecf20Sopenharmony_ci - s\_padding[42] 2658c2ecf20Sopenharmony_ci - 2668c2ecf20Sopenharmony_ci * - 0xFC 2678c2ecf20Sopenharmony_ci - \_\_be32 2688c2ecf20Sopenharmony_ci - s\_checksum 2698c2ecf20Sopenharmony_ci - Checksum of the entire superblock, with this field set to zero. 2708c2ecf20Sopenharmony_ci * - 0x100 2718c2ecf20Sopenharmony_ci - \_\_u8 2728c2ecf20Sopenharmony_ci - s\_users[16\*48] 2738c2ecf20Sopenharmony_ci - ids of all file systems sharing the log. e2fsprogs/Linux don't allow 2748c2ecf20Sopenharmony_ci shared external journals, but I imagine Lustre (or ocfs2?), which use 2758c2ecf20Sopenharmony_ci the jbd2 code, might. 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci.. _jbd2_compat: 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ciThe journal compat features are any combination of the following: 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci.. list-table:: 2828c2ecf20Sopenharmony_ci :widths: 16 64 2838c2ecf20Sopenharmony_ci :header-rows: 1 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci * - Value 2868c2ecf20Sopenharmony_ci - Description 2878c2ecf20Sopenharmony_ci * - 0x1 2888c2ecf20Sopenharmony_ci - Journal maintains checksums on the data blocks. 2898c2ecf20Sopenharmony_ci (JBD2\_FEATURE\_COMPAT\_CHECKSUM) 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci.. _jbd2_incompat: 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ciThe journal incompat features are any combination of the following: 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci.. list-table:: 2968c2ecf20Sopenharmony_ci :widths: 16 64 2978c2ecf20Sopenharmony_ci :header-rows: 1 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_ci * - Value 3008c2ecf20Sopenharmony_ci - Description 3018c2ecf20Sopenharmony_ci * - 0x1 3028c2ecf20Sopenharmony_ci - Journal has block revocation records. (JBD2\_FEATURE\_INCOMPAT\_REVOKE) 3038c2ecf20Sopenharmony_ci * - 0x2 3048c2ecf20Sopenharmony_ci - Journal can deal with 64-bit block numbers. 3058c2ecf20Sopenharmony_ci (JBD2\_FEATURE\_INCOMPAT\_64BIT) 3068c2ecf20Sopenharmony_ci * - 0x4 3078c2ecf20Sopenharmony_ci - Journal commits asynchronously. (JBD2\_FEATURE\_INCOMPAT\_ASYNC\_COMMIT) 3088c2ecf20Sopenharmony_ci * - 0x8 3098c2ecf20Sopenharmony_ci - This journal uses v2 of the checksum on-disk format. Each journal 3108c2ecf20Sopenharmony_ci metadata block gets its own checksum, and the block tags in the 3118c2ecf20Sopenharmony_ci descriptor table contain checksums for each of the data blocks in the 3128c2ecf20Sopenharmony_ci journal. (JBD2\_FEATURE\_INCOMPAT\_CSUM\_V2) 3138c2ecf20Sopenharmony_ci * - 0x10 3148c2ecf20Sopenharmony_ci - This journal uses v3 of the checksum on-disk format. This is the same as 3158c2ecf20Sopenharmony_ci v2, but the journal block tag size is fixed regardless of the size of 3168c2ecf20Sopenharmony_ci block numbers. (JBD2\_FEATURE\_INCOMPAT\_CSUM\_V3) 3178c2ecf20Sopenharmony_ci * - 0x20 3188c2ecf20Sopenharmony_ci - Journal has fast commit blocks. (JBD2\_FEATURE\_INCOMPAT\_FAST\_COMMIT) 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ci.. _jbd2_checksum_type: 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ciJournal checksum type codes are one of the following. crc32 or crc32c are the 3238c2ecf20Sopenharmony_cimost likely choices. 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci.. list-table:: 3268c2ecf20Sopenharmony_ci :widths: 16 64 3278c2ecf20Sopenharmony_ci :header-rows: 1 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_ci * - Value 3308c2ecf20Sopenharmony_ci - Description 3318c2ecf20Sopenharmony_ci * - 1 3328c2ecf20Sopenharmony_ci - CRC32 3338c2ecf20Sopenharmony_ci * - 2 3348c2ecf20Sopenharmony_ci - MD5 3358c2ecf20Sopenharmony_ci * - 3 3368c2ecf20Sopenharmony_ci - SHA1 3378c2ecf20Sopenharmony_ci * - 4 3388c2ecf20Sopenharmony_ci - CRC32C 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ciDescriptor Block 3418c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~ 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ciThe descriptor block contains an array of journal block tags that 3448c2ecf20Sopenharmony_cidescribe the final locations of the data blocks that follow in the 3458c2ecf20Sopenharmony_cijournal. Descriptor blocks are open-coded instead of being completely 3468c2ecf20Sopenharmony_cidescribed by a data structure, but here is the block structure anyway. 3478c2ecf20Sopenharmony_ciDescriptor blocks consume at least 36 bytes, but use a full block: 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_ci.. list-table:: 3508c2ecf20Sopenharmony_ci :widths: 8 8 24 40 3518c2ecf20Sopenharmony_ci :header-rows: 1 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci * - Offset 3548c2ecf20Sopenharmony_ci - Type 3558c2ecf20Sopenharmony_ci - Name 3568c2ecf20Sopenharmony_ci - Descriptor 3578c2ecf20Sopenharmony_ci * - 0x0 3588c2ecf20Sopenharmony_ci - journal\_header\_t 3598c2ecf20Sopenharmony_ci - (open coded) 3608c2ecf20Sopenharmony_ci - Common block header. 3618c2ecf20Sopenharmony_ci * - 0xC 3628c2ecf20Sopenharmony_ci - struct journal\_block\_tag\_s 3638c2ecf20Sopenharmony_ci - open coded array[] 3648c2ecf20Sopenharmony_ci - Enough tags either to fill up the block or to describe all the data 3658c2ecf20Sopenharmony_ci blocks that follow this descriptor block. 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ciJournal block tags have any of the following formats, depending on which 3688c2ecf20Sopenharmony_cijournal feature and block tag flags are set. 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ciIf JBD2\_FEATURE\_INCOMPAT\_CSUM\_V3 is set, the journal block tag is 3718c2ecf20Sopenharmony_cidefined as ``struct journal_block_tag3_s``, which looks like the 3728c2ecf20Sopenharmony_cifollowing. The size is 16 or 32 bytes. 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ci.. list-table:: 3758c2ecf20Sopenharmony_ci :widths: 8 8 24 40 3768c2ecf20Sopenharmony_ci :header-rows: 1 3778c2ecf20Sopenharmony_ci 3788c2ecf20Sopenharmony_ci * - Offset 3798c2ecf20Sopenharmony_ci - Type 3808c2ecf20Sopenharmony_ci - Name 3818c2ecf20Sopenharmony_ci - Descriptor 3828c2ecf20Sopenharmony_ci * - 0x0 3838c2ecf20Sopenharmony_ci - \_\_be32 3848c2ecf20Sopenharmony_ci - t\_blocknr 3858c2ecf20Sopenharmony_ci - Lower 32-bits of the location of where the corresponding data block 3868c2ecf20Sopenharmony_ci should end up on disk. 3878c2ecf20Sopenharmony_ci * - 0x4 3888c2ecf20Sopenharmony_ci - \_\_be32 3898c2ecf20Sopenharmony_ci - t\_flags 3908c2ecf20Sopenharmony_ci - Flags that go with the descriptor. See the table jbd2_tag_flags_ for 3918c2ecf20Sopenharmony_ci more info. 3928c2ecf20Sopenharmony_ci * - 0x8 3938c2ecf20Sopenharmony_ci - \_\_be32 3948c2ecf20Sopenharmony_ci - t\_blocknr\_high 3958c2ecf20Sopenharmony_ci - Upper 32-bits of the location of where the corresponding data block 3968c2ecf20Sopenharmony_ci should end up on disk. This is zero if JBD2\_FEATURE\_INCOMPAT\_64BIT is 3978c2ecf20Sopenharmony_ci not enabled. 3988c2ecf20Sopenharmony_ci * - 0xC 3998c2ecf20Sopenharmony_ci - \_\_be32 4008c2ecf20Sopenharmony_ci - t\_checksum 4018c2ecf20Sopenharmony_ci - Checksum of the journal UUID, the sequence number, and the data block. 4028c2ecf20Sopenharmony_ci * - 4038c2ecf20Sopenharmony_ci - 4048c2ecf20Sopenharmony_ci - 4058c2ecf20Sopenharmony_ci - This field appears to be open coded. It always comes at the end of the 4068c2ecf20Sopenharmony_ci tag, after t_checksum. This field is not present if the "same UUID" flag 4078c2ecf20Sopenharmony_ci is set. 4088c2ecf20Sopenharmony_ci * - 0x8 or 0xC 4098c2ecf20Sopenharmony_ci - char 4108c2ecf20Sopenharmony_ci - uuid[16] 4118c2ecf20Sopenharmony_ci - A UUID to go with this tag. This field appears to be copied from the 4128c2ecf20Sopenharmony_ci ``j_uuid`` field in ``struct journal_s``, but only tune2fs touches that 4138c2ecf20Sopenharmony_ci field. 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_ci.. _jbd2_tag_flags: 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_ciThe journal tag flags are any combination of the following: 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_ci.. list-table:: 4208c2ecf20Sopenharmony_ci :widths: 16 64 4218c2ecf20Sopenharmony_ci :header-rows: 1 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ci * - Value 4248c2ecf20Sopenharmony_ci - Description 4258c2ecf20Sopenharmony_ci * - 0x1 4268c2ecf20Sopenharmony_ci - On-disk block is escaped. The first four bytes of the data block just 4278c2ecf20Sopenharmony_ci happened to match the jbd2 magic number. 4288c2ecf20Sopenharmony_ci * - 0x2 4298c2ecf20Sopenharmony_ci - This block has the same UUID as previous, therefore the UUID field is 4308c2ecf20Sopenharmony_ci omitted. 4318c2ecf20Sopenharmony_ci * - 0x4 4328c2ecf20Sopenharmony_ci - The data block was deleted by the transaction. (Not used?) 4338c2ecf20Sopenharmony_ci * - 0x8 4348c2ecf20Sopenharmony_ci - This is the last tag in this descriptor block. 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ciIf JBD2\_FEATURE\_INCOMPAT\_CSUM\_V3 is NOT set, the journal block tag 4378c2ecf20Sopenharmony_ciis defined as ``struct journal_block_tag_s``, which looks like the 4388c2ecf20Sopenharmony_cifollowing. The size is 8, 12, 24, or 28 bytes: 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ci.. list-table:: 4418c2ecf20Sopenharmony_ci :widths: 8 8 24 40 4428c2ecf20Sopenharmony_ci :header-rows: 1 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ci * - Offset 4458c2ecf20Sopenharmony_ci - Type 4468c2ecf20Sopenharmony_ci - Name 4478c2ecf20Sopenharmony_ci - Descriptor 4488c2ecf20Sopenharmony_ci * - 0x0 4498c2ecf20Sopenharmony_ci - \_\_be32 4508c2ecf20Sopenharmony_ci - t\_blocknr 4518c2ecf20Sopenharmony_ci - Lower 32-bits of the location of where the corresponding data block 4528c2ecf20Sopenharmony_ci should end up on disk. 4538c2ecf20Sopenharmony_ci * - 0x4 4548c2ecf20Sopenharmony_ci - \_\_be16 4558c2ecf20Sopenharmony_ci - t\_checksum 4568c2ecf20Sopenharmony_ci - Checksum of the journal UUID, the sequence number, and the data block. 4578c2ecf20Sopenharmony_ci Note that only the lower 16 bits are stored. 4588c2ecf20Sopenharmony_ci * - 0x6 4598c2ecf20Sopenharmony_ci - \_\_be16 4608c2ecf20Sopenharmony_ci - t\_flags 4618c2ecf20Sopenharmony_ci - Flags that go with the descriptor. See the table jbd2_tag_flags_ for 4628c2ecf20Sopenharmony_ci more info. 4638c2ecf20Sopenharmony_ci * - 4648c2ecf20Sopenharmony_ci - 4658c2ecf20Sopenharmony_ci - 4668c2ecf20Sopenharmony_ci - This next field is only present if the super block indicates support for 4678c2ecf20Sopenharmony_ci 64-bit block numbers. 4688c2ecf20Sopenharmony_ci * - 0x8 4698c2ecf20Sopenharmony_ci - \_\_be32 4708c2ecf20Sopenharmony_ci - t\_blocknr\_high 4718c2ecf20Sopenharmony_ci - Upper 32-bits of the location of where the corresponding data block 4728c2ecf20Sopenharmony_ci should end up on disk. 4738c2ecf20Sopenharmony_ci * - 4748c2ecf20Sopenharmony_ci - 4758c2ecf20Sopenharmony_ci - 4768c2ecf20Sopenharmony_ci - This field appears to be open coded. It always comes at the end of the 4778c2ecf20Sopenharmony_ci tag, after t_flags or t_blocknr_high. This field is not present if the 4788c2ecf20Sopenharmony_ci "same UUID" flag is set. 4798c2ecf20Sopenharmony_ci * - 0x8 or 0xC 4808c2ecf20Sopenharmony_ci - char 4818c2ecf20Sopenharmony_ci - uuid[16] 4828c2ecf20Sopenharmony_ci - A UUID to go with this tag. This field appears to be copied from the 4838c2ecf20Sopenharmony_ci ``j_uuid`` field in ``struct journal_s``, but only tune2fs touches that 4848c2ecf20Sopenharmony_ci field. 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ciIf JBD2\_FEATURE\_INCOMPAT\_CSUM\_V2 or 4878c2ecf20Sopenharmony_ciJBD2\_FEATURE\_INCOMPAT\_CSUM\_V3 are set, the end of the block is a 4888c2ecf20Sopenharmony_ci``struct jbd2_journal_block_tail``, which looks like this: 4898c2ecf20Sopenharmony_ci 4908c2ecf20Sopenharmony_ci.. list-table:: 4918c2ecf20Sopenharmony_ci :widths: 8 8 24 40 4928c2ecf20Sopenharmony_ci :header-rows: 1 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_ci * - Offset 4958c2ecf20Sopenharmony_ci - Type 4968c2ecf20Sopenharmony_ci - Name 4978c2ecf20Sopenharmony_ci - Descriptor 4988c2ecf20Sopenharmony_ci * - 0x0 4998c2ecf20Sopenharmony_ci - \_\_be32 5008c2ecf20Sopenharmony_ci - t\_checksum 5018c2ecf20Sopenharmony_ci - Checksum of the journal UUID + the descriptor block, with this field set 5028c2ecf20Sopenharmony_ci to zero. 5038c2ecf20Sopenharmony_ci 5048c2ecf20Sopenharmony_ciData Block 5058c2ecf20Sopenharmony_ci~~~~~~~~~~ 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_ciIn general, the data blocks being written to disk through the journal 5088c2ecf20Sopenharmony_ciare written verbatim into the journal file after the descriptor block. 5098c2ecf20Sopenharmony_ciHowever, if the first four bytes of the block match the jbd2 magic 5108c2ecf20Sopenharmony_cinumber then those four bytes are replaced with zeroes and the “escaped” 5118c2ecf20Sopenharmony_ciflag is set in the descriptor block tag. 5128c2ecf20Sopenharmony_ci 5138c2ecf20Sopenharmony_ciRevocation Block 5148c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~ 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_ciA revocation block is used to prevent replay of a block in an earlier 5178c2ecf20Sopenharmony_citransaction. This is used to mark blocks that were journalled at one 5188c2ecf20Sopenharmony_citime but are no longer journalled. Typically this happens if a metadata 5198c2ecf20Sopenharmony_ciblock is freed and re-allocated as a file data block; in this case, a 5208c2ecf20Sopenharmony_cijournal replay after the file block was written to disk will cause 5218c2ecf20Sopenharmony_cicorruption. 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_ci**NOTE**: This mechanism is NOT used to express “this journal block is 5248c2ecf20Sopenharmony_cisuperseded by this other journal block”, as the author (djwong) 5258c2ecf20Sopenharmony_cimistakenly thought. Any block being added to a transaction will cause 5268c2ecf20Sopenharmony_cithe removal of all existing revocation records for that block. 5278c2ecf20Sopenharmony_ci 5288c2ecf20Sopenharmony_ciRevocation blocks are described in 5298c2ecf20Sopenharmony_ci``struct jbd2_journal_revoke_header_s``, are at least 16 bytes in 5308c2ecf20Sopenharmony_cilength, but use a full block: 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_ci.. list-table:: 5338c2ecf20Sopenharmony_ci :widths: 8 8 24 40 5348c2ecf20Sopenharmony_ci :header-rows: 1 5358c2ecf20Sopenharmony_ci 5368c2ecf20Sopenharmony_ci * - Offset 5378c2ecf20Sopenharmony_ci - Type 5388c2ecf20Sopenharmony_ci - Name 5398c2ecf20Sopenharmony_ci - Description 5408c2ecf20Sopenharmony_ci * - 0x0 5418c2ecf20Sopenharmony_ci - journal\_header\_t 5428c2ecf20Sopenharmony_ci - r\_header 5438c2ecf20Sopenharmony_ci - Common block header. 5448c2ecf20Sopenharmony_ci * - 0xC 5458c2ecf20Sopenharmony_ci - \_\_be32 5468c2ecf20Sopenharmony_ci - r\_count 5478c2ecf20Sopenharmony_ci - Number of bytes used in this block. 5488c2ecf20Sopenharmony_ci * - 0x10 5498c2ecf20Sopenharmony_ci - \_\_be32 or \_\_be64 5508c2ecf20Sopenharmony_ci - blocks[0] 5518c2ecf20Sopenharmony_ci - Blocks to revoke. 5528c2ecf20Sopenharmony_ci 5538c2ecf20Sopenharmony_ciAfter r\_count is a linear array of block numbers that are effectively 5548c2ecf20Sopenharmony_cirevoked by this transaction. The size of each block number is 8 bytes if 5558c2ecf20Sopenharmony_cithe superblock advertises 64-bit block number support, or 4 bytes 5568c2ecf20Sopenharmony_ciotherwise. 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_ciIf JBD2\_FEATURE\_INCOMPAT\_CSUM\_V2 or 5598c2ecf20Sopenharmony_ciJBD2\_FEATURE\_INCOMPAT\_CSUM\_V3 are set, the end of the revocation 5608c2ecf20Sopenharmony_ciblock is a ``struct jbd2_journal_revoke_tail``, which has this format: 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_ci.. list-table:: 5638c2ecf20Sopenharmony_ci :widths: 8 8 24 40 5648c2ecf20Sopenharmony_ci :header-rows: 1 5658c2ecf20Sopenharmony_ci 5668c2ecf20Sopenharmony_ci * - Offset 5678c2ecf20Sopenharmony_ci - Type 5688c2ecf20Sopenharmony_ci - Name 5698c2ecf20Sopenharmony_ci - Description 5708c2ecf20Sopenharmony_ci * - 0x0 5718c2ecf20Sopenharmony_ci - \_\_be32 5728c2ecf20Sopenharmony_ci - r\_checksum 5738c2ecf20Sopenharmony_ci - Checksum of the journal UUID + revocation block 5748c2ecf20Sopenharmony_ci 5758c2ecf20Sopenharmony_ciCommit Block 5768c2ecf20Sopenharmony_ci~~~~~~~~~~~~ 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_ciThe commit block is a sentry that indicates that a transaction has been 5798c2ecf20Sopenharmony_cicompletely written to the journal. Once this commit block reaches the 5808c2ecf20Sopenharmony_cijournal, the data stored with this transaction can be written to their 5818c2ecf20Sopenharmony_cifinal locations on disk. 5828c2ecf20Sopenharmony_ci 5838c2ecf20Sopenharmony_ciThe commit block is described by ``struct commit_header``, which is 32 5848c2ecf20Sopenharmony_cibytes long (but uses a full block): 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_ci.. list-table:: 5878c2ecf20Sopenharmony_ci :widths: 8 8 24 40 5888c2ecf20Sopenharmony_ci :header-rows: 1 5898c2ecf20Sopenharmony_ci 5908c2ecf20Sopenharmony_ci * - Offset 5918c2ecf20Sopenharmony_ci - Type 5928c2ecf20Sopenharmony_ci - Name 5938c2ecf20Sopenharmony_ci - Descriptor 5948c2ecf20Sopenharmony_ci * - 0x0 5958c2ecf20Sopenharmony_ci - journal\_header\_s 5968c2ecf20Sopenharmony_ci - (open coded) 5978c2ecf20Sopenharmony_ci - Common block header. 5988c2ecf20Sopenharmony_ci * - 0xC 5998c2ecf20Sopenharmony_ci - unsigned char 6008c2ecf20Sopenharmony_ci - h\_chksum\_type 6018c2ecf20Sopenharmony_ci - The type of checksum to use to verify the integrity of the data blocks 6028c2ecf20Sopenharmony_ci in the transaction. See jbd2_checksum_type_ for more info. 6038c2ecf20Sopenharmony_ci * - 0xD 6048c2ecf20Sopenharmony_ci - unsigned char 6058c2ecf20Sopenharmony_ci - h\_chksum\_size 6068c2ecf20Sopenharmony_ci - The number of bytes used by the checksum. Most likely 4. 6078c2ecf20Sopenharmony_ci * - 0xE 6088c2ecf20Sopenharmony_ci - unsigned char 6098c2ecf20Sopenharmony_ci - h\_padding[2] 6108c2ecf20Sopenharmony_ci - 6118c2ecf20Sopenharmony_ci * - 0x10 6128c2ecf20Sopenharmony_ci - \_\_be32 6138c2ecf20Sopenharmony_ci - h\_chksum[JBD2\_CHECKSUM\_BYTES] 6148c2ecf20Sopenharmony_ci - 32 bytes of space to store checksums. If 6158c2ecf20Sopenharmony_ci JBD2\_FEATURE\_INCOMPAT\_CSUM\_V2 or JBD2\_FEATURE\_INCOMPAT\_CSUM\_V3 6168c2ecf20Sopenharmony_ci are set, the first ``__be32`` is the checksum of the journal UUID and 6178c2ecf20Sopenharmony_ci the entire commit block, with this field zeroed. If 6188c2ecf20Sopenharmony_ci JBD2\_FEATURE\_COMPAT\_CHECKSUM is set, the first ``__be32`` is the 6198c2ecf20Sopenharmony_ci crc32 of all the blocks already written to the transaction. 6208c2ecf20Sopenharmony_ci * - 0x30 6218c2ecf20Sopenharmony_ci - \_\_be64 6228c2ecf20Sopenharmony_ci - h\_commit\_sec 6238c2ecf20Sopenharmony_ci - The time that the transaction was committed, in seconds since the epoch. 6248c2ecf20Sopenharmony_ci * - 0x38 6258c2ecf20Sopenharmony_ci - \_\_be32 6268c2ecf20Sopenharmony_ci - h\_commit\_nsec 6278c2ecf20Sopenharmony_ci - Nanoseconds component of the above timestamp. 6288c2ecf20Sopenharmony_ci 6298c2ecf20Sopenharmony_ciFast commits 6308c2ecf20Sopenharmony_ci~~~~~~~~~~~~ 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_ciFast commit area is organized as a log of tag length values. Each TLV has 6338c2ecf20Sopenharmony_cia ``struct ext4_fc_tl`` in the beginning which stores the tag and the length 6348c2ecf20Sopenharmony_ciof the entire field. It is followed by variable length tag specific value. 6358c2ecf20Sopenharmony_ciHere is the list of supported tags and their meanings: 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_ci.. list-table:: 6388c2ecf20Sopenharmony_ci :widths: 8 20 20 32 6398c2ecf20Sopenharmony_ci :header-rows: 1 6408c2ecf20Sopenharmony_ci 6418c2ecf20Sopenharmony_ci * - Tag 6428c2ecf20Sopenharmony_ci - Meaning 6438c2ecf20Sopenharmony_ci - Value struct 6448c2ecf20Sopenharmony_ci - Description 6458c2ecf20Sopenharmony_ci * - EXT4_FC_TAG_HEAD 6468c2ecf20Sopenharmony_ci - Fast commit area header 6478c2ecf20Sopenharmony_ci - ``struct ext4_fc_head`` 6488c2ecf20Sopenharmony_ci - Stores the TID of the transaction after which these fast commits should 6498c2ecf20Sopenharmony_ci be applied. 6508c2ecf20Sopenharmony_ci * - EXT4_FC_TAG_ADD_RANGE 6518c2ecf20Sopenharmony_ci - Add extent to inode 6528c2ecf20Sopenharmony_ci - ``struct ext4_fc_add_range`` 6538c2ecf20Sopenharmony_ci - Stores the inode number and extent to be added in this inode 6548c2ecf20Sopenharmony_ci * - EXT4_FC_TAG_DEL_RANGE 6558c2ecf20Sopenharmony_ci - Remove logical offsets to inode 6568c2ecf20Sopenharmony_ci - ``struct ext4_fc_del_range`` 6578c2ecf20Sopenharmony_ci - Stores the inode number and the logical offset range that needs to be 6588c2ecf20Sopenharmony_ci removed 6598c2ecf20Sopenharmony_ci * - EXT4_FC_TAG_CREAT 6608c2ecf20Sopenharmony_ci - Create directory entry for a newly created file 6618c2ecf20Sopenharmony_ci - ``struct ext4_fc_dentry_info`` 6628c2ecf20Sopenharmony_ci - Stores the parent inode number, inode number and directory entry of the 6638c2ecf20Sopenharmony_ci newly created file 6648c2ecf20Sopenharmony_ci * - EXT4_FC_TAG_LINK 6658c2ecf20Sopenharmony_ci - Link a directory entry to an inode 6668c2ecf20Sopenharmony_ci - ``struct ext4_fc_dentry_info`` 6678c2ecf20Sopenharmony_ci - Stores the parent inode number, inode number and directory entry 6688c2ecf20Sopenharmony_ci * - EXT4_FC_TAG_UNLINK 6698c2ecf20Sopenharmony_ci - Unlink a directory entry of an inode 6708c2ecf20Sopenharmony_ci - ``struct ext4_fc_dentry_info`` 6718c2ecf20Sopenharmony_ci - Stores the parent inode number, inode number and directory entry 6728c2ecf20Sopenharmony_ci 6738c2ecf20Sopenharmony_ci * - EXT4_FC_TAG_PAD 6748c2ecf20Sopenharmony_ci - Padding (unused area) 6758c2ecf20Sopenharmony_ci - None 6768c2ecf20Sopenharmony_ci - Unused bytes in the fast commit area. 6778c2ecf20Sopenharmony_ci 6788c2ecf20Sopenharmony_ci * - EXT4_FC_TAG_TAIL 6798c2ecf20Sopenharmony_ci - Mark the end of a fast commit 6808c2ecf20Sopenharmony_ci - ``struct ext4_fc_tail`` 6818c2ecf20Sopenharmony_ci - Stores the TID of the commit, CRC of the fast commit of which this tag 6828c2ecf20Sopenharmony_ci represents the end of 6838c2ecf20Sopenharmony_ci 684