Commit | Line | Data |
---|---|---|
70ad1ba7 JB |
1 | /* -*- mode: c; c-basic-offset: 8; -*- |
2 | * vim: noexpandtab sw=8 ts=8 sts=0: | |
3 | * | |
4 | * blockcheck.h | |
5 | * | |
6 | * Checksum and ECC codes for the OCFS2 userspace library. | |
7 | * | |
8 | * Copyright (C) 2004, 2008 Oracle. All rights reserved. | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or | |
11 | * modify it under the terms of the GNU General Public | |
12 | * License, version 2, as published by the Free Software Foundation. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | * General Public License for more details. | |
18 | */ | |
19 | ||
20 | #ifndef OCFS2_BLOCKCHECK_H | |
21 | #define OCFS2_BLOCKCHECK_H | |
22 | ||
23 | ||
24 | /* High level block API */ | |
25 | void ocfs2_compute_meta_ecc(struct super_block *sb, void *data, | |
26 | struct ocfs2_block_check *bc); | |
27 | int ocfs2_validate_meta_ecc(struct super_block *sb, void *data, | |
28 | struct ocfs2_block_check *bc); | |
29 | void ocfs2_compute_meta_ecc_bhs(struct super_block *sb, | |
30 | struct buffer_head **bhs, int nr, | |
31 | struct ocfs2_block_check *bc); | |
32 | int ocfs2_validate_meta_ecc_bhs(struct super_block *sb, | |
33 | struct buffer_head **bhs, int nr, | |
34 | struct ocfs2_block_check *bc); | |
35 | ||
36 | /* Lower level API */ | |
37 | void ocfs2_block_check_compute(void *data, size_t blocksize, | |
38 | struct ocfs2_block_check *bc); | |
39 | int ocfs2_block_check_validate(void *data, size_t blocksize, | |
40 | struct ocfs2_block_check *bc); | |
41 | void ocfs2_block_check_compute_bhs(struct buffer_head **bhs, int nr, | |
42 | struct ocfs2_block_check *bc); | |
43 | int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr, | |
44 | struct ocfs2_block_check *bc); | |
45 | ||
46 | /* | |
47 | * Hamming code functions | |
48 | */ | |
49 | ||
50 | /* | |
51 | * Encoding hamming code parity bits for a buffer. | |
52 | * | |
53 | * This is the low level encoder function. It can be called across | |
54 | * multiple hunks just like the crc32 code. 'd' is the number of bits | |
55 | * _in_this_hunk_. nr is the bit offset of this hunk. So, if you had | |
56 | * two 512B buffers, you would do it like so: | |
57 | * | |
58 | * parity = ocfs2_hamming_encode(0, buf1, 512 * 8, 0); | |
59 | * parity = ocfs2_hamming_encode(parity, buf2, 512 * 8, 512 * 8); | |
60 | * | |
61 | * If you just have one buffer, use ocfs2_hamming_encode_block(). | |
62 | */ | |
63 | u32 ocfs2_hamming_encode(u32 parity, void *data, unsigned int d, | |
64 | unsigned int nr); | |
65 | /* | |
66 | * Fix a buffer with a bit error. The 'fix' is the original parity | |
67 | * xor'd with the parity calculated now. | |
68 | * | |
69 | * Like ocfs2_hamming_encode(), this can handle hunks. nr is the bit | |
70 | * offset of the current hunk. If bit to be fixed is not part of the | |
71 | * current hunk, this does nothing. | |
72 | * | |
73 | * If you only have one buffer, use ocfs2_hamming_fix_block(). | |
74 | */ | |
75 | void ocfs2_hamming_fix(void *data, unsigned int d, unsigned int nr, | |
76 | unsigned int fix); | |
77 | ||
78 | /* Convenience wrappers for a single buffer of data */ | |
79 | extern u32 ocfs2_hamming_encode_block(void *data, unsigned int blocksize); | |
80 | extern void ocfs2_hamming_fix_block(void *data, unsigned int blocksize, | |
81 | unsigned int fix); | |
82 | #endif |