]>
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 | ||
14 | #ifdef DEBUGFS | |
cbe867f0 TT |
15 | #include <stdio.h> |
16 | #include <stdlib.h> | |
759c46cf DW |
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 | |
cc7067b4 TT |
27 | /* |
28 | * Pull in the definition of the e2fsck context structure | |
29 | */ | |
3882fb46 | 30 | #include "config.h" |
0e8a9560 | 31 | #include "e2fsck.h" |
759c46cf | 32 | #endif |
cc7067b4 | 33 | |
ac3256fd TT |
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 | ||
cc7067b4 | 42 | struct buffer_head { |
759c46cf DW |
43 | #ifdef DEBUGFS |
44 | ext2_filsys b_fs; | |
45 | #else | |
8cf93332 | 46 | e2fsck_t b_ctx; |
759c46cf DW |
47 | #endif |
48 | io_channel b_io; | |
49 | int b_size; | |
759c46cf | 50 | int b_err; |
c4d54aa2 TT |
51 | unsigned int b_dirty:1; |
52 | unsigned int b_uptodate:1; | |
53 | unsigned long long b_blocknr; | |
e35d548b | 54 | char b_data[1024]; |
cc7067b4 TT |
55 | }; |
56 | ||
57 | struct inode { | |
759c46cf DW |
58 | #ifdef DEBUGFS |
59 | ext2_filsys i_fs; | |
60 | #else | |
86c627ec | 61 | e2fsck_t i_ctx; |
759c46cf | 62 | #endif |
86c627ec | 63 | ext2_ino_t i_ino; |
cc7067b4 TT |
64 | struct ext2_inode i_ext2; |
65 | }; | |
66 | ||
8cf93332 | 67 | struct kdev_s { |
759c46cf DW |
68 | #ifdef DEBUGFS |
69 | ext2_filsys k_fs; | |
70 | #else | |
8cf93332 | 71 | e2fsck_t k_ctx; |
759c46cf | 72 | #endif |
8cf93332 TT |
73 | int k_dev; |
74 | }; | |
cc7067b4 | 75 | |
8cf93332 TT |
76 | #define K_DEV_FS 1 |
77 | #define K_DEV_JOURNAL 2 | |
78 | ||
759c46cf DW |
79 | #define lock_buffer(bh) do {} while (0) |
80 | #define unlock_buffer(bh) do {} while (0) | |
cc7067b4 | 81 | #define buffer_req(bh) 1 |
759c46cf | 82 | #define do_readahead(journal, start) do {} while (0) |
cc7067b4 TT |
83 | |
84 | typedef struct { | |
85 | int object_length; | |
1911bf11 | 86 | } lkmem_cache_t; |
cc7067b4 | 87 | |
759c46cf DW |
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) | |
8cf93332 | 91 | #define kmem_cache_destroy(cache) do_cache_destroy(cache) |
759c46cf | 92 | #define kmalloc(len, flags) malloc(len) |
cc7067b4 TT |
93 | #define kfree(p) free(p) |
94 | ||
e5ea6b14 TT |
95 | #define cond_resched() do { } while (0) |
96 | ||
185c4aea TT |
97 | #define __init |
98 | ||
99 | /* | |
100 | * Now pull in the real linux/jfs.h definitions. | |
101 | */ | |
102 | #include <ext2fs/kernel-jbd.h> | |
103 | ||
2acad6b4 TT |
104 | /* |
105 | * We use the standard libext2fs portability tricks for inline | |
efc6f628 | 106 | * functions. |
2acad6b4 | 107 | */ |
ab3f5c5a | 108 | #ifdef NO_INLINE_FUNCS |
759c46cf | 109 | extern lkmem_cache_t *do_cache_create(int len); |
1911bf11 | 110 | extern void do_cache_destroy(lkmem_cache_t *cache); |
2acad6b4 | 111 | extern size_t journal_tag_bytes(journal_t *journal); |
ac3256fd TT |
112 | extern __u32 __hash_32(__u32 val); |
113 | extern __u32 hash_32(__u32 val, unsigned int bits); | |
114 | extern __u32 hash_64(__u64 val, unsigned int bits); | |
ab3f5c5a | 115 | #endif |
efc6f628 | 116 | |
53ef44c4 TT |
117 | #if (defined(E2FSCK_INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS)) |
118 | #ifdef E2FSCK_INCLUDE_INLINE_FUNCS | |
ab3f5c5a TT |
119 | #if (__STDC_VERSION__ >= 199901L) |
120 | #define _INLINE_ extern inline | |
53ef44c4 | 121 | #else |
ab3f5c5a TT |
122 | #define _INLINE_ inline |
123 | #endif | |
124 | #else /* !E2FSCK_INCLUDE_INLINE FUNCS */ | |
125 | #if (__STDC_VERSION__ >= 199901L) | |
126 | #define _INLINE_ inline | |
127 | #else /* not C99 */ | |
53ef44c4 TT |
128 | #ifdef __GNUC__ |
129 | #define _INLINE_ extern __inline__ | |
130 | #else /* For Watcom C */ | |
131 | #define _INLINE_ extern inline | |
ab3f5c5a TT |
132 | #endif /* __GNUC__ */ |
133 | #endif /* __STDC_VERSION__ >= 199901L */ | |
134 | #endif /* E2FSCK_INCLUDE_INLINE_FUNCS */ | |
135 | ||
759c46cf | 136 | _INLINE_ lkmem_cache_t *do_cache_create(int len) |
cc7067b4 | 137 | { |
1911bf11 | 138 | lkmem_cache_t *new_cache; |
759c46cf | 139 | |
cc7067b4 TT |
140 | new_cache = malloc(sizeof(*new_cache)); |
141 | if (new_cache) | |
142 | new_cache->object_length = len; | |
143 | return new_cache; | |
144 | } | |
145 | ||
1911bf11 | 146 | _INLINE_ void do_cache_destroy(lkmem_cache_t *cache) |
8cf93332 TT |
147 | { |
148 | free(cache); | |
149 | } | |
8cf93332 | 150 | |
c8ca2397 TT |
151 | /* generic hashing taken from the Linux kernel */ |
152 | #define GOLDEN_RATIO_32 0x61C88647 | |
153 | #define GOLDEN_RATIO_64 0x61C8864680B583EBull | |
154 | ||
155 | _INLINE_ __u32 __hash_32(__u32 val) | |
156 | { | |
157 | return val * GOLDEN_RATIO_32; | |
158 | } | |
159 | ||
160 | _INLINE_ __u32 hash_32(__u32 val, unsigned int bits) | |
161 | { | |
162 | /* High bits are more random, so use them. */ | |
163 | return __hash_32(val) >> (32 - bits); | |
164 | } | |
165 | ||
166 | _INLINE_ __u32 hash_64(__u64 val, unsigned int bits) | |
167 | { | |
168 | if (sizeof(long) >= 8) { | |
169 | /* 64x64-bit multiply is efficient on all 64-bit processors */ | |
170 | return val * GOLDEN_RATIO_64 >> (64 - bits); | |
171 | } else { | |
172 | /* Hash 64 bits using only 32x32-bit multiply. */ | |
173 | return hash_32((__u32)val ^ __hash_32(val >> 32), bits); | |
174 | } | |
175 | } | |
176 | ||
185c4aea TT |
177 | #undef _INLINE_ |
178 | #endif | |
8cf93332 TT |
179 | |
180 | /* | |
181 | * Kernel compatibility functions are defined in journal.c | |
182 | */ | |
3b693d0b | 183 | int journal_bmap(journal_t *journal, blk64_t block, unsigned long long *phys); |
6dc64392 | 184 | struct buffer_head *getblk(kdev_t ctx, blk64_t blocknr, int blocksize); |
13af4b93 | 185 | int sync_blockdev(kdev_t kdev); |
8cf93332 TT |
186 | void ll_rw_block(int rw, int dummy, struct buffer_head *bh[]); |
187 | void mark_buffer_dirty(struct buffer_head *bh); | |
188 | void mark_buffer_uptodate(struct buffer_head *bh, int val); | |
189 | void brelse(struct buffer_head *bh); | |
190 | int buffer_uptodate(struct buffer_head *bh); | |
191 | void wait_on_buffer(struct buffer_head *bh); | |
3de085dd TT |
192 | |
193 | /* | |
194 | * Define newer 2.5 interfaces | |
195 | */ | |
196 | #define __getblk(dev, blocknr, blocksize) getblk(dev, blocknr, blocksize) | |
197 | #define set_buffer_uptodate(bh) mark_buffer_uptodate(bh, 1) | |
759c46cf DW |
198 | |
199 | #ifdef DEBUGFS | |
200 | #include <assert.h> | |
201 | #undef J_ASSERT | |
202 | #define J_ASSERT(x) assert(x) | |
203 | ||
204 | #define JSB_HAS_INCOMPAT_FEATURE(jsb, mask) \ | |
205 | ((jsb)->s_header.h_blocktype == ext2fs_cpu_to_be32(JFS_SUPERBLOCK_V2) && \ | |
206 | ((jsb)->s_feature_incompat & ext2fs_cpu_to_be32((mask)))) | |
759c46cf DW |
207 | #else /* !DEBUGFS */ |
208 | ||
209 | extern e2fsck_t e2fsck_global_ctx; /* Try your very best not to use this! */ | |
210 | ||
211 | #define J_ASSERT(assert) \ | |
212 | do { if (!(assert)) { \ | |
213 | printf ("Assertion failure in %s() at %s line %d: " \ | |
214 | "\"%s\"\n", \ | |
ac3256fd | 215 | __func__, __FILE__, __LINE__, # assert); \ |
759c46cf DW |
216 | fatal_error(e2fsck_global_ctx, 0); \ |
217 | } } while (0) | |
218 | ||
219 | #endif /* DEBUGFS */ | |
220 | ||
b4f02c9f | 221 | #ifndef EFSBADCRC |
b41a4ffa | 222 | #define EFSBADCRC EXT2_ET_BAD_CRC |
b4f02c9f TT |
223 | #endif |
224 | #ifndef EFSCORRUPTED | |
b41a4ffa | 225 | #define EFSCORRUPTED EXT2_ET_FILESYSTEM_CORRUPTED |
b4f02c9f TT |
226 | #endif |
227 | ||
81f95d43 TT |
228 | /* recovery.c */ |
229 | extern int journal_recover (journal_t *journal); | |
230 | extern int journal_skip_recovery (journal_t *); | |
231 | ||
232 | /* revoke.c */ | |
233 | extern int journal_init_revoke(journal_t *, int); | |
234 | extern void journal_destroy_revoke(journal_t *); | |
235 | extern void journal_destroy_revoke_caches(void); | |
236 | extern int journal_init_revoke_caches(void); | |
237 | ||
238 | extern int journal_set_revoke(journal_t *, unsigned long long, tid_t); | |
239 | extern int journal_test_revoke(journal_t *, unsigned long long, tid_t); | |
240 | extern void journal_clear_revoke(journal_t *); | |
241 | ||
759c46cf | 242 | #endif /* _JFS_USER_H */ |