]>
git.saurik.com Git - apple/hfs.git/blob - livefiles_cs_plugin/lf_cs_checksum.h
2 // Copyright (c) 2009-2019 Apple Inc. All rights reserved.
4 // lf_cs_checksum.h - Defines for checksum handling for livefiles
5 // Apple_CoreStorage plugin.
7 // This header is copied from CoreStorage project.
10 #ifndef _LF_CS_CHECKSUM_H
11 #define _LF_CS_CHECKSUM_H
21 // Every metadata block has a checksum to check the data integrity. Different
22 // checksum algorithms can be used by CoreStorage, and [[lvg_checksum_alg]] in
23 // [[lvg_info_t]] records what checksum algorithm to use. For the first
24 // prototype, I am copying the CRC algorithm from the UDF project.
26 // The fletcher 2 algorithm used by ZFS has fundamental flaws. And a variation
27 // of the fletcher 8 algorithm could be used, which is 2 times faster than
28 // CRC32 and 4 times faster than fletcher.
30 // <cksum definitions>=
32 #define MAX_CKSUM_NBYTES 8
36 CKSUM_ALG_CRC_32
, // CRC-32 algorithm copied from CRC32-C polynomial
38 typedef enum cksum_alg cksum_alg_t
;
41 #define BITS_PER_BYTE 8L
42 #define META_CKSUM_BITS (MAX_CKSUM_NBYTES * BITS_PER_BYTE)
45 // Initialize checksum for a certain algorithm
47 bool cksum_init(cksum_alg_t alg
, uint8_t cksum
[MAX_CKSUM_NBYTES
]);
50 // cksum - Calculate checksum of data for len bytes
52 // Existing value of cksum is also used to calculate the checksum. In order to
53 // calculate cksums of different memory chunks, this function can be called
56 // cksum(alg, data1, len1, cksum);
57 // cksum(alg, data2, len2, cksum);
59 // and the resultant cksum is calculated on two chunks
61 void cksum(cksum_alg_t alg
, const void *data
, size_t len
,
62 uint8_t cksum
[MAX_CKSUM_NBYTES
]);
64 #endif /* _LF_CS_CHECKSUM_H */