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
));
53 p
= xrealloc(p
, size
);
54 memcpy(ptr
, &p
, sizeof (p
));
59 * Mark a filesystem superblock as dirty
61 void ext2fs_mark_super_dirty(ext2_filsys fs
)
63 fs
->flags
|= EXT2_FLAG_DIRTY
| EXT2_FLAG_CHANGED
;
67 * Mark a filesystem as changed
69 void ext2fs_mark_changed(ext2_filsys fs
)
71 fs
->flags
|= EXT2_FLAG_CHANGED
;
75 * Check to see if a filesystem has changed
77 int ext2fs_test_changed(ext2_filsys fs
)
79 return (fs
->flags
& EXT2_FLAG_CHANGED
);
83 * Mark a filesystem as valid
85 void ext2fs_mark_valid(ext2_filsys fs
)
87 fs
->flags
|= EXT2_FLAG_VALID
;
91 * Mark a filesystem as NOT valid
93 void ext2fs_unmark_valid(ext2_filsys fs
)
95 fs
->flags
&= ~EXT2_FLAG_VALID
;
99 * Check to see if a filesystem is valid
101 int ext2fs_test_valid(ext2_filsys fs
)
103 return (fs
->flags
& EXT2_FLAG_VALID
);
107 * Mark the inode bitmap as dirty
109 void ext2fs_mark_ib_dirty(ext2_filsys fs
)
111 fs
->flags
|= EXT2_FLAG_IB_DIRTY
| EXT2_FLAG_CHANGED
;
115 * Mark the block bitmap as dirty
117 void ext2fs_mark_bb_dirty(ext2_filsys fs
)
119 fs
->flags
|= EXT2_FLAG_BB_DIRTY
| EXT2_FLAG_CHANGED
;
123 * Check to see if a filesystem's inode bitmap is dirty
125 int ext2fs_test_ib_dirty(ext2_filsys fs
)
127 return (fs
->flags
& EXT2_FLAG_IB_DIRTY
);
131 * Check to see if a filesystem's block bitmap is dirty
133 int ext2fs_test_bb_dirty(ext2_filsys fs
)
135 return (fs
->flags
& EXT2_FLAG_BB_DIRTY
);
139 * Return the group # of a block
141 int ext2fs_group_of_blk(ext2_filsys fs
, blk_t blk
)
143 return (blk
- fs
->super
->s_first_data_block
) /
144 fs
->super
->s_blocks_per_group
;
148 * Return the group # of an inode number
150 int ext2fs_group_of_ino(ext2_filsys fs
, ext2_ino_t ino
)
152 return (ino
- 1) / fs
->super
->s_inodes_per_group
;
155 blk_t
ext2fs_inode_data_blocks(ext2_filsys fs
,
156 struct ext2_inode
*inode
)
158 return inode
->i_blocks
-
159 (inode
->i_file_acl
? fs
->blocksize
>> 9 : 0);
170 __u16
ext2fs_swab16(__u16 val
)
172 return (val
>> 8) | (val
<< 8);
175 __u32
ext2fs_swab32(__u32 val
)
177 return ((val
>>24) | ((val
>>8)&0xFF00) |
178 ((val
<<8)&0xFF0000) | (val
<<24));
181 int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap
,
184 int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap
,
187 if ((bitno
< bitmap
->start
) || (bitno
> bitmap
->end
)) {
188 ext2fs_warn_bitmap2(bitmap
, EXT2FS_TEST_ERROR
, bitno
);
191 return ext2fs_test_bit(bitno
- bitmap
->start
, bitmap
->bitmap
);
194 int ext2fs_mark_block_bitmap(ext2fs_block_bitmap bitmap
,
197 return ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap
)
202 int ext2fs_unmark_block_bitmap(ext2fs_block_bitmap bitmap
,
205 return ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap
) bitmap
,
209 int ext2fs_test_block_bitmap(ext2fs_block_bitmap bitmap
,
212 return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap
) bitmap
,
216 int ext2fs_mark_inode_bitmap(ext2fs_inode_bitmap bitmap
,
219 return ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap
) bitmap
,
223 int ext2fs_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap
,
226 return ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap
) bitmap
,
230 int ext2fs_test_inode_bitmap(ext2fs_inode_bitmap bitmap
,
233 return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap
) bitmap
,
237 void ext2fs_fast_mark_block_bitmap(ext2fs_block_bitmap bitmap
,
240 ext2fs_set_bit(block
- bitmap
->start
, bitmap
->bitmap
);
243 void ext2fs_fast_unmark_block_bitmap(ext2fs_block_bitmap bitmap
,
246 ext2fs_clear_bit(block
- bitmap
->start
, bitmap
->bitmap
);
249 int ext2fs_fast_test_block_bitmap(ext2fs_block_bitmap bitmap
,
252 return ext2fs_test_bit(block
- bitmap
->start
, bitmap
->bitmap
);
255 void ext2fs_fast_mark_inode_bitmap(ext2fs_inode_bitmap bitmap
,
258 ext2fs_set_bit(inode
- bitmap
->start
, bitmap
->bitmap
);
261 void ext2fs_fast_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap
,
264 ext2fs_clear_bit(inode
- bitmap
->start
, bitmap
->bitmap
);
267 int ext2fs_fast_test_inode_bitmap(ext2fs_inode_bitmap bitmap
,
270 return ext2fs_test_bit(inode
- bitmap
->start
, bitmap
->bitmap
);
273 blk_t
ext2fs_get_block_bitmap_start(ext2fs_block_bitmap bitmap
)
275 return bitmap
->start
;
278 ext2_ino_t
ext2fs_get_inode_bitmap_start(ext2fs_inode_bitmap bitmap
)
280 return bitmap
->start
;
283 blk_t
ext2fs_get_block_bitmap_end(ext2fs_block_bitmap bitmap
)
288 ext2_ino_t
ext2fs_get_inode_bitmap_end(ext2fs_inode_bitmap bitmap
)
293 int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap
,
294 blk_t block
, int num
)
298 if ((block
< bitmap
->start
) || (block
+num
-1 > bitmap
->end
)) {
299 ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST
,
300 block
, bitmap
->description
);
303 for (i
=0; i
< num
; i
++) {
304 if (ext2fs_fast_test_block_bitmap(bitmap
, block
+i
))
310 int ext2fs_fast_test_block_bitmap_range(ext2fs_block_bitmap bitmap
,
311 blk_t block
, int num
)
315 for (i
=0; i
< num
; i
++) {
316 if (ext2fs_fast_test_block_bitmap(bitmap
, block
+i
))
322 void ext2fs_mark_block_bitmap_range(ext2fs_block_bitmap bitmap
,
323 blk_t block
, int num
)
327 if ((block
< bitmap
->start
) || (block
+num
-1 > bitmap
->end
)) {
328 ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK
, block
,
329 bitmap
->description
);
332 for (i
=0; i
< num
; i
++)
333 ext2fs_set_bit(block
+ i
- bitmap
->start
, bitmap
->bitmap
);
336 void ext2fs_fast_mark_block_bitmap_range(ext2fs_block_bitmap bitmap
,
337 blk_t block
, int num
)
341 for (i
=0; i
< num
; i
++)
342 ext2fs_set_bit(block
+ i
- bitmap
->start
, bitmap
->bitmap
);
345 void ext2fs_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap
,
346 blk_t block
, int num
)
350 if ((block
< bitmap
->start
) || (block
+num
-1 > bitmap
->end
)) {
351 ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK
, block
,
352 bitmap
->description
);
355 for (i
=0; i
< num
; i
++)
356 ext2fs_clear_bit(block
+ i
- bitmap
->start
, bitmap
->bitmap
);
359 void ext2fs_fast_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap
,
360 blk_t block
, int num
)
363 for (i
=0; i
< num
; i
++)
364 ext2fs_clear_bit(block
+ i
- bitmap
->start
, bitmap
->bitmap
);