From 407916f5af4443e0ddd9469c57fc1684c07f9294 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Fri, 7 Nov 2014 21:27:53 -0500 Subject: [PATCH] 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 --- lib/ext2fs/bmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) -- 1.8.3.1