• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 Library
9  * General Public License, version 2.
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 
ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap)30 void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap)
31 {
32 	ext2fs_free_generic_bitmap(bitmap);
33 }
34 
ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap)35 void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap)
36 {
37 	ext2fs_free_generic_bitmap(bitmap);
38 }
39 
ext2fs_copy_bitmap(ext2fs_generic_bitmap src,ext2fs_generic_bitmap * dest)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 
ext2fs_set_bitmap_padding(ext2fs_generic_bitmap map)46 void ext2fs_set_bitmap_padding(ext2fs_generic_bitmap map)
47 {
48 	ext2fs_set_generic_bitmap_padding(map);
49 }
50 
ext2fs_allocate_inode_bitmap(ext2_filsys fs,const char * descr,ext2fs_inode_bitmap * ret)51 errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
52 				       const char *descr,
53 				       ext2fs_inode_bitmap *ret)
54 {
55 	__u32		start, end, real_end;
56 
57 	EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
58 
59 	fs->write_bitmaps = ext2fs_write_bitmaps;
60 
61 	start = 1;
62 	end = fs->super->s_inodes_count;
63 	real_end = (EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count);
64 
65 	return (ext2fs_make_generic_bitmap(EXT2_ET_MAGIC_INODE_BITMAP, fs,
66 					   start, end, real_end,
67 					   descr, 0, ret));
68 }
69 
ext2fs_allocate_block_bitmap(ext2_filsys fs,const char * descr,ext2fs_block_bitmap * ret)70 errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
71 				       const char *descr,
72 				       ext2fs_block_bitmap *ret)
73 {
74 	__u32		start, end, real_end;
75 
76 	EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
77 
78 	fs->write_bitmaps = ext2fs_write_bitmaps;
79 
80 	start = fs->super->s_first_data_block;
81 	end = fs->super->s_blocks_count-1;
82 	real_end = (EXT2_BLOCKS_PER_GROUP(fs->super)
83 		    * fs->group_desc_count)-1 + start;
84 
85 	return (ext2fs_make_generic_bitmap(EXT2_ET_MAGIC_BLOCK_BITMAP, fs,
86 					   start, end, real_end,
87 					   descr, 0, ret));
88 }
89 
ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,ext2_ino_t end,ext2_ino_t * oend)90 errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
91 					ext2_ino_t end, ext2_ino_t *oend)
92 {
93 
94 	return (ext2fs_fudge_generic_bitmap_end(bitmap,
95 						EXT2_ET_MAGIC_INODE_BITMAP,
96 						EXT2_ET_FUDGE_INODE_BITMAP_END,
97 						end, oend));
98 }
99 
ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,blk_t end,blk_t * oend)100 errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
101 					blk_t end, blk_t *oend)
102 {
103 	return (ext2fs_fudge_generic_bitmap_end(bitmap,
104 						EXT2_ET_MAGIC_BLOCK_BITMAP,
105 						EXT2_ET_FUDGE_BLOCK_BITMAP_END,
106 						end, oend));
107 }
108 
ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap)109 void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap)
110 {
111 	ext2fs_clear_generic_bitmap(bitmap);
112 }
113 
ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap)114 void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap)
115 {
116 	ext2fs_clear_generic_bitmap(bitmap);
117 }
118 
ext2fs_resize_inode_bitmap(__u32 new_end,__u32 new_real_end,ext2fs_inode_bitmap bmap)119 errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
120 				     ext2fs_inode_bitmap bmap)
121 {
122 	return (ext2fs_resize_generic_bitmap(EXT2_ET_MAGIC_INODE_BITMAP,
123 					     new_end, new_real_end, bmap));
124 }
125 
ext2fs_resize_block_bitmap(__u32 new_end,__u32 new_real_end,ext2fs_block_bitmap bmap)126 errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
127 				     ext2fs_block_bitmap bmap)
128 {
129 	return (ext2fs_resize_generic_bitmap(EXT2_ET_MAGIC_BLOCK_BITMAP,
130 					     new_end, new_real_end, bmap));
131 }
132 
ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,ext2fs_block_bitmap bm2)133 errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
134 				      ext2fs_block_bitmap bm2)
135 {
136 	return (ext2fs_compare_generic_bitmap(EXT2_ET_MAGIC_BLOCK_BITMAP,
137 					      EXT2_ET_NEQ_BLOCK_BITMAP,
138 					      bm1, bm2));
139 }
140 
ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,ext2fs_inode_bitmap bm2)141 errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
142 				      ext2fs_inode_bitmap bm2)
143 {
144 	return (ext2fs_compare_generic_bitmap(EXT2_ET_MAGIC_INODE_BITMAP,
145 					      EXT2_ET_NEQ_INODE_BITMAP,
146 					      bm1, bm2));
147 }
148 
ext2fs_set_inode_bitmap_range(ext2fs_inode_bitmap bmap,ext2_ino_t start,unsigned int num,void * in)149 errcode_t ext2fs_set_inode_bitmap_range(ext2fs_inode_bitmap bmap,
150 					ext2_ino_t start, unsigned int num,
151 					void *in)
152 {
153 	return (ext2fs_set_generic_bitmap_range(bmap,
154 						EXT2_ET_MAGIC_INODE_BITMAP,
155 						start, num, in));
156 }
157 
ext2fs_get_inode_bitmap_range(ext2fs_inode_bitmap bmap,ext2_ino_t start,unsigned int num,void * out)158 errcode_t ext2fs_get_inode_bitmap_range(ext2fs_inode_bitmap bmap,
159 					ext2_ino_t start, unsigned int num,
160 					void *out)
161 {
162 	return (ext2fs_get_generic_bitmap_range(bmap,
163 						EXT2_ET_MAGIC_INODE_BITMAP,
164 						start, num, out));
165 }
166 
ext2fs_set_block_bitmap_range(ext2fs_block_bitmap bmap,blk_t start,unsigned int num,void * in)167 errcode_t ext2fs_set_block_bitmap_range(ext2fs_block_bitmap bmap,
168 					blk_t start, unsigned int num,
169 					void *in)
170 {
171 	return (ext2fs_set_generic_bitmap_range(bmap,
172 						EXT2_ET_MAGIC_BLOCK_BITMAP,
173 						start, num, in));
174 }
175 
ext2fs_get_block_bitmap_range(ext2fs_block_bitmap bmap,blk_t start,unsigned int num,void * out)176 errcode_t ext2fs_get_block_bitmap_range(ext2fs_block_bitmap bmap,
177 					blk_t start, unsigned int num,
178 					void *out)
179 {
180 	return (ext2fs_get_generic_bitmap_range(bmap,
181 						EXT2_ET_MAGIC_BLOCK_BITMAP,
182 						start, num, out));
183 }
184