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