• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * bitops.h --- Bitmap frobbing code.  The byte swapping routines are
3  * 	also included here.
4  *
5  * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
6  *
7  * %Begin-Header%
8  * This file may be redistributed under the terms of the GNU Library
9  * General Public License, version 2.
10  * %End-Header%
11  */
12 
13 #ifdef WORDS_BIGENDIAN
14 #define ext2fs_cpu_to_le64(x) ext2fs_swab64((x))
15 #define ext2fs_le64_to_cpu(x) ext2fs_swab64((x))
16 #define ext2fs_cpu_to_le32(x) ext2fs_swab32((x))
17 #define ext2fs_le32_to_cpu(x) ext2fs_swab32((x))
18 #define ext2fs_cpu_to_le16(x) ext2fs_swab16((x))
19 #define ext2fs_le16_to_cpu(x) ext2fs_swab16((x))
20 #define ext2fs_cpu_to_be64(x) ((__u64)(x))
21 #define ext2fs_be64_to_cpu(x) ((__u64)(x))
22 #define ext2fs_cpu_to_be32(x) ((__u32)(x))
23 #define ext2fs_be32_to_cpu(x) ((__u32)(x))
24 #define ext2fs_cpu_to_be16(x) ((__u16)(x))
25 #define ext2fs_be16_to_cpu(x) ((__u16)(x))
26 #else
27 #define ext2fs_cpu_to_le64(x) ((__u64)(x))
28 #define ext2fs_le64_to_cpu(x) ((__u64)(x))
29 #define ext2fs_cpu_to_le32(x) ((__u32)(x))
30 #define ext2fs_le32_to_cpu(x) ((__u32)(x))
31 #define ext2fs_cpu_to_le16(x) ((__u16)(x))
32 #define ext2fs_le16_to_cpu(x) ((__u16)(x))
33 #define ext2fs_cpu_to_be64(x) ext2fs_swab64((x))
34 #define ext2fs_be64_to_cpu(x) ext2fs_swab64((x))
35 #define ext2fs_cpu_to_be32(x) ext2fs_swab32((x))
36 #define ext2fs_be32_to_cpu(x) ext2fs_swab32((x))
37 #define ext2fs_cpu_to_be16(x) ext2fs_swab16((x))
38 #define ext2fs_be16_to_cpu(x) ext2fs_swab16((x))
39 #endif
40 
41 /*
42  * EXT2FS bitmap manipulation routines.
43  */
44 
45 /* Support for sending warning messages from the inline subroutines */
46 extern const char *ext2fs_block_string;
47 extern const char *ext2fs_inode_string;
48 extern const char *ext2fs_mark_string;
49 extern const char *ext2fs_unmark_string;
50 extern const char *ext2fs_test_string;
51 extern void ext2fs_warn_bitmap(errcode_t errcode, unsigned long arg,
52 			       const char *description);
53 extern void ext2fs_warn_bitmap2(ext2fs_generic_bitmap bitmap,
54 				int code, unsigned long arg);
55 
56 #ifdef NO_INLINE_FUNCS
57 extern void ext2fs_fast_set_bit(unsigned int nr,void * addr);
58 extern void ext2fs_fast_clear_bit(unsigned int nr, void * addr);
59 extern void ext2fs_fast_set_bit64(__u64 nr,void * addr);
60 extern void ext2fs_fast_clear_bit64(__u64 nr, void * addr);
61 extern __u16 ext2fs_swab16(__u16 val);
62 extern __u32 ext2fs_swab32(__u32 val);
63 extern __u64 ext2fs_swab64(__u64 val);
64 
65 extern int ext2fs_mark_block_bitmap(ext2fs_block_bitmap bitmap, blk_t block);
66 extern int ext2fs_unmark_block_bitmap(ext2fs_block_bitmap bitmap,
67 				       blk_t block);
68 extern int ext2fs_test_block_bitmap(ext2fs_block_bitmap bitmap, blk_t block);
69 
70 extern int ext2fs_mark_inode_bitmap(ext2fs_inode_bitmap bitmap, ext2_ino_t inode);
71 extern int ext2fs_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap,
72 				       ext2_ino_t inode);
73 extern int ext2fs_test_inode_bitmap(ext2fs_inode_bitmap bitmap, ext2_ino_t inode);
74 
75 extern void ext2fs_fast_mark_block_bitmap(ext2fs_block_bitmap bitmap,
76 					  blk_t block);
77 extern void ext2fs_fast_unmark_block_bitmap(ext2fs_block_bitmap bitmap,
78 					    blk_t block);
79 extern int ext2fs_fast_test_block_bitmap(ext2fs_block_bitmap bitmap,
80 					 blk_t block);
81 
82 extern void ext2fs_fast_mark_inode_bitmap(ext2fs_inode_bitmap bitmap,
83 					  ext2_ino_t inode);
84 extern void ext2fs_fast_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap,
85 					    ext2_ino_t inode);
86 extern int ext2fs_fast_test_inode_bitmap(ext2fs_inode_bitmap bitmap,
87 					 ext2_ino_t inode);
88 extern blk_t ext2fs_get_block_bitmap_start(ext2fs_block_bitmap bitmap);
89 extern ext2_ino_t ext2fs_get_inode_bitmap_start(ext2fs_inode_bitmap bitmap);
90 extern blk_t ext2fs_get_block_bitmap_end(ext2fs_block_bitmap bitmap);
91 extern ext2_ino_t ext2fs_get_inode_bitmap_end(ext2fs_inode_bitmap bitmap);
92 
93 extern void ext2fs_fast_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,
94 						blk_t block, int num);
95 extern void ext2fs_fast_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,
96 						  blk_t block, int num);
97 extern int ext2fs_fast_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
98 					       blk_t block, int num);
99 #endif
100 
101 /* These functions routines moved to gen_bitmap.c */
102 extern void ext2fs_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,
103 					   blk_t block, int num);
104 extern void ext2fs_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,
105 					     blk_t block, int num);
106 extern int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
107 					  blk_t block, int num);
108 extern int ext2fs_test_inode_bitmap_range(ext2fs_inode_bitmap bitmap,
109 					  ino_t inode, int num);
110 extern int ext2fs_mark_generic_bitmap(ext2fs_generic_bitmap bitmap,
111 					 __u32 bitno);
112 extern int ext2fs_unmark_generic_bitmap(ext2fs_generic_bitmap bitmap,
113 					   blk_t bitno);
114 extern int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap,
115 				      blk_t bitno);
116 extern int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
117 					  blk_t block, int num);
118 extern void ext2fs_set_bitmap_padding(ext2fs_generic_bitmap map);
119 extern __u32 ext2fs_get_generic_bitmap_start(ext2fs_generic_bitmap bitmap);
120 extern __u32 ext2fs_get_generic_bitmap_end(ext2fs_generic_bitmap bitmap);
121 
122 /* 64-bit versions */
123 
124 #ifdef NO_INLINE_FUNCS
125 extern int ext2fs_mark_block_bitmap2(ext2fs_block_bitmap bitmap,
126 				     blk64_t block);
127 extern int ext2fs_unmark_block_bitmap2(ext2fs_block_bitmap bitmap,
128 				       blk64_t block);
129 extern int ext2fs_test_block_bitmap2(ext2fs_block_bitmap bitmap,
130 				     blk64_t block);
131 
132 extern int ext2fs_mark_inode_bitmap2(ext2fs_inode_bitmap bitmap,
133 				     ext2_ino_t inode);
134 extern int ext2fs_unmark_inode_bitmap2(ext2fs_inode_bitmap bitmap,
135 				       ext2_ino_t inode);
136 extern int ext2fs_test_inode_bitmap2(ext2fs_inode_bitmap bitmap,
137 				     ext2_ino_t inode);
138 
139 extern void ext2fs_fast_mark_block_bitmap2(ext2fs_block_bitmap bitmap,
140 					   blk64_t block);
141 extern void ext2fs_fast_unmark_block_bitmap2(ext2fs_block_bitmap bitmap,
142 					     blk64_t block);
143 extern int ext2fs_fast_test_block_bitmap2(ext2fs_block_bitmap bitmap,
144 					  blk64_t block);
145 
146 extern void ext2fs_fast_mark_inode_bitmap2(ext2fs_inode_bitmap bitmap,
147 					   ext2_ino_t inode);
148 extern void ext2fs_fast_unmark_inode_bitmap2(ext2fs_inode_bitmap bitmap,
149 					    ext2_ino_t inode);
150 extern int ext2fs_fast_test_inode_bitmap2(ext2fs_inode_bitmap bitmap,
151 					  ext2_ino_t inode);
152 extern errcode_t ext2fs_find_first_zero_block_bitmap2(ext2fs_block_bitmap bitmap,
153 						      blk64_t start,
154 						      blk64_t end,
155 						      blk64_t *out);
156 extern errcode_t ext2fs_find_first_zero_inode_bitmap2(ext2fs_inode_bitmap bitmap,
157 						      ext2_ino_t start,
158 						      ext2_ino_t end,
159 						      ext2_ino_t *out);
160 extern blk64_t ext2fs_get_block_bitmap_start2(ext2fs_block_bitmap bitmap);
161 extern ext2_ino_t ext2fs_get_inode_bitmap_start2(ext2fs_inode_bitmap bitmap);
162 extern blk64_t ext2fs_get_block_bitmap_end2(ext2fs_block_bitmap bitmap);
163 extern ext2_ino_t ext2fs_get_inode_bitmap_end2(ext2fs_inode_bitmap bitmap);
164 
165 extern int ext2fs_fast_test_block_bitmap_range2(ext2fs_block_bitmap bitmap,
166 						blk64_t block,
167 						unsigned int num);
168 extern void ext2fs_fast_mark_block_bitmap_range2(ext2fs_block_bitmap bitmap,
169 						 blk64_t block,
170 						 unsigned int num);
171 extern void ext2fs_fast_unmark_block_bitmap_range2(ext2fs_block_bitmap bitmap,
172 						   blk64_t block,
173 						   unsigned int num);
174 #endif
175 
176 /* These routines moved to gen_bitmap64.c */
177 extern void ext2fs_clear_generic_bmap(ext2fs_generic_bitmap bitmap);
178 extern errcode_t ext2fs_compare_generic_bmap(errcode_t neq,
179 					     ext2fs_generic_bitmap bm1,
180 					     ext2fs_generic_bitmap bm2);
181 extern void ext2fs_set_generic_bmap_padding(ext2fs_generic_bitmap bmap);
182 extern int ext2fs_mark_generic_bmap(ext2fs_generic_bitmap bitmap,
183 				    blk64_t bitno);
184 extern int ext2fs_unmark_generic_bmap(ext2fs_generic_bitmap bitmap,
185 				      blk64_t bitno);
186 extern int ext2fs_test_generic_bmap(ext2fs_generic_bitmap bitmap,
187 				    blk64_t bitno);
188 extern int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap bitmap,
189 					   blk64_t block, unsigned int num);
190 extern __u64 ext2fs_get_generic_bmap_start(ext2fs_generic_bitmap bitmap);
191 extern __u64 ext2fs_get_generic_bmap_end(ext2fs_generic_bitmap bitmap);
192 extern int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap bitmap,
193 					   blk64_t block, unsigned int num);
194 extern void ext2fs_mark_block_bitmap_range2(ext2fs_block_bitmap bitmap,
195 					    blk64_t block, unsigned int num);
196 extern void ext2fs_unmark_block_bitmap_range2(ext2fs_block_bitmap bitmap,
197 					      blk64_t block, unsigned int num);
198 extern errcode_t ext2fs_find_first_zero_generic_bmap(ext2fs_generic_bitmap bitmap,
199 						     __u64 start, __u64 end,
200 						     __u64 *out);
201 
202 /*
203  * The inline routines themselves...
204  *
205  * If NO_INLINE_FUNCS is defined, then we won't try to do inline
206  * functions at all; they will be included as normal functions in
207  * inline.c
208  */
209 #ifdef NO_INLINE_FUNCS
210 #if (defined(__GNUC__) && (defined(__i386__) || defined(__i486__) || \
211 			   defined(__i586__)))
212 	/* This prevents bitops.c from trying to include the C */
213 	/* function version of these functions */
214 #define _EXT2_HAVE_ASM_BITOPS_
215 #endif
216 #endif /* NO_INLINE_FUNCS */
217 
218 #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
219 #ifdef INCLUDE_INLINE_FUNCS
220 #if (__STDC_VERSION__ >= 199901L)
221 #define _INLINE_ extern inline
222 #else
223 #define _INLINE_ inline
224 #endif
225 #else /* !INCLUDE_INLINE FUNCS */
226 #if (__STDC_VERSION__ >= 199901L)
227 #define _INLINE_ inline
228 #else /* not C99 */
229 #ifdef __GNUC__
230 #define _INLINE_ extern __inline__
231 #else				/* For Watcom C */
232 #define _INLINE_ extern inline
233 #endif /* __GNUC__ */
234 #endif /* __STDC_VERSION__ >= 199901L */
235 #endif /* INCLUDE_INLINE_FUNCS */
236 
237 /*
238  * Fast bit set/clear functions that doesn't need to return the
239  * previous bit value.
240  */
241 
ext2fs_fast_set_bit(unsigned int nr,void * addr)242 _INLINE_ void ext2fs_fast_set_bit(unsigned int nr,void * addr)
243 {
244 	unsigned char	*ADDR = (unsigned char *) addr;
245 
246 	ADDR += nr >> 3;
247 	*ADDR |= (unsigned char) (1 << (nr & 0x07));
248 }
249 
ext2fs_fast_clear_bit(unsigned int nr,void * addr)250 _INLINE_ void ext2fs_fast_clear_bit(unsigned int nr, void * addr)
251 {
252 	unsigned char	*ADDR = (unsigned char *) addr;
253 
254 	ADDR += nr >> 3;
255 	*ADDR &= (unsigned char) ~(1 << (nr & 0x07));
256 }
257 
258 
ext2fs_fast_set_bit64(__u64 nr,void * addr)259 _INLINE_ void ext2fs_fast_set_bit64(__u64 nr, void * addr)
260 {
261 	unsigned char	*ADDR = (unsigned char *) addr;
262 
263 	ADDR += nr >> 3;
264 	*ADDR |= (unsigned char) (1 << (nr & 0x07));
265 }
266 
ext2fs_fast_clear_bit64(__u64 nr,void * addr)267 _INLINE_ void ext2fs_fast_clear_bit64(__u64 nr, void * addr)
268 {
269 	unsigned char	*ADDR = (unsigned char *) addr;
270 
271 	ADDR += nr >> 3;
272 	*ADDR &= (unsigned char) ~(1 << (nr & 0x07));
273 }
274 
275 
276 #if ((defined __GNUC__) && !defined(_EXT2_USE_C_VERSIONS_) && \
277      (defined(__i386__) || defined(__i486__) || defined(__i586__)))
278 
279 #define _EXT2_HAVE_ASM_BITOPS_
280 #define _EXT2_HAVE_ASM_SWAB_
281 
282 /*
283  * These are done by inline assembly for speed reasons.....
284  *
285  * All bitoperations return 0 if the bit was cleared before the
286  * operation and != 0 if it was not.  Bit 0 is the LSB of addr; bit 32
287  * is the LSB of (addr+1).
288  */
289 
290 /*
291  * Some hacks to defeat gcc over-optimizations..
292  */
293 struct __dummy_h { unsigned long a[100]; };
294 #define EXT2FS_ADDR (*(struct __dummy_h *) addr)
295 #define EXT2FS_CONST_ADDR (*(const struct __dummy_h *) addr)
296 
ext2fs_set_bit(unsigned int nr,void * addr)297 _INLINE_ int ext2fs_set_bit(unsigned int nr, void * addr)
298 {
299 	int oldbit;
300 
301 	addr = (void *) (((unsigned char *) addr) + (nr >> 3));
302 	__asm__ __volatile__("btsl %2,%1\n\tsbbl %0,%0"
303 		:"=r" (oldbit),"+m" (EXT2FS_ADDR)
304 		:"r" (nr & 7));
305 	return oldbit;
306 }
307 
ext2fs_clear_bit(unsigned int nr,void * addr)308 _INLINE_ int ext2fs_clear_bit(unsigned int nr, void * addr)
309 {
310 	int oldbit;
311 
312 	addr = (void *) (((unsigned char *) addr) + (nr >> 3));
313 	__asm__ __volatile__("btrl %2,%1\n\tsbbl %0,%0"
314 		:"=r" (oldbit),"+m" (EXT2FS_ADDR)
315 		:"r" (nr & 7));
316 	return oldbit;
317 }
318 
ext2fs_test_bit(unsigned int nr,const void * addr)319 _INLINE_ int ext2fs_test_bit(unsigned int nr, const void * addr)
320 {
321 	int oldbit;
322 
323 	addr = (const void *) (((const unsigned char *) addr) + (nr >> 3));
324 	__asm__ __volatile__("btl %2,%1\n\tsbbl %0,%0"
325 		:"=r" (oldbit)
326 		:"m" (EXT2FS_CONST_ADDR),"r" (nr & 7));
327 	return oldbit;
328 }
329 
ext2fs_swab32(__u32 val)330 _INLINE_ __u32 ext2fs_swab32(__u32 val)
331 {
332 #ifdef EXT2FS_REQUIRE_486
333 	__asm__("bswap %0" : "=r" (val) : "0" (val));
334 #else
335 	__asm__("xchgb %b0,%h0\n\t"	/* swap lower bytes	*/
336 		"rorl $16,%0\n\t"	/* swap words		*/
337 		"xchgb %b0,%h0"		/* swap higher bytes	*/
338 		:"=q" (val)
339 		: "0" (val));
340 #endif
341 	return val;
342 }
343 
ext2fs_swab16(__u16 val)344 _INLINE_ __u16 ext2fs_swab16(__u16 val)
345 {
346 	__asm__("xchgb %b0,%h0"		/* swap bytes		*/ \
347 		: "=q" (val) \
348 		:  "0" (val)); \
349 		return val;
350 }
351 
352 #undef EXT2FS_ADDR
353 
354 #endif	/* i386 */
355 
356 
357 #if !defined(_EXT2_HAVE_ASM_SWAB_)
358 
ext2fs_swab16(__u16 val)359 _INLINE_ __u16 ext2fs_swab16(__u16 val)
360 {
361 	return (val >> 8) | (__u16) (val << 8);
362 }
363 
ext2fs_swab32(__u32 val)364 _INLINE_ __u32 ext2fs_swab32(__u32 val)
365 {
366 	return ((val>>24) | ((val>>8)&0xFF00) |
367 		((val<<8)&0xFF0000) | (val<<24));
368 }
369 
370 #endif /* !_EXT2_HAVE_ASM_SWAB */
371 
ext2fs_swab64(__u64 val)372 _INLINE_ __u64 ext2fs_swab64(__u64 val)
373 {
374 	return (ext2fs_swab32((__u32) (val >> 32)) |
375 		(((__u64)ext2fs_swab32(val & 0xFFFFFFFFUL)) << 32));
376 }
377 
ext2fs_mark_block_bitmap(ext2fs_block_bitmap bitmap,blk_t block)378 _INLINE_ int ext2fs_mark_block_bitmap(ext2fs_block_bitmap bitmap,
379 				       blk_t block)
380 {
381 	return ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) bitmap,
382 					  block);
383 }
384 
ext2fs_unmark_block_bitmap(ext2fs_block_bitmap bitmap,blk_t block)385 _INLINE_ int ext2fs_unmark_block_bitmap(ext2fs_block_bitmap bitmap,
386 					 blk_t block)
387 {
388 	return ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap,
389 					    block);
390 }
391 
ext2fs_test_block_bitmap(ext2fs_block_bitmap bitmap,blk_t block)392 _INLINE_ int ext2fs_test_block_bitmap(ext2fs_block_bitmap bitmap,
393 				       blk_t block)
394 {
395 	return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) bitmap,
396 					  block);
397 }
398 
ext2fs_mark_inode_bitmap(ext2fs_inode_bitmap bitmap,ext2_ino_t inode)399 _INLINE_ int ext2fs_mark_inode_bitmap(ext2fs_inode_bitmap bitmap,
400 				       ext2_ino_t inode)
401 {
402 	return ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) bitmap,
403 					  inode);
404 }
405 
ext2fs_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap,ext2_ino_t inode)406 _INLINE_ int ext2fs_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap,
407 					 ext2_ino_t inode)
408 {
409 	return ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap,
410 				     inode);
411 }
412 
ext2fs_test_inode_bitmap(ext2fs_inode_bitmap bitmap,ext2_ino_t inode)413 _INLINE_ int ext2fs_test_inode_bitmap(ext2fs_inode_bitmap bitmap,
414 				       ext2_ino_t inode)
415 {
416 	return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) bitmap,
417 					  inode);
418 }
419 
ext2fs_fast_mark_block_bitmap(ext2fs_block_bitmap bitmap,blk_t block)420 _INLINE_ void ext2fs_fast_mark_block_bitmap(ext2fs_block_bitmap bitmap,
421 					    blk_t block)
422 {
423 	ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) bitmap, block);
424 }
425 
ext2fs_fast_unmark_block_bitmap(ext2fs_block_bitmap bitmap,blk_t block)426 _INLINE_ void ext2fs_fast_unmark_block_bitmap(ext2fs_block_bitmap bitmap,
427 					      blk_t block)
428 {
429 	ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap, block);
430 }
431 
ext2fs_fast_test_block_bitmap(ext2fs_block_bitmap bitmap,blk_t block)432 _INLINE_ int ext2fs_fast_test_block_bitmap(ext2fs_block_bitmap bitmap,
433 					    blk_t block)
434 {
435 	return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) bitmap,
436 					  block);
437 }
438 
ext2fs_fast_mark_inode_bitmap(ext2fs_inode_bitmap bitmap,ext2_ino_t inode)439 _INLINE_ void ext2fs_fast_mark_inode_bitmap(ext2fs_inode_bitmap bitmap,
440 					    ext2_ino_t inode)
441 {
442 	ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) bitmap, inode);
443 }
444 
ext2fs_fast_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap,ext2_ino_t inode)445 _INLINE_ void ext2fs_fast_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap,
446 					      ext2_ino_t inode)
447 {
448 	ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap, inode);
449 }
450 
ext2fs_fast_test_inode_bitmap(ext2fs_inode_bitmap bitmap,ext2_ino_t inode)451 _INLINE_ int ext2fs_fast_test_inode_bitmap(ext2fs_inode_bitmap bitmap,
452 					   ext2_ino_t inode)
453 {
454 	return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) bitmap,
455 					  inode);
456 }
457 
ext2fs_get_block_bitmap_start(ext2fs_block_bitmap bitmap)458 _INLINE_ blk_t ext2fs_get_block_bitmap_start(ext2fs_block_bitmap bitmap)
459 {
460 	return ext2fs_get_generic_bitmap_start((ext2fs_generic_bitmap) bitmap);
461 }
462 
ext2fs_get_inode_bitmap_start(ext2fs_inode_bitmap bitmap)463 _INLINE_ ext2_ino_t ext2fs_get_inode_bitmap_start(ext2fs_inode_bitmap bitmap)
464 {
465 	return ext2fs_get_generic_bitmap_start((ext2fs_generic_bitmap) bitmap);
466 }
467 
ext2fs_get_block_bitmap_end(ext2fs_block_bitmap bitmap)468 _INLINE_ blk_t ext2fs_get_block_bitmap_end(ext2fs_block_bitmap bitmap)
469 {
470 	return ext2fs_get_generic_bitmap_end((ext2fs_generic_bitmap) bitmap);
471 }
472 
ext2fs_get_inode_bitmap_end(ext2fs_inode_bitmap bitmap)473 _INLINE_ ext2_ino_t ext2fs_get_inode_bitmap_end(ext2fs_inode_bitmap bitmap)
474 {
475 	return ext2fs_get_generic_bitmap_end((ext2fs_generic_bitmap) bitmap);
476 }
477 
ext2fs_fast_test_block_bitmap_range(ext2fs_block_bitmap bitmap,blk_t block,int num)478 _INLINE_ int ext2fs_fast_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
479 						 blk_t block, int num)
480 {
481 	return ext2fs_test_block_bitmap_range(bitmap, block, num);
482 }
483 
ext2fs_fast_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,blk_t block,int num)484 _INLINE_ void ext2fs_fast_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,
485 						  blk_t block, int num)
486 {
487 	ext2fs_mark_block_bitmap_range(bitmap, block, num);
488 }
489 
ext2fs_fast_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,blk_t block,int num)490 _INLINE_ void ext2fs_fast_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,
491 						    blk_t block, int num)
492 {
493 	ext2fs_unmark_block_bitmap_range(bitmap, block, num);
494 }
495 
496 /* 64-bit versions */
497 
ext2fs_mark_block_bitmap2(ext2fs_block_bitmap bitmap,blk64_t block)498 _INLINE_ int ext2fs_mark_block_bitmap2(ext2fs_block_bitmap bitmap,
499 				       blk64_t block)
500 {
501 	return ext2fs_mark_generic_bmap((ext2fs_generic_bitmap) bitmap,
502 					block);
503 }
504 
ext2fs_unmark_block_bitmap2(ext2fs_block_bitmap bitmap,blk64_t block)505 _INLINE_ int ext2fs_unmark_block_bitmap2(ext2fs_block_bitmap bitmap,
506 					 blk64_t block)
507 {
508 	return ext2fs_unmark_generic_bmap((ext2fs_generic_bitmap) bitmap, block);
509 }
510 
ext2fs_test_block_bitmap2(ext2fs_block_bitmap bitmap,blk64_t block)511 _INLINE_ int ext2fs_test_block_bitmap2(ext2fs_block_bitmap bitmap,
512 				       blk64_t block)
513 {
514 	return ext2fs_test_generic_bmap((ext2fs_generic_bitmap) bitmap,
515 					block);
516 }
517 
ext2fs_mark_inode_bitmap2(ext2fs_inode_bitmap bitmap,ext2_ino_t inode)518 _INLINE_ int ext2fs_mark_inode_bitmap2(ext2fs_inode_bitmap bitmap,
519 				       ext2_ino_t inode)
520 {
521 	return ext2fs_mark_generic_bmap((ext2fs_generic_bitmap) bitmap,
522 					inode);
523 }
524 
ext2fs_unmark_inode_bitmap2(ext2fs_inode_bitmap bitmap,ext2_ino_t inode)525 _INLINE_ int ext2fs_unmark_inode_bitmap2(ext2fs_inode_bitmap bitmap,
526 					 ext2_ino_t inode)
527 {
528 	return ext2fs_unmark_generic_bmap((ext2fs_generic_bitmap) bitmap,
529 					  inode);
530 }
531 
ext2fs_test_inode_bitmap2(ext2fs_inode_bitmap bitmap,ext2_ino_t inode)532 _INLINE_ int ext2fs_test_inode_bitmap2(ext2fs_inode_bitmap bitmap,
533 				       ext2_ino_t inode)
534 {
535 	return ext2fs_test_generic_bmap((ext2fs_generic_bitmap) bitmap,
536 					inode);
537 }
538 
ext2fs_fast_mark_block_bitmap2(ext2fs_block_bitmap bitmap,blk64_t block)539 _INLINE_ void ext2fs_fast_mark_block_bitmap2(ext2fs_block_bitmap bitmap,
540 					     blk64_t block)
541 {
542 	ext2fs_mark_generic_bmap((ext2fs_generic_bitmap) bitmap, block);
543 }
544 
ext2fs_fast_unmark_block_bitmap2(ext2fs_block_bitmap bitmap,blk64_t block)545 _INLINE_ void ext2fs_fast_unmark_block_bitmap2(ext2fs_block_bitmap bitmap,
546 					       blk64_t block)
547 {
548 	ext2fs_unmark_generic_bmap((ext2fs_generic_bitmap) bitmap, block);
549 }
550 
ext2fs_fast_test_block_bitmap2(ext2fs_block_bitmap bitmap,blk64_t block)551 _INLINE_ int ext2fs_fast_test_block_bitmap2(ext2fs_block_bitmap bitmap,
552 					    blk64_t block)
553 {
554 	return ext2fs_test_generic_bmap((ext2fs_generic_bitmap) bitmap,
555 					block);
556 }
557 
ext2fs_fast_mark_inode_bitmap2(ext2fs_inode_bitmap bitmap,ext2_ino_t inode)558 _INLINE_ void ext2fs_fast_mark_inode_bitmap2(ext2fs_inode_bitmap bitmap,
559 					     ext2_ino_t inode)
560 {
561 	ext2fs_mark_generic_bmap((ext2fs_generic_bitmap) bitmap, inode);
562 }
563 
ext2fs_fast_unmark_inode_bitmap2(ext2fs_inode_bitmap bitmap,ext2_ino_t inode)564 _INLINE_ void ext2fs_fast_unmark_inode_bitmap2(ext2fs_inode_bitmap bitmap,
565 					       ext2_ino_t inode)
566 {
567 	ext2fs_unmark_generic_bmap((ext2fs_generic_bitmap) bitmap, inode);
568 }
569 
ext2fs_fast_test_inode_bitmap2(ext2fs_inode_bitmap bitmap,ext2_ino_t inode)570 _INLINE_ int ext2fs_fast_test_inode_bitmap2(ext2fs_inode_bitmap bitmap,
571 					    ext2_ino_t inode)
572 {
573 	return ext2fs_test_generic_bmap((ext2fs_generic_bitmap) bitmap,
574 					inode);
575 }
576 
ext2fs_find_first_zero_block_bitmap2(ext2fs_block_bitmap bitmap,blk64_t start,blk64_t end,blk64_t * out)577 _INLINE_ errcode_t ext2fs_find_first_zero_block_bitmap2(ext2fs_block_bitmap bitmap,
578 							blk64_t start,
579 							blk64_t end,
580 							blk64_t *out)
581 {
582 	__u64 o;
583 	errcode_t rv;
584 
585 	rv = ext2fs_find_first_zero_generic_bmap((ext2fs_generic_bitmap) bitmap,
586 						 start, end, &o);
587 	if (!rv)
588 		*out = o;
589 	return rv;
590 }
591 
ext2fs_find_first_zero_inode_bitmap2(ext2fs_inode_bitmap bitmap,ext2_ino_t start,ext2_ino_t end,ext2_ino_t * out)592 _INLINE_ errcode_t ext2fs_find_first_zero_inode_bitmap2(ext2fs_inode_bitmap bitmap,
593 							ext2_ino_t start,
594 							ext2_ino_t end,
595 							ext2_ino_t *out)
596 {
597 	__u64 o;
598 	errcode_t rv;
599 
600 	rv = ext2fs_find_first_zero_generic_bmap((ext2fs_generic_bitmap) bitmap,
601 						 start, end, &o);
602 	if (!rv)
603 		*out = (ext2_ino_t) o;
604 	return rv;
605 }
606 
ext2fs_get_block_bitmap_start2(ext2fs_block_bitmap bitmap)607 _INLINE_ blk64_t ext2fs_get_block_bitmap_start2(ext2fs_block_bitmap bitmap)
608 {
609 	return ext2fs_get_generic_bmap_start((ext2fs_generic_bitmap) bitmap);
610 }
611 
ext2fs_get_inode_bitmap_start2(ext2fs_inode_bitmap bitmap)612 _INLINE_ ext2_ino_t ext2fs_get_inode_bitmap_start2(ext2fs_inode_bitmap bitmap)
613 {
614 	return (ext2_ino_t) ext2fs_get_generic_bmap_start((ext2fs_generic_bitmap) bitmap);
615 }
616 
ext2fs_get_block_bitmap_end2(ext2fs_block_bitmap bitmap)617 _INLINE_ blk64_t ext2fs_get_block_bitmap_end2(ext2fs_block_bitmap bitmap)
618 {
619 	return ext2fs_get_generic_bmap_end((ext2fs_generic_bitmap) bitmap);
620 }
621 
ext2fs_get_inode_bitmap_end2(ext2fs_inode_bitmap bitmap)622 _INLINE_ ext2_ino_t ext2fs_get_inode_bitmap_end2(ext2fs_inode_bitmap bitmap)
623 {
624 	return (ext2_ino_t) ext2fs_get_generic_bmap_end((ext2fs_generic_bitmap) bitmap);
625 }
626 
ext2fs_fast_test_block_bitmap_range2(ext2fs_block_bitmap bitmap,blk64_t block,unsigned int num)627 _INLINE_ int ext2fs_fast_test_block_bitmap_range2(ext2fs_block_bitmap bitmap,
628 						  blk64_t block,
629 						  unsigned int num)
630 {
631 	return ext2fs_test_block_bitmap_range2(bitmap, block, num);
632 }
633 
ext2fs_fast_mark_block_bitmap_range2(ext2fs_block_bitmap bitmap,blk64_t block,unsigned int num)634 _INLINE_ void ext2fs_fast_mark_block_bitmap_range2(ext2fs_block_bitmap bitmap,
635 						   blk64_t block,
636 						   unsigned int num)
637 {
638 	ext2fs_mark_block_bitmap_range2(bitmap, block, num);
639 }
640 
ext2fs_fast_unmark_block_bitmap_range2(ext2fs_block_bitmap bitmap,blk64_t block,unsigned int num)641 _INLINE_ void ext2fs_fast_unmark_block_bitmap_range2(ext2fs_block_bitmap bitmap,
642 						     blk64_t block,
643 						     unsigned int num)
644 {
645 	ext2fs_unmark_block_bitmap_range2(bitmap, block, num);
646 }
647 
648 #undef _INLINE_
649 #endif
650 
651 #ifndef _EXT2_HAVE_ASM_BITOPS_
652 extern int ext2fs_set_bit(unsigned int nr,void * addr);
653 extern int ext2fs_clear_bit(unsigned int nr, void * addr);
654 extern int ext2fs_test_bit(unsigned int nr, const void * addr);
655 #endif
656 
657 extern int ext2fs_set_bit64(__u64 nr,void * addr);
658 extern int ext2fs_clear_bit64(__u64 nr, void * addr);
659 extern int ext2fs_test_bit64(__u64 nr, const void * addr);
660 extern unsigned int ext2fs_bitcount(const void *addr, unsigned int nbytes);
661