1168404Spjd/*
2168404Spjd * CDDL HEADER START
3168404Spjd *
4168404Spjd * The contents of this file are subject to the terms of the
5168404Spjd * Common Development and Distribution License (the "License").
6168404Spjd * You may not use this file except in compliance with the License.
7168404Spjd *
8168404Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9168404Spjd * or http://www.opensolaris.org/os/licensing.
10168404Spjd * See the License for the specific language governing permissions
11168404Spjd * and limitations under the License.
12168404Spjd *
13168404Spjd * When distributing Covered Code, include this CDDL HEADER in each
14168404Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15168404Spjd * If applicable, add the following below this CDDL HEADER, with the
16168404Spjd * fields enclosed by brackets "[]" replaced with your own identifying
17168404Spjd * information: Portions Copyright [yyyy] [name of copyright owner]
18168404Spjd *
19168404Spjd * CDDL HEADER END
20168404Spjd */
21168404Spjd/*
22219089Spjd * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23168404Spjd */
24168404Spjd
25168404Spjd#ifndef _SYS_ZIO_CHECKSUM_H
26168404Spjd#define	_SYS_ZIO_CHECKSUM_H
27168404Spjd
28168404Spjd#include <sys/zio.h>
29168404Spjd
30168404Spjd#ifdef	__cplusplus
31168404Spjdextern "C" {
32168404Spjd#endif
33168404Spjd
34168404Spjd/*
35168404Spjd * Signature for checksum functions.
36168404Spjd */
37168404Spjdtypedef void zio_checksum_t(const void *data, uint64_t size, zio_cksum_t *zcp);
38168404Spjd
39168404Spjd/*
40168404Spjd * Information about each checksum function.
41168404Spjd */
42168404Spjdtypedef struct zio_checksum_info {
43168404Spjd	zio_checksum_t	*ci_func[2]; /* checksum function for each byteorder */
44168404Spjd	int		ci_correctable;	/* number of correctable bits	*/
45219089Spjd	int		ci_eck;		/* uses zio embedded checksum? */
46219089Spjd	int		ci_dedup;	/* strong enough for dedup? */
47168404Spjd	char		*ci_name;	/* descriptive name */
48168404Spjd} zio_checksum_info_t;
49168404Spjd
50219089Spjdtypedef struct zio_bad_cksum {
51219089Spjd	zio_cksum_t		zbc_expected;
52219089Spjd	zio_cksum_t		zbc_actual;
53219089Spjd	const char		*zbc_checksum_name;
54219089Spjd	uint8_t			zbc_byteswapped;
55219089Spjd	uint8_t			zbc_injected;
56219089Spjd	uint8_t			zbc_has_cksum;	/* expected/actual valid */
57219089Spjd} zio_bad_cksum_t;
58219089Spjd
59168404Spjdextern zio_checksum_info_t zio_checksum_table[ZIO_CHECKSUM_FUNCTIONS];
60168404Spjd
61168404Spjd/*
62168404Spjd * Checksum routines.
63168404Spjd */
64168404Spjdextern zio_checksum_t zio_checksum_SHA256;
65168404Spjd
66185029Spjdextern void zio_checksum_compute(zio_t *zio, enum zio_checksum checksum,
67168404Spjd    void *data, uint64_t size);
68219089Spjdextern int zio_checksum_error(zio_t *zio, zio_bad_cksum_t *out);
69219089Spjdextern enum zio_checksum spa_dedup_checksum(spa_t *spa);
70168404Spjd
71168404Spjd#ifdef	__cplusplus
72168404Spjd}
73168404Spjd#endif
74168404Spjd
75168404Spjd#endif	/* _SYS_ZIO_CHECKSUM_H */
76