From: Darrick J. Wong Date: Sat, 8 Nov 2014 02:27:53 +0000 (-0500) Subject: libext2fs: fix endian handling error; reduce fragmentation some X-Git-Tag: v1.42.13~20 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=407916f5af4443e0ddd9469c57fc1684c07f9294;p=tools%2Fe2fsprogs.git libext2fs: fix endian handling error; reduce fragmentation some If we're going to read the "nr - 1" entry in an indirect block for use as a "goal" input to the block allocator, we need to byteswap the entry. While we're at it, if we're allocating blocks for the zeroth entry in the indirect block, we might as well use the indirect block as the starting point to try to reduce fragmentation. (d_fallocate_blkmap will test this...) Signed-off-by: Darrick J. Wong Signed-off-by: Theodore Ts'o --- diff --git a/lib/ext2fs/bmap.c b/lib/ext2fs/bmap.c index db2fd72..a8bb00d 100644 --- a/lib/ext2fs/bmap.c +++ b/lib/ext2fs/bmap.c @@ -67,7 +67,7 @@ static _BMAP_INLINE_ errcode_t block_ind_bmap(ext2_filsys fs, int flags, #endif if (!b && (flags & BMAP_ALLOC)) { - b = nr ? ((blk_t *) block_buf)[nr-1] : 0; + b = nr ? ext2fs_le32_to_cpu(((blk_t *)block_buf)[nr - 1]) : ind; retval = ext2fs_alloc_block(fs, b, block_buf + fs->blocksize, &b); if (retval)