Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2011 - 2012 Samsung Electronics |
| 4 | * EXT4 filesystem implementation in Uboot by |
| 5 | * Uma Shankar <uma.shankar@samsung.com> |
| 6 | * Manjunatha C Achar <a.manjunatha@samsung.com> |
| 7 | * |
| 8 | * Journal data structures and headers for Journaling feature of ext4 |
| 9 | * have been referred from JBD2 (Journaling Block device 2) |
| 10 | * implementation in Linux Kernel. |
| 11 | * |
| 12 | * Written by Stephen C. Tweedie <sct@redhat.com> |
| 13 | * |
| 14 | * Copyright 1998-2000 Red Hat, Inc --- All Rights Reserved |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #ifndef __EXT4_JRNL__ |
| 18 | #define __EXT4_JRNL__ |
| 19 | |
Marek Szyprowski | a958815 | 2019-06-21 15:35:35 +0200 | [diff] [blame] | 20 | #define EXT4_FEATURE_COMPAT_HAS_JOURNAL 0x0004 |
| 21 | |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 22 | #define EXT2_JOURNAL_INO 8 /* Journal inode */ |
| 23 | #define EXT2_JOURNAL_SUPERBLOCK 0 /* Journal Superblock number */ |
| 24 | |
| 25 | #define JBD2_FEATURE_COMPAT_CHECKSUM 0x00000001 |
| 26 | #define EXT3_JOURNAL_MAGIC_NUMBER 0xc03b3998U |
| 27 | #define TRANSACTION_RUNNING 1 |
| 28 | #define TRANSACTION_COMPLETE 0 |
| 29 | #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */ |
| 30 | #define EXT3_JOURNAL_DESCRIPTOR_BLOCK 1 |
| 31 | #define EXT3_JOURNAL_COMMIT_BLOCK 2 |
| 32 | #define EXT3_JOURNAL_SUPERBLOCK_V1 3 |
| 33 | #define EXT3_JOURNAL_SUPERBLOCK_V2 4 |
| 34 | #define EXT3_JOURNAL_REVOKE_BLOCK 5 |
| 35 | #define EXT3_JOURNAL_FLAG_ESCAPE 1 |
| 36 | #define EXT3_JOURNAL_FLAG_SAME_UUID 2 |
| 37 | #define EXT3_JOURNAL_FLAG_DELETED 4 |
| 38 | #define EXT3_JOURNAL_FLAG_LAST_TAG 8 |
| 39 | |
| 40 | /* Maximum entries in 1 journal transaction */ |
| 41 | #define MAX_JOURNAL_ENTRIES 100 |
| 42 | struct journal_log { |
| 43 | char *buf; |
| 44 | int blknr; |
| 45 | }; |
| 46 | |
| 47 | struct dirty_blocks { |
| 48 | char *buf; |
| 49 | int blknr; |
| 50 | }; |
| 51 | |
| 52 | /* Standard header for all descriptor blocks: */ |
| 53 | struct journal_header_t { |
Michael Walle | 2a81961 | 2016-08-29 10:46:43 +0200 | [diff] [blame] | 54 | __be32 h_magic; |
| 55 | __be32 h_blocktype; |
| 56 | __be32 h_sequence; |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | /* The journal superblock. All fields are in big-endian byte order. */ |
| 60 | struct journal_superblock_t { |
| 61 | /* 0x0000 */ |
| 62 | struct journal_header_t s_header; |
| 63 | |
| 64 | /* Static information describing the journal */ |
Michael Walle | 2a81961 | 2016-08-29 10:46:43 +0200 | [diff] [blame] | 65 | __be32 s_blocksize; /* journal device blocksize */ |
| 66 | __be32 s_maxlen; /* total blocks in journal file */ |
| 67 | __be32 s_first; /* first block of log information */ |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 68 | |
| 69 | /* Dynamic information describing the current state of the log */ |
Michael Walle | 2a81961 | 2016-08-29 10:46:43 +0200 | [diff] [blame] | 70 | __be32 s_sequence; /* first commit ID expected in log */ |
| 71 | __be32 s_start; /* blocknr of start of log */ |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 72 | |
| 73 | /* Error value, as set by journal_abort(). */ |
Michael Walle | 2a81961 | 2016-08-29 10:46:43 +0200 | [diff] [blame] | 74 | __be32 s_errno; |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 75 | |
| 76 | /* Remaining fields are only valid in a version-2 superblock */ |
Michael Walle | 2a81961 | 2016-08-29 10:46:43 +0200 | [diff] [blame] | 77 | __be32 s_feature_compat; /* compatible feature set */ |
| 78 | __be32 s_feature_incompat; /* incompatible feature set */ |
| 79 | __be32 s_feature_ro_compat; /* readonly-compatible feature set */ |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 80 | /* 0x0030 */ |
| 81 | __u8 s_uuid[16]; /* 128-bit uuid for journal */ |
| 82 | |
| 83 | /* 0x0040 */ |
Michael Walle | 2a81961 | 2016-08-29 10:46:43 +0200 | [diff] [blame] | 84 | __be32 s_nr_users; /* Nr of filesystems sharing log */ |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 85 | |
Michael Walle | 2a81961 | 2016-08-29 10:46:43 +0200 | [diff] [blame] | 86 | __be32 s_dynsuper; /* Blocknr of dynamic superblock copy */ |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 87 | |
| 88 | /* 0x0048 */ |
Michael Walle | 2a81961 | 2016-08-29 10:46:43 +0200 | [diff] [blame] | 89 | __be32 s_max_transaction; /* Limit of journal blocks per trans. */ |
| 90 | __be32 s_max_trans_data; /* Limit of data blocks per trans. */ |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 91 | |
| 92 | /* 0x0050 */ |
Michael Walle | 2a81961 | 2016-08-29 10:46:43 +0200 | [diff] [blame] | 93 | __be32 s_padding[44]; |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 94 | |
| 95 | /* 0x0100 */ |
| 96 | __u8 s_users[16 * 48]; /* ids of all fs'es sharing the log */ |
| 97 | /* 0x0400 */ |
| 98 | } ; |
| 99 | |
| 100 | struct ext3_journal_block_tag { |
Michael Walle | 2a81961 | 2016-08-29 10:46:43 +0200 | [diff] [blame] | 101 | __be32 block; |
| 102 | __be32 flags; |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | struct journal_revoke_header_t { |
| 106 | struct journal_header_t r_header; |
Michael Walle | 2a81961 | 2016-08-29 10:46:43 +0200 | [diff] [blame] | 107 | __be32 r_count; /* Count of bytes used in the block */ |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | struct revoke_blk_list { |
| 111 | char *content; /* revoke block itself */ |
| 112 | struct revoke_blk_list *next; |
| 113 | }; |
| 114 | |
| 115 | extern struct ext2_data *ext4fs_root; |
| 116 | |
| 117 | int ext4fs_init_journal(void); |
| 118 | int ext4fs_log_gdt(char *gd_table); |
| 119 | int ext4fs_check_journal_state(int recovery_flag); |
Michael Walle | 13179c2 | 2016-09-01 11:21:40 +0200 | [diff] [blame] | 120 | int ext4fs_log_journal(char *journal_buffer, uint32_t blknr); |
| 121 | int ext4fs_put_metadata(char *metadata_buffer, uint32_t blknr); |
Uma Shankar | a74a99a | 2012-05-25 21:22:49 +0530 | [diff] [blame] | 122 | void ext4fs_update_journal(void); |
| 123 | void ext4fs_dump_metadata(void); |
| 124 | void ext4fs_push_revoke_blk(char *buffer); |
| 125 | void ext4fs_free_journal(void); |
| 126 | void ext4fs_free_revoke_blks(void); |
| 127 | #endif |