xfs: fix rounding error of fiemap length parameter
authorBrian Foster <bfoster@redhat.com>
Mon, 4 Aug 2014 01:35:35 +0000 (11:35 +1000)
committerDave Chinner <david@fromorbit.com>
Mon, 4 Aug 2014 01:35:35 +0000 (11:35 +1000)
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>
fs/xfs/xfs_iops.c

index d75621ae3e3682db1a9787b53939124fe51c9df1..72129493e9d3563687a6606223a123692fe13a5c 100644 (file)
@@ -1055,12 +1055,12 @@ xfs_vn_fiemap(
                return error;
 
        /* Set up bmap header for xfs internal routine */
-       bm.bmv_offset = BTOBB(start);
+       bm.bmv_offset = BTOBBT(start);
        /* Special case for whole file */
        if (length == FIEMAP_MAX_OFFSET)
                bm.bmv_length = -1LL;
        else
-               bm.bmv_length = BTOBB(length);
+               bm.bmv_length = BTOBB(start + length) - bm.bmv_offset;
 
        /* We add one because in getbmap world count includes the header */
        bm.bmv_count = !fieinfo->fi_extents_max ? MAXEXTNUM :