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
17 #if EXT2_FLAT_INCLUDES
22 #include "ext2fs/ext2_fs.h"
23 #include "ext2fs/ext2fs.h"
24 #include "blkid/blkid.h"
28 * Pull in the definition of the e2fsck context structure
34 #if __STDC_VERSION__ < 199901L
35 # if __GNUC__ >= 2 || _MSC_VER >= 1300
36 # define __func__ __FUNCTION__
38 # define __func__ "<unknown>"
51 unsigned int b_dirty:1;
52 unsigned int b_uptodate:1;
53 unsigned long long b_blocknr;
64 struct ext2_inode i_ext2;
77 #define K_DEV_JOURNAL 2
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)
84 typedef struct kmem_cache {
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)
95 static inline void *kmalloc_array(unsigned n, unsigned size, int flags)
97 if (n && (~0U)/n < size)
99 return malloc(n * size);
102 #define cond_resched() do { } while (0)
107 * Now pull in the real linux/jfs.h definitions.
109 #include <ext2fs/kernel-jbd.h>
112 * We use the standard libext2fs portability tricks for inline
115 #ifdef NO_INLINE_FUNCS
116 extern kmem_cache_t *do_cache_create(int len);
117 extern void do_cache_destroy(kmem_cache_t *cache);
118 extern size_t journal_tag_bytes(journal_t *journal);
119 extern __u32 __hash_32(__u32 val);
120 extern __u32 hash_32(__u32 val, unsigned int bits);
121 extern __u32 hash_64(__u64 val, unsigned int bits);
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_ kmem_cache_t *do_cache_create(int len)
145 kmem_cache_t *new_cache;
147 new_cache = malloc(sizeof(*new_cache));
149 new_cache->object_length = len;
153 _INLINE_ void do_cache_destroy(kmem_cache_t *cache)
158 /* generic hashing taken from the Linux kernel */
159 #define GOLDEN_RATIO_32 0x61C88647
160 #define GOLDEN_RATIO_64 0x61C8864680B583EBull
162 _INLINE_ __u32 __hash_32(__u32 val)
164 return val * GOLDEN_RATIO_32;
167 _INLINE_ __u32 hash_32(__u32 val, unsigned int bits)
169 /* High bits are more random, so use them. */
170 return __hash_32(val) >> (32 - bits);
173 _INLINE_ __u32 hash_64(__u64 val, unsigned int bits)
175 if (sizeof(long) >= 8) {
176 /* 64x64-bit multiply is efficient on all 64-bit processors */
177 return val * GOLDEN_RATIO_64 >> (64 - bits);
179 /* Hash 64 bits using only 32x32-bit multiply. */
180 return hash_32((__u32)val ^ __hash_32(val >> 32), bits);
188 * Kernel compatibility functions are defined in journal.c
190 int jbd2_journal_bmap(journal_t *journal, unsigned long block,
191 unsigned long long *phys);
192 struct buffer_head *getblk(kdev_t ctx, unsigned long long blocknr,
194 int sync_blockdev(kdev_t kdev);
195 void ll_rw_block(int rw, int op_flags, int nr, struct buffer_head *bh[]);
196 void mark_buffer_dirty(struct buffer_head *bh);
197 void mark_buffer_uptodate(struct buffer_head *bh, int val);
198 void brelse(struct buffer_head *bh);
199 int buffer_uptodate(struct buffer_head *bh);
200 void wait_on_buffer(struct buffer_head *bh);
203 * Define newer 2.5 interfaces
205 #define __getblk(dev, blocknr, blocksize) getblk(dev, blocknr, blocksize)
206 #define set_buffer_uptodate(bh) mark_buffer_uptodate(bh, 1)
211 #define J_ASSERT(x) assert(x)
213 #define JSB_HAS_INCOMPAT_FEATURE(jsb, mask) \
214 ((jsb)->s_header.h_blocktype == ext2fs_cpu_to_be32(JBD2_SUPERBLOCK_V2) && \
215 ((jsb)->s_feature_incompat & ext2fs_cpu_to_be32((mask))))
218 extern e2fsck_t e2fsck_global_ctx; /* Try your very best not to use this! */
220 #define J_ASSERT(assert) \
221 do { if (!(assert)) { \
222 printf ("Assertion failure in %s() at %s line %d: " \
224 __func__, __FILE__, __LINE__, # assert); \
225 fatal_error(e2fsck_global_ctx, 0); \
231 #define EFSBADCRC EXT2_ET_BAD_CRC
234 #define EFSCORRUPTED EXT2_ET_FILESYSTEM_CORRUPTED
237 static inline void jbd2_descriptor_block_csum_set(journal_t *j,
238 struct buffer_head *bh)
240 struct jbd2_journal_block_tail *tail;
243 if (!jbd2_journal_has_csum_v2or3(j))
246 tail = (struct jbd2_journal_block_tail *)(bh->b_data + j->j_blocksize -
247 sizeof(struct jbd2_journal_block_tail));
248 tail->t_checksum = 0;
249 csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize);
250 tail->t_checksum = cpu_to_be32(csum);
254 extern int jbd2_journal_recover (journal_t *journal);
255 extern int jbd2_journal_skip_recovery (journal_t *);
258 extern int jbd2_journal_init_revoke(journal_t *, int);
259 extern void jbd2_journal_destroy_revoke(journal_t *);
260 extern void jbd2_journal_destroy_revoke_record_cache(void);
261 extern void jbd2_journal_destroy_revoke_table_cache(void);
262 extern int jbd2_journal_init_revoke_record_cache(void);
263 extern int jbd2_journal_init_revoke_table_cache(void);
266 extern int jbd2_journal_set_revoke(journal_t *, unsigned long long, tid_t);
267 extern int jbd2_journal_test_revoke(journal_t *, unsigned long long, tid_t);
268 extern void jbd2_journal_clear_revoke(journal_t *);
270 #endif /* _JFS_USER_H */