bitops.h revision 21c84b71e205b5ab13f14343da5645dcc985856d
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);
7850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
793839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o/*
803839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * The inline routines themselves...
813839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o *
823839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * If NO_INLINE_FUNCS is defined, then we won't try to do inline
8350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o * functions at all; they will be included as normal functions in
8450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o * inline.c
853839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o */
8650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#ifdef NO_INLINE_FUNCS
8750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#if (defined(__i386__) || defined(__i486__) || defined(__i586__) || \
8850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o     defined(__mc68000__) || defined(__sparc__))
8950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	/* This prevents bitops.c from trying to include the C */
9050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	/* function version of these functions */
9150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#define _EXT2_HAVE_ASM_BITOPS_
9250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#endif
9350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#endif /* NO_INLINE_FUNCS */
9450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
953839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
963839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#ifdef INCLUDE_INLINE_FUNCS
973839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#define _INLINE_ extern
983839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#else
993839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#define _INLINE_ extern __inline__
1003839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#endif
1013839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
1023839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#if (defined(__i386__) || defined(__i486__) || defined(__i586__))
103f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
104f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o#define _EXT2_HAVE_ASM_BITOPS_
105f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
1063839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o/*
1073839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * These are done by inline assembly for speed reasons.....
1083839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o *
1093839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * All bitoperations return 0 if the bit was cleared before the
1103839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * operation and != 0 if it was not.  Bit 0 is the LSB of addr; bit 32
1113839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * is the LSB of (addr+1).
1123839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o */
1133839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
1143839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o/*
1153839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * Some hacks to defeat gcc over-optimizations..
1163839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o */
1173839e65723771b85975f4263102dd3ceec4523cTheodore Ts'ostruct __dummy_h { unsigned long a[100]; };
11874becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o#define EXT2FS_ADDR (*(struct __dummy_h *) addr)
11974becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o#define EXT2FS_CONST_ADDR (*(const struct __dummy_h *) addr)
1203839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
12174becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o_INLINE_ int ext2fs_set_bit(int nr, void * addr)
1223839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o{
1233839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	int oldbit;
1243839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
1253839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	__asm__ __volatile__("btsl %2,%1\n\tsbbl %0,%0"
12674becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o		:"=r" (oldbit),"=m" (EXT2FS_ADDR)
1273839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o		:"r" (nr));
1283839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	return oldbit;
1293839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o}
1303839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
13174becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o_INLINE_ int ext2fs_clear_bit(int nr, void * addr)
1323839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o{
1333839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	int oldbit;
1343839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
1353839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	__asm__ __volatile__("btrl %2,%1\n\tsbbl %0,%0"
13674becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o		:"=r" (oldbit),"=m" (EXT2FS_ADDR)
1373839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o		:"r" (nr));
1383839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	return oldbit;
1393839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o}
1403839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
14174becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o_INLINE_ int ext2fs_test_bit(int nr, const void * addr)
1423839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o{
1433839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	int oldbit;
1443839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
1453839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	__asm__ __volatile__("btl %2,%1\n\tsbbl %0,%0"
1463839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o		:"=r" (oldbit)
14774becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o		:"m" (EXT2FS_CONST_ADDR),"r" (nr));
1483839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	return oldbit;
1493839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o}
1503839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
15174becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o#undef EXT2FS_ADDR
1523839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
1533839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#endif	/* i386 */
1543839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
155f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o#ifdef __mc68000__
156f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
157f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o#define _EXT2_HAVE_ASM_BITOPS_
158f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
15974becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o_INLINE_ int ext2fs_set_bit(int nr,void * addr)
160f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o{
161f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	char retval;
162f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
163f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	__asm__ __volatile__ ("bfset %2@{%1:#1}; sne %0"
1647f88b04341d88c5df0360d930832c38040303b61Theodore Ts'o	     : "=d" (retval) : "d" (nr^7), "a" (addr));
165f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
166f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	return retval;
167f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o}
168f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
16974becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o_INLINE_ int ext2fs_clear_bit(int nr, void * addr)
170f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o{
171f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	char retval;
172f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
173f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	__asm__ __volatile__ ("bfclr %2@{%1:#1}; sne %0"
1747f88b04341d88c5df0360d930832c38040303b61Theodore Ts'o	     : "=d" (retval) : "d" (nr^7), "a" (addr));
175f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
176f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	return retval;
177f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o}
178f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
17974becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o_INLINE_ int ext2fs_test_bit(int nr, const void * addr)
180f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o{
181f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	char retval;
182f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
183f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	__asm__ __volatile__ ("bftst %2@{%1:#1}; sne %0"
1847f88b04341d88c5df0360d930832c38040303b61Theodore Ts'o	     : "=d" (retval) : "d" (nr^7), "a" (addr));
185f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
186f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	return retval;
187f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o}
188f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
189f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o#endif /* __mc68000__ */
190f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
19150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#ifdef __sparc__
19250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
19350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#define _EXT2_HAVE_ASM_BITOPS_
19450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
1951e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#ifndef EXT2_OLD_BITOPS
1961e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
1971e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o/*
1981e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o * Do the bitops so that we are compatible with the standard i386
1991e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o * convention.
2001e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o */
2011e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2021e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o_INLINE_ int ext2fs_set_bit(int nr,void * addr)
2031e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o{
2041e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#if 1
2051e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	int		mask;
2061e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	unsigned char	*ADDR = (unsigned char *) addr;
2071e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2081e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	ADDR += nr >> 3;
2091e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	mask = 1 << (nr & 0x07);
2101e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	__asm__ __volatile__("ldub	[%0], %%g6\n\t"
2111e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o			     "or	%%g6, %2, %%g5\n\t"
2121e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o			     "stb	%%g5, [%0]\n\t"
2131e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o			     "and	%%g6, %2, %0\n"
2141e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	: "=&r" (ADDR)
2151e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	: "0" (ADDR), "r" (mask)
2161e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	: "g5", "g6");
2171e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	return (int) ADDR;
2181e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#else
2191e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	int		mask, retval;
2201e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	unsigned char	*ADDR = (unsigned char *) addr;
2211e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2221e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	ADDR += nr >> 3;
2231e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	mask = 1 << (nr & 0x07);
2241e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	retval = (mask & *ADDR) != 0;
2251e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	*ADDR |= mask;
2261e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	return retval;
2271e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#endif
2281e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o}
2291e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2301e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o_INLINE_ int ext2fs_clear_bit(int nr, void * addr)
2311e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o{
2321e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#if 1
2331e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	int		mask;
2341e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	unsigned char	*ADDR = (unsigned char *) addr;
2351e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2361e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	ADDR += nr >> 3;
2371e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	mask = 1 << (nr & 0x07);
2381e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	__asm__ __volatile__("ldub	[%0], %%g6\n\t"
2391e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o			     "andn	%%g6, %2, %%g5\n\t"
2401e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o			     "stb	%%g5, [%0]\n\t"
2411e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o			     "and	%%g6, %2, %0\n"
2421e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	: "=&r" (ADDR)
2431e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	: "0" (ADDR), "r" (mask)
2441e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	: "g5", "g6");
2451e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	return (int) ADDR;
2461e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2471e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#else
2481e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	int		mask, retval;
2491e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	unsigned char	*ADDR = (unsigned char *) addr;
2501e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2511e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	ADDR += nr >> 3;
2521e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	mask = 1 << (nr & 0x07);
2531e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	retval = (mask & *ADDR) != 0;
2541e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	*ADDR &= ~mask;
2551e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	return retval;
2561e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#endif
2571e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o}
2581e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2591e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o_INLINE_ int ext2fs_test_bit(int nr, const void * addr)
2601e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o{
2611e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	int			mask;
2621e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	const unsigned char	*ADDR = (const unsigned char *) addr;
2631e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2641e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	ADDR += nr >> 3;
2651e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	mask = 1 << (nr & 0x07);
2661e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	return ((mask & *ADDR) != 0);
2671e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o}
2681e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2691e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#else
2701e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
2711e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o/* Do things the old, unplesant way. */
2721e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
27374becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o_INLINE_ int ext2fs_set_bit(int nr, void *addr)
27450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
27550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	int		mask, retval;
27650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	unsigned long	*ADDR = (unsigned long *) addr;
27750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
27850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	ADDR += nr >> 5;
27950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	mask = 1 << (nr & 31);
28050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	retval = ((mask & *ADDR) != 0);
28150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	*ADDR |= mask;
28250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	return retval;
28350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
28450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
28574becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o_INLINE_ int ext2fs_clear_bit(int nr, void *addr)
28650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
28750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	int		mask, retval;
28850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	unsigned long	*ADDR = (unsigned long *) addr;
28950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
29050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	ADDR += nr >> 5;
29150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	mask = 1 << (nr & 31);
29250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	retval = ((mask & *ADDR) != 0);
29350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	*ADDR &= ~mask;
29450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	return retval;
29550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
29650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
29774becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o_INLINE_ int ext2fs_test_bit(int nr, const void *addr)
29850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
29950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	int			mask;
30050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	const unsigned long	*ADDR = (const unsigned long *) addr;
30150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
30250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	ADDR += nr >> 5;
30350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	mask = 1 << (nr & 31);
30450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	return ((mask & *ADDR) != 0);
30550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
3061e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#endif
30750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
30850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#endif /* __sparc__ */
30950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
31050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#ifndef _EXT2_HAVE_ASM_SWAB
31150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
31250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o_INLINE_ __u16 ext2fs_swab16(__u16 val)
31350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
31450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	return (val >> 8) | (val << 8);
31550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
31650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
31750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o_INLINE_ __u32 ext2fs_swab32(__u32 val)
31850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
31950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	return ((val>>24) | ((val>>8)&0xFF00) |
32050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		((val<<8)&0xFF0000) | (val<<24));
32150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
32250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
32350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#endif /* !_EXT2_HAVE_ASM_SWAB */
32450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
3251e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o_INLINE_ void ext2fs_mark_generic_bitmap(ext2fs_generic_bitmap bitmap,
32621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o					 __u32 bitno);
32721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o_INLINE_ void ext2fs_unmark_generic_bitmap(ext2fs_generic_bitmap bitmap,
32821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o					   blk_t bitno);
32921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o_INLINE_ int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap,
33021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o					blk_t bitno);
33121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
33221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o_INLINE_ void ext2fs_mark_generic_bitmap(ext2fs_generic_bitmap bitmap,
33321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o					 __u32 bitno)
3343839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o{
3351e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	if ((bitno < bitmap->start) || (bitno > bitmap->end)) {
3361e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o		ext2fs_warn_bitmap2(bitmap, EXT2FS_MARK_ERROR, bitno);
3373839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o		return;
3383839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	}
3391e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	ext2fs_set_bit(bitno - bitmap->start, bitmap->bitmap);
3403839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o}
3413839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
3421e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o_INLINE_ void ext2fs_unmark_generic_bitmap(ext2fs_generic_bitmap bitmap,
34321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o					   blk_t bitno)
3443839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o{
3451e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	if ((bitno < bitmap->start) || (bitno > bitmap->end)) {
3461e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o		ext2fs_warn_bitmap2(bitmap, EXT2FS_UNMARK_ERROR, bitno);
3473839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o		return;
3483839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	}
3491e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	ext2fs_clear_bit(bitno - bitmap->start, bitmap->bitmap);
3503839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o}
3513839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
3521e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o_INLINE_ int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap,
35321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o					blk_t bitno)
3543839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o{
3551e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	if ((bitno < bitmap->start) || (bitno > bitmap->end)) {
3561e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o		ext2fs_warn_bitmap2(bitmap, EXT2FS_UNMARK_ERROR, bitno);
3573839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o		return 0;
3583839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	}
3591e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	return ext2fs_test_bit(bitno - bitmap->start, bitmap->bitmap);
3601e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o}
3611e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
3621e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o_INLINE_ void ext2fs_mark_block_bitmap(ext2fs_block_bitmap bitmap,
3631e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o				       blk_t block)
3641e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o{
3651e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) bitmap, block);
3661e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o}
3671e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
3681e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o_INLINE_ void ext2fs_unmark_block_bitmap(ext2fs_block_bitmap bitmap,
3691e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o					 blk_t block)
3701e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o{
3711e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap, block);
3721e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o}
3731e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
3741e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o_INLINE_ int ext2fs_test_block_bitmap(ext2fs_block_bitmap bitmap,
3751e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o				       blk_t block)
3761e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o{
3771e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) bitmap,
3781e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o					  block);
3793839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o}
3803839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
381f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o_INLINE_ void ext2fs_mark_inode_bitmap(ext2fs_inode_bitmap bitmap,
382f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o				       ino_t inode)
3833839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o{
3841e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) bitmap, inode);
3853839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o}
3863839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
387f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o_INLINE_ void ext2fs_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap,
388f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o					 ino_t inode)
3893839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o{
3901e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap, inode);
3913839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o}
3923839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
393f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o_INLINE_ int ext2fs_test_inode_bitmap(ext2fs_inode_bitmap bitmap,
394f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o				       ino_t inode)
3953839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o{
3961e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o	return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) bitmap,
3971e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o					  inode);
3983839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o}
3993839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
40050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o_INLINE_ void ext2fs_fast_mark_block_bitmap(ext2fs_block_bitmap bitmap,
40150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o					    blk_t block)
40250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
40350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#ifdef EXT2FS_DEBUG_FAST_OPS
40450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	if ((block < bitmap->start) || (block > bitmap->end)) {
40550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block,
40650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o				   bitmap->description);
40750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		return;
40850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	}
40950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#endif
41074becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o	ext2fs_set_bit(block - bitmap->start, bitmap->bitmap);
41150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
41250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
41350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o_INLINE_ void ext2fs_fast_unmark_block_bitmap(ext2fs_block_bitmap bitmap,
41450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o					      blk_t block)
41550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
41650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#ifdef EXT2FS_DEBUG_FAST_OPS
41750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	if ((block < bitmap->start) || (block > bitmap->end)) {
41850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK,
41950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o				   block, bitmap->description);
42050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		return;
42150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	}
42250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#endif
42374becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o	ext2fs_clear_bit(block - bitmap->start, bitmap->bitmap);
42450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
42550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
42650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o_INLINE_ int ext2fs_fast_test_block_bitmap(ext2fs_block_bitmap bitmap,
42750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o					    blk_t block)
42850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
42950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#ifdef EXT2FS_DEBUG_FAST_OPS
43050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	if ((block < bitmap->start) || (block > bitmap->end)) {
43150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST,
43250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o				   block, bitmap->description);
43350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		return 0;
43450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	}
43550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#endif
43674becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o	return ext2fs_test_bit(block - bitmap->start, bitmap->bitmap);
43750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
43850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
43950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o_INLINE_ void ext2fs_fast_mark_inode_bitmap(ext2fs_inode_bitmap bitmap,
44050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o					    ino_t inode)
44150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
44250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#ifdef EXT2FS_DEBUG_FAST_OPS
44350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	if ((inode < bitmap->start) || (inode > bitmap->end)) {
44450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_INODE_MARK,
44550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o				   inode, bitmap->description);
44650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		return;
44750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	}
44850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#endif
44974becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o	ext2fs_set_bit(inode - bitmap->start, bitmap->bitmap);
45050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
45150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
45250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o_INLINE_ void ext2fs_fast_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap,
45350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o					      ino_t inode)
45450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
45550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#ifdef EXT2FS_DEBUG_FAST_OPS
45650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	if ((inode < bitmap->start) || (inode > bitmap->end)) {
45750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_INODE_UNMARK,
45850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o				   inode, bitmap->description);
45950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		return;
46050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	}
46150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#endif
46274becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o	ext2fs_clear_bit(inode - bitmap->start, bitmap->bitmap);
46350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
46450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
46550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o_INLINE_ int ext2fs_fast_test_inode_bitmap(ext2fs_inode_bitmap bitmap,
46650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o					   ino_t inode)
46750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
46850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#ifdef EXT2FS_DEBUG_FAST_OPS
46950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	if ((inode < bitmap->start) || (inode > bitmap->end)) {
47050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_INODE_TEST,
47150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o				   inode, bitmap->description);
47250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o		return 0;
47350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	}
47450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#endif
47574becf3c0a065f8d64e07ce4d31f9fe53be91d62Theodore Ts'o	return ext2fs_test_bit(inode - bitmap->start, bitmap->bitmap);
47650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
47750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
47850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o_INLINE_ blk_t ext2fs_get_block_bitmap_start(ext2fs_block_bitmap bitmap)
47950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
48050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	return bitmap->start;
48150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
48250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
48321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o_INLINE_ ino_t ext2fs_get_inode_bitmap_start(ext2fs_inode_bitmap bitmap)
48450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
48550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	return bitmap->start;
48650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
48750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
48850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o_INLINE_ blk_t ext2fs_get_block_bitmap_end(ext2fs_block_bitmap bitmap)
48950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
49050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	return bitmap->end;
49150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
49250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
49321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o_INLINE_ ino_t ext2fs_get_inode_bitmap_end(ext2fs_inode_bitmap bitmap)
49450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o{
49550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	return bitmap->end;
49650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o}
49750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
49821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o_INLINE_ int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
49921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o					    blk_t block, int num)
50021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o{
50121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	int	i;
50221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
50321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
50421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST,
50521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o				   block, bitmap->description);
50621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		return 0;
50721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	}
50821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	for (i=0; i < num; i++) {
50921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		if (ext2fs_fast_test_block_bitmap(bitmap, block+i))
51021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o			return 0;
51121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	}
51221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	return 1;
51321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o}
51421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
51521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o_INLINE_ int ext2fs_fast_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
51621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o						 blk_t block, int num)
51721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o{
51821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	int	i;
51921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
52021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o#ifdef EXT2FS_DEBUG_FAST_OPS
52121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
52221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST,
52321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o				   block, bitmap->description);
52421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		return 0;
52521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	}
52621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o#endif
52721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	for (i=0; i < num; i++) {
52821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		if (ext2fs_fast_test_block_bitmap(bitmap, block+i))
52921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o			return 0;
53021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	}
53121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	return 1;
53221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o}
53321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
53421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o_INLINE_ void ext2fs_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,
53521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o					     blk_t block, int num)
53621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o{
53721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	int	i;
53821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
53921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
54021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block,
54121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o				   bitmap->description);
54221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		return;
54321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	}
54421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	for (i=0; i < num; i++)
54521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		ext2fs_set_bit(block + i - bitmap->start, bitmap->bitmap);
54621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o}
54721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
54821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o_INLINE_ void ext2fs_fast_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,
54921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o						  blk_t block, int num)
55021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o{
55121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	int	i;
55221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
55321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o#ifdef EXT2FS_DEBUG_FAST_OPS
55421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
55521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block,
55621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o				   bitmap->description);
55721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		return;
55821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	}
55921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o#endif
56021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	for (i=0; i < num; i++)
56121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		ext2fs_set_bit(block + i - bitmap->start, bitmap->bitmap);
56221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o}
56321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
56421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o_INLINE_ void ext2fs_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,
56521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o					       blk_t block, int num)
56621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o{
56721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	int	i;
56821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
56921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
57021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block,
57121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o				   bitmap->description);
57221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		return;
57321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	}
57421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	for (i=0; i < num; i++)
57521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		ext2fs_clear_bit(block + i - bitmap->start, bitmap->bitmap);
57621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o}
57721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
57821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o_INLINE_ void ext2fs_fast_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,
57921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o						    blk_t block, int num)
58021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o{
58121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	int	i;
58221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
58321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o#ifdef EXT2FS_DEBUG_FAST_OPS
58421c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
58521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block,
58621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o				   bitmap->description);
58721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		return;
58821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	}
58921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o#endif
59021c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o	for (i=0; i < num; i++)
59121c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o		ext2fs_clear_bit(block + i - bitmap->start, bitmap->bitmap);
59221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o}
59321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o
5943839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#undef _INLINE_
5953839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#endif
59650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o
597