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