4 #define XFS_CRC_SEED (~(__uint32_t)0)
7 * Calculate the intermediate checksum for a buffer that has the CRC field
8 * inside it. The offset of the 32bit crc fields is passed as the
9 * cksum_offset parameter.
11 static inline __uint32_t
12 xfs_start_cksum(char *buffer
, size_t length
, unsigned long cksum_offset
)
17 /* Calculate CRC up to the checksum. */
18 crc
= crc32c(XFS_CRC_SEED
, buffer
, cksum_offset
);
20 /* Skip checksum field */
21 crc
= crc32c(crc
, &zero
, sizeof(__u32
));
23 /* Calculate the rest of the CRC. */
24 return crc32c(crc
, &buffer
[cksum_offset
+ sizeof(__be32
)],
25 length
- (cksum_offset
+ sizeof(__be32
)));
29 * Convert the intermediate checksum to the final ondisk format.
31 * The CRC32c calculation uses LE format even on BE machines, but returns the
32 * result in host endian format. Hence we need to byte swap it back to LE format
33 * so that it is consistent on disk.
36 xfs_end_cksum(__uint32_t crc
)
38 return ~cpu_to_le32(crc
);
42 * Helper to generate the checksum for a buffer.
45 xfs_update_cksum(char *buffer
, size_t length
, unsigned long cksum_offset
)
47 __uint32_t crc
= xfs_start_cksum(buffer
, length
, cksum_offset
);
49 *(__le32
*)(buffer
+ cksum_offset
) = xfs_end_cksum(crc
);
53 * Helper to verify the checksum for a buffer.
56 xfs_verify_cksum(char *buffer
, size_t length
, unsigned long cksum_offset
)
58 __uint32_t crc
= xfs_start_cksum(buffer
, length
, cksum_offset
);
60 return *(__le32
*)(buffer
+ cksum_offset
) == xfs_end_cksum(crc
);
63 #endif /* _XFS_CKSUM_H */