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.
25 #include <sys/types.h>
33 void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap)
35 ext2fs_free_generic_bmap(bitmap);
38 void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap)
40 ext2fs_free_generic_bmap(bitmap);
43 errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
44 ext2fs_generic_bitmap *dest)
46 return (ext2fs_copy_generic_bmap(src, dest));
49 errcode_t ext2fs_merge_bitmap(ext2fs_generic_bitmap src,
50 ext2fs_generic_bitmap dest,
51 ext2fs_generic_bitmap dup,
52 ext2fs_generic_bitmap dup_allowed)
54 return ext2fs_merge_generic_bmap(src, dest, dup,
58 void ext2fs_set_bitmap_padding(ext2fs_generic_bitmap map)
60 ext2fs_set_generic_bmap_padding(map);
63 errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
65 ext2fs_inode_bitmap *ret)
67 __u64 start, end, real_end;
69 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
71 if (ext2fs_has_feature_journal_dev(fs->super))
72 return EXT2_ET_EXTERNAL_JOURNAL_NOSUPP;
74 fs->write_bitmaps = ext2fs_write_bitmaps;
77 end = fs->super->s_inodes_count;
78 real_end = (__u64)EXT2_INODES_PER_GROUP(fs->super) *
81 /* Are we permitted to use new-style bitmaps? */
82 if (fs->flags & EXT2_FLAG_64BITS)
83 return (ext2fs_alloc_generic_bmap(fs,
84 EXT2_ET_MAGIC_INODE_BITMAP64,
85 fs->default_bitmap_type,
86 start, end, real_end, descr, ret));
88 /* Otherwise, check to see if the file system is small enough
89 * to use old-style 32-bit bitmaps */
90 if ((end > ~0U) || (real_end > ~0U))
91 return EXT2_ET_CANT_USE_LEGACY_BITMAPS;
93 return (ext2fs_make_generic_bitmap(EXT2_ET_MAGIC_INODE_BITMAP, fs,
96 (ext2fs_generic_bitmap *) ret));
99 errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
101 ext2fs_block_bitmap *ret)
103 __u64 start, end, real_end;
105 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
107 if (ext2fs_has_feature_journal_dev(fs->super))
108 return EXT2_ET_EXTERNAL_JOURNAL_NOSUPP;
110 fs->write_bitmaps = ext2fs_write_bitmaps;
112 start = EXT2FS_B2C(fs, fs->super->s_first_data_block);
113 end = EXT2FS_B2C(fs, ext2fs_blocks_count(fs->super)-1);
114 real_end = ((__u64) EXT2_CLUSTERS_PER_GROUP(fs->super)
115 * (__u64) fs->group_desc_count)-1 + start;
117 if (fs->flags & EXT2_FLAG_64BITS)
118 return (ext2fs_alloc_generic_bmap(fs,
119 EXT2_ET_MAGIC_BLOCK_BITMAP64,
120 fs->default_bitmap_type,
121 start, end, real_end, descr, ret));
123 if ((end > ~0U) || (real_end > ~0U))
124 return EXT2_ET_CANT_USE_LEGACY_BITMAPS;
126 return (ext2fs_make_generic_bitmap(EXT2_ET_MAGIC_BLOCK_BITMAP, fs,
127 start, end, real_end,
129 (ext2fs_generic_bitmap *) ret));
133 * ext2fs_allocate_block_bitmap() really allocates a per-cluster
134 * bitmap for backwards compatibility. This function allocates a
135 * block bitmap which is truly per-block, even if clusters/bigalloc
136 * are enabled. mke2fs and e2fsck need this for tracking the
137 * allocation of the file system metadata blocks.
139 errcode_t ext2fs_allocate_subcluster_bitmap(ext2_filsys fs,
141 ext2fs_block_bitmap *ret)
143 __u64 start, end, real_end;
144 ext2fs_generic_bitmap bmap;
145 ext2fs_generic_bitmap_64 bmap64;
148 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
150 if (ext2fs_has_feature_journal_dev(fs->super))
151 return EXT2_ET_EXTERNAL_JOURNAL_NOSUPP;
153 fs->write_bitmaps = ext2fs_write_bitmaps;
155 if (!fs->cluster_ratio_bits)
156 return ext2fs_allocate_block_bitmap(fs, descr, ret);
158 if ((fs->flags & EXT2_FLAG_64BITS) == 0)
159 return EXT2_ET_CANT_USE_LEGACY_BITMAPS;
161 start = fs->super->s_first_data_block;
162 end = ext2fs_blocks_count(fs->super)-1;
163 real_end = ((__u64) EXT2_BLOCKS_PER_GROUP(fs->super)
164 * (__u64) fs->group_desc_count)-1 + start;
166 retval = ext2fs_alloc_generic_bmap(fs, EXT2_ET_MAGIC_BLOCK_BITMAP64,
167 fs->default_bitmap_type, start,
168 end, real_end, descr, &bmap);
171 bmap64 = (ext2fs_generic_bitmap_64) bmap;
172 bmap64->cluster_bits = 0;
177 int ext2fs_get_bitmap_granularity(ext2fs_block_bitmap bitmap)
179 ext2fs_generic_bitmap_64 bmap = (ext2fs_generic_bitmap_64) bitmap;
181 if (!EXT2FS_IS_64_BITMAP(bmap))
184 return bmap->cluster_bits;
187 errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
188 ext2_ino_t end, ext2_ino_t *oend)
193 retval = ext2fs_fudge_generic_bmap_end((ext2fs_generic_bitmap) bitmap,
194 EXT2_ET_FUDGE_INODE_BITMAP_END,
201 errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
202 blk_t end, blk_t *oend)
204 return (ext2fs_fudge_generic_bitmap_end(bitmap,
205 EXT2_ET_MAGIC_BLOCK_BITMAP,
206 EXT2_ET_FUDGE_BLOCK_BITMAP_END,
210 errcode_t ext2fs_fudge_block_bitmap_end2(ext2fs_block_bitmap bitmap,
211 blk64_t end, blk64_t *oend)
213 return (ext2fs_fudge_generic_bmap_end(bitmap,
214 EXT2_ET_FUDGE_BLOCK_BITMAP_END,
218 void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap)
220 ext2fs_clear_generic_bmap(bitmap);
223 void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap)
225 ext2fs_clear_generic_bmap(bitmap);
228 errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
229 ext2fs_inode_bitmap bmap)
231 return (ext2fs_resize_generic_bitmap(EXT2_ET_MAGIC_INODE_BITMAP,
232 new_end, new_real_end, bmap));
235 errcode_t ext2fs_resize_inode_bitmap2(__u64 new_end, __u64 new_real_end,
236 ext2fs_inode_bitmap bmap)
238 return (ext2fs_resize_generic_bmap(bmap, new_end, new_real_end));
241 errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
242 ext2fs_block_bitmap bmap)
244 return (ext2fs_resize_generic_bitmap(EXT2_ET_MAGIC_BLOCK_BITMAP,
245 new_end, new_real_end, bmap));
248 errcode_t ext2fs_resize_block_bitmap2(__u64 new_end, __u64 new_real_end,
249 ext2fs_block_bitmap bmap)
251 return (ext2fs_resize_generic_bmap(bmap, new_end, new_real_end));
254 errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
255 ext2fs_block_bitmap bm2)
257 return (ext2fs_compare_generic_bmap(EXT2_ET_NEQ_BLOCK_BITMAP,
261 errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
262 ext2fs_inode_bitmap bm2)
264 return (ext2fs_compare_generic_bmap(EXT2_ET_NEQ_INODE_BITMAP,
268 errcode_t ext2fs_set_inode_bitmap_range(ext2fs_inode_bitmap bmap,
269 ext2_ino_t start, unsigned int num,
272 return (ext2fs_set_generic_bitmap_range(bmap,
273 EXT2_ET_MAGIC_INODE_BITMAP,
277 errcode_t ext2fs_set_inode_bitmap_range2(ext2fs_inode_bitmap bmap,
278 __u64 start, size_t num,
281 return (ext2fs_set_generic_bmap_range(bmap, start, num, in));
284 errcode_t ext2fs_get_inode_bitmap_range(ext2fs_inode_bitmap bmap,
285 ext2_ino_t start, unsigned int num,
288 return (ext2fs_get_generic_bitmap_range(bmap,
289 EXT2_ET_MAGIC_INODE_BITMAP,
293 errcode_t ext2fs_get_inode_bitmap_range2(ext2fs_inode_bitmap bmap,
294 __u64 start, size_t num,
297 return (ext2fs_get_generic_bmap_range(bmap, start, num, out));
300 errcode_t ext2fs_set_block_bitmap_range(ext2fs_block_bitmap bmap,
301 blk_t start, unsigned int num,
304 return (ext2fs_set_generic_bitmap_range(bmap,
305 EXT2_ET_MAGIC_BLOCK_BITMAP,
309 errcode_t ext2fs_set_block_bitmap_range2(ext2fs_block_bitmap bmap,
310 blk64_t start, size_t num,
313 return (ext2fs_set_generic_bmap_range(bmap, start, num, in));
316 errcode_t ext2fs_get_block_bitmap_range(ext2fs_block_bitmap bmap,
317 blk_t start, unsigned int num,
320 return (ext2fs_get_generic_bitmap_range(bmap,
321 EXT2_ET_MAGIC_BLOCK_BITMAP,
325 errcode_t ext2fs_get_block_bitmap_range2(ext2fs_block_bitmap bmap,
326 blk64_t start, size_t num,
329 return (ext2fs_get_generic_bmap_range(bmap, start, num, out));