This source file includes following definitions.
- xfs_start_cksum_safe
- xfs_start_cksum_update
- xfs_end_cksum
- xfs_update_cksum
- xfs_verify_cksum
1
2 #ifndef _XFS_CKSUM_H
3 #define _XFS_CKSUM_H 1
4
5 #define XFS_CRC_SEED (~(uint32_t)0)
6
7
8
9
10
11
12
13 static inline uint32_t
14 xfs_start_cksum_safe(char *buffer, size_t length, unsigned long cksum_offset)
15 {
16 uint32_t zero = 0;
17 uint32_t crc;
18
19
20 crc = crc32c(XFS_CRC_SEED, buffer, cksum_offset);
21
22
23 crc = crc32c(crc, &zero, sizeof(__u32));
24
25
26 return crc32c(crc, &buffer[cksum_offset + sizeof(__be32)],
27 length - (cksum_offset + sizeof(__be32)));
28 }
29
30
31
32
33
34 static inline uint32_t
35 xfs_start_cksum_update(char *buffer, size_t length, unsigned long cksum_offset)
36 {
37
38 *(__le32 *)(buffer + cksum_offset) = 0;
39
40
41 return crc32c(XFS_CRC_SEED, buffer, length);
42 }
43
44
45
46
47
48
49
50
51 static inline __le32
52 xfs_end_cksum(uint32_t crc)
53 {
54 return ~cpu_to_le32(crc);
55 }
56
57
58
59
60
61
62
63 static inline void
64 xfs_update_cksum(char *buffer, size_t length, unsigned long cksum_offset)
65 {
66 uint32_t crc = xfs_start_cksum_update(buffer, length, cksum_offset);
67
68 *(__le32 *)(buffer + cksum_offset) = xfs_end_cksum(crc);
69 }
70
71
72
73
74 static inline int
75 xfs_verify_cksum(char *buffer, size_t length, unsigned long cksum_offset)
76 {
77 uint32_t crc = xfs_start_cksum_safe(buffer, length, cksum_offset);
78
79 return *(__le32 *)(buffer + cksum_offset) == xfs_end_cksum(crc);
80 }
81
82 #endif