87 lines
2.7 KiB
C
87 lines
2.7 KiB
C
|
/*
|
||
|
* check_uninit.c --- check_block_uninit() and check_inode_uninit() functions
|
||
|
* copy-pasted from e2fsprogs: lib/ext2fs/alloc.c
|
||
|
*
|
||
|
* Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
|
||
|
*
|
||
|
* %Begin-Header%
|
||
|
* This file may be redistributed under the terms of the GNU Library
|
||
|
* General Public License, version 2.
|
||
|
* %End-Header%
|
||
|
*/
|
||
|
|
||
|
#include "check_uninit.h"
|
||
|
|
||
|
/*
|
||
|
* Check for uninit block bitmaps and deal with them appropriately
|
||
|
*/
|
||
|
void check_block_uninit(ext2_filsys fs, ext2fs_block_bitmap map, dgrp_t group)
|
||
|
{
|
||
|
blk_t i;
|
||
|
blk64_t blk, super_blk, old_desc_blk, new_desc_blk;
|
||
|
int old_desc_blocks;
|
||
|
|
||
|
if (!(EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
|
||
|
EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) ||
|
||
|
!(ext2fs_bg_flags_test(fs, group, EXT2_BG_BLOCK_UNINIT)))
|
||
|
return;
|
||
|
|
||
|
blk = (group * fs->super->s_blocks_per_group) +
|
||
|
fs->super->s_first_data_block;
|
||
|
|
||
|
ext2fs_super_and_bgd_loc2(fs, group, &super_blk,
|
||
|
&old_desc_blk, &new_desc_blk, 0);
|
||
|
|
||
|
if (fs->super->s_feature_incompat &
|
||
|
EXT2_FEATURE_INCOMPAT_META_BG)
|
||
|
old_desc_blocks = fs->super->s_first_meta_bg;
|
||
|
else
|
||
|
old_desc_blocks = fs->desc_blocks + fs->super->s_reserved_gdt_blocks;
|
||
|
|
||
|
for (i=0; i < fs->super->s_blocks_per_group; i++, blk++)
|
||
|
ext2fs_fast_unmark_block_bitmap2(map, blk);
|
||
|
|
||
|
blk = (group * fs->super->s_blocks_per_group) +
|
||
|
fs->super->s_first_data_block;
|
||
|
for (i=0; i < fs->super->s_blocks_per_group; i++, blk++) {
|
||
|
if ((blk == super_blk) ||
|
||
|
(old_desc_blk && old_desc_blocks &&
|
||
|
(blk >= old_desc_blk) &&
|
||
|
(blk < old_desc_blk + old_desc_blocks)) ||
|
||
|
(new_desc_blk && (blk == new_desc_blk)) ||
|
||
|
(blk == ext2fs_block_bitmap_loc(fs, group)) ||
|
||
|
(blk == ext2fs_inode_bitmap_loc(fs, group)) ||
|
||
|
(blk >= ext2fs_inode_table_loc(fs, group) &&
|
||
|
(blk < ext2fs_inode_table_loc(fs, group)
|
||
|
+ fs->inode_blocks_per_group)))
|
||
|
ext2fs_fast_mark_block_bitmap2(map, blk);
|
||
|
}
|
||
|
ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT);
|
||
|
ext2fs_group_desc_csum_set(fs, group);
|
||
|
ext2fs_mark_super_dirty(fs);
|
||
|
ext2fs_mark_bb_dirty(fs);
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* Check for uninit inode bitmaps and deal with them appropriately
|
||
|
*/
|
||
|
void check_inode_uninit(ext2_filsys fs, ext2fs_inode_bitmap map, dgrp_t group)
|
||
|
{
|
||
|
ext2_ino_t i, ino;
|
||
|
|
||
|
if (!(EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
|
||
|
EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) ||
|
||
|
!(ext2fs_bg_flags_test(fs, group, EXT2_BG_INODE_UNINIT)))
|
||
|
return;
|
||
|
|
||
|
ino = (group * fs->super->s_inodes_per_group) + 1;
|
||
|
for (i=0; i < fs->super->s_inodes_per_group; i++, ino++)
|
||
|
ext2fs_fast_unmark_inode_bitmap2(map, ino);
|
||
|
|
||
|
ext2fs_bg_flags_clear(fs, group, EXT2_BG_INODE_UNINIT);
|
||
|
ext2fs_group_desc_csum_set(fs, group);
|
||
|
ext2fs_mark_ib_dirty(fs);
|
||
|
ext2fs_mark_super_dirty(fs);
|
||
|
check_block_uninit(fs, fs->block_map, group);
|
||
|
}
|