2 * rs_bitmap.c --- routine for changing the size of a bitmap
4 * Copyright (C) 1996, 1997 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Public
19 #ifdef HAVE_SYS_STAT_H
22 #ifdef HAVE_SYS_TYPES_H
23 #include <sys/types.h>
26 #if EXT2_FLAT_INCLUDES
29 #include <linux/ext2_fs.h>
34 errcode_t ext2fs_resize_generic_bitmap(__u32 new_end, __u32 new_real_end,
35 ext2fs_generic_bitmap bmap)
38 size_t size, new_size;
42 return EXT2_ET_INVALID_ARGUMENT;
44 EXT2_CHECK_MAGIC(bmap, EXT2_ET_MAGIC_GENERIC_BITMAP);
47 * If we're expanding the bitmap, make sure all of the new
48 * parts of the bitmap are zero.
50 if (new_end > bmap->end) {
51 bitno = bmap->real_end;
54 for (; bitno > bmap->end; bitno--)
55 ext2fs_clear_bit(bitno - bmap->start, bmap->bitmap);
57 if (new_real_end == bmap->real_end) {
62 size = ((bmap->real_end - bmap->start) / 8) + 1;
63 new_size = ((new_real_end - bmap->start) / 8) + 1;
65 if (size != new_size) {
66 retval = ext2fs_resize_mem(size, new_size,
67 (void **) &bmap->bitmap);
72 memset(bmap->bitmap + size, 0, new_size - size);
75 bmap->real_end = new_real_end;
79 errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
80 ext2fs_inode_bitmap bmap)
85 return EXT2_ET_INVALID_ARGUMENT;
87 EXT2_CHECK_MAGIC(bmap, EXT2_ET_MAGIC_INODE_BITMAP);
89 bmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
90 retval = ext2fs_resize_generic_bitmap(new_end, new_real_end,
92 bmap->magic = EXT2_ET_MAGIC_INODE_BITMAP;
96 errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
97 ext2fs_block_bitmap bmap)
102 return EXT2_ET_INVALID_ARGUMENT;
104 EXT2_CHECK_MAGIC(bmap, EXT2_ET_MAGIC_BLOCK_BITMAP);
106 bmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
107 retval = ext2fs_resize_generic_bitmap(new_end, new_real_end,
109 bmap->magic = EXT2_ET_MAGIC_BLOCK_BITMAP;