2 * Compatibility header file for e2fsck which should be included
3 * instead of linux/jfs.h
5 * Copyright (C) 2000 Stephen C. Tweedie
7 * This file may be redistributed under the terms of the
8 * GNU General Public License version 2 or at your discretion
19 #if EXT2_FLAT_INCLUDES
24 #include "ext2fs/ext2_fs.h"
25 #include "ext2fs/ext2fs.h"
26 #include "blkid/blkid.h"
30 * Pull in the definition of the e2fsck context structure
35 #if __STDC_VERSION__ < 199901L
36 # if __GNUC__ >= 2 || _MSC_VER >= 1300
37 # define __func__ __FUNCTION__
39 # define __func__ "<unknown>"
52 unsigned int b_dirty:1;
53 unsigned int b_uptodate:1;
54 unsigned long long b_blocknr;
65 struct ext2_inode i_ext2;
78 #define K_DEV_JOURNAL 2
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)
86 unsigned int object_size;
89 #define cond_resched() do { } while (0)
94 * Now pull in the real linux/jfs.h definitions.
96 #include <ext2fs/kernel-jbd.h>
99 * We use the standard libext2fs portability tricks for inline
102 #ifdef NO_INLINE_FUNCS
103 extern struct kmem_cache *kmem_cache_create(const char *name,
107 void (*ctor)(void *));
108 extern void kmem_cache_destroy(struct kmem_cache *s);
109 extern void *kmem_cache_alloc(struct kmem_cache *cachep, gfp_t flags);
110 extern void kmem_cache_free(struct kmem_cache *s, void *objp);
111 extern void *kmalloc(size_t size, gfp_t flags);
112 extern void kfree(const void *objp);
113 extern size_t journal_tag_bytes(journal_t *journal);
114 extern __u32 __hash_32(__u32 val);
115 extern __u32 hash_32(__u32 val, unsigned int bits);
116 extern __u32 hash_64(__u64 val, unsigned int bits);
117 extern void *kmalloc_array(unsigned n, unsigned size, int flags);
118 extern __u32 jbd2_chksum(journal_t *j, __u32 crc, const void *address,
119 unsigned int length);
120 extern void jbd2_descriptor_block_csum_set(journal_t *j,
121 struct buffer_head *bh);
124 #if (defined(E2FSCK_INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
125 #ifdef E2FSCK_INCLUDE_INLINE_FUNCS
126 #if (__STDC_VERSION__ >= 199901L)
127 #define _INLINE_ extern inline
129 #define _INLINE_ inline
131 #else /* !E2FSCK_INCLUDE_INLINE FUNCS */
132 #if (__STDC_VERSION__ >= 199901L)
133 #define _INLINE_ inline
136 #define _INLINE_ extern __inline__
137 #else /* For Watcom C */
138 #define _INLINE_ extern inline
139 #endif /* __GNUC__ */
140 #endif /* __STDC_VERSION__ >= 199901L */
141 #endif /* E2FSCK_INCLUDE_INLINE_FUNCS */
143 _INLINE_ struct kmem_cache *
144 kmem_cache_create(const char *name EXT2FS_ATTR((unused)),
146 unsigned int align EXT2FS_ATTR((unused)),
147 unsigned int flags EXT2FS_ATTR((unused)),
148 void (*ctor)(void *) EXT2FS_ATTR((unused)))
150 struct kmem_cache *new_cache;
152 new_cache = malloc(sizeof(*new_cache));
154 new_cache->object_size = size;
158 _INLINE_ void kmem_cache_destroy(struct kmem_cache *s)
163 _INLINE_ void *kmem_cache_alloc(struct kmem_cache *cachep,
164 gfp_t flags EXT2FS_ATTR((unused)))
166 return malloc(cachep->object_size);
169 _INLINE_ void kmem_cache_free(struct kmem_cache *s EXT2FS_ATTR((unused)),
175 _INLINE_ void *kmalloc(size_t size, gfp_t flags EXT2FS_ATTR((unused)))
180 _INLINE_ void kfree(const void *objp)
185 /* generic hashing taken from the Linux kernel */
186 #define GOLDEN_RATIO_32 0x61C88647
187 #define GOLDEN_RATIO_64 0x61C8864680B583EBull
189 _INLINE_ __u32 __hash_32(__u32 val)
191 return val * GOLDEN_RATIO_32;
194 _INLINE_ __u32 hash_32(__u32 val, unsigned int bits)
196 /* High bits are more random, so use them. */
197 return __hash_32(val) >> (32 - bits);
200 _INLINE_ __u32 hash_64(__u64 val, unsigned int bits)
202 if (sizeof(long) >= 8) {
203 /* 64x64-bit multiply is efficient on all 64-bit processors */
204 return val * GOLDEN_RATIO_64 >> (64 - bits);
206 /* Hash 64 bits using only 32x32-bit multiply. */
207 return hash_32((__u32)val ^ __hash_32(val >> 32), bits);
211 _INLINE_ void *kmalloc_array(unsigned n, unsigned size,
212 int flags EXT2FS_ATTR((unused)))
214 if (n && (~0U)/n < size)
216 return malloc(n * size);
219 _INLINE_ __u32 jbd2_chksum(journal_t *j EXT2FS_ATTR((unused)),
220 __u32 crc, const void *address,
223 return ext2fs_crc32c_le(crc, address, length);
226 _INLINE_ void jbd2_descriptor_block_csum_set(journal_t *j,
227 struct buffer_head *bh)
229 struct jbd2_journal_block_tail *tail;
232 if (!jbd2_journal_has_csum_v2or3(j))
235 tail = (struct jbd2_journal_block_tail *)(bh->b_data + j->j_blocksize -
236 sizeof(struct jbd2_journal_block_tail));
237 tail->t_checksum = 0;
238 csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize);
239 tail->t_checksum = cpu_to_be32(csum);
245 * Kernel compatibility functions are defined in journal.c
247 int jbd2_journal_bmap(journal_t *journal, unsigned long block,
248 unsigned long long *phys);
249 struct buffer_head *getblk(kdev_t ctx, unsigned long long blocknr,
251 int sync_blockdev(kdev_t kdev);
252 void ll_rw_block(int rw, int op_flags, int nr, struct buffer_head *bh[]);
253 void mark_buffer_dirty(struct buffer_head *bh);
254 void mark_buffer_uptodate(struct buffer_head *bh, int val);
255 void brelse(struct buffer_head *bh);
256 int buffer_uptodate(struct buffer_head *bh);
257 void wait_on_buffer(struct buffer_head *bh);
260 * Define newer 2.5 interfaces
262 #define __getblk(dev, blocknr, blocksize) getblk(dev, blocknr, blocksize)
263 #define set_buffer_uptodate(bh) mark_buffer_uptodate(bh, 1)
268 #define J_ASSERT(x) assert(x)
270 #define JSB_HAS_INCOMPAT_FEATURE(jsb, mask) \
271 ((jsb)->s_header.h_blocktype == ext2fs_cpu_to_be32(JBD2_SUPERBLOCK_V2) && \
272 ((jsb)->s_feature_incompat & ext2fs_cpu_to_be32((mask))))
275 extern e2fsck_t e2fsck_global_ctx; /* Try your very best not to use this! */
277 #define J_ASSERT(assert) \
278 do { if (!(assert)) { \
279 printf ("Assertion failure in %s() at %s line %d: " \
281 __func__, __FILE__, __LINE__, # assert); \
282 fatal_error(e2fsck_global_ctx, 0); \
288 #define EFSBADCRC EXT2_ET_BAD_CRC
291 #define EFSCORRUPTED EXT2_ET_FILESYSTEM_CORRUPTED
295 extern int jbd2_journal_recover (journal_t *journal);
296 extern int jbd2_journal_skip_recovery (journal_t *);
299 extern int jbd2_journal_init_revoke(journal_t *, int);
300 extern void jbd2_journal_destroy_revoke(journal_t *);
301 extern void jbd2_journal_destroy_revoke_record_cache(void);
302 extern void jbd2_journal_destroy_revoke_table_cache(void);
303 extern int jbd2_journal_init_revoke_record_cache(void);
304 extern int jbd2_journal_init_revoke_table_cache(void);
307 extern int jbd2_journal_set_revoke(journal_t *, unsigned long long, tid_t);
308 extern int jbd2_journal_test_revoke(journal_t *, unsigned long long, tid_t);
309 extern void jbd2_journal_clear_revoke(journal_t *);
311 #endif /* _JFS_USER_H */