xref: /titanic_41/usr/src/uts/common/sys/lvm/md_crc.h (revision 95efa359b507db290a2484b8f615822b1e06096f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_MD_CRC_H
28 #define	_SYS_MD_CRC_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /* md_crc.c */
39 /*
40  * Structure to hold fields to be skipped when calculating the checksum
41  */
42 typedef struct crc_skip {
43 	struct crc_skip	*skip_next;
44 	int		skip_offset;
45 	int		skip_size;
46 } crc_skip_t;
47 
48 extern uint_t			crcfunc(uint_t check,
49 				    uchar_t *record,
50 				    uint_t *result,
51 				    size_t size,
52 				    crc_skip_t *skip);
53 extern void			crcfreetab(void);
54 
55 /*
56  * The following crc defines allow for a number of areas to be skipped
57  * (not be included in the data being crc'd) in the record
58  * block (mddb_rb_32). These areas are the 12 byte area covering
59  *	rb_checksum_fiddle, rb_private and rb_userdata
60  *
61  * In addition the skipped areas include the timestamps in the crc for
62  * MN disksets.
63  */
64 #ifndef DEBUG
65 #define	crcgen(record, result, size, skip) \
66 	(void) crcfunc(0, (uchar_t *)(record), (uint_t *)(result), \
67 	    (size_t)(size), (crc_skip_t *)(skip))
68 
69 #else /* DEBUG */
70 
71 #ifdef	_KERNEL
72 #define	crcgen(record, result, size, skip)		{\
73 	uint_t b = crcfunc(0, (uchar_t *)(record), (uint_t *)(result), \
74 	    (size_t)(size), (crc_skip_t *)(skip)); \
75 	(void) crcfunc(0, (uchar_t *)(record), (uint_t *)(result), \
76 	    (size_t)(size), (crc_skip_t *)(skip)); \
77 	ASSERT (*((uint_t *)(result)) == b); \
78 }
79 #else	/* !_KERNEL */
80 #define	crcgen(record, result, size, skip)		{\
81 	uint_t b = crcfunc(0, (uchar_t *)(record), (uint_t *)(result), \
82 	    (size_t)(size), (crc_skip_t *)(skip)); \
83 	(void) crcfunc(0, (uchar_t *)(record), (uint_t *)(result), \
84 	    (size_t)(size), (crc_skip_t *)(skip)); \
85 	assert (*((uint_t *)(result)) == b); \
86 }
87 #endif	/* _KERNEL */
88 #endif	/* DEBUG */
89 
90 #define	crcchk(record, result, size, skip) crcfunc(1, (uchar_t *)(record), \
91 	(uint_t *)(result), (size_t)(size), (crc_skip_t *)(skip))
92 
93 #ifdef	__cplusplus
94 }
95 #endif
96 
97 #endif	/* _SYS_MD_CRC_H */
98