summaryrefslogtreecommitdiffstats
path: root/fs/xfs/libxfs/xfs_types.c
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2020-12-04 13:28:35 -0800
committerDarrick J. Wong <darrick.wong@oracle.com>2020-12-09 09:49:38 -0800
commit33005fd0a537501111fc97ec330b721388c6b451 (patch)
tree1838c7876c83cac6d755b34b920ea1ca006ddcb3 /fs/xfs/libxfs/xfs_types.c
parent18695ad4251462b33787b7e375dbda57c1969c8f (diff)
downloadlinux-stable-33005fd0a537501111fc97ec330b721388c6b451.tar.gz
linux-stable-33005fd0a537501111fc97ec330b721388c6b451.tar.bz2
linux-stable-33005fd0a537501111fc97ec330b721388c6b451.zip
xfs: refactor file range validation
Refactor all the open-coded validation of file block ranges into a single helper, and teach the bmap scrubber to check the ranges. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'fs/xfs/libxfs/xfs_types.c')
-rw-r--r--fs/xfs/libxfs/xfs_types.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/fs/xfs/libxfs/xfs_types.c b/fs/xfs/libxfs/xfs_types.c
index 7b310eb296b7..b254fbeaaa50 100644
--- a/fs/xfs/libxfs/xfs_types.c
+++ b/fs/xfs/libxfs/xfs_types.c
@@ -258,3 +258,28 @@ xfs_verify_dablk(
return dabno <= max_dablk;
}
+
+/* Check that a file block offset does not exceed the maximum. */
+bool
+xfs_verify_fileoff(
+ struct xfs_mount *mp,
+ xfs_fileoff_t off)
+{
+ return off <= XFS_MAX_FILEOFF;
+}
+
+/* Check that a range of file block offsets do not exceed the maximum. */
+bool
+xfs_verify_fileext(
+ struct xfs_mount *mp,
+ xfs_fileoff_t off,
+ xfs_fileoff_t len)
+{
+ if (off + len <= off)
+ return false;
+
+ if (!xfs_verify_fileoff(mp, off))
+ return false;
+
+ return xfs_verify_fileoff(mp, off + len - 1);
+}