blob: 4c6c7dedd3028a1c0e5168f2ee12f88ce88f2db6 [file] [log] [blame]
"Robert P. J. Day"63fc1a92006-07-02 19:47:05 +00001/* vi: set sw=4 ts=4: */
Mike Frysinger1fd98e02005-05-09 22:10:42 +00002/*
3 * linux/include/linux/jbd.h
Tim Rikerc1ef7bd2006-01-25 00:08:53 +00004 *
Mike Frysinger1fd98e02005-05-09 22:10:42 +00005 * Written by Stephen C. Tweedie <sct@redhat.com>
6 *
7 * Copyright 1998-2000 Red Hat, Inc --- All Rights Reserved
8 *
9 * This file is part of the Linux kernel and is made available under
10 * the terms of the GNU General Public License, version 2, or at your
11 * option, any later version, incorporated herein by reference.
12 *
13 * Definitions for transaction data structures for the buffer cache
14 * filesystem journaling support.
15 */
16
17#ifndef _LINUX_JBD_H
18#define _LINUX_JBD_H
19
Rob Landley43ac8882006-04-01 00:40:33 +000020#include <sys/types.h>
21#include <linux/types.h>
Rob Landley03e78e72006-04-01 17:36:31 +000022#include "ext2fs.h"
Mike Frysinger1fd98e02005-05-09 22:10:42 +000023
24/*
25 * Standard header for all descriptor blocks:
26 */
Rob Landley43ac8882006-04-01 00:40:33 +000027
Mike Frysinger1fd98e02005-05-09 22:10:42 +000028typedef struct journal_header_s
29{
30 __u32 h_magic;
31 __u32 h_blocktype;
32 __u32 h_sequence;
33} journal_header_t;
34
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000035/*
Rob Landley43ac8882006-04-01 00:40:33 +000036 * This is the global e2fsck structure.
Mike Frysinger1fd98e02005-05-09 22:10:42 +000037 */
Rob Landley43ac8882006-04-01 00:40:33 +000038typedef struct e2fsck_struct *e2fsck_t;
Mike Frysinger1fd98e02005-05-09 22:10:42 +000039
40
Rob Landley43ac8882006-04-01 00:40:33 +000041struct inode {
42 e2fsck_t i_ctx;
43 ext2_ino_t i_ino;
44 struct ext2_inode i_ext2;
45};
Mike Frysinger1fd98e02005-05-09 22:10:42 +000046
47
48/*
49 * The journal superblock. All fields are in big-endian byte order.
50 */
51typedef struct journal_superblock_s
52{
53/* 0x0000 */
54 journal_header_t s_header;
55
56/* 0x000C */
57 /* Static information describing the journal */
58 __u32 s_blocksize; /* journal device blocksize */
59 __u32 s_maxlen; /* total blocks in journal file */
60 __u32 s_first; /* first block of log information */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000061
Mike Frysinger1fd98e02005-05-09 22:10:42 +000062/* 0x0018 */
63 /* Dynamic information describing the current state of the log */
64 __u32 s_sequence; /* first commit ID expected in log */
65 __u32 s_start; /* blocknr of start of log */
66
67/* 0x0020 */
68 /* Error value, as set by journal_abort(). */
69 __s32 s_errno;
70
71/* 0x0024 */
72 /* Remaining fields are only valid in a version-2 superblock */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000073 __u32 s_feature_compat; /* compatible feature set */
74 __u32 s_feature_incompat; /* incompatible feature set */
75 __u32 s_feature_ro_compat; /* readonly-compatible feature set */
Mike Frysinger1fd98e02005-05-09 22:10:42 +000076/* 0x0030 */
77 __u8 s_uuid[16]; /* 128-bit uuid for journal */
78
79/* 0x0040 */
80 __u32 s_nr_users; /* Nr of filesystems sharing log */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000081
Mike Frysinger1fd98e02005-05-09 22:10:42 +000082 __u32 s_dynsuper; /* Blocknr of dynamic superblock copy*/
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000083
Mike Frysinger1fd98e02005-05-09 22:10:42 +000084/* 0x0048 */
85 __u32 s_max_transaction; /* Limit of journal blocks per trans.*/
86 __u32 s_max_trans_data; /* Limit of data blocks per trans. */
87
88/* 0x0050 */
89 __u32 s_padding[44];
90
91/* 0x0100 */
92 __u8 s_users[16*48]; /* ids of all fs'es sharing the log */
93/* 0x0400 */
94} journal_superblock_t;
95
Rob Landley43ac8882006-04-01 00:40:33 +000096
97extern int journal_blocks_per_page(struct inode *inode);
98extern int jbd_blocks_per_page(struct inode *inode);
99
100#define JFS_MIN_JOURNAL_BLOCKS 1024
101
102
103/*
104 * Internal structures used by the logging mechanism:
105 */
106
107#define JFS_MAGIC_NUMBER 0xc03b3998U /* The first 4 bytes of /dev/random! */
108
109/*
110 * Descriptor block types:
111 */
112
113#define JFS_DESCRIPTOR_BLOCK 1
114#define JFS_COMMIT_BLOCK 2
115#define JFS_SUPERBLOCK_V1 3
116#define JFS_SUPERBLOCK_V2 4
117#define JFS_REVOKE_BLOCK 5
118
119/*
120 * The block tag: used to describe a single buffer in the journal
121 */
122typedef struct journal_block_tag_s
123{
124 __u32 t_blocknr; /* The on-disk block number */
125 __u32 t_flags; /* See below */
126} journal_block_tag_t;
127
128/*
129 * The revoke descriptor: used on disk to describe a series of blocks to
130 * be revoked from the log
131 */
132typedef struct journal_revoke_header_s
133{
134 journal_header_t r_header;
135 int r_count; /* Count of bytes used in the block */
136} journal_revoke_header_t;
137
138
139/* Definitions for the journal tag flags word: */
140#define JFS_FLAG_ESCAPE 1 /* on-disk block is escaped */
141#define JFS_FLAG_SAME_UUID 2 /* block has same uuid as previous */
142#define JFS_FLAG_DELETED 4 /* block deleted by this transaction */
143#define JFS_FLAG_LAST_TAG 8 /* last tag in this descriptor block */
144
145
146
147
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000148#define JFS_HAS_COMPAT_FEATURE(j,mask) \
149 ((j)->j_format_version >= 2 && \
150 ((j)->j_superblock->s_feature_compat & cpu_to_be32((mask))))
151#define JFS_HAS_RO_COMPAT_FEATURE(j,mask) \
152 ((j)->j_format_version >= 2 && \
153 ((j)->j_superblock->s_feature_ro_compat & cpu_to_be32((mask))))
154#define JFS_HAS_INCOMPAT_FEATURE(j,mask) \
155 ((j)->j_format_version >= 2 && \
156 ((j)->j_superblock->s_feature_incompat & cpu_to_be32((mask))))
157
158#define JFS_FEATURE_INCOMPAT_REVOKE 0x00000001
159
160/* Features known to this kernel version: */
161#define JFS_KNOWN_COMPAT_FEATURES 0
162#define JFS_KNOWN_ROCOMPAT_FEATURES 0
163#define JFS_KNOWN_INCOMPAT_FEATURES JFS_FEATURE_INCOMPAT_REVOKE
164
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000165/* Comparison functions for transaction IDs: perform comparisons using
166 * modulo arithmetic so that they work over sequence number wraps. */
167
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000168
169/*
170 * Definitions which augment the buffer_head layer
171 */
172
173/* journaling buffer types */
174#define BJ_None 0 /* Not journaled */
175#define BJ_SyncData 1 /* Normal data: flush before commit */
176#define BJ_AsyncData 2 /* writepage data: wait on it before commit */
177#define BJ_Metadata 3 /* Normal journaled metadata */
178#define BJ_Forget 4 /* Buffer superceded by this transaction */
179#define BJ_IO 5 /* Buffer is for temporary IO use */
180#define BJ_Shadow 6 /* Buffer contents being shadowed to the log */
181#define BJ_LogCtl 7 /* Buffer contains log descriptors */
182#define BJ_Reserved 8 /* Buffer is reserved for access by journal */
183#define BJ_Types 9
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000184
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000185
Rob Landley43ac8882006-04-01 00:40:33 +0000186struct kdev_s {
187 e2fsck_t k_ctx;
188 int k_dev;
189};
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000190
Rob Landley43ac8882006-04-01 00:40:33 +0000191typedef struct kdev_s *kdev_t;
192typedef unsigned int tid_t;
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000193
Rob Landley43ac8882006-04-01 00:40:33 +0000194struct journal_s
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000195{
Rob Landley43ac8882006-04-01 00:40:33 +0000196 unsigned long j_flags;
197 int j_errno;
198 struct buffer_head * j_sb_buffer;
199 struct journal_superblock_s *j_superblock;
200 int j_format_version;
201 unsigned long j_head;
202 unsigned long j_tail;
203 unsigned long j_free;
204 unsigned long j_first, j_last;
205 kdev_t j_dev;
206 kdev_t j_fs_dev;
207 int j_blocksize;
208 unsigned int j_blk_offset;
209 unsigned int j_maxlen;
210 struct inode * j_inode;
211 tid_t j_tail_sequence;
212 tid_t j_transaction_sequence;
213 __u8 j_uuid[16];
214 struct jbd_revoke_table_s *j_revoke;
215};
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000216
Rob Landley43ac8882006-04-01 00:40:33 +0000217typedef struct journal_s journal_t;
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000218
Rob Landley43ac8882006-04-01 00:40:33 +0000219extern int journal_recover (journal_t *journal);
220extern int journal_skip_recovery (journal_t *);
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000221
Rob Landley43ac8882006-04-01 00:40:33 +0000222/* Primary revoke support */
223extern int journal_init_revoke(journal_t *, int);
224extern void journal_destroy_revoke_caches(void);
225extern int journal_init_revoke_caches(void);
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000226
Rob Landley43ac8882006-04-01 00:40:33 +0000227/* Recovery revoke support */
228extern int journal_set_revoke(journal_t *, unsigned long, tid_t);
229extern int journal_test_revoke(journal_t *, unsigned long, tid_t);
230extern void journal_clear_revoke(journal_t *);
231extern void journal_brelse_array(struct buffer_head *b[], int n);
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000232
Rob Landley43ac8882006-04-01 00:40:33 +0000233extern void journal_destroy_revoke(journal_t *);
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000234
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000235
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000236#endif /* _LINUX_JBD_H */