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
20 #ifdef HAVE_SYS_STAT_H
23 #ifdef HAVE_SYS_TYPES_H
24 #include <sys/types.h>
27 #include <linux/ext2_fs.h>
31 errcode_t ext2fs_resize_generic_bitmap(__u32 new_end, __u32 new_real_end,
32 ext2fs_generic_bitmap bmap)
34 size_t size, new_size;
39 return EXT2_INVALID_ARGUMENT;
41 EXT2_CHECK_MAGIC(bmap, EXT2_ET_MAGIC_GENERIC_BITMAP);
44 * If we're expanding the bitmap, make sure all of the new
45 * parts of the bitmap are zero.
47 if (new_end > bmap->end) {
48 bitno = bmap->real_end;
51 for (; bitno > bmap->end; bitno--)
52 ext2fs_clear_bit(bitno - bmap->start, bmap->bitmap);
54 if (new_real_end == bmap->real_end) {
59 size = ((bmap->real_end - bmap->start) / 8) + 1;
60 new_size = ((new_real_end - bmap->start) / 8) + 1;
62 new_bitmap = realloc(bmap->bitmap, new_size);
64 return EXT2_NO_MEMORY;
66 memset(new_bitmap + size, 0, new_size - size);
68 bmap->bitmap = new_bitmap;
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_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_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;