xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/zio_checksum.h (revision cde58dbc6a23d4d38db7c8866312be83221c765f)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5ea8dc4b6Seschrock  * Common Development and Distribution License (the "License").
6ea8dc4b6Seschrock  * You may not use this file except in compliance with the License.
7fa9e4066Sahrens  *
8fa9e4066Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens  * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens  * See the License for the specific language governing permissions
11fa9e4066Sahrens  * and limitations under the License.
12fa9e4066Sahrens  *
13fa9e4066Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens  *
19fa9e4066Sahrens  * CDDL HEADER END
20fa9e4066Sahrens  */
21fa9e4066Sahrens /*
22*cde58dbcSMatthew Ahrens  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23fa9e4066Sahrens  */
24fa9e4066Sahrens 
25fa9e4066Sahrens #ifndef _SYS_ZIO_CHECKSUM_H
26fa9e4066Sahrens #define	_SYS_ZIO_CHECKSUM_H
27fa9e4066Sahrens 
28fa9e4066Sahrens #include <sys/zio.h>
29fa9e4066Sahrens 
30fa9e4066Sahrens #ifdef	__cplusplus
31fa9e4066Sahrens extern "C" {
32fa9e4066Sahrens #endif
33fa9e4066Sahrens 
34fa9e4066Sahrens /*
35fa9e4066Sahrens  * Signature for checksum functions.
36fa9e4066Sahrens  */
37fa9e4066Sahrens typedef void zio_checksum_t(const void *data, uint64_t size, zio_cksum_t *zcp);
38fa9e4066Sahrens 
39fa9e4066Sahrens /*
40fa9e4066Sahrens  * Information about each checksum function.
41fa9e4066Sahrens  */
42fa9e4066Sahrens typedef struct zio_checksum_info {
43fa9e4066Sahrens 	zio_checksum_t	*ci_func[2]; /* checksum function for each byteorder */
44fa9e4066Sahrens 	int		ci_correctable;	/* number of correctable bits	*/
456e1f5caaSNeil Perrin 	int		ci_eck;		/* uses zio embedded checksum? */
46b24ab676SJeff Bonwick 	int		ci_dedup;	/* strong enough for dedup? */
47fa9e4066Sahrens 	char		*ci_name;	/* descriptive name */
48fa9e4066Sahrens } zio_checksum_info_t;
49fa9e4066Sahrens 
5022fe2c88SJonathan Adams typedef struct zio_bad_cksum {
5122fe2c88SJonathan Adams 	zio_cksum_t		zbc_expected;
5222fe2c88SJonathan Adams 	zio_cksum_t		zbc_actual;
5322fe2c88SJonathan Adams 	const char		*zbc_checksum_name;
5422fe2c88SJonathan Adams 	uint8_t			zbc_byteswapped;
5522fe2c88SJonathan Adams 	uint8_t			zbc_injected;
5622fe2c88SJonathan Adams 	uint8_t			zbc_has_cksum;	/* expected/actual valid */
5722fe2c88SJonathan Adams } zio_bad_cksum_t;
5822fe2c88SJonathan Adams 
59fa9e4066Sahrens extern zio_checksum_info_t zio_checksum_table[ZIO_CHECKSUM_FUNCTIONS];
60fa9e4066Sahrens 
61fa9e4066Sahrens /*
62fa9e4066Sahrens  * Checksum routines.
63fa9e4066Sahrens  */
64fa9e4066Sahrens extern zio_checksum_t zio_checksum_SHA256;
65fa9e4066Sahrens 
66e14bb325SJeff Bonwick extern void zio_checksum_compute(zio_t *zio, enum zio_checksum checksum,
67fa9e4066Sahrens     void *data, uint64_t size);
6822fe2c88SJonathan Adams extern int zio_checksum_error(zio_t *zio, zio_bad_cksum_t *out);
69*cde58dbcSMatthew Ahrens extern enum zio_checksum spa_dedup_checksum(spa_t *spa);
70fa9e4066Sahrens 
71fa9e4066Sahrens #ifdef	__cplusplus
72fa9e4066Sahrens }
73fa9e4066Sahrens #endif
74fa9e4066Sahrens 
75fa9e4066Sahrens #endif	/* _SYS_ZIO_CHECKSUM_H */
76