Whamcloud - gitweb
libext2fs: 32-bit bitmap refactorization, part 1
[tools/e2fsprogs.git] / lib / ext2fs / bitmaps.c
1 /*
2  * bitmaps.c --- routines to read, write, and manipulate the inode and
3  * block bitmaps.
4  *
5  * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
6  *
7  * %Begin-Header%
8  * This file may be redistributed under the terms of the GNU Public
9  * License.
10  * %End-Header%
11  */
12
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 #if HAVE_SYS_STAT_H
21 #include <sys/stat.h>
22 #endif
23 #if HAVE_SYS_TYPES_H
24 #include <sys/types.h>
25 #endif
26
27 #include "ext2_fs.h"
28 #include "ext2fs.h"
29
30 void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap)
31 {
32         ext2fs_free_generic_bitmap(bitmap);
33 }
34
35 void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap)
36 {
37         ext2fs_free_generic_bitmap(bitmap);
38 }
39
40 errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
41                              ext2fs_generic_bitmap *dest)
42 {
43         return (ext2fs_copy_generic_bitmap(src, dest));
44 }
45
46 void ext2fs_set_bitmap_padding(ext2fs_generic_bitmap map)
47 {
48         ext2fs_set_generic_bitmap_padding(map);
49 }       
50
51 errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
52                                        const char *descr,
53                                        ext2fs_inode_bitmap *ret)
54 {
55         errcode_t       retval;
56         __u32           start, end, real_end;
57
58         EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
59
60         fs->write_bitmaps = ext2fs_write_bitmaps;
61
62         start = 1;
63         end = fs->super->s_inodes_count;
64         real_end = (EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count);
65
66         return (ext2fs_make_generic_bitmap(EXT2_ET_MAGIC_INODE_BITMAP, fs,
67                                            start, end, real_end,
68                                            descr, 0, ret));
69 }
70
71 errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
72                                        const char *descr,
73                                        ext2fs_block_bitmap *ret)
74 {
75         errcode_t       retval;
76         __u32           start, end, real_end;
77
78         EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
79
80         fs->write_bitmaps = ext2fs_write_bitmaps;
81
82         start = fs->super->s_first_data_block;
83         end = fs->super->s_blocks_count-1;
84         real_end = (EXT2_BLOCKS_PER_GROUP(fs->super)  
85                     * fs->group_desc_count)-1 + start;
86         
87         return (ext2fs_make_generic_bitmap(EXT2_ET_MAGIC_BLOCK_BITMAP, fs,
88                                            start, end, real_end,
89                                            descr, 0, ret));
90 }
91
92 errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
93                                         ext2_ino_t end, ext2_ino_t *oend)
94 {
95
96         return (ext2fs_fudge_generic_bitmap_end(bitmap,
97                                                 EXT2_ET_MAGIC_INODE_BITMAP,
98                                                 EXT2_ET_FUDGE_INODE_BITMAP_END,
99                                                 end, oend));
100 }
101
102 errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
103                                         blk_t end, blk_t *oend)
104 {
105         return (ext2fs_fudge_generic_bitmap_end(bitmap,
106                                                 EXT2_ET_MAGIC_BLOCK_BITMAP,
107                                                 EXT2_ET_FUDGE_BLOCK_BITMAP_END,
108                                                 end, oend));
109 }
110
111 void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap)
112 {
113         ext2fs_clear_generic_bitmap(bitmap);
114 }
115
116 void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap)
117 {
118         ext2fs_clear_generic_bitmap(bitmap);
119 }