Changes to update Tomato RAF.
[tomato.git] / release / src / router / busybox / e2fsprogs / old_e2fsprogs / ext2fs / rs_bitmap.c
blob32e87b77a9de41aa05d1e572eafa7fbfdb7ed631
1 /* vi: set sw=4 ts=4: */
2 /*
3 * rs_bitmap.c --- routine for changing the size of a bitmap
5 * Copyright (C) 1996, 1997 Theodore Ts'o.
7 * %Begin-Header%
8 * This file may be redistributed under the terms of the GNU Public
9 * License.
10 * %End-Header%
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 #ifdef HAVE_SYS_STAT_H
21 #include <sys/stat.h>
22 #endif
23 #ifdef HAVE_SYS_TYPES_H
24 #include <sys/types.h>
25 #endif
27 #include "ext2_fs.h"
28 #include "ext2fs.h"
30 errcode_t ext2fs_resize_generic_bitmap(__u32 new_end, __u32 new_real_end,
31 ext2fs_generic_bitmap bmap)
33 errcode_t retval;
34 size_t size, new_size;
35 __u32 bitno;
37 if (!bmap)
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;
48 if (bitno > new_end)
49 bitno = new_end;
50 for (; bitno > bmap->end; bitno--)
51 ext2fs_clear_bit(bitno - bmap->start, bmap->bitmap);
53 if (new_real_end == bmap->real_end) {
54 bmap->end = new_end;
55 return 0;
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);
63 if (retval)
64 return retval;
66 if (new_size > size)
67 memset(bmap->bitmap + size, 0, new_size - size);
69 bmap->end = new_end;
70 bmap->real_end = new_real_end;
71 return 0;
74 errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
75 ext2fs_inode_bitmap bmap)
77 errcode_t retval;
79 if (!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,
86 bmap);
87 bmap->magic = EXT2_ET_MAGIC_INODE_BITMAP;
88 return retval;
91 errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
92 ext2fs_block_bitmap bmap)
94 errcode_t retval;
96 if (!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,
103 bmap);
104 bmap->magic = EXT2_ET_MAGIC_BLOCK_BITMAP;
105 return retval;