4 * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Public
19 errcode_t ext2fs_get_mem(unsigned long size, void *ptr)
21 void **pp = (void **)ptr;
25 return EXT2_ET_NO_MEMORY;
32 errcode_t ext2fs_free_mem(void *ptr)
34 void **pp = (void **)ptr;
44 errcode_t ext2fs_resize_mem(unsigned long EXT2FS_ATTR((unused)) old_size,
45 unsigned long size, void *ptr)
49 /* Use "memcpy" for pointer assignments here to avoid problems
50 * with C99 strict type aliasing rules. */
51 memcpy(&p, ptr, sizeof (p));
54 return EXT2_ET_NO_MEMORY;
55 memcpy(ptr, &p, sizeof (p));
60 * Mark a filesystem superblock as dirty
62 void ext2fs_mark_super_dirty(ext2_filsys fs)
64 fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
68 * Mark a filesystem as changed
70 void ext2fs_mark_changed(ext2_filsys fs)
72 fs->flags |= EXT2_FLAG_CHANGED;
76 * Check to see if a filesystem has changed
78 int ext2fs_test_changed(ext2_filsys fs)
80 return (fs->flags & EXT2_FLAG_CHANGED);
84 * Mark a filesystem as valid
86 void ext2fs_mark_valid(ext2_filsys fs)
88 fs->flags |= EXT2_FLAG_VALID;
92 * Mark a filesystem as NOT valid
94 void ext2fs_unmark_valid(ext2_filsys fs)
96 fs->flags &= ~EXT2_FLAG_VALID;
100 * Check to see if a filesystem is valid
102 int ext2fs_test_valid(ext2_filsys fs)
104 return (fs->flags & EXT2_FLAG_VALID);
108 * Mark the inode bitmap as dirty
110 void ext2fs_mark_ib_dirty(ext2_filsys fs)
112 fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
116 * Mark the block bitmap as dirty
118 void ext2fs_mark_bb_dirty(ext2_filsys fs)
120 fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
124 * Check to see if a filesystem's inode bitmap is dirty
126 int ext2fs_test_ib_dirty(ext2_filsys fs)
128 return (fs->flags & EXT2_FLAG_IB_DIRTY);
132 * Check to see if a filesystem's block bitmap is dirty
134 int ext2fs_test_bb_dirty(ext2_filsys fs)
136 return (fs->flags & EXT2_FLAG_BB_DIRTY);
140 * Return the group # of a block
142 int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
144 return (blk - fs->super->s_first_data_block) /
145 fs->super->s_blocks_per_group;
149 * Return the group # of an inode number
151 int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino)
153 return (ino - 1) / fs->super->s_inodes_per_group;
156 blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
157 struct ext2_inode *inode)
159 return inode->i_blocks -
160 (inode->i_file_acl ? fs->blocksize >> 9 : 0);
171 __u16 ext2fs_swab16(__u16 val)
173 return (val >> 8) | (val << 8);
176 __u32 ext2fs_swab32(__u32 val)
178 return ((val>>24) | ((val>>8)&0xFF00) |
179 ((val<<8)&0xFF0000) | (val<<24));
182 int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap,
185 int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap,
188 if ((bitno < bitmap->start) || (bitno > bitmap->end)) {
189 ext2fs_warn_bitmap2(bitmap, EXT2FS_TEST_ERROR, bitno);
192 return ext2fs_test_bit(bitno - bitmap->start, bitmap->bitmap);
195 int ext2fs_mark_block_bitmap(ext2fs_block_bitmap bitmap,
198 return ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap)
203 int ext2fs_unmark_block_bitmap(ext2fs_block_bitmap bitmap,
206 return ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap,
210 int ext2fs_test_block_bitmap(ext2fs_block_bitmap bitmap,
213 return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) bitmap,
217 int ext2fs_mark_inode_bitmap(ext2fs_inode_bitmap bitmap,
220 return ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) bitmap,
224 int ext2fs_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap,
227 return ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap,
231 int ext2fs_test_inode_bitmap(ext2fs_inode_bitmap bitmap,
234 return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) bitmap,
238 void ext2fs_fast_mark_block_bitmap(ext2fs_block_bitmap bitmap,
241 ext2fs_set_bit(block - bitmap->start, bitmap->bitmap);
244 void ext2fs_fast_unmark_block_bitmap(ext2fs_block_bitmap bitmap,
247 ext2fs_clear_bit(block - bitmap->start, bitmap->bitmap);
250 int ext2fs_fast_test_block_bitmap(ext2fs_block_bitmap bitmap,
253 return ext2fs_test_bit(block - bitmap->start, bitmap->bitmap);
256 void ext2fs_fast_mark_inode_bitmap(ext2fs_inode_bitmap bitmap,
259 ext2fs_set_bit(inode - bitmap->start, bitmap->bitmap);
262 void ext2fs_fast_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap,
265 ext2fs_clear_bit(inode - bitmap->start, bitmap->bitmap);
268 int ext2fs_fast_test_inode_bitmap(ext2fs_inode_bitmap bitmap,
271 return ext2fs_test_bit(inode - bitmap->start, bitmap->bitmap);
274 blk_t ext2fs_get_block_bitmap_start(ext2fs_block_bitmap bitmap)
276 return bitmap->start;
279 ext2_ino_t ext2fs_get_inode_bitmap_start(ext2fs_inode_bitmap bitmap)
281 return bitmap->start;
284 blk_t ext2fs_get_block_bitmap_end(ext2fs_block_bitmap bitmap)
289 ext2_ino_t ext2fs_get_inode_bitmap_end(ext2fs_inode_bitmap bitmap)
294 int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
295 blk_t block, int num)
299 if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
300 ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST,
301 block, bitmap->description);
304 for (i=0; i < num; i++) {
305 if (ext2fs_fast_test_block_bitmap(bitmap, block+i))
311 int ext2fs_fast_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
312 blk_t block, int num)
316 for (i=0; i < num; i++) {
317 if (ext2fs_fast_test_block_bitmap(bitmap, block+i))
323 void ext2fs_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,
324 blk_t block, int num)
328 if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
329 ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block,
330 bitmap->description);
333 for (i=0; i < num; i++)
334 ext2fs_set_bit(block + i - bitmap->start, bitmap->bitmap);
337 void ext2fs_fast_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,
338 blk_t block, int num)
342 for (i=0; i < num; i++)
343 ext2fs_set_bit(block + i - bitmap->start, bitmap->bitmap);
346 void ext2fs_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,
347 blk_t block, int num)
351 if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
352 ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block,
353 bitmap->description);
356 for (i=0; i < num; i++)
357 ext2fs_clear_bit(block + i - bitmap->start, bitmap->bitmap);
360 void ext2fs_fast_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,
361 blk_t block, int num)
364 for (i=0; i < num; i++)
365 ext2fs_clear_bit(block + i - bitmap->start, bitmap->bitmap);