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