xref: /openbmc/u-boot/fs/ext4/ext4_journal.h (revision 9b914727)
1 /*
2  * (C) Copyright 2011 - 2012 Samsung Electronics
3  * EXT4 filesystem implementation in Uboot by
4  * Uma Shankar <uma.shankar@samsung.com>
5  * Manjunatha C Achar <a.manjunatha@samsung.com>
6  *
7  * Journal data structures and headers for Journaling feature of ext4
8  * have been referred from JBD2 (Journaling Block device 2)
9  * implementation in Linux Kernel.
10  *
11  * Written by Stephen C. Tweedie <sct@redhat.com>
12  *
13  * Copyright 1998-2000 Red Hat, Inc --- All Rights Reserved
14  * This file is part of the Linux kernel and is made available under
15  * the terms of the GNU General Public License, version 2, or at your
16  * option, any later version, incorporated herein by reference.
17  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 2 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31  */
32 
33 #ifndef __EXT4_JRNL__
34 #define __EXT4_JRNL__
35 
36 #define EXT2_JOURNAL_INO		8	/* Journal inode */
37 #define EXT2_JOURNAL_SUPERBLOCK	0	/* Journal  Superblock number */
38 
39 #define JBD2_FEATURE_COMPAT_CHECKSUM	0x00000001
40 #define EXT3_JOURNAL_MAGIC_NUMBER	0xc03b3998U
41 #define TRANSACTION_RUNNING		1
42 #define TRANSACTION_COMPLETE		0
43 #define EXT3_FEATURE_INCOMPAT_RECOVER	0x0004	/* Needs recovery */
44 #define EXT3_JOURNAL_DESCRIPTOR_BLOCK	1
45 #define EXT3_JOURNAL_COMMIT_BLOCK	2
46 #define EXT3_JOURNAL_SUPERBLOCK_V1	3
47 #define EXT3_JOURNAL_SUPERBLOCK_V2	4
48 #define EXT3_JOURNAL_REVOKE_BLOCK	5
49 #define EXT3_JOURNAL_FLAG_ESCAPE	1
50 #define EXT3_JOURNAL_FLAG_SAME_UUID	2
51 #define EXT3_JOURNAL_FLAG_DELETED	4
52 #define EXT3_JOURNAL_FLAG_LAST_TAG	8
53 
54 /* Maximum entries in 1 journal transaction */
55 #define MAX_JOURNAL_ENTRIES 100
56 struct journal_log {
57 	char *buf;
58 	int blknr;
59 };
60 
61 struct dirty_blocks {
62 	char *buf;
63 	int blknr;
64 };
65 
66 /* Standard header for all descriptor blocks: */
67 struct journal_header_t {
68 	__u32 h_magic;
69 	__u32 h_blocktype;
70 	__u32 h_sequence;
71 };
72 
73 /* The journal superblock.  All fields are in big-endian byte order. */
74 struct journal_superblock_t {
75 	/* 0x0000 */
76 	struct journal_header_t s_header;
77 
78 	/* Static information describing the journal */
79 	__u32 s_blocksize;	/* journal device blocksize */
80 	__u32 s_maxlen;		/* total blocks in journal file */
81 	__u32 s_first;		/* first block of log information */
82 
83 	/* Dynamic information describing the current state of the log */
84 	__u32 s_sequence;	/* first commit ID expected in log */
85 	__u32 s_start;		/* blocknr of start of log */
86 
87 	/* Error value, as set by journal_abort(). */
88 	__s32 s_errno;
89 
90 	/* Remaining fields are only valid in a version-2 superblock */
91 	__u32 s_feature_compat;	/* compatible feature set */
92 	__u32 s_feature_incompat;	/* incompatible feature set */
93 	__u32 s_feature_ro_compat;	/* readonly-compatible feature set */
94 	/* 0x0030 */
95 	__u8 s_uuid[16];	/* 128-bit uuid for journal */
96 
97 	/* 0x0040 */
98 	__u32 s_nr_users;	/* Nr of filesystems sharing log */
99 
100 	__u32 s_dynsuper;	/* Blocknr of dynamic superblock copy */
101 
102 	/* 0x0048 */
103 	__u32 s_max_transaction;	/* Limit of journal blocks per trans. */
104 	__u32 s_max_trans_data;	/* Limit of data blocks per trans. */
105 
106 	/* 0x0050 */
107 	__u32 s_padding[44];
108 
109 	/* 0x0100 */
110 	__u8 s_users[16 * 48];	/* ids of all fs'es sharing the log */
111 	/* 0x0400 */
112 } ;
113 
114 struct ext3_journal_block_tag {
115 	uint32_t block;
116 	uint32_t flags;
117 };
118 
119 struct journal_revoke_header_t {
120 	struct journal_header_t r_header;
121 	int r_count;		/* Count of bytes used in the block */
122 };
123 
124 struct revoke_blk_list {
125 	char *content;		/* revoke block itself */
126 	struct revoke_blk_list *next;
127 };
128 
129 extern struct ext2_data *ext4fs_root;
130 
131 int ext4fs_init_journal(void);
132 int ext4fs_log_gdt(char *gd_table);
133 int ext4fs_check_journal_state(int recovery_flag);
134 int ext4fs_log_journal(char *journal_buffer, long int blknr);
135 int ext4fs_put_metadata(char *metadata_buffer, long int blknr);
136 void ext4fs_update_journal(void);
137 void ext4fs_dump_metadata(void);
138 void ext4fs_push_revoke_blk(char *buffer);
139 void ext4fs_free_journal(void);
140 void ext4fs_free_revoke_blks(void);
141 #endif
142