1*0c3983b2SBen Gras /* $NetBSD: disklabel_dkcksum.c,v 1.4 2005/05/15 21:01:34 thorpej Exp $ */
2*0c3983b2SBen Gras
3*0c3983b2SBen Gras /*-
4*0c3983b2SBen Gras * Copyright (c) 1991, 1993
5*0c3983b2SBen Gras * The Regents of the University of California. All rights reserved.
6*0c3983b2SBen Gras *
7*0c3983b2SBen Gras * Redistribution and use in source and binary forms, with or without
8*0c3983b2SBen Gras * modification, are permitted provided that the following conditions
9*0c3983b2SBen Gras * are met:
10*0c3983b2SBen Gras * 1. Redistributions of source code must retain the above copyright
11*0c3983b2SBen Gras * notice, this list of conditions and the following disclaimer.
12*0c3983b2SBen Gras * 2. Redistributions in binary form must reproduce the above copyright
13*0c3983b2SBen Gras * notice, this list of conditions and the following disclaimer in the
14*0c3983b2SBen Gras * documentation and/or other materials provided with the distribution.
15*0c3983b2SBen Gras * 3. Neither the name of the University nor the names of its contributors
16*0c3983b2SBen Gras * may be used to endorse or promote products derived from this software
17*0c3983b2SBen Gras * without specific prior written permission.
18*0c3983b2SBen Gras *
19*0c3983b2SBen Gras * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*0c3983b2SBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*0c3983b2SBen Gras * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*0c3983b2SBen Gras * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*0c3983b2SBen Gras * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*0c3983b2SBen Gras * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*0c3983b2SBen Gras * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*0c3983b2SBen Gras * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*0c3983b2SBen Gras * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*0c3983b2SBen Gras * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*0c3983b2SBen Gras * SUCH DAMAGE.
30*0c3983b2SBen Gras */
31*0c3983b2SBen Gras
32*0c3983b2SBen Gras #include <sys/cdefs.h>
33*0c3983b2SBen Gras #ifndef lint
34*0c3983b2SBen Gras #if 0
35*0c3983b2SBen Gras static char sccsid[] = "@(#)dkcksum.c 8.1 (Berkeley) 6/5/93";
36*0c3983b2SBen Gras #else
37*0c3983b2SBen Gras __RCSID("$NetBSD: disklabel_dkcksum.c,v 1.4 2005/05/15 21:01:34 thorpej Exp $");
38*0c3983b2SBen Gras #endif
39*0c3983b2SBen Gras #endif /* not lint */
40*0c3983b2SBen Gras
41*0c3983b2SBen Gras #include <sys/types.h>
42*0c3983b2SBen Gras #include <sys/disklabel.h>
43*0c3983b2SBen Gras
44*0c3983b2SBen Gras #include <util.h>
45*0c3983b2SBen Gras
46*0c3983b2SBen Gras uint16_t
disklabel_dkcksum(struct disklabel * lp)47*0c3983b2SBen Gras disklabel_dkcksum(struct disklabel *lp)
48*0c3983b2SBen Gras {
49*0c3983b2SBen Gras uint16_t *start, *end;
50*0c3983b2SBen Gras uint16_t sum;
51*0c3983b2SBen Gras
52*0c3983b2SBen Gras sum = 0;
53*0c3983b2SBen Gras start = (uint16_t *)(void *)lp;
54*0c3983b2SBen Gras end = (uint16_t *)(void *)&lp->d_partitions[lp->d_npartitions];
55*0c3983b2SBen Gras while (start < end)
56*0c3983b2SBen Gras sum ^= *start++;
57*0c3983b2SBen Gras return (sum);
58*0c3983b2SBen Gras }
59