diff mbox series

[05/14] libxfs: add xfs_calc_chsum()

Message ID 20241229133836.1194272-6-aalbersh@kernel.org (mailing list archive)
State New
Headers show
Series Direct mapped extended attribute data | expand

Commit Message

Andrey Albershteyn Dec. 29, 2024, 1:38 p.m. UTC
From: Andrey Albershteyn <aalbersh@redhat.com>

Calculate CRC of the buffer which will not be placed in this same
buffer (common case for all other xfs_cksum.h uses).

Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
---
 fs/xfs/libxfs/xfs_cksum.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/fs/xfs/libxfs/xfs_cksum.h b/fs/xfs/libxfs/xfs_cksum.h
index 999a290cfd72..90884ed0ef23 100644
--- a/fs/xfs/libxfs/xfs_cksum.h
+++ b/fs/xfs/libxfs/xfs_cksum.h
@@ -79,4 +79,16 @@  xfs_verify_cksum(char *buffer, size_t length, unsigned long cksum_offset)
 	return *(__le32 *)(buffer + cksum_offset) == xfs_end_cksum(crc);
 }
 
+/*
+ * Helper to calculate the checksum of a buffer which is outside of the buffer
+ */
+static inline uint32_t
+xfs_calc_cksum(char *buffer, size_t length, uint32_t *dst)
+{
+	uint32_t crc = crc32c(XFS_CRC_SEED, buffer, length);
+	if (dst)
+		*dst = crc;
+	return crc;
+}
+
 #endif /* _XFS_CKSUM_H */