]> git.saurik.com Git - apple/hfs.git/blob - livefiles_cs_plugin/lf_cs_checksum.h
hfs-556.41.1.tar.gz
[apple/hfs.git] / livefiles_cs_plugin / lf_cs_checksum.h
1 //
2 // Copyright (c) 2009-2019 Apple Inc. All rights reserved.
3 //
4 // lf_cs_checksum.h - Defines for checksum handling for livefiles
5 // Apple_CoreStorage plugin.
6 //
7 // This header is copied from CoreStorage project.
8 //
9
10 #ifndef _LF_CS_CHECKSUM_H
11 #define _LF_CS_CHECKSUM_H
12
13 #include <stdint.h>
14 #include <string.h>
15 #include <stddef.h>
16 #include <stdbool.h>
17
18 //
19 // Checksum Algorithm
20 //
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.
25 //
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.
29 //
30 // <cksum definitions>=
31 //
32 #define MAX_CKSUM_NBYTES 8
33
34 enum cksum_alg {
35 CKSUM_NONE,
36 CKSUM_ALG_CRC_32, // CRC-32 algorithm copied from CRC32-C polynomial
37 };
38 typedef enum cksum_alg cksum_alg_t;
39
40
41 #define BITS_PER_BYTE 8L
42 #define META_CKSUM_BITS (MAX_CKSUM_NBYTES * BITS_PER_BYTE)
43
44 //
45 // Initialize checksum for a certain algorithm
46 //
47 bool cksum_init(cksum_alg_t alg, uint8_t cksum[MAX_CKSUM_NBYTES]);
48
49 //
50 // cksum - Calculate checksum of data for len bytes
51 //
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
54 // several times:
55 //
56 // cksum(alg, data1, len1, cksum);
57 // cksum(alg, data2, len2, cksum);
58 //
59 // and the resultant cksum is calculated on two chunks
60 //
61 void cksum(cksum_alg_t alg, const void *data, size_t len,
62 uint8_t cksum[MAX_CKSUM_NBYTES]);
63
64 #endif /* _LF_CS_CHECKSUM_H */