blob: c9cf195f33322dda8a55088147363ee2a95c3b68 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Uma Shankara74a99a2012-05-25 21:22:49 +05302/*
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 Shankara74a99a2012-05-25 21:22:49 +053015 */
16
17#ifndef __EXT4_JRNL__
18#define __EXT4_JRNL__
19
20#define EXT2_JOURNAL_INO 8 /* Journal inode */
21#define EXT2_JOURNAL_SUPERBLOCK 0 /* Journal Superblock number */
22
23#define JBD2_FEATURE_COMPAT_CHECKSUM 0x00000001
24#define EXT3_JOURNAL_MAGIC_NUMBER 0xc03b3998U
25#define TRANSACTION_RUNNING 1
26#define TRANSACTION_COMPLETE 0
27#define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
28#define EXT3_JOURNAL_DESCRIPTOR_BLOCK 1
29#define EXT3_JOURNAL_COMMIT_BLOCK 2
30#define EXT3_JOURNAL_SUPERBLOCK_V1 3
31#define EXT3_JOURNAL_SUPERBLOCK_V2 4
32#define EXT3_JOURNAL_REVOKE_BLOCK 5
33#define EXT3_JOURNAL_FLAG_ESCAPE 1
34#define EXT3_JOURNAL_FLAG_SAME_UUID 2
35#define EXT3_JOURNAL_FLAG_DELETED 4
36#define EXT3_JOURNAL_FLAG_LAST_TAG 8
37
38/* Maximum entries in 1 journal transaction */
39#define MAX_JOURNAL_ENTRIES 100
40struct journal_log {
41 char *buf;
42 int blknr;
43};
44
45struct dirty_blocks {
46 char *buf;
47 int blknr;
48};
49
50/* Standard header for all descriptor blocks: */
51struct journal_header_t {
Michael Walle2a819612016-08-29 10:46:43 +020052 __be32 h_magic;
53 __be32 h_blocktype;
54 __be32 h_sequence;
Uma Shankara74a99a2012-05-25 21:22:49 +053055};
56
57/* The journal superblock. All fields are in big-endian byte order. */
58struct journal_superblock_t {
59 /* 0x0000 */
60 struct journal_header_t s_header;
61
62 /* Static information describing the journal */
Michael Walle2a819612016-08-29 10:46:43 +020063 __be32 s_blocksize; /* journal device blocksize */
64 __be32 s_maxlen; /* total blocks in journal file */
65 __be32 s_first; /* first block of log information */
Uma Shankara74a99a2012-05-25 21:22:49 +053066
67 /* Dynamic information describing the current state of the log */
Michael Walle2a819612016-08-29 10:46:43 +020068 __be32 s_sequence; /* first commit ID expected in log */
69 __be32 s_start; /* blocknr of start of log */
Uma Shankara74a99a2012-05-25 21:22:49 +053070
71 /* Error value, as set by journal_abort(). */
Michael Walle2a819612016-08-29 10:46:43 +020072 __be32 s_errno;
Uma Shankara74a99a2012-05-25 21:22:49 +053073
74 /* Remaining fields are only valid in a version-2 superblock */
Michael Walle2a819612016-08-29 10:46:43 +020075 __be32 s_feature_compat; /* compatible feature set */
76 __be32 s_feature_incompat; /* incompatible feature set */
77 __be32 s_feature_ro_compat; /* readonly-compatible feature set */
Uma Shankara74a99a2012-05-25 21:22:49 +053078 /* 0x0030 */
79 __u8 s_uuid[16]; /* 128-bit uuid for journal */
80
81 /* 0x0040 */
Michael Walle2a819612016-08-29 10:46:43 +020082 __be32 s_nr_users; /* Nr of filesystems sharing log */
Uma Shankara74a99a2012-05-25 21:22:49 +053083
Michael Walle2a819612016-08-29 10:46:43 +020084 __be32 s_dynsuper; /* Blocknr of dynamic superblock copy */
Uma Shankara74a99a2012-05-25 21:22:49 +053085
86 /* 0x0048 */
Michael Walle2a819612016-08-29 10:46:43 +020087 __be32 s_max_transaction; /* Limit of journal blocks per trans. */
88 __be32 s_max_trans_data; /* Limit of data blocks per trans. */
Uma Shankara74a99a2012-05-25 21:22:49 +053089
90 /* 0x0050 */
Michael Walle2a819612016-08-29 10:46:43 +020091 __be32 s_padding[44];
Uma Shankara74a99a2012-05-25 21:22:49 +053092
93 /* 0x0100 */
94 __u8 s_users[16 * 48]; /* ids of all fs'es sharing the log */
95 /* 0x0400 */
96} ;
97
98struct ext3_journal_block_tag {
Michael Walle2a819612016-08-29 10:46:43 +020099 __be32 block;
100 __be32 flags;
Uma Shankara74a99a2012-05-25 21:22:49 +0530101};
102
103struct journal_revoke_header_t {
104 struct journal_header_t r_header;
Michael Walle2a819612016-08-29 10:46:43 +0200105 __be32 r_count; /* Count of bytes used in the block */
Uma Shankara74a99a2012-05-25 21:22:49 +0530106};
107
108struct revoke_blk_list {
109 char *content; /* revoke block itself */
110 struct revoke_blk_list *next;
111};
112
113extern struct ext2_data *ext4fs_root;
114
115int ext4fs_init_journal(void);
116int ext4fs_log_gdt(char *gd_table);
117int ext4fs_check_journal_state(int recovery_flag);
Michael Walle13179c22016-09-01 11:21:40 +0200118int ext4fs_log_journal(char *journal_buffer, uint32_t blknr);
119int ext4fs_put_metadata(char *metadata_buffer, uint32_t blknr);
Uma Shankara74a99a2012-05-25 21:22:49 +0530120void ext4fs_update_journal(void);
121void ext4fs_dump_metadata(void);
122void ext4fs_push_revoke_blk(char *buffer);
123void ext4fs_free_journal(void);
124void ext4fs_free_revoke_blks(void);
125#endif