linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/2][64-BIT] ext2fs_group_first_block2(): 32-bit truncation.
@ 2009-04-18  6:05 Nick Dokos
  2009-04-18 13:09 ` Eric Sandeen
  2009-04-21  0:50 ` Valerie Aurora Henson
  0 siblings, 2 replies; 3+ messages in thread
From: Nick Dokos @ 2009-04-18  6:05 UTC (permalink / raw)
  To: linux-ext4; +Cc: nicholas.dokos, Theodore Ts'o, Valerie Aurora

ext2fs_group_first_block2() returns the product of the group number
and the number of blocks per group (from the superblock). Unfortunately,
both of these are 32-bit quantities, so the multiplication result is
also 32 bits wide. It is then returned as a 64-bit quantity, but by then,
it's too late.

Cast one of the operands to blk64_t, so the multiplication will be done
in 64 bits.

e2fsck was complaining about a group that was marked BLOCK_UNINIT, but
had blocks in use (it turned out that a different group had blocks in
use, but the block numbers of the two different groups differed by
2^32, so this bug conflated them). With this change, this complaint
goes away. In addition, dumpe2fs produces the right blocks for all the
groups, whereas it was wrapping them at the 32-bit boundary previously.

Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
---
 lib/ext2fs/blknum.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/lib/ext2fs/blknum.c b/lib/ext2fs/blknum.c
index b9666fb..fd56d53 100644
--- a/lib/ext2fs/blknum.c
+++ b/lib/ext2fs/blknum.c
@@ -28,7 +28,7 @@ dgrp_t ext2fs_group_of_blk2(ext2_filsys fs, blk64_t blk)
 blk64_t ext2fs_group_first_block2(ext2_filsys fs, dgrp_t group)
 {
 	return fs->super->s_first_data_block +
-		(group * fs->super->s_blocks_per_group);
+		((blk64_t)group * fs->super->s_blocks_per_group);
 }
 
 /*
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2][64-BIT] ext2fs_group_first_block2(): 32-bit truncation.
  2009-04-18  6:05 [PATCH 2/2][64-BIT] ext2fs_group_first_block2(): 32-bit truncation Nick Dokos
@ 2009-04-18 13:09 ` Eric Sandeen
  2009-04-21  0:50 ` Valerie Aurora Henson
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Sandeen @ 2009-04-18 13:09 UTC (permalink / raw)
  To: nicholas.dokos; +Cc: linux-ext4, Theodore Ts'o, Valerie Aurora

Nick Dokos wrote:
> ext2fs_group_first_block2() returns the product of the group number
> and the number of blocks per group (from the superblock). Unfortunately,
> both of these are 32-bit quantities, so the multiplication result is
> also 32 bits wide. It is then returned as a 64-bit quantity, but by then,
> it's too late.
> 
> Cast one of the operands to blk64_t, so the multiplication will be done
> in 64 bits.
> 
> e2fsck was complaining about a group that was marked BLOCK_UNINIT, but
> had blocks in use (it turned out that a different group had blocks in
> use, but the block numbers of the two different groups differed by
> 2^32, so this bug conflated them). With this change, this complaint
> goes away. In addition, dumpe2fs produces the right blocks for all the
> groups, whereas it was wrapping them at the 32-bit boundary previously.
> 
> Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>

This one looks obviously correct, thanks.

Reviewed-by: Eric Sandeen <sandeen@redhat.com>

> ---
>  lib/ext2fs/blknum.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/lib/ext2fs/blknum.c b/lib/ext2fs/blknum.c
> index b9666fb..fd56d53 100644
> --- a/lib/ext2fs/blknum.c
> +++ b/lib/ext2fs/blknum.c
> @@ -28,7 +28,7 @@ dgrp_t ext2fs_group_of_blk2(ext2_filsys fs, blk64_t blk)
>  blk64_t ext2fs_group_first_block2(ext2_filsys fs, dgrp_t group)
>  {
>  	return fs->super->s_first_data_block +
> -		(group * fs->super->s_blocks_per_group);
> +		((blk64_t)group * fs->super->s_blocks_per_group);
>  }
>  
>  /*


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2][64-BIT] ext2fs_group_first_block2(): 32-bit truncation.
  2009-04-18  6:05 [PATCH 2/2][64-BIT] ext2fs_group_first_block2(): 32-bit truncation Nick Dokos
  2009-04-18 13:09 ` Eric Sandeen
@ 2009-04-21  0:50 ` Valerie Aurora Henson
  1 sibling, 0 replies; 3+ messages in thread
From: Valerie Aurora Henson @ 2009-04-21  0:50 UTC (permalink / raw)
  To: Nick Dokos; +Cc: linux-ext4, Theodore Ts'o

On Sat, Apr 18, 2009 at 02:05:13AM -0400, Nick Dokos wrote:
> ext2fs_group_first_block2() returns the product of the group number
> and the number of blocks per group (from the superblock). Unfortunately,
> both of these are 32-bit quantities, so the multiplication result is
> also 32 bits wide. It is then returned as a 64-bit quantity, but by then,
> it's too late.
> 
> Cast one of the operands to blk64_t, so the multiplication will be done
> in 64 bits.
> 
> e2fsck was complaining about a group that was marked BLOCK_UNINIT, but
> had blocks in use (it turned out that a different group had blocks in
> use, but the block numbers of the two different groups differed by
> 2^32, so this bug conflated them). With this change, this complaint
> goes away. In addition, dumpe2fs produces the right blocks for all the
> groups, whereas it was wrapping them at the 32-bit boundary previously.
> 
> Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>

Signed-off-by: Valerie Aurora (Henson) <vaurora@redhat.com>

Pulled and pushed.

-VAL

> ---
>  lib/ext2fs/blknum.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/lib/ext2fs/blknum.c b/lib/ext2fs/blknum.c
> index b9666fb..fd56d53 100644
> --- a/lib/ext2fs/blknum.c
> +++ b/lib/ext2fs/blknum.c
> @@ -28,7 +28,7 @@ dgrp_t ext2fs_group_of_blk2(ext2_filsys fs, blk64_t blk)
>  blk64_t ext2fs_group_first_block2(ext2_filsys fs, dgrp_t group)
>  {
>  	return fs->super->s_first_data_block +
> -		(group * fs->super->s_blocks_per_group);
> +		((blk64_t)group * fs->super->s_blocks_per_group);
>  }
>  
>  /*
> -- 
> 1.6.0.6
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-04-21  0:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-18  6:05 [PATCH 2/2][64-BIT] ext2fs_group_first_block2(): 32-bit truncation Nick Dokos
2009-04-18 13:09 ` Eric Sandeen
2009-04-21  0:50 ` Valerie Aurora Henson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).