bitops.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. /*
  2. * bitops.h --- Bitmap frobbing code. The byte swapping routines are
  3. * also included here.
  4. *
  5. * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
  6. *
  7. * %Begin-Header%
  8. * This file may be redistributed under the terms of the GNU Public
  9. * License.
  10. * %End-Header%
  11. *
  12. * i386 bitops operations taken from <asm/bitops.h>, Copyright 1992,
  13. * Linus Torvalds.
  14. */
  15. #include <strings.h>
  16. extern int ext2fs_set_bit(int nr,void * addr);
  17. extern int ext2fs_clear_bit(int nr, void * addr);
  18. extern int ext2fs_test_bit(int nr, const void * addr);
  19. extern __u16 ext2fs_swab16(__u16 val);
  20. extern __u32 ext2fs_swab32(__u32 val);
  21. #ifdef WORDS_BIGENDIAN
  22. #define ext2fs_cpu_to_le32(x) ext2fs_swab32((x))
  23. #define ext2fs_le32_to_cpu(x) ext2fs_swab32((x))
  24. #define ext2fs_cpu_to_le16(x) ext2fs_swab16((x))
  25. #define ext2fs_le16_to_cpu(x) ext2fs_swab16((x))
  26. #define ext2fs_cpu_to_be32(x) ((__u32)(x))
  27. #define ext2fs_be32_to_cpu(x) ((__u32)(x))
  28. #define ext2fs_cpu_to_be16(x) ((__u16)(x))
  29. #define ext2fs_be16_to_cpu(x) ((__u16)(x))
  30. #else
  31. #define ext2fs_cpu_to_le32(x) ((__u32)(x))
  32. #define ext2fs_le32_to_cpu(x) ((__u32)(x))
  33. #define ext2fs_cpu_to_le16(x) ((__u16)(x))
  34. #define ext2fs_le16_to_cpu(x) ((__u16)(x))
  35. #define ext2fs_cpu_to_be32(x) ext2fs_swab32((x))
  36. #define ext2fs_be32_to_cpu(x) ext2fs_swab32((x))
  37. #define ext2fs_cpu_to_be16(x) ext2fs_swab16((x))
  38. #define ext2fs_be16_to_cpu(x) ext2fs_swab16((x))
  39. #endif
  40. /*
  41. * EXT2FS bitmap manipulation routines.
  42. */
  43. /* Support for sending warning messages from the inline subroutines */
  44. extern const char *ext2fs_block_string;
  45. extern const char *ext2fs_inode_string;
  46. extern const char *ext2fs_mark_string;
  47. extern const char *ext2fs_unmark_string;
  48. extern const char *ext2fs_test_string;
  49. extern void ext2fs_warn_bitmap(errcode_t errcode, unsigned long arg,
  50. const char *description);
  51. extern void ext2fs_warn_bitmap2(ext2fs_generic_bitmap bitmap,
  52. int code, unsigned long arg);
  53. extern int ext2fs_mark_block_bitmap(ext2fs_block_bitmap bitmap, blk_t block);
  54. extern int ext2fs_unmark_block_bitmap(ext2fs_block_bitmap bitmap,
  55. blk_t block);
  56. extern int ext2fs_test_block_bitmap(ext2fs_block_bitmap bitmap, blk_t block);
  57. extern int ext2fs_mark_inode_bitmap(ext2fs_inode_bitmap bitmap, ext2_ino_t inode);
  58. extern int ext2fs_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap,
  59. ext2_ino_t inode);
  60. extern int ext2fs_test_inode_bitmap(ext2fs_inode_bitmap bitmap, ext2_ino_t inode);
  61. extern void ext2fs_fast_mark_block_bitmap(ext2fs_block_bitmap bitmap,
  62. blk_t block);
  63. extern void ext2fs_fast_unmark_block_bitmap(ext2fs_block_bitmap bitmap,
  64. blk_t block);
  65. extern int ext2fs_fast_test_block_bitmap(ext2fs_block_bitmap bitmap,
  66. blk_t block);
  67. extern void ext2fs_fast_mark_inode_bitmap(ext2fs_inode_bitmap bitmap,
  68. ext2_ino_t inode);
  69. extern void ext2fs_fast_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap,
  70. ext2_ino_t inode);
  71. extern int ext2fs_fast_test_inode_bitmap(ext2fs_inode_bitmap bitmap,
  72. ext2_ino_t inode);
  73. extern blk_t ext2fs_get_block_bitmap_start(ext2fs_block_bitmap bitmap);
  74. extern ext2_ino_t ext2fs_get_inode_bitmap_start(ext2fs_inode_bitmap bitmap);
  75. extern blk_t ext2fs_get_block_bitmap_end(ext2fs_block_bitmap bitmap);
  76. extern ext2_ino_t ext2fs_get_inode_bitmap_end(ext2fs_inode_bitmap bitmap);
  77. extern void ext2fs_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,
  78. blk_t block, int num);
  79. extern void ext2fs_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,
  80. blk_t block, int num);
  81. extern int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
  82. blk_t block, int num);
  83. extern void ext2fs_fast_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,
  84. blk_t block, int num);
  85. extern void ext2fs_fast_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,
  86. blk_t block, int num);
  87. extern int ext2fs_fast_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
  88. blk_t block, int num);
  89. extern void ext2fs_set_bitmap_padding(ext2fs_generic_bitmap map);
  90. /* These two routines moved to gen_bitmap.c */
  91. extern int ext2fs_mark_generic_bitmap(ext2fs_generic_bitmap bitmap,
  92. __u32 bitno);
  93. extern int ext2fs_unmark_generic_bitmap(ext2fs_generic_bitmap bitmap,
  94. blk_t bitno);
  95. /*
  96. * The inline routines themselves...
  97. *
  98. * If NO_INLINE_FUNCS is defined, then we won't try to do inline
  99. * functions at all; they will be included as normal functions in
  100. * inline.c
  101. */
  102. #ifdef NO_INLINE_FUNCS
  103. #if (defined(__GNUC__) && (defined(__i386__) || defined(__i486__) || \
  104. defined(__i586__) || defined(__mc68000__) || \
  105. defined(__sparc__)))
  106. /* This prevents bitops.c from trying to include the C */
  107. /* function version of these functions */
  108. #define _EXT2_HAVE_ASM_BITOPS_
  109. #endif
  110. #endif /* NO_INLINE_FUNCS */
  111. #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
  112. #ifdef INCLUDE_INLINE_FUNCS
  113. #define _INLINE_ extern
  114. #else
  115. #ifdef __GNUC__
  116. #define _INLINE_ extern __inline__
  117. #else /* For Watcom C */
  118. #define _INLINE_ extern inline
  119. #endif
  120. #endif
  121. #if ((defined __GNUC__) && !defined(_EXT2_USE_C_VERSIONS_) && \
  122. (defined(__i386__) || defined(__i486__) || defined(__i586__)))
  123. #define _EXT2_HAVE_ASM_BITOPS_
  124. #define _EXT2_HAVE_ASM_SWAB_
  125. #define _EXT2_HAVE_ASM_FINDBIT_
  126. /*
  127. * These are done by inline assembly for speed reasons.....
  128. *
  129. * All bitoperations return 0 if the bit was cleared before the
  130. * operation and != 0 if it was not. Bit 0 is the LSB of addr; bit 32
  131. * is the LSB of (addr+1).
  132. */
  133. /*
  134. * Some hacks to defeat gcc over-optimizations..
  135. */
  136. struct __dummy_h { unsigned long a[100]; };
  137. #define EXT2FS_ADDR (*(struct __dummy_h *) addr)
  138. #define EXT2FS_CONST_ADDR (*(const struct __dummy_h *) addr)
  139. _INLINE_ int ext2fs_set_bit(int nr, void * addr)
  140. {
  141. int oldbit;
  142. __asm__ __volatile__("btsl %2,%1\n\tsbbl %0,%0"
  143. :"=r" (oldbit),"=m" (EXT2FS_ADDR)
  144. :"r" (nr));
  145. return oldbit;
  146. }
  147. _INLINE_ int ext2fs_clear_bit(int nr, void * addr)
  148. {
  149. int oldbit;
  150. __asm__ __volatile__("btrl %2,%1\n\tsbbl %0,%0"
  151. :"=r" (oldbit),"=m" (EXT2FS_ADDR)
  152. :"r" (nr));
  153. return oldbit;
  154. }
  155. _INLINE_ int ext2fs_test_bit(int nr, const void * addr)
  156. {
  157. int oldbit;
  158. __asm__ __volatile__("btl %2,%1\n\tsbbl %0,%0"
  159. :"=r" (oldbit)
  160. :"m" (EXT2FS_CONST_ADDR),"r" (nr));
  161. return oldbit;
  162. }
  163. #if 0
  164. _INLINE_ int ext2fs_find_first_bit_set(void * addr, unsigned size)
  165. {
  166. int d0, d1, d2;
  167. int res;
  168. if (!size)
  169. return 0;
  170. /* This looks at memory. Mark it volatile to tell gcc not to move it around */
  171. __asm__ __volatile__(
  172. "cld\n\t"
  173. "xorl %%eax,%%eax\n\t"
  174. "xorl %%edx,%%edx\n\t"
  175. "repe; scasl\n\t"
  176. "je 1f\n\t"
  177. "movl -4(%%edi),%%eax\n\t"
  178. "subl $4,%%edi\n\t"
  179. "bsfl %%eax,%%edx\n"
  180. "1:\tsubl %%esi,%%edi\n\t"
  181. "shll $3,%%edi\n\t"
  182. "addl %%edi,%%edx"
  183. :"=d" (res), "=&c" (d0), "=&D" (d1), "=&a" (d2)
  184. :"1" ((size + 31) >> 5), "2" (addr), "S" (addr));
  185. return res;
  186. }
  187. _INLINE_ int ext2fs_find_next_bit_set (void * addr, int size, int offset)
  188. {
  189. unsigned long * p = ((unsigned long *) addr) + (offset >> 5);
  190. int set = 0, bit = offset & 31, res;
  191. if (bit) {
  192. /*
  193. * Look for zero in first byte
  194. */
  195. __asm__("bsfl %1,%0\n\t"
  196. "jne 1f\n\t"
  197. "movl $32, %0\n"
  198. "1:"
  199. : "=r" (set)
  200. : "r" (*p >> bit));
  201. if (set < (32 - bit))
  202. return set + offset;
  203. set = 32 - bit;
  204. p++;
  205. }
  206. /*
  207. * No bit found yet, search remaining full bytes for a bit
  208. */
  209. res = ext2fs_find_first_bit_set(p, size - 32 * (p - (unsigned long *) addr));
  210. return (offset + set + res);
  211. }
  212. #endif
  213. #ifdef EXT2FS_ENABLE_SWAPFS
  214. _INLINE_ __u32 ext2fs_swab32(__u32 val)
  215. {
  216. #ifdef EXT2FS_REQUIRE_486
  217. __asm__("bswap %0" : "=r" (val) : "0" (val));
  218. #else
  219. __asm__("xchgb %b0,%h0\n\t" /* swap lower bytes */
  220. "rorl $16,%0\n\t" /* swap words */
  221. "xchgb %b0,%h0" /* swap higher bytes */
  222. :"=q" (val)
  223. : "0" (val));
  224. #endif
  225. return val;
  226. }
  227. _INLINE_ __u16 ext2fs_swab16(__u16 val)
  228. {
  229. __asm__("xchgb %b0,%h0" /* swap bytes */ \
  230. : "=q" (val) \
  231. : "0" (val)); \
  232. return val;
  233. }
  234. #endif
  235. #undef EXT2FS_ADDR
  236. #endif /* i386 */
  237. #ifdef __mc68000__
  238. #define _EXT2_HAVE_ASM_BITOPS_
  239. _INLINE_ int ext2fs_set_bit(int nr,void * addr)
  240. {
  241. char retval;
  242. __asm__ __volatile__ ("bfset %2@{%1:#1}; sne %0"
  243. : "=d" (retval) : "d" (nr^7), "a" (addr));
  244. return retval;
  245. }
  246. _INLINE_ int ext2fs_clear_bit(int nr, void * addr)
  247. {
  248. char retval;
  249. __asm__ __volatile__ ("bfclr %2@{%1:#1}; sne %0"
  250. : "=d" (retval) : "d" (nr^7), "a" (addr));
  251. return retval;
  252. }
  253. _INLINE_ int ext2fs_test_bit(int nr, const void * addr)
  254. {
  255. char retval;
  256. __asm__ __volatile__ ("bftst %2@{%1:#1}; sne %0"
  257. : "=d" (retval) : "d" (nr^7), "a" (addr));
  258. return retval;
  259. }
  260. #endif /* __mc68000__ */
  261. #if !defined(_EXT2_HAVE_ASM_SWAB_) && defined(EXT2FS_ENABLE_SWAPFS)
  262. _INLINE_ __u16 ext2fs_swab16(__u16 val)
  263. {
  264. return (val >> 8) | (val << 8);
  265. }
  266. _INLINE_ __u32 ext2fs_swab32(__u32 val)
  267. {
  268. return ((val>>24) | ((val>>8)&0xFF00) |
  269. ((val<<8)&0xFF0000) | (val<<24));
  270. }
  271. #endif /* !_EXT2_HAVE_ASM_SWAB */
  272. #if !defined(_EXT2_HAVE_ASM_FINDBIT_)
  273. _INLINE_ int ext2fs_find_first_bit_set(void * addr, unsigned size)
  274. {
  275. unsigned char *cp = (unsigned char *) addr;
  276. int res = 0, d0;
  277. if (!size)
  278. return 0;
  279. while ((size > res) && (*cp == 0)) {
  280. cp++;
  281. res += 8;
  282. }
  283. d0 = ffs(*cp);
  284. if (d0 == 0)
  285. return size;
  286. return res + d0 - 1;
  287. }
  288. _INLINE_ int ext2fs_find_next_bit_set (void * addr, int size, int offset)
  289. {
  290. unsigned char * p;
  291. int set = 0, bit = offset & 7, res = 0, d0;
  292. res = offset >> 3;
  293. p = ((unsigned char *) addr) + res;
  294. if (bit) {
  295. set = ffs(*p & ~((1 << bit) - 1));
  296. if (set)
  297. return (offset & ~7) + set - 1;
  298. p++;
  299. res += 8;
  300. }
  301. while ((size > res) && (*p == 0)) {
  302. p++;
  303. res += 8;
  304. }
  305. d0 = ffs(*p);
  306. if (d0 == 0)
  307. return size;
  308. return (res + d0 - 1);
  309. }
  310. #endif
  311. _INLINE_ int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap,
  312. blk_t bitno);
  313. _INLINE_ int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap,
  314. blk_t bitno)
  315. {
  316. if ((bitno < bitmap->start) || (bitno > bitmap->end)) {
  317. ext2fs_warn_bitmap2(bitmap, EXT2FS_TEST_ERROR, bitno);
  318. return 0;
  319. }
  320. return ext2fs_test_bit(bitno - bitmap->start, bitmap->bitmap);
  321. }
  322. _INLINE_ int ext2fs_mark_block_bitmap(ext2fs_block_bitmap bitmap,
  323. blk_t block)
  324. {
  325. return ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap)
  326. bitmap,
  327. block);
  328. }
  329. _INLINE_ int ext2fs_unmark_block_bitmap(ext2fs_block_bitmap bitmap,
  330. blk_t block)
  331. {
  332. return ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap,
  333. block);
  334. }
  335. _INLINE_ int ext2fs_test_block_bitmap(ext2fs_block_bitmap bitmap,
  336. blk_t block)
  337. {
  338. return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) bitmap,
  339. block);
  340. }
  341. _INLINE_ int ext2fs_mark_inode_bitmap(ext2fs_inode_bitmap bitmap,
  342. ext2_ino_t inode)
  343. {
  344. return ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) bitmap,
  345. inode);
  346. }
  347. _INLINE_ int ext2fs_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap,
  348. ext2_ino_t inode)
  349. {
  350. return ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap,
  351. inode);
  352. }
  353. _INLINE_ int ext2fs_test_inode_bitmap(ext2fs_inode_bitmap bitmap,
  354. ext2_ino_t inode)
  355. {
  356. return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) bitmap,
  357. inode);
  358. }
  359. _INLINE_ void ext2fs_fast_mark_block_bitmap(ext2fs_block_bitmap bitmap,
  360. blk_t block)
  361. {
  362. #ifdef EXT2FS_DEBUG_FAST_OPS
  363. if ((block < bitmap->start) || (block > bitmap->end)) {
  364. ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block,
  365. bitmap->description);
  366. return;
  367. }
  368. #endif
  369. ext2fs_set_bit(block - bitmap->start, bitmap->bitmap);
  370. }
  371. _INLINE_ void ext2fs_fast_unmark_block_bitmap(ext2fs_block_bitmap bitmap,
  372. blk_t block)
  373. {
  374. #ifdef EXT2FS_DEBUG_FAST_OPS
  375. if ((block < bitmap->start) || (block > bitmap->end)) {
  376. ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK,
  377. block, bitmap->description);
  378. return;
  379. }
  380. #endif
  381. ext2fs_clear_bit(block - bitmap->start, bitmap->bitmap);
  382. }
  383. _INLINE_ int ext2fs_fast_test_block_bitmap(ext2fs_block_bitmap bitmap,
  384. blk_t block)
  385. {
  386. #ifdef EXT2FS_DEBUG_FAST_OPS
  387. if ((block < bitmap->start) || (block > bitmap->end)) {
  388. ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST,
  389. block, bitmap->description);
  390. return 0;
  391. }
  392. #endif
  393. return ext2fs_test_bit(block - bitmap->start, bitmap->bitmap);
  394. }
  395. _INLINE_ void ext2fs_fast_mark_inode_bitmap(ext2fs_inode_bitmap bitmap,
  396. ext2_ino_t inode)
  397. {
  398. #ifdef EXT2FS_DEBUG_FAST_OPS
  399. if ((inode < bitmap->start) || (inode > bitmap->end)) {
  400. ext2fs_warn_bitmap(EXT2_ET_BAD_INODE_MARK,
  401. inode, bitmap->description);
  402. return;
  403. }
  404. #endif
  405. ext2fs_set_bit(inode - bitmap->start, bitmap->bitmap);
  406. }
  407. _INLINE_ void ext2fs_fast_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap,
  408. ext2_ino_t inode)
  409. {
  410. #ifdef EXT2FS_DEBUG_FAST_OPS
  411. if ((inode < bitmap->start) || (inode > bitmap->end)) {
  412. ext2fs_warn_bitmap(EXT2_ET_BAD_INODE_UNMARK,
  413. inode, bitmap->description);
  414. return;
  415. }
  416. #endif
  417. ext2fs_clear_bit(inode - bitmap->start, bitmap->bitmap);
  418. }
  419. _INLINE_ int ext2fs_fast_test_inode_bitmap(ext2fs_inode_bitmap bitmap,
  420. ext2_ino_t inode)
  421. {
  422. #ifdef EXT2FS_DEBUG_FAST_OPS
  423. if ((inode < bitmap->start) || (inode > bitmap->end)) {
  424. ext2fs_warn_bitmap(EXT2_ET_BAD_INODE_TEST,
  425. inode, bitmap->description);
  426. return 0;
  427. }
  428. #endif
  429. return ext2fs_test_bit(inode - bitmap->start, bitmap->bitmap);
  430. }
  431. _INLINE_ blk_t ext2fs_get_block_bitmap_start(ext2fs_block_bitmap bitmap)
  432. {
  433. return bitmap->start;
  434. }
  435. _INLINE_ ext2_ino_t ext2fs_get_inode_bitmap_start(ext2fs_inode_bitmap bitmap)
  436. {
  437. return bitmap->start;
  438. }
  439. _INLINE_ blk_t ext2fs_get_block_bitmap_end(ext2fs_block_bitmap bitmap)
  440. {
  441. return bitmap->end;
  442. }
  443. _INLINE_ ext2_ino_t ext2fs_get_inode_bitmap_end(ext2fs_inode_bitmap bitmap)
  444. {
  445. return bitmap->end;
  446. }
  447. _INLINE_ int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
  448. blk_t block, int num)
  449. {
  450. int i;
  451. if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
  452. ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST,
  453. block, bitmap->description);
  454. return 0;
  455. }
  456. for (i=0; i < num; i++) {
  457. if (ext2fs_fast_test_block_bitmap(bitmap, block+i))
  458. return 0;
  459. }
  460. return 1;
  461. }
  462. _INLINE_ int ext2fs_fast_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
  463. blk_t block, int num)
  464. {
  465. int i;
  466. #ifdef EXT2FS_DEBUG_FAST_OPS
  467. if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
  468. ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST,
  469. block, bitmap->description);
  470. return 0;
  471. }
  472. #endif
  473. for (i=0; i < num; i++) {
  474. if (ext2fs_fast_test_block_bitmap(bitmap, block+i))
  475. return 0;
  476. }
  477. return 1;
  478. }
  479. _INLINE_ void ext2fs_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,
  480. blk_t block, int num)
  481. {
  482. int i;
  483. if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
  484. ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block,
  485. bitmap->description);
  486. return;
  487. }
  488. for (i=0; i < num; i++)
  489. ext2fs_set_bit(block + i - bitmap->start, bitmap->bitmap);
  490. }
  491. _INLINE_ void ext2fs_fast_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,
  492. blk_t block, int num)
  493. {
  494. int i;
  495. #ifdef EXT2FS_DEBUG_FAST_OPS
  496. if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
  497. ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block,
  498. bitmap->description);
  499. return;
  500. }
  501. #endif
  502. for (i=0; i < num; i++)
  503. ext2fs_set_bit(block + i - bitmap->start, bitmap->bitmap);
  504. }
  505. _INLINE_ void ext2fs_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,
  506. blk_t block, int num)
  507. {
  508. int i;
  509. if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
  510. ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block,
  511. bitmap->description);
  512. return;
  513. }
  514. for (i=0; i < num; i++)
  515. ext2fs_clear_bit(block + i - bitmap->start, bitmap->bitmap);
  516. }
  517. _INLINE_ void ext2fs_fast_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,
  518. blk_t block, int num)
  519. {
  520. int i;
  521. #ifdef EXT2FS_DEBUG_FAST_OPS
  522. if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
  523. ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block,
  524. bitmap->description);
  525. return;
  526. }
  527. #endif
  528. for (i=0; i < num; i++)
  529. ext2fs_clear_bit(block + i - bitmap->start, bitmap->bitmap);
  530. }
  531. #undef _INLINE_
  532. #endif