• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "config.h"
15 
16 #ifdef DEBUGFS
17 #include <stdio.h>
18 #include <stdlib.h>
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
29 /*
30  * Pull in the definition of the e2fsck context structure
31  */
32 #include "e2fsck.h"
33 #endif
34 
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 
43 struct buffer_head {
44 #ifdef DEBUGFS
45 	ext2_filsys	b_fs;
46 #else
47 	e2fsck_t	b_ctx;
48 #endif
49 	io_channel	b_io;
50 	int		b_size;
51 	int		b_err;
52 	unsigned int	b_dirty:1;
53 	unsigned int	b_uptodate:1;
54 	unsigned long long b_blocknr;
55 	char		b_data[4096];
56 };
57 
58 struct inode {
59 #ifdef DEBUGFS
60 	ext2_filsys	i_fs;
61 #else
62 	e2fsck_t	i_ctx;
63 #endif
64 	ext2_ino_t	i_ino;
65 	struct ext2_inode i_ext2;
66 };
67 
68 struct kdev_s {
69 #ifdef DEBUGFS
70 	ext2_filsys	k_fs;
71 #else
72 	e2fsck_t	k_ctx;
73 #endif
74 	int		k_dev;
75 };
76 
77 #define K_DEV_FS	1
78 #define K_DEV_JOURNAL	2
79 
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)
84 
85 typedef struct kmem_cache {
86 	int	object_length;
87 } kmem_cache_t;
88 
89 #define kmem_cache_alloc(cache, flags) malloc((cache)->object_length)
90 #define kmem_cache_free(cache, obj) free(obj)
91 #define kmem_cache_create(name, len, a, b, c) do_cache_create(len)
92 #define kmem_cache_destroy(cache) do_cache_destroy(cache)
93 #define kmalloc(len, flags) malloc(len)
94 #define kfree(p) free(p)
95 
kmalloc_array(unsigned n,unsigned size,int flags EXT2FS_ATTR ((unused)))96 static inline void *kmalloc_array(unsigned n, unsigned size,
97 				  int flags EXT2FS_ATTR((unused)))
98 {
99 	if (n && (~0U)/n < size)
100 		return NULL;
101 	return malloc(n * size);
102 }
103 
104 #define cond_resched()	do { } while (0)
105 
106 #define __init
107 
108 /*
109  * Now pull in the real linux/jfs.h definitions.
110  */
111 #include <ext2fs/kernel-jbd.h>
112 
113 /*
114  * We use the standard libext2fs portability tricks for inline
115  * functions.
116  */
117 #ifdef NO_INLINE_FUNCS
118 extern kmem_cache_t *do_cache_create(int len);
119 extern void do_cache_destroy(kmem_cache_t *cache);
120 extern size_t journal_tag_bytes(journal_t *journal);
121 extern __u32 __hash_32(__u32 val);
122 extern __u32 hash_32(__u32 val, unsigned int bits);
123 extern __u32 hash_64(__u64 val, unsigned int bits);
124 #endif
125 
126 #if (defined(E2FSCK_INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
127 #ifdef E2FSCK_INCLUDE_INLINE_FUNCS
128 #if (__STDC_VERSION__ >= 199901L)
129 #define _INLINE_ extern inline
130 #else
131 #define _INLINE_ inline
132 #endif
133 #else /* !E2FSCK_INCLUDE_INLINE FUNCS */
134 #if (__STDC_VERSION__ >= 199901L)
135 #define _INLINE_ inline
136 #else /* not C99 */
137 #ifdef __GNUC__
138 #define _INLINE_ extern __inline__
139 #else				/* For Watcom C */
140 #define _INLINE_ extern inline
141 #endif /* __GNUC__ */
142 #endif /* __STDC_VERSION__ >= 199901L */
143 #endif /* E2FSCK_INCLUDE_INLINE_FUNCS */
144 
do_cache_create(int len)145 _INLINE_ kmem_cache_t *do_cache_create(int len)
146 {
147 	kmem_cache_t *new_cache;
148 
149 	new_cache = malloc(sizeof(*new_cache));
150 	if (new_cache)
151 		new_cache->object_length = len;
152 	return new_cache;
153 }
154 
do_cache_destroy(kmem_cache_t * cache)155 _INLINE_ void do_cache_destroy(kmem_cache_t *cache)
156 {
157 	free(cache);
158 }
159 
160 /* generic hashing taken from the Linux kernel */
161 #define GOLDEN_RATIO_32 0x61C88647
162 #define GOLDEN_RATIO_64 0x61C8864680B583EBull
163 
__hash_32(__u32 val)164 _INLINE_ __u32 __hash_32(__u32 val)
165 {
166 	return val * GOLDEN_RATIO_32;
167 }
168 
hash_32(__u32 val,unsigned int bits)169 _INLINE_ __u32 hash_32(__u32 val, unsigned int bits)
170 {
171 	/* High bits are more random, so use them. */
172 	return __hash_32(val) >> (32 - bits);
173 }
174 
hash_64(__u64 val,unsigned int bits)175 _INLINE_ __u32 hash_64(__u64 val, unsigned int bits)
176 {
177 	if (sizeof(long) >= 8) {
178 		/* 64x64-bit multiply is efficient on all 64-bit processors */
179 		return val * GOLDEN_RATIO_64 >> (64 - bits);
180 	} else {
181 		/* Hash 64 bits using only 32x32-bit multiply. */
182 		return hash_32((__u32)val ^ __hash_32(val >> 32), bits);
183 	}
184 }
185 
186 #undef _INLINE_
187 #endif
188 
189 /*
190  * Kernel compatibility functions are defined in journal.c
191  */
192 int jbd2_journal_bmap(journal_t *journal, unsigned long block,
193 		      unsigned long long *phys);
194 struct buffer_head *getblk(kdev_t ctx, unsigned long long blocknr,
195 			   int blocksize);
196 int sync_blockdev(kdev_t kdev);
197 void ll_rw_block(int rw, int op_flags, int nr, struct buffer_head *bh[]);
198 void mark_buffer_dirty(struct buffer_head *bh);
199 void mark_buffer_uptodate(struct buffer_head *bh, int val);
200 void brelse(struct buffer_head *bh);
201 int buffer_uptodate(struct buffer_head *bh);
202 void wait_on_buffer(struct buffer_head *bh);
203 
204 /*
205  * Define newer 2.5 interfaces
206  */
207 #define __getblk(dev, blocknr, blocksize) getblk(dev, blocknr, blocksize)
208 #define set_buffer_uptodate(bh) mark_buffer_uptodate(bh, 1)
209 
210 #ifdef DEBUGFS
211 #include <assert.h>
212 #undef J_ASSERT
213 #define J_ASSERT(x)	assert(x)
214 
215 #define JSB_HAS_INCOMPAT_FEATURE(jsb, mask)				\
216 	((jsb)->s_header.h_blocktype == ext2fs_cpu_to_be32(JBD2_SUPERBLOCK_V2) &&	\
217 	 ((jsb)->s_feature_incompat & ext2fs_cpu_to_be32((mask))))
218 #else  /* !DEBUGFS */
219 
220 extern e2fsck_t e2fsck_global_ctx;  /* Try your very best not to use this! */
221 
222 #define J_ASSERT(assert)						\
223 	do { if (!(assert)) {						\
224 		printf ("Assertion failure in %s() at %s line %d: "	\
225 			"\"%s\"\n",					\
226 			__func__, __FILE__, __LINE__, # assert);	\
227 		fatal_error(e2fsck_global_ctx, 0);			\
228 	} } while (0)
229 
230 #endif /* DEBUGFS */
231 
232 #ifndef EFSBADCRC
233 #define EFSBADCRC	EXT2_ET_BAD_CRC
234 #endif
235 #ifndef EFSCORRUPTED
236 #define EFSCORRUPTED	EXT2_ET_FILESYSTEM_CORRUPTED
237 #endif
238 
jbd2_descriptor_block_csum_set(journal_t * j,struct buffer_head * bh)239 static inline void jbd2_descriptor_block_csum_set(journal_t *j,
240 						  struct buffer_head *bh)
241 {
242 	struct jbd2_journal_block_tail *tail;
243 	__u32 csum;
244 
245 	if (!jbd2_journal_has_csum_v2or3(j))
246 		return;
247 
248 	tail = (struct jbd2_journal_block_tail *)(bh->b_data + j->j_blocksize -
249 			sizeof(struct jbd2_journal_block_tail));
250 	tail->t_checksum = 0;
251 	csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize);
252 	tail->t_checksum = cpu_to_be32(csum);
253 }
254 
255 /* recovery.c */
256 extern int	jbd2_journal_recover    (journal_t *journal);
257 extern int	jbd2_journal_skip_recovery (journal_t *);
258 
259 /* revoke.c */
260 extern int	jbd2_journal_init_revoke(journal_t *, int);
261 extern void	jbd2_journal_destroy_revoke(journal_t *);
262 extern void	jbd2_journal_destroy_revoke_record_cache(void);
263 extern void	jbd2_journal_destroy_revoke_table_cache(void);
264 extern int	jbd2_journal_init_revoke_record_cache(void);
265 extern int	jbd2_journal_init_revoke_table_cache(void);
266 
267 
268 extern int	jbd2_journal_set_revoke(journal_t *, unsigned long long, tid_t);
269 extern int	jbd2_journal_test_revoke(journal_t *, unsigned long long, tid_t);
270 extern void	jbd2_journal_clear_revoke(journal_t *);
271 
272 #endif /* _JFS_USER_H */
273