From: Tomasz Majkowski Date: Fri, 20 Mar 2009 16:01:58 +0000 (+0100) Subject: xfs_io: fix extent array reallocation X-Git-Tag: v3.0.1~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f6d1a56367179f41a3eac1a1481863586015ff0d;p=thirdparty%2Fxfsprogs-dev.git xfs_io: fix extent array reallocation The XFS_IOC_FSGETXATTRA ioctl only returns the number of allocated extents, so when we reallocate the extent array in the bmap command we have to account for the worst case where there is a whole between each two allocated extents. Also add some slack to that case to allow for a file growing while we are racing with it. Signed-off-by: Christoph Hellwig Reviewed-by: Felix Blyakher --- diff --git a/io/bmap.c b/io/bmap.c index db1496ccc..f79cf8cc4 100644 --- a/io/bmap.c +++ b/io/bmap.c @@ -217,8 +217,8 @@ bmap_f( exitcode = 1; return 0; } - if (fsx.fsx_nextents >= map_size-1) { - map_size = 2*(fsx.fsx_nextents+1); + if (2 * fsx.fsx_nextents > map_size) { + map_size = 2 * fsx.fsx_nextents + 1; map = realloc(map, map_size*sizeof(*map)); if (map == NULL) { fprintf(stderr,