2 * bitmaps.c --- routines to read, write, and manipulate the inode and
5 * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
8 * This file may be redistributed under the terms of the GNU Library
9 * General Public License, version 2.
24 #include <sys/types.h>
32 void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap)
34 ext2fs_free_generic_bmap(bitmap);
37 void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap)
39 ext2fs_free_generic_bmap(bitmap);
42 errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
43 ext2fs_generic_bitmap *dest)
45 return (ext2fs_copy_generic_bmap(src, dest));
47 void ext2fs_set_bitmap_padding(ext2fs_generic_bitmap map)
49 ext2fs_set_generic_bmap_padding(map);
52 errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
54 ext2fs_inode_bitmap *ret)
56 __u64 start, end, real_end;
58 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
60 fs->write_bitmaps = ext2fs_write_bitmaps;
63 end = fs->super->s_inodes_count;
64 real_end = (EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count);
66 /* Are we permitted to use new-style bitmaps? */
67 if (fs->flags & EXT2_FLAG_64BITS)
68 return (ext2fs_alloc_generic_bmap(fs,
69 EXT2_ET_MAGIC_INODE_BITMAP64,
70 EXT2FS_BMAP64_BITARRAY,
71 start, end, real_end, descr, ret));
73 /* Otherwise, check to see if the file system is small enough
74 * to use old-style 32-bit bitmaps */
75 if ((end > ~0U) || (real_end > ~0U))
76 return EXT2_ET_CANT_USE_LEGACY_BITMAPS;
78 return (ext2fs_make_generic_bitmap(EXT2_ET_MAGIC_INODE_BITMAP, fs,
81 (ext2fs_generic_bitmap *) ret));
84 errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
86 ext2fs_block_bitmap *ret)
88 __u64 start, end, real_end;
90 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
92 fs->write_bitmaps = ext2fs_write_bitmaps;
94 start = EXT2FS_B2C(fs, fs->super->s_first_data_block);
95 end = EXT2FS_B2C(fs, ext2fs_blocks_count(fs->super)-1);
96 real_end = ((__u64) EXT2_CLUSTERS_PER_GROUP(fs->super)
97 * (__u64) fs->group_desc_count)-1 + start;
99 if (fs->flags & EXT2_FLAG_64BITS)
100 return (ext2fs_alloc_generic_bmap(fs,
101 EXT2_ET_MAGIC_BLOCK_BITMAP64,
102 EXT2FS_BMAP64_BITARRAY,
103 start, end, real_end, descr, ret));
105 if ((end > ~0U) || (real_end > ~0U))
106 return EXT2_ET_CANT_USE_LEGACY_BITMAPS;
108 return (ext2fs_make_generic_bitmap(EXT2_ET_MAGIC_BLOCK_BITMAP, fs,
109 start, end, real_end,
111 (ext2fs_generic_bitmap *) ret));
115 * ext2fs_allocate_block_bitmap() really allocates a per-cluster
116 * bitmap for backwards compatibility. This function allocates a
117 * block bitmap which is truly per-block, even if clusters/bigalloc
118 * are enabled. mke2fs and e2fsck need this for tracking the
119 * allocation of the file system metadata blocks.
121 errcode_t ext2fs_allocate_subcluster_bitmap(ext2_filsys fs,
123 ext2fs_block_bitmap *ret)
125 __u64 start, end, real_end;
126 ext2fs_generic_bitmap bmap;
129 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
131 fs->write_bitmaps = ext2fs_write_bitmaps;
133 if (!fs->cluster_ratio_bits)
134 return ext2fs_allocate_block_bitmap(fs, descr, ret);
136 if ((fs->flags & EXT2_FLAG_64BITS) == 0)
137 return EXT2_ET_CANT_USE_LEGACY_BITMAPS;
139 start = fs->super->s_first_data_block;
140 end = ext2fs_blocks_count(fs->super)-1;
141 real_end = ((__u64) EXT2_BLOCKS_PER_GROUP(fs->super)
142 * (__u64) fs->group_desc_count)-1 + start;
144 retval = ext2fs_alloc_generic_bmap(fs, EXT2_ET_MAGIC_BLOCK_BITMAP64,
145 EXT2FS_BMAP64_BITARRAY, start,
146 end, real_end, descr, &bmap);
149 bmap->cluster_bits = 0;
154 int ext2fs_get_bitmap_granularity(ext2fs_block_bitmap bitmap)
156 ext2fs_generic_bitmap bmap = bitmap;
158 if (!EXT2FS_IS_64_BITMAP(bmap))
161 return bmap->cluster_bits;
164 errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
165 ext2_ino_t end, ext2_ino_t *oend)
170 retval = ext2fs_fudge_generic_bmap_end((ext2fs_generic_bitmap) bitmap,
171 EXT2_ET_FUDGE_INODE_BITMAP_END,
178 errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
179 blk_t end, blk_t *oend)
181 return (ext2fs_fudge_generic_bitmap_end(bitmap,
182 EXT2_ET_MAGIC_BLOCK_BITMAP,
183 EXT2_ET_FUDGE_BLOCK_BITMAP_END,
187 errcode_t ext2fs_fudge_block_bitmap_end2(ext2fs_block_bitmap bitmap,
188 blk64_t end, blk64_t *oend)
190 return (ext2fs_fudge_generic_bmap_end(bitmap,
191 EXT2_ET_FUDGE_BLOCK_BITMAP_END,
195 void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap)
197 ext2fs_clear_generic_bmap(bitmap);
200 void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap)
202 ext2fs_clear_generic_bmap(bitmap);
205 errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
206 ext2fs_inode_bitmap bmap)
208 return (ext2fs_resize_generic_bitmap(EXT2_ET_MAGIC_INODE_BITMAP,
209 new_end, new_real_end, bmap));
212 errcode_t ext2fs_resize_inode_bitmap2(__u64 new_end, __u64 new_real_end,
213 ext2fs_inode_bitmap bmap)
215 return (ext2fs_resize_generic_bmap(bmap, new_end, new_real_end));
218 errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
219 ext2fs_block_bitmap bmap)
221 return (ext2fs_resize_generic_bitmap(EXT2_ET_MAGIC_BLOCK_BITMAP,
222 new_end, new_real_end, bmap));
225 errcode_t ext2fs_resize_block_bitmap2(__u64 new_end, __u64 new_real_end,
226 ext2fs_block_bitmap bmap)
228 return (ext2fs_resize_generic_bmap(bmap, new_end, new_real_end));
231 errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
232 ext2fs_block_bitmap bm2)
234 return (ext2fs_compare_generic_bmap(EXT2_ET_NEQ_BLOCK_BITMAP,
238 errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
239 ext2fs_inode_bitmap bm2)
241 return (ext2fs_compare_generic_bmap(EXT2_ET_NEQ_INODE_BITMAP,
245 errcode_t ext2fs_set_inode_bitmap_range(ext2fs_inode_bitmap bmap,
246 ext2_ino_t start, unsigned int num,
249 return (ext2fs_set_generic_bitmap_range(bmap,
250 EXT2_ET_MAGIC_INODE_BITMAP,
254 errcode_t ext2fs_set_inode_bitmap_range2(ext2fs_inode_bitmap bmap,
255 __u64 start, size_t num,
258 return (ext2fs_set_generic_bmap_range(bmap, start, num, in));
261 errcode_t ext2fs_get_inode_bitmap_range(ext2fs_inode_bitmap bmap,
262 ext2_ino_t start, unsigned int num,
265 return (ext2fs_get_generic_bitmap_range(bmap,
266 EXT2_ET_MAGIC_INODE_BITMAP,
270 errcode_t ext2fs_get_inode_bitmap_range2(ext2fs_inode_bitmap bmap,
271 __u64 start, size_t num,
274 return (ext2fs_get_generic_bmap_range(bmap, start, num, out));
277 errcode_t ext2fs_set_block_bitmap_range(ext2fs_block_bitmap bmap,
278 blk_t start, unsigned int num,
281 return (ext2fs_set_generic_bitmap_range(bmap,
282 EXT2_ET_MAGIC_BLOCK_BITMAP,
286 errcode_t ext2fs_set_block_bitmap_range2(ext2fs_block_bitmap bmap,
287 blk64_t start, size_t num,
290 return (ext2fs_set_generic_bmap_range(bmap, start, num, in));
293 errcode_t ext2fs_get_block_bitmap_range(ext2fs_block_bitmap bmap,
294 blk_t start, unsigned int num,
297 return (ext2fs_get_generic_bitmap_range(bmap,
298 EXT2_ET_MAGIC_BLOCK_BITMAP,
302 errcode_t ext2fs_get_block_bitmap_range2(ext2fs_block_bitmap bmap,
303 blk64_t start, size_t num,
306 return (ext2fs_get_generic_bmap_range(bmap, start, num, out));