aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorBrian Foster <bfoster@redhat.com>2014-08-03 21:35:35 -0400
committerDave Chinner <david@fromorbit.com>2014-08-03 21:35:35 -0400
commiteedf32bfcace7d8e20cc66757d74fc68f3439ff7 (patch)
treee6e719201cbdb4b2ce72cc6d93e06fe14c604b07 /fs
parent2451337dd043901b5270b7586942abe564443e3d (diff)
xfs: fix rounding error of fiemap length parameter
The offset and length parameters are converted from bytes to basic blocks by xfs_vn_fiemap(). The BTOBB() converter rounds the value up to the nearest basic block. This leads to unexpected behavior when unaligned offsets are provided to FIEMAP. Fix the conversions of byte values to block values to cover the provided offsets. Round down the start offset to the nearest basic block. Calculate the end offset based on the provided values, round up and calculate length based on the start block offset. Reported-by: Chandan Rajendra <chandan@linux.vnet.ibm.com> Signed-off-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Dave Chinner <david@fromorbit.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/xfs/xfs_iops.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
index d75621ae3e36..72129493e9d3 100644
--- a/fs/xfs/xfs_iops.c
+++ b/fs/xfs/xfs_iops.c
@@ -1055,12 +1055,12 @@ xfs_vn_fiemap(
1055 return error; 1055 return error;
1056 1056
1057 /* Set up bmap header for xfs internal routine */ 1057 /* Set up bmap header for xfs internal routine */
1058 bm.bmv_offset = BTOBB(start); 1058 bm.bmv_offset = BTOBBT(start);
1059 /* Special case for whole file */ 1059 /* Special case for whole file */
1060 if (length == FIEMAP_MAX_OFFSET) 1060 if (length == FIEMAP_MAX_OFFSET)
1061 bm.bmv_length = -1LL; 1061 bm.bmv_length = -1LL;
1062 else 1062 else
1063 bm.bmv_length = BTOBB(length); 1063 bm.bmv_length = BTOBB(start + length) - bm.bmv_offset;
1064 1064
1065 /* We add one because in getbmap world count includes the header */ 1065 /* We add one because in getbmap world count includes the header */
1066 bm.bmv_count = !fieinfo->fi_extents_max ? MAXEXTNUM : 1066 bm.bmv_count = !fieinfo->fi_extents_max ? MAXEXTNUM :