Re: [PATCH 5/8] omfs: add file routines

From: Miklos Szeredi
Date: Mon Apr 21 2008 - 11:29:35 EST


> +static int omfs_get_block(struct inode *inode, sector_t block,
> + struct buffer_head *bh_result, int create)
> +{
> + struct buffer_head *bh;
> + sector_t next, offset;
> + int ret = 0;
> + u64 new_block;
> + int extent_count;
> + struct omfs_extent *oe;
> + struct omfs_extent_entry *entry;
> + struct omfs_sb_info *sbi = OMFS_SB(inode->i_sb);
> + int max_blocks = bh_result->b_size >> inode->i_blkbits;
> + int remain;
> +
> + bh = sb_bread(inode->i_sb, clus_to_blk(sbi, inode->i_ino));
> + if (!bh)
> + goto err;
> +
> + oe = (struct omfs_extent *)(&bh->b_data[OMFS_EXTENT_START]);
> + next = inode->i_ino;
> +
> + for (;;) {
> +
> + if (omfs_is_bad(sbi, (struct omfs_header *) bh->b_data, next)) {
> + brelse(bh);
> + goto err;

Please:
ret = -EIO;
if (omfs_is_bad(sbi, (struct omfs_header *) bh->b_data, next))
goto out_brelse;


> + }
> + extent_count = be32_to_cpu(oe->e_extent_count);
> + next = be64_to_cpu(oe->e_next);
> + entry = &oe->e_entry;
> +
> + offset = find_block(inode, entry, block, extent_count, &remain);
> + if (offset > 0) {
> + brelse(bh);
> +
> + map_bh(bh_result, inode->i_sb, offset);
> + if (remain > max_blocks)
> + remain = max_blocks;
> + bh_result->b_size = (remain << inode->i_blkbits);
> + return 0;

This instead?

if (offset > 0) {
ret = 0;
map_bh(bh_result, inode->i_sb, offset);
if (remain > max_blocks)
remain = max_blocks;
bh_result->b_size = (remain << inode->i_blkbits);
goto out_brelse;
}

Miklos

> + }
> + if (next == ~0)
> + break;
> +
> + brelse(bh);
> + bh = sb_bread(inode->i_sb, clus_to_blk(sbi, next));
> + if (!bh)
> + goto err;
> + oe = (struct omfs_extent *) (&bh->b_data[OMFS_EXTENT_CONT]);
> + }
> + if (create) {
> + ret = omfs_grow_extent(inode, oe, &new_block);
> + if (ret == 0) {
> + mark_buffer_dirty(bh);
> + mark_inode_dirty(inode);
> + map_bh(bh_result, inode->i_sb,
> + clus_to_blk(sbi, new_block));
> + }
> + }
> + brelse(bh);
> + return ret;
> +err:
> + return -EIO;
> +}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/