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));
48 void ext2fs_set_bitmap_padding(ext2fs_generic_bitmap map)
50 ext2fs_set_generic_bmap_padding(map);
53 errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
55 ext2fs_inode_bitmap *ret)
57 __u64 start, end, real_end;
59 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
61 if (ext2fs_has_feature_journal_dev(fs->super))
62 return EXT2_ET_EXTERNAL_JOURNAL_NOSUPP;
64 fs->write_bitmaps = ext2fs_write_bitmaps;
67 end = fs->super->s_inodes_count;
68 real_end = (__u64)EXT2_INODES_PER_GROUP(fs->super) *
71 /* Are we permitted to use new-style bitmaps? */
72 if (fs->flags & EXT2_FLAG_64BITS)
73 return (ext2fs_alloc_generic_bmap(fs,
74 EXT2_ET_MAGIC_INODE_BITMAP64,
75 fs->default_bitmap_type,
76 start, end, real_end, descr, ret));
78 /* Otherwise, check to see if the file system is small enough
79 * to use old-style 32-bit bitmaps */
80 if ((end > ~0U) || (real_end > ~0U))
81 return EXT2_ET_CANT_USE_LEGACY_BITMAPS;
83 return (ext2fs_make_generic_bitmap(EXT2_ET_MAGIC_INODE_BITMAP, fs,
86 (ext2fs_generic_bitmap *) ret));
89 errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
91 ext2fs_block_bitmap *ret)
93 __u64 start, end, real_end;
95 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
97 if (ext2fs_has_feature_journal_dev(fs->super))
98 return EXT2_ET_EXTERNAL_JOURNAL_NOSUPP;
100 fs->write_bitmaps = ext2fs_write_bitmaps;
102 start = EXT2FS_B2C(fs, fs->super->s_first_data_block);
103 end = EXT2FS_B2C(fs, ext2fs_blocks_count(fs->super)-1);
104 real_end = ((__u64) EXT2_CLUSTERS_PER_GROUP(fs->super)
105 * (__u64) fs->group_desc_count)-1 + start;
107 if (fs->flags & EXT2_FLAG_64BITS)
108 return (ext2fs_alloc_generic_bmap(fs,
109 EXT2_ET_MAGIC_BLOCK_BITMAP64,
110 fs->default_bitmap_type,
111 start, end, real_end, descr, ret));
113 if ((end > ~0U) || (real_end > ~0U))
114 return EXT2_ET_CANT_USE_LEGACY_BITMAPS;
116 return (ext2fs_make_generic_bitmap(EXT2_ET_MAGIC_BLOCK_BITMAP, fs,
117 start, end, real_end,
119 (ext2fs_generic_bitmap *) ret));
123 * ext2fs_allocate_block_bitmap() really allocates a per-cluster
124 * bitmap for backwards compatibility. This function allocates a
125 * block bitmap which is truly per-block, even if clusters/bigalloc
126 * are enabled. mke2fs and e2fsck need this for tracking the
127 * allocation of the file system metadata blocks.
129 errcode_t ext2fs_allocate_subcluster_bitmap(ext2_filsys fs,
131 ext2fs_block_bitmap *ret)
133 __u64 start, end, real_end;
134 ext2fs_generic_bitmap bmap;
135 ext2fs_generic_bitmap_64 bmap64;
138 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
140 if (ext2fs_has_feature_journal_dev(fs->super))
141 return EXT2_ET_EXTERNAL_JOURNAL_NOSUPP;
143 fs->write_bitmaps = ext2fs_write_bitmaps;
145 if (!fs->cluster_ratio_bits)
146 return ext2fs_allocate_block_bitmap(fs, descr, ret);
148 if ((fs->flags & EXT2_FLAG_64BITS) == 0)
149 return EXT2_ET_CANT_USE_LEGACY_BITMAPS;
151 start = fs->super->s_first_data_block;
152 end = ext2fs_blocks_count(fs->super)-1;
153 real_end = ((__u64) EXT2_BLOCKS_PER_GROUP(fs->super)
154 * (__u64) fs->group_desc_count)-1 + start;
156 retval = ext2fs_alloc_generic_bmap(fs, EXT2_ET_MAGIC_BLOCK_BITMAP64,
157 fs->default_bitmap_type, start,
158 end, real_end, descr, &bmap);
161 bmap64 = (ext2fs_generic_bitmap_64) bmap;
162 bmap64->cluster_bits = 0;
167 int ext2fs_get_bitmap_granularity(ext2fs_block_bitmap bitmap)
169 ext2fs_generic_bitmap_64 bmap = (ext2fs_generic_bitmap_64) bitmap;
171 if (!EXT2FS_IS_64_BITMAP(bmap))
174 return bmap->cluster_bits;
177 errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
178 ext2_ino_t end, ext2_ino_t *oend)
183 retval = ext2fs_fudge_generic_bmap_end((ext2fs_generic_bitmap) bitmap,
184 EXT2_ET_FUDGE_INODE_BITMAP_END,
191 errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
192 blk_t end, blk_t *oend)
194 return (ext2fs_fudge_generic_bitmap_end(bitmap,
195 EXT2_ET_MAGIC_BLOCK_BITMAP,
196 EXT2_ET_FUDGE_BLOCK_BITMAP_END,
200 errcode_t ext2fs_fudge_block_bitmap_end2(ext2fs_block_bitmap bitmap,
201 blk64_t end, blk64_t *oend)
203 return (ext2fs_fudge_generic_bmap_end(bitmap,
204 EXT2_ET_FUDGE_BLOCK_BITMAP_END,
208 void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap)
210 ext2fs_clear_generic_bmap(bitmap);
213 void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap)
215 ext2fs_clear_generic_bmap(bitmap);
218 errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
219 ext2fs_inode_bitmap bmap)
221 return (ext2fs_resize_generic_bitmap(EXT2_ET_MAGIC_INODE_BITMAP,
222 new_end, new_real_end, bmap));
225 errcode_t ext2fs_resize_inode_bitmap2(__u64 new_end, __u64 new_real_end,
226 ext2fs_inode_bitmap bmap)
228 return (ext2fs_resize_generic_bmap(bmap, new_end, new_real_end));
231 errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
232 ext2fs_block_bitmap bmap)
234 return (ext2fs_resize_generic_bitmap(EXT2_ET_MAGIC_BLOCK_BITMAP,
235 new_end, new_real_end, bmap));
238 errcode_t ext2fs_resize_block_bitmap2(__u64 new_end, __u64 new_real_end,
239 ext2fs_block_bitmap bmap)
241 return (ext2fs_resize_generic_bmap(bmap, new_end, new_real_end));
244 errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
245 ext2fs_block_bitmap bm2)
247 return (ext2fs_compare_generic_bmap(EXT2_ET_NEQ_BLOCK_BITMAP,
251 errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
252 ext2fs_inode_bitmap bm2)
254 return (ext2fs_compare_generic_bmap(EXT2_ET_NEQ_INODE_BITMAP,
258 errcode_t ext2fs_set_inode_bitmap_range(ext2fs_inode_bitmap bmap,
259 ext2_ino_t start, unsigned int num,
262 return (ext2fs_set_generic_bitmap_range(bmap,
263 EXT2_ET_MAGIC_INODE_BITMAP,
267 errcode_t ext2fs_set_inode_bitmap_range2(ext2fs_inode_bitmap bmap,
268 __u64 start, size_t num,
271 return (ext2fs_set_generic_bmap_range(bmap, start, num, in));
274 errcode_t ext2fs_get_inode_bitmap_range(ext2fs_inode_bitmap bmap,
275 ext2_ino_t start, unsigned int num,
278 return (ext2fs_get_generic_bitmap_range(bmap,
279 EXT2_ET_MAGIC_INODE_BITMAP,
283 errcode_t ext2fs_get_inode_bitmap_range2(ext2fs_inode_bitmap bmap,
284 __u64 start, size_t num,
287 return (ext2fs_get_generic_bmap_range(bmap, start, num, out));
290 errcode_t ext2fs_set_block_bitmap_range(ext2fs_block_bitmap bmap,
291 blk_t start, unsigned int num,
294 return (ext2fs_set_generic_bitmap_range(bmap,
295 EXT2_ET_MAGIC_BLOCK_BITMAP,
299 errcode_t ext2fs_set_block_bitmap_range2(ext2fs_block_bitmap bmap,
300 blk64_t start, size_t num,
303 return (ext2fs_set_generic_bmap_range(bmap, start, num, in));
306 errcode_t ext2fs_get_block_bitmap_range(ext2fs_block_bitmap bmap,
307 blk_t start, unsigned int num,
310 return (ext2fs_get_generic_bitmap_range(bmap,
311 EXT2_ET_MAGIC_BLOCK_BITMAP,
315 errcode_t ext2fs_get_block_bitmap_range2(ext2fs_block_bitmap bmap,
316 blk64_t start, size_t num,
319 return (ext2fs_get_generic_bmap_range(bmap, start, num, out));