1 /*
2 * Compatibility header file for e2fsck which should be included
3 * instead of linux/jfs.h
4 *
5 * Copyright (C) 2000 Stephen C. Tweedie
6 *
7 * This file may be redistributed under the terms of the
8 * GNU General Public License version 2 or at your discretion
9 * any later version.
10 */
11 #ifndef _JFS_USER_H
12 #define _JFS_USER_H
13
14 #ifdef DEBUGFS
15 #include <stdio.h>
16 #include <stdlib.h>
17 #if EXT2_FLAT_INCLUDES
18 #include "ext2_fs.h"
19 #include "ext2fs.h"
20 #include "blkid.h"
21 #else
22 #include "ext2fs/ext2_fs.h"
23 #include "ext2fs/ext2fs.h"
24 #include "blkid/blkid.h"
25 #endif
26 #else
27 /*
28 * Pull in the definition of the e2fsck context structure
29 */
30 #include "config.h"
31 #include "e2fsck.h"
32 #endif
33
34 #if __STDC_VERSION__ < 199901L
35 # if __GNUC__ >= 2 || _MSC_VER >= 1300
36 # define __func__ __FUNCTION__
37 # else
38 # define __func__ "<unknown>"
39 # endif
40 #endif
41
42 struct buffer_head {
43 #ifdef DEBUGFS
44 ext2_filsys b_fs;
45 #else
46 e2fsck_t b_ctx;
47 #endif
48 io_channel b_io;
49 int b_size;
50 int b_err;
51 unsigned int b_dirty:1;
52 unsigned int b_uptodate:1;
53 unsigned long long b_blocknr;
54 char b_data[4096];
55 };
56
57 struct inode {
58 #ifdef DEBUGFS
59 ext2_filsys i_fs;
60 #else
61 e2fsck_t i_ctx;
62 #endif
63 ext2_ino_t i_ino;
64 struct ext2_inode i_ext2;
65 };
66
67 struct kdev_s {
68 #ifdef DEBUGFS
69 ext2_filsys k_fs;
70 #else
71 e2fsck_t k_ctx;
72 #endif
73 int k_dev;
74 };
75
76 #define K_DEV_FS 1
77 #define K_DEV_JOURNAL 2
78
79 #define lock_buffer(bh) do {} while (0)
80 #define unlock_buffer(bh) do {} while (0)
81 #define buffer_req(bh) 1
82 #define do_readahead(journal, start) do {} while (0)
83
84 typedef struct kmem_cache {
85 int object_length;
86 } kmem_cache_t;
87
88 #define kmem_cache_alloc(cache, flags) malloc((cache)->object_length)
89 #define kmem_cache_free(cache, obj) free(obj)
90 #define kmem_cache_create(name, len, a, b, c) do_cache_create(len)
91 #define kmem_cache_destroy(cache) do_cache_destroy(cache)
92 #define kmalloc(len, flags) malloc(len)
93 #define kfree(p) free(p)
94
kmalloc_array(unsigned n,unsigned size,int flags EXT2FS_ATTR ((unused)))95 static inline void *kmalloc_array(unsigned n, unsigned size,
96 int flags EXT2FS_ATTR((unused)))
97 {
98 if (n && (~0U)/n < size)
99 return NULL;
100 return malloc(n * size);
101 }
102
103 #define cond_resched() do { } while (0)
104
105 #define __init
106
107 /*
108 * Now pull in the real linux/jfs.h definitions.
109 */
110 #include <ext2fs/kernel-jbd.h>
111
112 /*
113 * We use the standard libext2fs portability tricks for inline
114 * functions.
115 */
116 #ifdef NO_INLINE_FUNCS
117 extern kmem_cache_t *do_cache_create(int len);
118 extern void do_cache_destroy(kmem_cache_t *cache);
119 extern size_t journal_tag_bytes(journal_t *journal);
120 extern __u32 __hash_32(__u32 val);
121 extern __u32 hash_32(__u32 val, unsigned int bits);
122 extern __u32 hash_64(__u64 val, unsigned int bits);
123 #endif
124
125 #if (defined(E2FSCK_INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
126 #ifdef E2FSCK_INCLUDE_INLINE_FUNCS
127 #if (__STDC_VERSION__ >= 199901L)
128 #define _INLINE_ extern inline
129 #else
130 #define _INLINE_ inline
131 #endif
132 #else /* !E2FSCK_INCLUDE_INLINE FUNCS */
133 #if (__STDC_VERSION__ >= 199901L)
134 #define _INLINE_ inline
135 #else /* not C99 */
136 #ifdef __GNUC__
137 #define _INLINE_ extern __inline__
138 #else /* For Watcom C */
139 #define _INLINE_ extern inline
140 #endif /* __GNUC__ */
141 #endif /* __STDC_VERSION__ >= 199901L */
142 #endif /* E2FSCK_INCLUDE_INLINE_FUNCS */
143
do_cache_create(int len)144 _INLINE_ kmem_cache_t *do_cache_create(int len)
145 {
146 kmem_cache_t *new_cache;
147
148 new_cache = malloc(sizeof(*new_cache));
149 if (new_cache)
150 new_cache->object_length = len;
151 return new_cache;
152 }
153
do_cache_destroy(kmem_cache_t * cache)154 _INLINE_ void do_cache_destroy(kmem_cache_t *cache)
155 {
156 free(cache);
157 }
158
159 /* generic hashing taken from the Linux kernel */
160 #define GOLDEN_RATIO_32 0x61C88647
161 #define GOLDEN_RATIO_64 0x61C8864680B583EBull
162
__hash_32(__u32 val)163 _INLINE_ __u32 __hash_32(__u32 val)
164 {
165 return val * GOLDEN_RATIO_32;
166 }
167
hash_32(__u32 val,unsigned int bits)168 _INLINE_ __u32 hash_32(__u32 val, unsigned int bits)
169 {
170 /* High bits are more random, so use them. */
171 return __hash_32(val) >> (32 - bits);
172 }
173
hash_64(__u64 val,unsigned int bits)174 _INLINE_ __u32 hash_64(__u64 val, unsigned int bits)
175 {
176 if (sizeof(long) >= 8) {
177 /* 64x64-bit multiply is efficient on all 64-bit processors */
178 return val * GOLDEN_RATIO_64 >> (64 - bits);
179 } else {
180 /* Hash 64 bits using only 32x32-bit multiply. */
181 return hash_32((__u32)val ^ __hash_32(val >> 32), bits);
182 }
183 }
184
185 #undef _INLINE_
186 #endif
187
188 /*
189 * Kernel compatibility functions are defined in journal.c
190 */
191 int jbd2_journal_bmap(journal_t *journal, unsigned long block,
192 unsigned long long *phys);
193 struct buffer_head *getblk(kdev_t ctx, unsigned long long blocknr,
194 int blocksize);
195 int sync_blockdev(kdev_t kdev);
196 void ll_rw_block(int rw, int op_flags, int nr, struct buffer_head *bh[]);
197 void mark_buffer_dirty(struct buffer_head *bh);
198 void mark_buffer_uptodate(struct buffer_head *bh, int val);
199 void brelse(struct buffer_head *bh);
200 int buffer_uptodate(struct buffer_head *bh);
201 void wait_on_buffer(struct buffer_head *bh);
202
203 /*
204 * Define newer 2.5 interfaces
205 */
206 #define __getblk(dev, blocknr, blocksize) getblk(dev, blocknr, blocksize)
207 #define set_buffer_uptodate(bh) mark_buffer_uptodate(bh, 1)
208
209 #ifdef DEBUGFS
210 #include <assert.h>
211 #undef J_ASSERT
212 #define J_ASSERT(x) assert(x)
213
214 #define JSB_HAS_INCOMPAT_FEATURE(jsb, mask) \
215 ((jsb)->s_header.h_blocktype == ext2fs_cpu_to_be32(JBD2_SUPERBLOCK_V2) && \
216 ((jsb)->s_feature_incompat & ext2fs_cpu_to_be32((mask))))
217 #else /* !DEBUGFS */
218
219 extern e2fsck_t e2fsck_global_ctx; /* Try your very best not to use this! */
220
221 #define J_ASSERT(assert) \
222 do { if (!(assert)) { \
223 printf ("Assertion failure in %s() at %s line %d: " \
224 "\"%s\"\n", \
225 __func__, __FILE__, __LINE__, # assert); \
226 fatal_error(e2fsck_global_ctx, 0); \
227 } } while (0)
228
229 #endif /* DEBUGFS */
230
231 #ifndef EFSBADCRC
232 #define EFSBADCRC EXT2_ET_BAD_CRC
233 #endif
234 #ifndef EFSCORRUPTED
235 #define EFSCORRUPTED EXT2_ET_FILESYSTEM_CORRUPTED
236 #endif
237
jbd2_descriptor_block_csum_set(journal_t * j,struct buffer_head * bh)238 static inline void jbd2_descriptor_block_csum_set(journal_t *j,
239 struct buffer_head *bh)
240 {
241 struct jbd2_journal_block_tail *tail;
242 __u32 csum;
243
244 if (!jbd2_journal_has_csum_v2or3(j))
245 return;
246
247 tail = (struct jbd2_journal_block_tail *)(bh->b_data + j->j_blocksize -
248 sizeof(struct jbd2_journal_block_tail));
249 tail->t_checksum = 0;
250 csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize);
251 tail->t_checksum = cpu_to_be32(csum);
252 }
253
254 /* recovery.c */
255 extern int jbd2_journal_recover (journal_t *journal);
256 extern int jbd2_journal_skip_recovery (journal_t *);
257
258 /* revoke.c */
259 extern int jbd2_journal_init_revoke(journal_t *, int);
260 extern void jbd2_journal_destroy_revoke(journal_t *);
261 extern void jbd2_journal_destroy_revoke_record_cache(void);
262 extern void jbd2_journal_destroy_revoke_table_cache(void);
263 extern int jbd2_journal_init_revoke_record_cache(void);
264 extern int jbd2_journal_init_revoke_table_cache(void);
265
266
267 extern int jbd2_journal_set_revoke(journal_t *, unsigned long long, tid_t);
268 extern int jbd2_journal_test_revoke(journal_t *, unsigned long long, tid_t);
269 extern void jbd2_journal_clear_revoke(journal_t *);
270
271 #endif /* _JFS_USER_H */
272