1 /* vi: set sw=4 ts=4: */
3 * rs_bitmap.c --- routine for changing the size of a bitmap
5 * Copyright (C) 1996, 1997 Theodore Ts'o.
8 * This file may be redistributed under the terms of the GNU Public
20 #ifdef HAVE_SYS_STAT_H
23 #ifdef HAVE_SYS_TYPES_H
24 #include <sys/types.h>
30 errcode_t
ext2fs_resize_generic_bitmap(__u32 new_end
, __u32 new_real_end
,
31 ext2fs_generic_bitmap bmap
)
34 size_t size
, new_size
;
38 return EXT2_ET_INVALID_ARGUMENT
;
40 EXT2_CHECK_MAGIC(bmap
, EXT2_ET_MAGIC_GENERIC_BITMAP
);
43 * If we're expanding the bitmap, make sure all of the new
44 * parts of the bitmap are zero.
46 if (new_end
> bmap
->end
) {
47 bitno
= bmap
->real_end
;
50 for (; bitno
> bmap
->end
; bitno
--)
51 ext2fs_clear_bit(bitno
- bmap
->start
, bmap
->bitmap
);
53 if (new_real_end
== bmap
->real_end
) {
58 size
= ((bmap
->real_end
- bmap
->start
) / 8) + 1;
59 new_size
= ((new_real_end
- bmap
->start
) / 8) + 1;
61 if (size
!= new_size
) {
62 retval
= ext2fs_resize_mem(size
, new_size
, &bmap
->bitmap
);
67 memset(bmap
->bitmap
+ size
, 0, new_size
- size
);
70 bmap
->real_end
= new_real_end
;
74 errcode_t
ext2fs_resize_inode_bitmap(__u32 new_end
, __u32 new_real_end
,
75 ext2fs_inode_bitmap bmap
)
80 return EXT2_ET_INVALID_ARGUMENT
;
82 EXT2_CHECK_MAGIC(bmap
, EXT2_ET_MAGIC_INODE_BITMAP
);
84 bmap
->magic
= EXT2_ET_MAGIC_GENERIC_BITMAP
;
85 retval
= ext2fs_resize_generic_bitmap(new_end
, new_real_end
,
87 bmap
->magic
= EXT2_ET_MAGIC_INODE_BITMAP
;
91 errcode_t
ext2fs_resize_block_bitmap(__u32 new_end
, __u32 new_real_end
,
92 ext2fs_block_bitmap bmap
)
97 return EXT2_ET_INVALID_ARGUMENT
;
99 EXT2_CHECK_MAGIC(bmap
, EXT2_ET_MAGIC_BLOCK_BITMAP
);
101 bmap
->magic
= EXT2_ET_MAGIC_GENERIC_BITMAP
;
102 retval
= ext2fs_resize_generic_bitmap(new_end
, new_real_end
,
104 bmap
->magic
= EXT2_ET_MAGIC_BLOCK_BITMAP
;