Patchwork e2fsck: fix error in computing blocks of the ending group

login
register
mail settings
Submitter Yongqiang Yang
Date July 19, 2011, 3:46 p.m.
Message ID <1311090411-13766-1-git-send-email-xiaoqiangnk@gmail.com>
Download mbox | patch
Permalink /patch/105481/
State Superseded
Headers show

Comments

Yongqiang Yang - July 19, 2011, 3:46 p.m.
If the blocks of a filesystem is a multiple of blocks_per_group,
blocks of the ending group is computed wrongly.  This patch computes
it by substracting blocks processed from blocks of the filesystem.

Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com>
---
 e2fsck/pass5.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Eric Sandeen - July 19, 2011, 4:18 p.m.
On 07/19/2011 10:46 AM, Yongqiang Yang wrote:
> If the blocks of a filesystem is a multiple of blocks_per_group,
> blocks of the ending group is computed wrongly.  This patch computes
> it by substracting blocks processed from blocks of the filesystem.
> 
> Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com>
> ---
>  e2fsck/pass5.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/e2fsck/pass5.c b/e2fsck/pass5.c
> index f9d746c..7c4e336 100644
> --- a/e2fsck/pass5.c
> +++ b/e2fsck/pass5.c
> @@ -227,7 +227,7 @@ redo_counts:
>  				if (group == (int)fs->group_desc_count - 1)
>  					cmp_block =
>  						EXT2FS_NUM_B2C(fs,
> -		ext2fs_blocks_count(fs->super) % fs->super->s_blocks_per_group);
> +					ext2fs_blocks_count(fs->super) - i);
>  			}
>  
>  			bitmap = 0;

I think it would be clearer to just get the last group block count from
superblock information, rather than from using the loop counter.

For example resize does:

        if (i == fs->group_desc_count-1) {
                numblocks = (ext2fs_blocks_count(fs->super) -
                             fs->super->s_first_data_block) %
                                     fs->super->s_blocks_per_group;
                if (!numblocks)
                        numblocks = fs->super->s_blocks_per_group;


same as this function in alloc_sb.c:

        if (group == fs->group_desc_count-1) {
                num_blocks = (ext2fs_blocks_count(fs->super) -
                             fs->super->s_first_data_block) %
                        fs->super->s_blocks_per_group;
                if (!num_blocks)
                        num_blocks = fs->super->s_blocks_per_group;


Hm, seems maybe an ext2fs_blocks_in_group() helper function might be
nice, since this is a little verbose, and is used fairly often.

-Eric
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Eric Sandeen - July 21, 2011, 5:40 p.m.
On 7/19/11 11:18 AM, Eric Sandeen wrote:
> On 07/19/2011 10:46 AM, Yongqiang Yang wrote:
>> If the blocks of a filesystem is a multiple of blocks_per_group,
>> blocks of the ending group is computed wrongly.  This patch computes
>> it by substracting blocks processed from blocks of the filesystem.
>>
>> Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com>
>> ---
>>  e2fsck/pass5.c |    2 +-
>>  1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/e2fsck/pass5.c b/e2fsck/pass5.c
>> index f9d746c..7c4e336 100644
>> --- a/e2fsck/pass5.c
>> +++ b/e2fsck/pass5.c
>> @@ -227,7 +227,7 @@ redo_counts:
>>  				if (group == (int)fs->group_desc_count - 1)
>>  					cmp_block =
>>  						EXT2FS_NUM_B2C(fs,
>> -		ext2fs_blocks_count(fs->super) % fs->super->s_blocks_per_group);
>> +					ext2fs_blocks_count(fs->super) - i);
>>  			}
>>  
>>  			bitmap = 0;
> 
> I think it would be clearer to just get the last group block count from
> superblock information, rather than from using the loop counter.

Actually I see that I misread this... here we are dealing with
clusters per group and my proposed blocks per group helper won't help.
Sorry for the noise, I think your patch should go in as proposed.

I'll still send my helper, but I don't think it will help in this
location, and your patch is correct.

-Eric
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/e2fsck/pass5.c b/e2fsck/pass5.c
index f9d746c..7c4e336 100644
--- a/e2fsck/pass5.c
+++ b/e2fsck/pass5.c
@@ -227,7 +227,7 @@  redo_counts:
 				if (group == (int)fs->group_desc_count - 1)
 					cmp_block =
 						EXT2FS_NUM_B2C(fs,
-		ext2fs_blocks_count(fs->super) % fs->super->s_blocks_per_group);
+					ext2fs_blocks_count(fs->super) - i);
 			}
 
 			bitmap = 0;