]>
Commit | Line | Data |
---|---|---|
cc7067b4 TT |
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 | */ | |
759c46cf DW |
11 | #ifndef _JFS_USER_H |
12 | #define _JFS_USER_H | |
13 | ||
1950b654 CC |
14 | #include "config.h" |
15 | ||
759c46cf | 16 | #ifdef DEBUGFS |
cbe867f0 TT |
17 | #include <stdio.h> |
18 | #include <stdlib.h> | |
759c46cf DW |
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 | |
cc7067b4 TT |
29 | /* |
30 | * Pull in the definition of the e2fsck context structure | |
31 | */ | |
0e8a9560 | 32 | #include "e2fsck.h" |
759c46cf | 33 | #endif |
cc7067b4 | 34 | |
ac3256fd TT |
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 | ||
cc7067b4 | 43 | struct buffer_head { |
759c46cf DW |
44 | #ifdef DEBUGFS |
45 | ext2_filsys b_fs; | |
46 | #else | |
8cf93332 | 47 | e2fsck_t b_ctx; |
759c46cf DW |
48 | #endif |
49 | io_channel b_io; | |
50 | int b_size; | |
759c46cf | 51 | int b_err; |
c4d54aa2 TT |
52 | unsigned int b_dirty:1; |
53 | unsigned int b_uptodate:1; | |
54 | unsigned long long b_blocknr; | |
865221f5 | 55 | char b_data[4096]; |
cc7067b4 TT |
56 | }; |
57 | ||
58 | struct inode { | |
759c46cf DW |
59 | #ifdef DEBUGFS |
60 | ext2_filsys i_fs; | |
61 | #else | |
86c627ec | 62 | e2fsck_t i_ctx; |
759c46cf | 63 | #endif |
86c627ec | 64 | ext2_ino_t i_ino; |
cc7067b4 TT |
65 | struct ext2_inode i_ext2; |
66 | }; | |
67 | ||
8cf93332 | 68 | struct kdev_s { |
759c46cf DW |
69 | #ifdef DEBUGFS |
70 | ext2_filsys k_fs; | |
71 | #else | |
8cf93332 | 72 | e2fsck_t k_ctx; |
759c46cf | 73 | #endif |
8cf93332 TT |
74 | int k_dev; |
75 | }; | |
cc7067b4 | 76 | |
8cf93332 TT |
77 | #define K_DEV_FS 1 |
78 | #define K_DEV_JOURNAL 2 | |
79 | ||
759c46cf DW |
80 | #define lock_buffer(bh) do {} while (0) |
81 | #define unlock_buffer(bh) do {} while (0) | |
cc7067b4 | 82 | #define buffer_req(bh) 1 |
759c46cf | 83 | #define do_readahead(journal, start) do {} while (0) |
cc7067b4 | 84 | |
013e5d86 EB |
85 | struct kmem_cache { |
86 | unsigned int object_size; | |
87 | }; | |
cc7067b4 | 88 | |
e5ea6b14 TT |
89 | #define cond_resched() do { } while (0) |
90 | ||
185c4aea TT |
91 | #define __init |
92 | ||
93 | /* | |
94 | * Now pull in the real linux/jfs.h definitions. | |
95 | */ | |
96 | #include <ext2fs/kernel-jbd.h> | |
97 | ||
2acad6b4 TT |
98 | /* |
99 | * We use the standard libext2fs portability tricks for inline | |
efc6f628 | 100 | * functions. |
2acad6b4 | 101 | */ |
ab3f5c5a | 102 | #ifdef NO_INLINE_FUNCS |
013e5d86 EB |
103 | extern struct kmem_cache *kmem_cache_create(const char *name, |
104 | unsigned int size, | |
105 | unsigned int align, | |
106 | unsigned int flags, | |
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); | |
2acad6b4 | 113 | extern size_t journal_tag_bytes(journal_t *journal); |
ac3256fd TT |
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); | |
d55f8b8c TT |
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); | |
ab3f5c5a | 122 | #endif |
efc6f628 | 123 | |
53ef44c4 TT |
124 | #if (defined(E2FSCK_INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS)) |
125 | #ifdef E2FSCK_INCLUDE_INLINE_FUNCS | |
ab3f5c5a TT |
126 | #if (__STDC_VERSION__ >= 199901L) |
127 | #define _INLINE_ extern inline | |
53ef44c4 | 128 | #else |
ab3f5c5a TT |
129 | #define _INLINE_ inline |
130 | #endif | |
131 | #else /* !E2FSCK_INCLUDE_INLINE FUNCS */ | |
132 | #if (__STDC_VERSION__ >= 199901L) | |
133 | #define _INLINE_ inline | |
134 | #else /* not C99 */ | |
53ef44c4 TT |
135 | #ifdef __GNUC__ |
136 | #define _INLINE_ extern __inline__ | |
137 | #else /* For Watcom C */ | |
138 | #define _INLINE_ extern inline | |
ab3f5c5a TT |
139 | #endif /* __GNUC__ */ |
140 | #endif /* __STDC_VERSION__ >= 199901L */ | |
141 | #endif /* E2FSCK_INCLUDE_INLINE_FUNCS */ | |
142 | ||
013e5d86 EB |
143 | _INLINE_ struct kmem_cache * |
144 | kmem_cache_create(const char *name EXT2FS_ATTR((unused)), | |
145 | unsigned int size, | |
146 | unsigned int align EXT2FS_ATTR((unused)), | |
147 | unsigned int flags EXT2FS_ATTR((unused)), | |
148 | void (*ctor)(void *) EXT2FS_ATTR((unused))) | |
cc7067b4 | 149 | { |
013e5d86 | 150 | struct kmem_cache *new_cache; |
759c46cf | 151 | |
cc7067b4 TT |
152 | new_cache = malloc(sizeof(*new_cache)); |
153 | if (new_cache) | |
013e5d86 | 154 | new_cache->object_size = size; |
cc7067b4 TT |
155 | return new_cache; |
156 | } | |
157 | ||
013e5d86 EB |
158 | _INLINE_ void kmem_cache_destroy(struct kmem_cache *s) |
159 | { | |
160 | free(s); | |
161 | } | |
162 | ||
163 | _INLINE_ void *kmem_cache_alloc(struct kmem_cache *cachep, | |
164 | gfp_t flags EXT2FS_ATTR((unused))) | |
165 | { | |
166 | return malloc(cachep->object_size); | |
167 | } | |
168 | ||
169 | _INLINE_ void kmem_cache_free(struct kmem_cache *s EXT2FS_ATTR((unused)), | |
170 | void *objp) | |
171 | { | |
172 | free(objp); | |
173 | } | |
174 | ||
175 | _INLINE_ void *kmalloc(size_t size, gfp_t flags EXT2FS_ATTR((unused))) | |
176 | { | |
177 | return malloc(size); | |
178 | } | |
179 | ||
180 | _INLINE_ void kfree(const void *objp) | |
8cf93332 | 181 | { |
d6ed2479 TT |
182 | #ifdef HAVE_INTPTR_T |
183 | /* | |
184 | * Work around a botch in the C standard, which triggers | |
185 | * compiler warnings. For better or for worse, the kernel | |
186 | * uses const void * for kfree, while the C standard mandates | |
187 | * the use of void *. See: https://yarchive.net/comp/const.html | |
188 | */ | |
189 | free((void *)(intptr_t)objp); | |
190 | #else | |
013e5d86 | 191 | free((void *)objp); |
d6ed2479 | 192 | #endif |
8cf93332 | 193 | } |
8cf93332 | 194 | |
c8ca2397 TT |
195 | /* generic hashing taken from the Linux kernel */ |
196 | #define GOLDEN_RATIO_32 0x61C88647 | |
197 | #define GOLDEN_RATIO_64 0x61C8864680B583EBull | |
198 | ||
199 | _INLINE_ __u32 __hash_32(__u32 val) | |
200 | { | |
201 | return val * GOLDEN_RATIO_32; | |
202 | } | |
203 | ||
204 | _INLINE_ __u32 hash_32(__u32 val, unsigned int bits) | |
205 | { | |
206 | /* High bits are more random, so use them. */ | |
207 | return __hash_32(val) >> (32 - bits); | |
208 | } | |
209 | ||
210 | _INLINE_ __u32 hash_64(__u64 val, unsigned int bits) | |
211 | { | |
212 | if (sizeof(long) >= 8) { | |
213 | /* 64x64-bit multiply is efficient on all 64-bit processors */ | |
214 | return val * GOLDEN_RATIO_64 >> (64 - bits); | |
215 | } else { | |
216 | /* Hash 64 bits using only 32x32-bit multiply. */ | |
217 | return hash_32((__u32)val ^ __hash_32(val >> 32), bits); | |
218 | } | |
219 | } | |
220 | ||
d55f8b8c TT |
221 | _INLINE_ void *kmalloc_array(unsigned n, unsigned size, |
222 | int flags EXT2FS_ATTR((unused))) | |
223 | { | |
224 | if (n && (~0U)/n < size) | |
225 | return NULL; | |
226 | return malloc(n * size); | |
227 | } | |
228 | ||
229 | _INLINE_ __u32 jbd2_chksum(journal_t *j EXT2FS_ATTR((unused)), | |
230 | __u32 crc, const void *address, | |
231 | unsigned int length) | |
232 | { | |
233 | return ext2fs_crc32c_le(crc, address, length); | |
234 | } | |
235 | ||
236 | _INLINE_ void jbd2_descriptor_block_csum_set(journal_t *j, | |
237 | struct buffer_head *bh) | |
238 | { | |
239 | struct jbd2_journal_block_tail *tail; | |
240 | __u32 csum; | |
241 | ||
242 | if (!jbd2_journal_has_csum_v2or3(j)) | |
243 | return; | |
244 | ||
245 | tail = (struct jbd2_journal_block_tail *)(bh->b_data + j->j_blocksize - | |
246 | sizeof(struct jbd2_journal_block_tail)); | |
247 | tail->t_checksum = 0; | |
248 | csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize); | |
249 | tail->t_checksum = cpu_to_be32(csum); | |
250 | } | |
185c4aea TT |
251 | #undef _INLINE_ |
252 | #endif | |
8cf93332 TT |
253 | |
254 | /* | |
255 | * Kernel compatibility functions are defined in journal.c | |
256 | */ | |
4305084d | 257 | int jbd2_journal_bmap(journal_t *journal, unsigned long block, |
8335d3c5 | 258 | unsigned long long *phys); |
4305084d TT |
259 | struct buffer_head *getblk(kdev_t ctx, unsigned long long blocknr, |
260 | int blocksize); | |
13af4b93 | 261 | int sync_blockdev(kdev_t kdev); |
db113c0e | 262 | void ll_rw_block(int rw, int op_flags, int nr, struct buffer_head *bh[]); |
8cf93332 TT |
263 | void mark_buffer_dirty(struct buffer_head *bh); |
264 | void mark_buffer_uptodate(struct buffer_head *bh, int val); | |
265 | void brelse(struct buffer_head *bh); | |
266 | int buffer_uptodate(struct buffer_head *bh); | |
267 | void wait_on_buffer(struct buffer_head *bh); | |
3de085dd TT |
268 | |
269 | /* | |
270 | * Define newer 2.5 interfaces | |
271 | */ | |
272 | #define __getblk(dev, blocknr, blocksize) getblk(dev, blocknr, blocksize) | |
273 | #define set_buffer_uptodate(bh) mark_buffer_uptodate(bh, 1) | |
759c46cf DW |
274 | |
275 | #ifdef DEBUGFS | |
276 | #include <assert.h> | |
277 | #undef J_ASSERT | |
278 | #define J_ASSERT(x) assert(x) | |
279 | ||
280 | #define JSB_HAS_INCOMPAT_FEATURE(jsb, mask) \ | |
8335d3c5 | 281 | ((jsb)->s_header.h_blocktype == ext2fs_cpu_to_be32(JBD2_SUPERBLOCK_V2) && \ |
759c46cf | 282 | ((jsb)->s_feature_incompat & ext2fs_cpu_to_be32((mask)))) |
759c46cf DW |
283 | #else /* !DEBUGFS */ |
284 | ||
285 | extern e2fsck_t e2fsck_global_ctx; /* Try your very best not to use this! */ | |
286 | ||
287 | #define J_ASSERT(assert) \ | |
288 | do { if (!(assert)) { \ | |
289 | printf ("Assertion failure in %s() at %s line %d: " \ | |
290 | "\"%s\"\n", \ | |
ac3256fd | 291 | __func__, __FILE__, __LINE__, # assert); \ |
759c46cf DW |
292 | fatal_error(e2fsck_global_ctx, 0); \ |
293 | } } while (0) | |
294 | ||
295 | #endif /* DEBUGFS */ | |
296 | ||
b4f02c9f | 297 | #ifndef EFSBADCRC |
b41a4ffa | 298 | #define EFSBADCRC EXT2_ET_BAD_CRC |
b4f02c9f TT |
299 | #endif |
300 | #ifndef EFSCORRUPTED | |
b41a4ffa | 301 | #define EFSCORRUPTED EXT2_ET_FILESYSTEM_CORRUPTED |
b4f02c9f TT |
302 | #endif |
303 | ||
81f95d43 | 304 | /* recovery.c */ |
8335d3c5 TT |
305 | extern int jbd2_journal_recover (journal_t *journal); |
306 | extern int jbd2_journal_skip_recovery (journal_t *); | |
81f95d43 TT |
307 | |
308 | /* revoke.c */ | |
8335d3c5 TT |
309 | extern int jbd2_journal_init_revoke(journal_t *, int); |
310 | extern void jbd2_journal_destroy_revoke(journal_t *); | |
2faf75d2 TT |
311 | extern void jbd2_journal_destroy_revoke_record_cache(void); |
312 | extern void jbd2_journal_destroy_revoke_table_cache(void); | |
313 | extern int jbd2_journal_init_revoke_record_cache(void); | |
314 | extern int jbd2_journal_init_revoke_table_cache(void); | |
315 | ||
8335d3c5 TT |
316 | |
317 | extern int jbd2_journal_set_revoke(journal_t *, unsigned long long, tid_t); | |
318 | extern int jbd2_journal_test_revoke(journal_t *, unsigned long long, tid_t); | |
319 | extern void jbd2_journal_clear_revoke(journal_t *); | |
81f95d43 | 320 | |
759c46cf | 321 | #endif /* _JFS_USER_H */ |