[ Pobierz całość w formacie PDF ]
.\n",*prealloc_count);}#endifj = tmp;mark_buffer_dirty(bh, 1);if (sb->s_flags & MS_SYNCHRONOUS) {ll_rw_block (WRITE, 1, &bh);wait_on_buffer (bh);}if (j >= es->s_blocks_count) {ext2_error (sb, "ext2_new_block","block >= blocks count - ""block_group = %d, block=%d", i, j);unlock_super (sb);return 0;}if (!(bh = getblk (sb->s_dev, j, sb->s_blocksize))) {ext2_error (sb, "ext2_new_block", "cannot get block %d", j);unlock_super (sb);return 0;}memset(bh->b_data, 0, sb->s_blocksize);mark_buffer_uptodate(bh, 1);mark_buffer_dirty(bh, 1);brelse (bh);ext2_debug ("allocating block %d.""Goal hits %d of %d.\n", j, goal_hits, goal_attempts);gdp->bg_free_blocks_count--;mark_buffer_dirty(bh2, 1);es->s_free_blocks_count--;mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);sb->s_dirt = 1;unlock_super (sb);*err = 0;return j;}unsigned long ext2_count_free_blocks (struct super_block * sb){#ifdef EXT2FS_DEBUGstruct ext2_super_block * es;unsigned long desc_count, bitmap_count, x;int bitmap_nr;struct ext2_group_desc * gdp;int i;lock_super (sb);es = sb->u.ext2_sb.s_es;desc_count = 0;bitmap_count = 0;gdp = NULL;for (i = 0; i < sb->u.ext2_sb.s_groups_count; i++) {gdp = get_group_desc (sb, i, NULL);desc_count += gdp->bg_free_blocks_count;bitmap_nr = load_block_bitmap (sb, i);x = ext2_count_free (sb->u.ext2_sb.s_block_bitmap[bitmap_nr],sb->s_blocksize);printk ("group %d: stored = %d, counted = %lu\n",i, gdp->bg_free_blocks_count, x);bitmap_count += x;}printk("ext2_count_free_blocks: stored = %lu, computed = %lu, %lu\n",es->s_free_blocks_count, desc_count, bitmap_count);unlock_super (sb);return bitmap_count;#elsereturn sb->u.ext2_sb.s_es->s_free_blocks_count;#endif}static inline int block_in_use (unsigned long block,struct super_block * sb,unsigned char * map){return test_bit ((block - sb->u.ext2_sb.s_es->s_first_data_block) %EXT2_BLOCKS_PER_GROUP(sb), map);}void ext2_check_blocks_bitmap (struct super_block * sb){struct buffer_head * bh;struct ext2_super_block * es;unsigned long desc_count, bitmap_count, x;unsigned long desc_blocks;int bitmap_nr;struct ext2_group_desc * gdp;int i, j;lock_super (sb);es = sb->u.ext2_sb.s_es;desc_count = 0;bitmap_count = 0;gdp = NULL;desc_blocks = (sb->u.ext2_sb.s_groups_count + EXT2_DESC_PER_BLOCK(sb) - 1) /EXT2_DESC_PER_BLOCK(sb);for (i = 0; i < sb->u.ext2_sb.s_groups_count; i++) {gdp = get_group_desc (sb, i, NULL);desc_count += gdp->bg_free_blocks_count;bitmap_nr = load_block_bitmap (sb, i);bh = sb->u.ext2_sb.s_block_bitmap[bitmap_nr];if (!test_bit (0, bh->b_data))ext2_error (sb, "ext2_check_blocks_bitmap","Superblock in group %d is marked free", i);for (j = 0; j < desc_blocks; j++)if (!test_bit (j + 1, bh->b_data))ext2_error (sb, "ext2_check_blocks_bitmap","Descriptor block #%d in group ""%d is marked free", j, i);if (!block_in_use (gdp->bg_block_bitmap, sb, bh->b_data))ext2_error (sb, "ext2_check_blocks_bitmap","Block bitmap for group %d is marked free",i);if (!block_in_use (gdp->bg_inode_bitmap, sb, bh->b_data))ext2_error (sb, "ext2_check_blocks_bitmap","Inode bitmap for group %d is marked free",i);for (j = 0; j < sb->u.ext2_sb.s_itb_per_group; j++)if (!block_in_use (gdp->bg_inode_table + j, sb, bh->b_data))ext2_error (sb, "ext2_check_blocks_bitmap","Block #%d of the inode table in ""group %d is marked free", j, i);x = ext2_count_free (bh, sb->s_blocksize);if (gdp->bg_free_blocks_count != x)ext2_error (sb, "ext2_check_blocks_bitmap","Wrong free blocks count for group %d, ""stored = %d, counted = %lu", i,gdp->bg_free_blocks_count, x);bitmap_count += x;}if (es->s_free_blocks_count != bitmap_count)ext2_error (sb, "ext2_check_blocks_bitmap","Wrong free blocks count in super block, ""stored = %lu, counted = %lu",(unsigned long) es->s_free_blocks_count, bitmap_count);unlock_super (sb);}
[ Pobierz całość w formacie PDF ]