summaryrefslogtreecommitdiff
path: root/fs/xfs/libxfs/xfs_group.h
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/libxfs/xfs_group.h')
-rw-r--r--fs/xfs/libxfs/xfs_group.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/fs/xfs/libxfs/xfs_group.h b/fs/xfs/libxfs/xfs_group.h
index 5b7362277c3f..242b05627c7a 100644
--- a/fs/xfs/libxfs/xfs_group.h
+++ b/fs/xfs/libxfs/xfs_group.h
@@ -12,6 +12,10 @@ struct xfs_group {
atomic_t xg_ref; /* passive reference count */
atomic_t xg_active_ref; /* active reference count */
+ /* Precalculated geometry info */
+ uint32_t xg_block_count; /* max usable gbno */
+ uint32_t xg_min_gbno; /* min usable gbno */
+
#ifdef __KERNEL__
/* -- kernel only structures below this line -- */
@@ -128,4 +132,33 @@ xfs_fsb_to_gbno(
return fsbno & mp->m_groups[type].blkmask;
}
+static inline bool
+xfs_verify_gbno(
+ struct xfs_group *xg,
+ uint32_t gbno)
+{
+ if (gbno >= xg->xg_block_count)
+ return false;
+ if (gbno < xg->xg_min_gbno)
+ return false;
+ return true;
+}
+
+static inline bool
+xfs_verify_gbext(
+ struct xfs_group *xg,
+ uint32_t gbno,
+ uint32_t glen)
+{
+ uint32_t end;
+
+ if (!xfs_verify_gbno(xg, gbno))
+ return false;
+ if (glen == 0 || check_add_overflow(gbno, glen - 1, &end))
+ return false;
+ if (!xfs_verify_gbno(xg, end))
+ return false;
+ return true;
+}
+
#endif /* __LIBXFS_GROUP_H */