bitops.h revision 5953b9de9ce59661640f851b217421d734bb0302
13839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o/*
250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o * bitops.h --- Bitmap frobbing code.  The byte swapping routines are
350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o * 	also included here.
43839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o *
521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o *
721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o * %Begin-Header%
821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o * This file may be redistributed under the terms of the GNU Public
921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o * License.
1021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o * %End-Header%
113839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o *
1221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o * i386 bitops operations taken from <asm/bitops.h>, Copyright 1992,
1321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o * Linus Torvalds.
143839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o */
153839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
163839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
1774becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'oextern int ext2fs_set_bit(int nr,void * addr);
1874becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'oextern int ext2fs_clear_bit(int nr, void * addr);
1974becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'oextern int ext2fs_test_bit(int nr, const void * addr);
2050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'oextern __u16 ext2fs_swab16(__u16 val);
2150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'oextern __u32 ext2fs_swab32(__u32 val);
223839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
233839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o/*
243839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * EXT2FS bitmap manipulation routines.
253839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o */
263839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
273839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o/* Support for sending warning messages from the inline subroutines */
283839e65723771b85975f4263102dd3ceec4523cTheodore Ts'oextern const char *ext2fs_block_string;
293839e65723771b85975f4263102dd3ceec4523cTheodore Ts'oextern const char *ext2fs_inode_string;
303839e65723771b85975f4263102dd3ceec4523cTheodore Ts'oextern const char *ext2fs_mark_string;
313839e65723771b85975f4263102dd3ceec4523cTheodore Ts'oextern const char *ext2fs_unmark_string;
323839e65723771b85975f4263102dd3ceec4523cTheodore Ts'oextern const char *ext2fs_test_string;
33f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'oextern void ext2fs_warn_bitmap(errcode_t errcode, unsigned long arg,
34f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o			       const char *description);
351e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'oextern void ext2fs_warn_bitmap2(ext2fs_generic_bitmap bitmap,
361e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o				int code, unsigned long arg);
37f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
38f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'oextern void ext2fs_mark_block_bitmap(ext2fs_block_bitmap bitmap, blk_t block);
39f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'oextern void ext2fs_unmark_block_bitmap(ext2fs_block_bitmap bitmap,
40f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o				       blk_t block);
41f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'oextern int ext2fs_test_block_bitmap(ext2fs_block_bitmap bitmap, blk_t block);
42f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
43f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'oextern void ext2fs_mark_inode_bitmap(ext2fs_inode_bitmap bitmap, ino_t inode);
44f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'oextern void ext2fs_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap,
45f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o				       ino_t inode);
46f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'oextern int ext2fs_test_inode_bitmap(ext2fs_inode_bitmap bitmap, ino_t inode);
473839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
4850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'oextern void ext2fs_fast_mark_block_bitmap(ext2fs_block_bitmap bitmap,
4950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o					  blk_t block);
5050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'oextern void ext2fs_fast_unmark_block_bitmap(ext2fs_block_bitmap bitmap,
5150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o					    blk_t block);
5250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'oextern int ext2fs_fast_test_block_bitmap(ext2fs_block_bitmap bitmap,
5350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o					 blk_t block);
5450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
5550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'oextern void ext2fs_fast_mark_inode_bitmap(ext2fs_inode_bitmap bitmap,
5650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o					  ino_t inode);
5750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'oextern void ext2fs_fast_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap,
5850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o					    ino_t inode);
5950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'oextern int ext2fs_fast_test_inode_bitmap(ext2fs_inode_bitmap bitmap,
6050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o					 ino_t inode);
6150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'oextern blk_t ext2fs_get_block_bitmap_start(ext2fs_block_bitmap bitmap);
6221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'oextern ino_t ext2fs_get_inode_bitmap_start(ext2fs_inode_bitmap bitmap);
6350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'oextern blk_t ext2fs_get_block_bitmap_end(ext2fs_block_bitmap bitmap);
6421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'oextern ino_t ext2fs_get_inode_bitmap_end(ext2fs_inode_bitmap bitmap);
6521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
6621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'oextern void ext2fs_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,
6721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o					   blk_t block, int num);
6821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'oextern void ext2fs_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,
6921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o					     blk_t block, int num);
7021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'oextern int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
7121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o					  blk_t block, int num);
7221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'oextern void ext2fs_fast_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,
7321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o						blk_t block, int num);
7421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'oextern void ext2fs_fast_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,
7521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o						  blk_t block, int num);
7621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'oextern int ext2fs_fast_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
7721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o					       blk_t block, int num);
78fff876b7c7716d5eef713101e47bff15edb9d9a9Theodore Ts'oextern void ext2fs_set_bitmap_padding(ext2fs_generic_bitmap map);
7950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
803839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o/*
813839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * The inline routines themselves...
823839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o *
833839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * If NO_INLINE_FUNCS is defined, then we won't try to do inline
8450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o * functions at all; they will be included as normal functions in
8550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o * inline.c
863839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o */
8750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#ifdef NO_INLINE_FUNCS
885953b9de9ce59661640f851b217421d734bb0302Theodore Ts'o#if (defined(__GNUC__) && (defined(__i386__) || defined(__i486__) || \
895953b9de9ce59661640f851b217421d734bb0302Theodore Ts'o			   defined(__i586__) || defined(__mc68000__) || \
905953b9de9ce59661640f851b217421d734bb0302Theodore Ts'o			   defined(__sparc__)))
9150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	/* This prevents bitops.c from trying to include the C */
9250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	/* function version of these functions */
9350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#define _EXT2_HAVE_ASM_BITOPS_
9450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#endif
9550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#endif /* NO_INLINE_FUNCS */
9650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
973839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
983839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#ifdef INCLUDE_INLINE_FUNCS
993839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#define _INLINE_ extern
1003839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#else
1013839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#define _INLINE_ extern __inline__
1023839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#endif
1033839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
1045953b9de9ce59661640f851b217421d734bb0302Theodore Ts'o#if ((defined __GNUC__) && (defined(__i386__) || defined(__i486__) || \
1055953b9de9ce59661640f851b217421d734bb0302Theodore Ts'o			    defined(__i586__)))
106f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
107f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o#define _EXT2_HAVE_ASM_BITOPS_
108f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
1093839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o/*
1103839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * These are done by inline assembly for speed reasons.....
1113839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o *
1123839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * All bitoperations return 0 if the bit was cleared before the
1133839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * operation and != 0 if it was not.  Bit 0 is the LSB of addr; bit 32
1143839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * is the LSB of (addr+1).
1153839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o */
1163839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
1173839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o/*
1183839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * Some hacks to defeat gcc over-optimizations..
1193839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o */
1203839e65723771b85975f4263102dd3ceec4523cTheodore Ts'ostruct __dummy_h { unsigned long a[100]; };
12174becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o#define EXT2FS_ADDR (*(struct __dummy_h *) addr)
12274becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o#define EXT2FS_CONST_ADDR (*(const struct __dummy_h *) addr)
1233839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
12474becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o_INLINE_ int ext2fs_set_bit(int nr, void * addr)
1253839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o{
1263839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	int oldbit;
1273839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
1283839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	__asm__ __volatile__("btsl %2,%1\n\tsbbl %0,%0"
12974becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o		:"=r" (oldbit),"=m" (EXT2FS_ADDR)
1303839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o		:"r" (nr));
1313839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	return oldbit;
1323839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o}
1333839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
13474becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o_INLINE_ int ext2fs_clear_bit(int nr, void * addr)
1353839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o{
1363839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	int oldbit;
1373839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
1383839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	__asm__ __volatile__("btrl %2,%1\n\tsbbl %0,%0"
13974becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o		:"=r" (oldbit),"=m" (EXT2FS_ADDR)
1403839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o		:"r" (nr));
1413839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	return oldbit;
1423839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o}
1433839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
14474becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o_INLINE_ int ext2fs_test_bit(int nr, const void * addr)
1453839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o{
1463839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	int oldbit;
1473839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
1483839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	__asm__ __volatile__("btl %2,%1\n\tsbbl %0,%0"
1493839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o		:"=r" (oldbit)
15074becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o		:"m" (EXT2FS_CONST_ADDR),"r" (nr));
1513839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	return oldbit;
1523839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o}
1533839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
15474becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o#undef EXT2FS_ADDR
1553839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
1563839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#endif	/* i386 */
1573839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
158f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o#ifdef __mc68000__
159f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
160f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o#define _EXT2_HAVE_ASM_BITOPS_
161f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
16274becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o_INLINE_ int ext2fs_set_bit(int nr,void * addr)
163f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o{
164f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	char retval;
165f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
166f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	__asm__ __volatile__ ("bfset %2@{%1:#1}; sne %0"
1677f88b04341d88c5df0360d930832c38040303b61Theodore Ts'o	     : "=d" (retval) : "d" (nr^7), "a" (addr));
168f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
169f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	return retval;
170f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o}
171f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
17274becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o_INLINE_ int ext2fs_clear_bit(int nr, void * addr)
173f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o{
174f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	char retval;
175f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
176f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	__asm__ __volatile__ ("bfclr %2@{%1:#1}; sne %0"
1777f88b04341d88c5df0360d930832c38040303b61Theodore Ts'o	     : "=d" (retval) : "d" (nr^7), "a" (addr));
178f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
179f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	return retval;
180f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o}
181f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
18274becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o_INLINE_ int ext2fs_test_bit(int nr, const void * addr)
183f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o{
184f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	char retval;
185f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
186f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	__asm__ __volatile__ ("bftst %2@{%1:#1}; sne %0"
1877f88b04341d88c5df0360d930832c38040303b61Theodore Ts'o	     : "=d" (retval) : "d" (nr^7), "a" (addr));
188f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
189f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	return retval;
190f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o}
191f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
192f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o#endif /* __mc68000__ */
193f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
19450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#ifdef __sparc__
19550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
19650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#define _EXT2_HAVE_ASM_BITOPS_
19750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
1981e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#ifndef EXT2_OLD_BITOPS
1991e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2001e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o/*
2011e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o * Do the bitops so that we are compatible with the standard i386
2021e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o * convention.
2031e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o */
2041e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2051e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o_INLINE_ int ext2fs_set_bit(int nr,void * addr)
2061e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o{
2071e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#if 1
2081e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	int		mask;
2091e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	unsigned char	*ADDR = (unsigned char *) addr;
2101e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2111e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	ADDR += nr >> 3;
2121e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	mask = 1 << (nr & 0x07);
2131e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	__asm__ __volatile__("ldub	[%0], %%g6\n\t"
2141e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o			     "or	%%g6, %2, %%g5\n\t"
2151e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o			     "stb	%%g5, [%0]\n\t"
2161e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o			     "and	%%g6, %2, %0\n"
2171e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	: "=&r" (ADDR)
2181e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	: "0" (ADDR), "r" (mask)
2191e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	: "g5", "g6");
2201e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	return (int) ADDR;
2211e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#else
2221e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	int		mask, retval;
2231e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	unsigned char	*ADDR = (unsigned char *) addr;
2241e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2251e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	ADDR += nr >> 3;
2261e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	mask = 1 << (nr & 0x07);
2271e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	retval = (mask & *ADDR) != 0;
2281e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	*ADDR |= mask;
2291e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	return retval;
2301e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#endif
2311e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o}
2321e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2331e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o_INLINE_ int ext2fs_clear_bit(int nr, void * addr)
2341e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o{
2351e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#if 1
2361e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	int		mask;
2371e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	unsigned char	*ADDR = (unsigned char *) addr;
2381e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2391e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	ADDR += nr >> 3;
2401e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	mask = 1 << (nr & 0x07);
2411e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	__asm__ __volatile__("ldub	[%0], %%g6\n\t"
2421e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o			     "andn	%%g6, %2, %%g5\n\t"
2431e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o			     "stb	%%g5, [%0]\n\t"
2441e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o			     "and	%%g6, %2, %0\n"
2451e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	: "=&r" (ADDR)
2461e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	: "0" (ADDR), "r" (mask)
2471e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	: "g5", "g6");
2481e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	return (int) ADDR;
2491e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2501e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#else
2511e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	int		mask, retval;
2521e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	unsigned char	*ADDR = (unsigned char *) addr;
2531e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2541e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	ADDR += nr >> 3;
2551e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	mask = 1 << (nr & 0x07);
2561e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	retval = (mask & *ADDR) != 0;
2571e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	*ADDR &= ~mask;
2581e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	return retval;
2591e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#endif
2601e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o}
2611e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2621e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o_INLINE_ int ext2fs_test_bit(int nr, const void * addr)
2631e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o{
2641e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	int			mask;
2651e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	const unsigned char	*ADDR = (const unsigned char *) addr;
2661e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2671e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	ADDR += nr >> 3;
2681e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	mask = 1 << (nr & 0x07);
2691e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	return ((mask & *ADDR) != 0);
2701e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o}
2711e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2721e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#else
2731e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2741e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o/* Do things the old, unplesant way. */
2751e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
27674becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o_INLINE_ int ext2fs_set_bit(int nr, void *addr)
27750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
27850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	int		mask, retval;
27950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	unsigned long	*ADDR = (unsigned long *) addr;
28050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
28150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	ADDR += nr >> 5;
28250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	mask = 1 << (nr & 31);
28350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	retval = ((mask & *ADDR) != 0);
28450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	*ADDR |= mask;
28550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	return retval;
28650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
28750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
28874becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o_INLINE_ int ext2fs_clear_bit(int nr, void *addr)
28950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
29050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	int		mask, retval;
29150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	unsigned long	*ADDR = (unsigned long *) addr;
29250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
29350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	ADDR += nr >> 5;
29450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	mask = 1 << (nr & 31);
29550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	retval = ((mask & *ADDR) != 0);
29650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	*ADDR &= ~mask;
29750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	return retval;
29850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
29950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
30074becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o_INLINE_ int ext2fs_test_bit(int nr, const void *addr)
30150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
30250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	int			mask;
30350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	const unsigned long	*ADDR = (const unsigned long *) addr;
30450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
30550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	ADDR += nr >> 5;
30650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	mask = 1 << (nr & 31);
30750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	return ((mask & *ADDR) != 0);
30850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
3091e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#endif
31050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
31150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#endif /* __sparc__ */
31250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
31350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#ifndef _EXT2_HAVE_ASM_SWAB
31450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
31550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o_INLINE_ __u16 ext2fs_swab16(__u16 val)
31650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
31750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	return (val >> 8) | (val << 8);
31850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
31950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
32050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o_INLINE_ __u32 ext2fs_swab32(__u32 val)
32150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
32250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	return ((val>>24) | ((val>>8)&0xFF00) |
32350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		((val<<8)&0xFF0000) | (val<<24));
32450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
32550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
32650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#endif /* !_EXT2_HAVE_ASM_SWAB */
32750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
3281e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o_INLINE_ void ext2fs_mark_generic_bitmap(ext2fs_generic_bitmap bitmap,
32921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o					 __u32 bitno);
33021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o_INLINE_ void ext2fs_unmark_generic_bitmap(ext2fs_generic_bitmap bitmap,
33121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o					   blk_t bitno);
33221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o_INLINE_ int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap,
33321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o					blk_t bitno);
33421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
33521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o_INLINE_ void ext2fs_mark_generic_bitmap(ext2fs_generic_bitmap bitmap,
33621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o					 __u32 bitno)
3373839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o{
3381e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	if ((bitno < bitmap->start) || (bitno > bitmap->end)) {
3391e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o		ext2fs_warn_bitmap2(bitmap, EXT2FS_MARK_ERROR, bitno);
3403839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o		return;
3413839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	}
3421e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	ext2fs_set_bit(bitno - bitmap->start, bitmap->bitmap);
3433839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o}
3443839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
3451e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o_INLINE_ void ext2fs_unmark_generic_bitmap(ext2fs_generic_bitmap bitmap,
34621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o					   blk_t bitno)
3473839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o{
3481e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	if ((bitno < bitmap->start) || (bitno > bitmap->end)) {
3491e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o		ext2fs_warn_bitmap2(bitmap, EXT2FS_UNMARK_ERROR, bitno);
3503839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o		return;
3513839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	}
3521e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	ext2fs_clear_bit(bitno - bitmap->start, bitmap->bitmap);
3533839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o}
3543839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
3551e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o_INLINE_ int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap,
35621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o					blk_t bitno)
3573839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o{
3581e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	if ((bitno < bitmap->start) || (bitno > bitmap->end)) {
359521e36857227b21e7ab47b0a97f788d2af9f9717Theodore Ts'o		ext2fs_warn_bitmap2(bitmap, EXT2FS_TEST_ERROR, bitno);
3603839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o		return 0;
3613839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	}
3621e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	return ext2fs_test_bit(bitno - bitmap->start, bitmap->bitmap);
3631e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o}
3641e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
3651e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o_INLINE_ void ext2fs_mark_block_bitmap(ext2fs_block_bitmap bitmap,
3661e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o				       blk_t block)
3671e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o{
3681e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) bitmap, block);
3691e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o}
3701e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
3711e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o_INLINE_ void ext2fs_unmark_block_bitmap(ext2fs_block_bitmap bitmap,
3721e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o					 blk_t block)
3731e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o{
3741e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap, block);
3751e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o}
3761e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
3771e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o_INLINE_ int ext2fs_test_block_bitmap(ext2fs_block_bitmap bitmap,
3781e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o				       blk_t block)
3791e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o{
3801e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) bitmap,
3811e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o					  block);
3823839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o}
3833839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
384f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o_INLINE_ void ext2fs_mark_inode_bitmap(ext2fs_inode_bitmap bitmap,
385f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o				       ino_t inode)
3863839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o{
3871e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) bitmap, inode);
3883839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o}
3893839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
390f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o_INLINE_ void ext2fs_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap,
391f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o					 ino_t inode)
3923839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o{
3931e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap, inode);
3943839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o}
3953839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
396f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o_INLINE_ int ext2fs_test_inode_bitmap(ext2fs_inode_bitmap bitmap,
397f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o				       ino_t inode)
3983839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o{
3991e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) bitmap,
4001e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o					  inode);
4013839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o}
4023839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
40350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o_INLINE_ void ext2fs_fast_mark_block_bitmap(ext2fs_block_bitmap bitmap,
40450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o					    blk_t block)
40550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
40650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#ifdef EXT2FS_DEBUG_FAST_OPS
40750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	if ((block < bitmap->start) || (block > bitmap->end)) {
40850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block,
40950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o				   bitmap->description);
41050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		return;
41150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	}
41250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#endif
41374becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o	ext2fs_set_bit(block - bitmap->start, bitmap->bitmap);
41450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
41550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
41650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o_INLINE_ void ext2fs_fast_unmark_block_bitmap(ext2fs_block_bitmap bitmap,
41750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o					      blk_t block)
41850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
41950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#ifdef EXT2FS_DEBUG_FAST_OPS
42050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	if ((block < bitmap->start) || (block > bitmap->end)) {
42150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK,
42250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o				   block, bitmap->description);
42350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		return;
42450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	}
42550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#endif
42674becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o	ext2fs_clear_bit(block - bitmap->start, bitmap->bitmap);
42750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
42850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
42950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o_INLINE_ int ext2fs_fast_test_block_bitmap(ext2fs_block_bitmap bitmap,
43050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o					    blk_t block)
43150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
43250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#ifdef EXT2FS_DEBUG_FAST_OPS
43350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	if ((block < bitmap->start) || (block > bitmap->end)) {
43450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST,
43550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o				   block, bitmap->description);
43650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		return 0;
43750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	}
43850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#endif
43974becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o	return ext2fs_test_bit(block - bitmap->start, bitmap->bitmap);
44050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
44150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
44250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o_INLINE_ void ext2fs_fast_mark_inode_bitmap(ext2fs_inode_bitmap bitmap,
44350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o					    ino_t inode)
44450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
44550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#ifdef EXT2FS_DEBUG_FAST_OPS
44650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	if ((inode < bitmap->start) || (inode > bitmap->end)) {
44750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_INODE_MARK,
44850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o				   inode, bitmap->description);
44950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		return;
45050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	}
45150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#endif
45274becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o	ext2fs_set_bit(inode - bitmap->start, bitmap->bitmap);
45350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
45450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
45550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o_INLINE_ void ext2fs_fast_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap,
45650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o					      ino_t inode)
45750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
45850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#ifdef EXT2FS_DEBUG_FAST_OPS
45950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	if ((inode < bitmap->start) || (inode > bitmap->end)) {
46050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_INODE_UNMARK,
46150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o				   inode, bitmap->description);
46250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		return;
46350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	}
46450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#endif
46574becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o	ext2fs_clear_bit(inode - bitmap->start, bitmap->bitmap);
46650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
46750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
46850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o_INLINE_ int ext2fs_fast_test_inode_bitmap(ext2fs_inode_bitmap bitmap,
46950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o					   ino_t inode)
47050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
47150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#ifdef EXT2FS_DEBUG_FAST_OPS
47250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	if ((inode < bitmap->start) || (inode > bitmap->end)) {
47350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_INODE_TEST,
47450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o				   inode, bitmap->description);
47550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		return 0;
47650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	}
47750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#endif
47874becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o	return ext2fs_test_bit(inode - bitmap->start, bitmap->bitmap);
47950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
48050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
48150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o_INLINE_ blk_t ext2fs_get_block_bitmap_start(ext2fs_block_bitmap bitmap)
48250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
48350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	return bitmap->start;
48450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
48550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
48621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o_INLINE_ ino_t ext2fs_get_inode_bitmap_start(ext2fs_inode_bitmap bitmap)
48750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
48850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	return bitmap->start;
48950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
49050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
49150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o_INLINE_ blk_t ext2fs_get_block_bitmap_end(ext2fs_block_bitmap bitmap)
49250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
49350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	return bitmap->end;
49450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
49550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
49621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o_INLINE_ ino_t ext2fs_get_inode_bitmap_end(ext2fs_inode_bitmap bitmap)
49750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
49850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	return bitmap->end;
49950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
50050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
50121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o_INLINE_ int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
50221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o					    blk_t block, int num)
50321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o{
50421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	int	i;
50521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
50621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
50721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST,
50821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o				   block, bitmap->description);
50921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		return 0;
51021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	}
51121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	for (i=0; i < num; i++) {
51221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		if (ext2fs_fast_test_block_bitmap(bitmap, block+i))
51321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o			return 0;
51421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	}
51521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	return 1;
51621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o}
51721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
51821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o_INLINE_ int ext2fs_fast_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
51921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o						 blk_t block, int num)
52021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o{
52121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	int	i;
52221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
52321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o#ifdef EXT2FS_DEBUG_FAST_OPS
52421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
52521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST,
52621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o				   block, bitmap->description);
52721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		return 0;
52821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	}
52921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o#endif
53021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	for (i=0; i < num; i++) {
53121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		if (ext2fs_fast_test_block_bitmap(bitmap, block+i))
53221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o			return 0;
53321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	}
53421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	return 1;
53521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o}
53621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
53721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o_INLINE_ void ext2fs_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,
53821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o					     blk_t block, int num)
53921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o{
54021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	int	i;
54121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
54221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
54321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block,
54421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o				   bitmap->description);
54521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		return;
54621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	}
54721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	for (i=0; i < num; i++)
54821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		ext2fs_set_bit(block + i - bitmap->start, bitmap->bitmap);
54921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o}
55021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
55121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o_INLINE_ void ext2fs_fast_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,
55221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o						  blk_t block, int num)
55321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o{
55421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	int	i;
55521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
55621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o#ifdef EXT2FS_DEBUG_FAST_OPS
55721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
55821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block,
55921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o				   bitmap->description);
56021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		return;
56121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	}
56221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o#endif
56321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	for (i=0; i < num; i++)
56421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		ext2fs_set_bit(block + i - bitmap->start, bitmap->bitmap);
56521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o}
56621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
56721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o_INLINE_ void ext2fs_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,
56821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o					       blk_t block, int num)
56921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o{
57021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	int	i;
57121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
57221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
57321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block,
57421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o				   bitmap->description);
57521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		return;
57621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	}
57721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	for (i=0; i < num; i++)
57821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		ext2fs_clear_bit(block + i - bitmap->start, bitmap->bitmap);
57921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o}
58021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
58121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o_INLINE_ void ext2fs_fast_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,
58221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o						    blk_t block, int num)
58321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o{
58421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	int	i;
58521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
58621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o#ifdef EXT2FS_DEBUG_FAST_OPS
58721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
58821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block,
58921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o				   bitmap->description);
59021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		return;
59121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	}
59221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o#endif
59321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	for (i=0; i < num; i++)
59421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		ext2fs_clear_bit(block + i - bitmap->start, bitmap->bitmap);
59521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o}
59621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
5973839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#undef _INLINE_
5983839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#endif
59950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
600