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