gen_bitmap.c revision 271a375b596240866b4a2967e3b6f38ff7cecdf8
1/* 2 * gen_bitmap.c --- Generic bitmap routines that used to be inlined. 3 * 4 * Copyright (C) 2001 Theodore Ts'o. 5 * 6 * %Begin-Header% 7 * This file may be redistributed under the terms of the GNU Public 8 * License. 9 * %End-Header% 10 */ 11 12 13#include <stdio.h> 14#include <string.h> 15#if HAVE_UNISTD_H 16#include <unistd.h> 17#endif 18#include <fcntl.h> 19#include <time.h> 20#if HAVE_SYS_STAT_H 21#include <sys/stat.h> 22#endif 23#if HAVE_SYS_TYPES_H 24#include <sys/types.h> 25#endif 26 27#include "ext2_fs.h" 28#include "ext2fs.h" 29 30int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap, 31 blk_t bitno) 32{ 33 if ((bitno < bitmap->start) || (bitno > bitmap->end)) { 34 ext2fs_warn_bitmap2(bitmap, EXT2FS_TEST_ERROR, bitno); 35 return 0; 36 } 37 return ext2fs_test_bit(bitno - bitmap->start, bitmap->bitmap); 38} 39 40int ext2fs_mark_generic_bitmap(ext2fs_generic_bitmap bitmap, 41 __u32 bitno) 42{ 43 if ((bitno < bitmap->start) || (bitno > bitmap->end)) { 44 ext2fs_warn_bitmap2(bitmap, EXT2FS_MARK_ERROR, bitno); 45 return 0; 46 } 47 return ext2fs_set_bit(bitno - bitmap->start, bitmap->bitmap); 48} 49 50int ext2fs_unmark_generic_bitmap(ext2fs_generic_bitmap bitmap, 51 blk_t bitno) 52{ 53 if ((bitno < bitmap->start) || (bitno > bitmap->end)) { 54 ext2fs_warn_bitmap2(bitmap, EXT2FS_UNMARK_ERROR, bitno); 55 return 0; 56 } 57 return ext2fs_clear_bit(bitno - bitmap->start, bitmap->bitmap); 58} 59 60__u32 ext2fs_get_generic_bitmap_start(ext2fs_generic_bitmap bitmap) 61{ 62 return bitmap->start; 63} 64 65__u32 ext2fs_get_generic_bitmap_end(ext2fs_generic_bitmap bitmap) 66{ 67 return bitmap->end; 68} 69 70int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap, 71 blk_t block, int num) 72{ 73 int i; 74 75 if ((block < bitmap->start) || (block+num-1 > bitmap->end)) { 76 ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST, 77 block, bitmap->description); 78 return 0; 79 } 80 for (i=0; i < num; i++) { 81 if (ext2fs_fast_test_block_bitmap(bitmap, block+i)) 82 return 0; 83 } 84 return 1; 85} 86 87void ext2fs_mark_block_bitmap_range(ext2fs_block_bitmap bitmap, 88 blk_t block, int num) 89{ 90 int i; 91 92 if ((block < bitmap->start) || (block+num-1 > bitmap->end)) { 93 ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block, 94 bitmap->description); 95 return; 96 } 97 for (i=0; i < num; i++) 98 ext2fs_fast_set_bit(block + i - bitmap->start, bitmap->bitmap); 99} 100 101void ext2fs_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap, 102 blk_t block, int num) 103{ 104 int i; 105 106 if ((block < bitmap->start) || (block+num-1 > bitmap->end)) { 107 ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block, 108 bitmap->description); 109 return; 110 } 111 for (i=0; i < num; i++) 112 ext2fs_fast_clear_bit(block + i - bitmap->start, 113 bitmap->bitmap); 114} 115 116