blob: 08592b4738265cc346c464b8f595cf1274f81224 [file] [log] [blame]
Theodore Ts'o3034f622001-06-11 15:17:45 +00001/*
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
Theodore Ts'ob15beaa2007-07-22 17:42:52 -040030int 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
Theodore Ts'o3034f622001-06-11 15:17:45 +000040int 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}
Theodore Ts'o8df18272007-07-22 18:54:10 -040059
60int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
61 blk_t block, int num)
62{
63 int i;
64
65 if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
66 ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST,
67 block, bitmap->description);
68 return 0;
69 }
70 for (i=0; i < num; i++) {
71 if (ext2fs_fast_test_block_bitmap(bitmap, block+i))
72 return 0;
73 }
74 return 1;
75}
76
77void ext2fs_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,
78 blk_t block, int num)
79{
80 int i;
81
82 if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
83 ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block,
84 bitmap->description);
85 return;
86 }
87 for (i=0; i < num; i++)
88 ext2fs_fast_set_bit(block + i - bitmap->start, bitmap->bitmap);
89}
90
91void ext2fs_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,
92 blk_t block, int num)
93{
94 int i;
95
96 if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
97 ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block,
98 bitmap->description);
99 return;
100 }
101 for (i=0; i < num; i++)
102 ext2fs_fast_clear_bit(block + i - bitmap->start,
103 bitmap->bitmap);
104}
105