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>
29 errcode_t ext2fs_resize_generic_bitmap(__u32 new_end, __u32 new_real_end,
30 ext2fs_generic_bitmap bmap)
33 size_t size, new_size;
37 return EXT2_ET_INVALID_ARGUMENT;
39 EXT2_CHECK_MAGIC(bmap, EXT2_ET_MAGIC_GENERIC_BITMAP);
42 * If we're expanding the bitmap, make sure all of the new
43 * parts of the bitmap are zero.
45 if (new_end > bmap->end) {
46 bitno = bmap->real_end;
49 for (; bitno > bmap->end; bitno--)
50 ext2fs_clear_bit(bitno - bmap->start, bmap->bitmap);
52 if (new_real_end == bmap->real_end) {
57 size = ((bmap->real_end - bmap->start) / 8) + 1;
58 new_size = ((new_real_end - bmap->start) / 8) + 1;
60 if (size != new_size) {
61 retval = ext2fs_resize_mem(size, new_size, &bmap->bitmap);
66 memset(bmap->bitmap + size, 0, new_size - size);
69 bmap->real_end = new_real_end;
73 errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
74 ext2fs_inode_bitmap bmap)
79 return EXT2_ET_INVALID_ARGUMENT;
81 EXT2_CHECK_MAGIC(bmap, EXT2_ET_MAGIC_INODE_BITMAP);
83 bmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
84 retval = ext2fs_resize_generic_bitmap(new_end, new_real_end,
86 bmap->magic = EXT2_ET_MAGIC_INODE_BITMAP;
90 errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
91 ext2fs_block_bitmap bmap)
96 return EXT2_ET_INVALID_ARGUMENT;
98 EXT2_CHECK_MAGIC(bmap, EXT2_ET_MAGIC_BLOCK_BITMAP);
100 bmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
101 retval = ext2fs_resize_generic_bitmap(new_end, new_real_end,
103 bmap->magic = EXT2_ET_MAGIC_BLOCK_BITMAP;