1 /* vi: set sw=4 ts=4: */
5 * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
8 * This file may be redistributed under the terms of the GNU Public
20 errcode_t ext2fs_get_mem(unsigned long size, void *ptr)
22 void **pp = (void **)ptr;
26 return EXT2_ET_NO_MEMORY;
33 errcode_t ext2fs_free_mem(void *ptr)
35 void **pp = (void **)ptr;
45 errcode_t ext2fs_resize_mem(unsigned long EXT2FS_ATTR((unused)) old_size,
46 unsigned long size, void *ptr)
50 /* Use "memcpy" for pointer assignments here to avoid problems
51 * with C99 strict type aliasing rules. */
52 memcpy(&p, ptr, sizeof (p));
55 return EXT2_ET_NO_MEMORY;
56 memcpy(ptr, &p, sizeof (p));
61 * Mark a filesystem superblock as dirty
63 void ext2fs_mark_super_dirty(ext2_filsys fs)
65 fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
69 * Mark a filesystem as changed
71 void ext2fs_mark_changed(ext2_filsys fs)
73 fs->flags |= EXT2_FLAG_CHANGED;
77 * Check to see if a filesystem has changed
79 int ext2fs_test_changed(ext2_filsys fs)
81 return (fs->flags & EXT2_FLAG_CHANGED);
85 * Mark a filesystem as valid
87 void ext2fs_mark_valid(ext2_filsys fs)
89 fs->flags |= EXT2_FLAG_VALID;
93 * Mark a filesystem as NOT valid
95 void ext2fs_unmark_valid(ext2_filsys fs)
97 fs->flags &= ~EXT2_FLAG_VALID;
101 * Check to see if a filesystem is valid
103 int ext2fs_test_valid(ext2_filsys fs)
105 return (fs->flags & EXT2_FLAG_VALID);
109 * Mark the inode bitmap as dirty
111 void ext2fs_mark_ib_dirty(ext2_filsys fs)
113 fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
117 * Mark the block bitmap as dirty
119 void ext2fs_mark_bb_dirty(ext2_filsys fs)
121 fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
125 * Check to see if a filesystem's inode bitmap is dirty
127 int ext2fs_test_ib_dirty(ext2_filsys fs)
129 return (fs->flags & EXT2_FLAG_IB_DIRTY);
133 * Check to see if a filesystem's block bitmap is dirty
135 int ext2fs_test_bb_dirty(ext2_filsys fs)
137 return (fs->flags & EXT2_FLAG_BB_DIRTY);
141 * Return the group # of a block
143 int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
145 return (blk - fs->super->s_first_data_block) /
146 fs->super->s_blocks_per_group;
150 * Return the group # of an inode number
152 int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino)
154 return (ino - 1) / fs->super->s_inodes_per_group;
157 blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
158 struct ext2_inode *inode)
160 return inode->i_blocks -
161 (inode->i_file_acl ? fs->blocksize >> 9 : 0);
172 __u16 ext2fs_swab16(__u16 val)
174 return (val >> 8) | (val << 8);
177 __u32 ext2fs_swab32(__u32 val)
179 return ((val>>24) | ((val>>8)&0xFF00) |
180 ((val<<8)&0xFF0000) | (val<<24));
183 int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap,
186 int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap,
189 if ((bitno < bitmap->start) || (bitno > bitmap->end)) {
190 ext2fs_warn_bitmap2(bitmap, EXT2FS_TEST_ERROR, bitno);
193 return ext2fs_test_bit(bitno - bitmap->start, bitmap->bitmap);
196 int ext2fs_mark_block_bitmap(ext2fs_block_bitmap bitmap,
199 return ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap)
204 int ext2fs_unmark_block_bitmap(ext2fs_block_bitmap bitmap,
207 return ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap,
211 int ext2fs_test_block_bitmap(ext2fs_block_bitmap bitmap,
214 return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) bitmap,
218 int ext2fs_mark_inode_bitmap(ext2fs_inode_bitmap bitmap,
221 return ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) bitmap,
225 int ext2fs_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap,
228 return ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap,
232 int ext2fs_test_inode_bitmap(ext2fs_inode_bitmap bitmap,
235 return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) bitmap,
239 void ext2fs_fast_mark_block_bitmap(ext2fs_block_bitmap bitmap,
242 ext2fs_set_bit(block - bitmap->start, bitmap->bitmap);
245 void ext2fs_fast_unmark_block_bitmap(ext2fs_block_bitmap bitmap,
248 ext2fs_clear_bit(block - bitmap->start, bitmap->bitmap);
251 int ext2fs_fast_test_block_bitmap(ext2fs_block_bitmap bitmap,
254 return ext2fs_test_bit(block - bitmap->start, bitmap->bitmap);
257 void ext2fs_fast_mark_inode_bitmap(ext2fs_inode_bitmap bitmap,
260 ext2fs_set_bit(inode - bitmap->start, bitmap->bitmap);
263 void ext2fs_fast_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap,
266 ext2fs_clear_bit(inode - bitmap->start, bitmap->bitmap);
269 int ext2fs_fast_test_inode_bitmap(ext2fs_inode_bitmap bitmap,
272 return ext2fs_test_bit(inode - bitmap->start, bitmap->bitmap);
275 blk_t ext2fs_get_block_bitmap_start(ext2fs_block_bitmap bitmap)
277 return bitmap->start;
280 ext2_ino_t ext2fs_get_inode_bitmap_start(ext2fs_inode_bitmap bitmap)
282 return bitmap->start;
285 blk_t ext2fs_get_block_bitmap_end(ext2fs_block_bitmap bitmap)
290 ext2_ino_t ext2fs_get_inode_bitmap_end(ext2fs_inode_bitmap bitmap)
295 int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
296 blk_t block, int num)
300 if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
301 ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST,
302 block, bitmap->description);
305 for (i=0; i < num; i++) {
306 if (ext2fs_fast_test_block_bitmap(bitmap, block+i))
312 int ext2fs_fast_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
313 blk_t block, int num)
317 for (i=0; i < num; i++) {
318 if (ext2fs_fast_test_block_bitmap(bitmap, block+i))
324 void ext2fs_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,
325 blk_t block, int num)
329 if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
330 ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block,
331 bitmap->description);
334 for (i=0; i < num; i++)
335 ext2fs_set_bit(block + i - bitmap->start, bitmap->bitmap);
338 void ext2fs_fast_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,
339 blk_t block, int num)
343 for (i=0; i < num; i++)
344 ext2fs_set_bit(block + i - bitmap->start, bitmap->bitmap);
347 void ext2fs_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,
348 blk_t block, int num)
352 if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
353 ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block,
354 bitmap->description);
357 for (i=0; i < num; i++)
358 ext2fs_clear_bit(block + i - bitmap->start, bitmap->bitmap);
361 void ext2fs_fast_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,
362 blk_t block, int num)
365 for (i=0; i < num; i++)
366 ext2fs_clear_bit(block + i - bitmap->start, bitmap->bitmap);