--- linux-2.6.16-ming/fs/ext3/balloc.c | 35 +++++------------------------- linux-2.6.16-ming/fs/ext3/resize.c | 10 ++++---- linux-2.6.16-ming/include/linux/ext3_fs.h | 23 ++++++++++++++++++- 3 files changed, 33 insertions(+), 35 deletions(-) diff -puN fs/ext3/balloc.c~ext3_get_group_offset fs/ext3/balloc.c --- linux-2.6.16/fs/ext3/balloc.c~ext3_get_group_offset 2006-05-22 15:14:02.000000000 -0700 +++ linux-2.6.16-ming/fs/ext3/balloc.c 2006-05-22 15:14:02.000000000 -0700 @@ -20,7 +20,6 @@ #include #include #include -#include /* * balloc.c contains the blocks allocation and deallocation routines @@ -39,27 +38,6 @@ #define in_range(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1) - -unsigned int ext3_block_group(struct super_block * sb, ext3_fsblk_t blocknr) -{ - struct ext3_super_block *es = EXT3_SB(sb)->s_es; - ext3_fsblk_t blockgrp = blocknr - le32_to_cpu(es->s_first_data_block); - sector_div(blockgrp, EXT3_BLOCKS_PER_GROUP(sb)); - - return (unsigned int)blockgrp; -} - -ext3_grpblk_t ext3_block_group_offset(struct super_block * sb, ext3_fsblk_t blocknr) -{ - struct ext3_super_block *es = EXT3_SB(sb)->s_es; - ext3_fsblk_t blockgrp = blocknr - le32_to_cpu(es->s_first_data_block); - ext3_grpblk_t offset; - - offset = sector_div(blockgrp, EXT3_BLOCKS_PER_GROUP(sb)); - - return offset; -} - struct ext3_group_desc * ext3_get_group_desc(struct super_block * sb, unsigned int block_group, struct buffer_head ** bh) @@ -361,8 +339,7 @@ void ext3_free_blocks_sb(handle_t *handl do_more: overflow = 0; - block_group = ext3_block_group(sb, block); - bit = ext3_block_group_offset (sb, block); + ext3_get_group_no_and_offset(sb, block, &block_group, &bit); /* * Check to see if we are freeing blocks across a group * boundary. @@ -1287,7 +1264,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h if (goal < le32_to_cpu(es->s_first_data_block) || goal >= le32_to_cpu(es->s_blocks_count)) goal = le32_to_cpu(es->s_first_data_block); - group_no = ext3_block_group (sb, goal); + ext3_get_group_no_and_offset(sb, goal, &group_no, &grp_target_blk); gdp = ext3_get_group_desc(sb, group_no, &gdp_bh); if (!gdp) goto io_error; @@ -1304,7 +1281,6 @@ retry: my_rsv = NULL; if (free_blocks > 0) { - grp_target_blk = ext3_block_group_offset(sb, goal); bitmap_bh = read_block_bitmap(sb, group_no); if (!bitmap_bh) goto io_error; @@ -1545,9 +1521,10 @@ ext3_fsblk_t ext3_count_free_blocks(stru static inline int block_in_use(ext3_fsblk_t block, struct super_block *sb, unsigned char *map) { - return ext3_test_bit ((block - - le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block)) % - EXT3_BLOCKS_PER_GROUP(sb), map); + ext3_grpblk_t offset; + + ext3_get_group_no_and_offset(sb, block, NULL, &offset); + return ext3_test_bit (offset, map); } static inline int test_root(int a, int b) diff -puN fs/ext3/resize.c~ext3_get_group_offset fs/ext3/resize.c --- linux-2.6.16/fs/ext3/resize.c~ext3_get_group_offset 2006-05-22 15:14:02.000000000 -0700 +++ linux-2.6.16-ming/fs/ext3/resize.c 2006-05-22 15:14:02.000000000 -0700 @@ -15,7 +15,6 @@ #include #include #include -#include #include #include @@ -37,7 +36,7 @@ static int verify_group_input(struct sup le16_to_cpu(es->s_reserved_gdt_blocks)) : 0; ext3_fsblk_t metaend = start + overhead; struct buffer_head *bh = NULL; - ext3_grpblk_t free_blocks_count; + ext3_grpblk_t free_blocks_count, offset; int err = -EINVAL; input->free_blocks_count = free_blocks_count = @@ -50,12 +49,13 @@ static int verify_group_input(struct sup "no-super", input->group, input->blocks_count, free_blocks_count, input->reserved_blocks); + ext3_get_group_no_and_offset(sb, start, NULL, &offset); if (group != sbi->s_groups_count) ext3_warning(sb, __FUNCTION__, "Cannot add at group %u (only %lu groups)", input->group, sbi->s_groups_count); - else if (ext3_block_group_offset(sb,start) != 0) - ext3_warning(sb, __FUNCTION__, "Last group not full"); + else if (offset != 0) + ext3_warning(sb, __FUNCTION__, "Last group not full"); else if (input->reserved_blocks > input->blocks_count / 5) ext3_warning(sb, __FUNCTION__, "Reserved blocks too high (%u)", input->reserved_blocks); @@ -947,7 +947,7 @@ int ext3_group_extend(struct super_block } /* Handle the remaining blocks in the last group only. */ - last = ext3_block_group_offset(sb, o_blocks_count); + ext3_get_group_no_and_offset(sb, o_blocks_count, NULL, &last); if (last == 0) { ext3_warning(sb, __FUNCTION__, diff -puN include/linux/ext3_fs.h~ext3_get_group_offset include/linux/ext3_fs.h --- linux-2.6.16/include/linux/ext3_fs.h~ext3_get_group_offset 2006-05-22 15:14:02.000000000 -0700 +++ linux-2.6.16-ming/include/linux/ext3_fs.h 2006-05-22 15:14:02.000000000 -0700 @@ -19,7 +19,7 @@ #include #include #include - +#include struct statfs; @@ -726,6 +726,27 @@ ext3_group_first_block_no(struct super_b #define ERR_BAD_DX_DIR -75000 /* + * This function calculate the block group number and offset, + * given a block number + */ + +static inline void ext3_get_group_no_and_offset(struct super_block * sb, + ext3_fsblk_t blocknr, unsigned long* blockgrpp, + ext3_grpblk_t *offsetp) +{ + struct ext3_super_block *es = EXT3_SB(sb)->s_es; + ext3_grpblk_t offset; + + blocknr = blocknr - le32_to_cpu(es->s_first_data_block); + offset = sector_div(blocknr, EXT3_BLOCKS_PER_GROUP(sb)); + if (offsetp) + *offsetp = offset; + if (blockgrpp) + *blockgrpp = blocknr; + +} + +/* * Function prototypes */ _