linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kalpak Shah <kalpak@clusterfs.com>
To: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Cc: cmm@us.ibm.com, linux-ext4@vger.kernel.org,
	Andreas Dilger <adilger@clusterfs.com>
Subject: Re: [PATCH] ext2/ext3/ext4: Add block bitmap validation
Date: Fri, 03 Aug 2007 13:14:11 +0530	[thread overview]
Message-ID: <1186127051.3866.12.camel@garfield> (raw)
In-Reply-To: <11861250501999-git-send-email-aneesh.kumar@linux.vnet.ibm.com>

On Fri, 2007-08-03 at 12:40 +0530, Aneesh Kumar K.V wrote:
>  	desc = ext2_get_group_desc (sb, block_group, NULL);
>  	if (!desc)
> -		goto error_out;
> -	bh = sb_bread(sb, le32_to_cpu(desc->bg_block_bitmap));
> +		return NULL;
> +	bitmap_blk = le32_to_cpu(desc->bg_block_bitmap);
> +	bh = sb_bread(sb, bitmap_blk);
>  	if (!bh)
> -		ext2_error (sb, "read_block_bitmap",
> +		ext2_error (sb, __FUNCTION__,
>  			    "Cannot read block bitmap - "
>  			    "block_group = %d, block_bitmap = %u",
>  			    block_group, le32_to_cpu(desc->bg_block_bitmap));

bitmap_blk should be used here instead of
le32_to_cpu(desc->bg_block_bitmap). It reduces one endianness
conversion.

> -error_out:
> +
> +	/* check whether block bitmap block number is set */
> +	if (!block_in_use(bitmap_blk, sb, bh->b_data)) {
> +		/* bad block bitmap */
> +		goto error_out;
> +	}
> +	/* check whether the inode bitmap block number is set */
> +	bitmap_blk = le32_to_cpu(desc->bg_inode_bitmap);
> +	if (!block_in_use(bitmap_blk, sb, bh->b_data)) {
> +		/* bad block bitmap */
> +		goto error_out;
> +	}
> +	/* check whether the inode table block number is set */
> +	bitmap_blk = le32_to_cpu(desc->bg_inode_table);
> +	for (i = 0; i < EXT2_SB(sb)->s_itb_per_group; i++, bitmap_blk++) {
> +		if (!block_in_use(bitmap_blk, sb, bh->b_data)) {
> +			/* bad block bitmap */
> +			goto error_out;
> +		}
> +	}

Why not reduce a lot of this code by having:
int block_range_in_use(ext4_fsblk_t start_blk, ext4_fsblk_t num_blks,
struct super_block *sb, unsigned char *map)?

It will also help to do away with a lot of repetitive calculations in
block_in_use().

> +	ext3_error(sb, __FUNCTION__,
> +			"Invalid block bitmap - "
> +			"block_group = %d, block = %lu",
> +			block_group, bitmap_blk);

Please align this according to kernel coding style.

Thanks,
Kalpak.

  reply	other threads:[~2007-08-03  7:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-03  7:10 [PATCH] ext2/ext3/ext4: Add block bitmap validation Aneesh Kumar K.V
2007-08-03  7:44 ` Kalpak Shah [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-07-10  4:43 Aneesh Kumar K.V
2007-07-09 18:24 Aneesh Kumar K.V
2007-07-09 19:16 ` Andreas Dilger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1186127051.3866.12.camel@garfield \
    --to=kalpak@clusterfs.com \
    --cc=adilger@clusterfs.com \
    --cc=aneesh.kumar@linux.vnet.ibm.com \
    --cc=cmm@us.ibm.com \
    --cc=linux-ext4@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).