1*f2b0a446Sthorpej /* $NetBSD: disklabel_dkcksum.c,v 1.4 2005/05/15 21:01:34 thorpej Exp $ */
2448f6217Selric
3448f6217Selric /*-
4448f6217Selric * Copyright (c) 1991, 1993
5448f6217Selric * The Regents of the University of California. All rights reserved.
6448f6217Selric *
7448f6217Selric * Redistribution and use in source and binary forms, with or without
8448f6217Selric * modification, are permitted provided that the following conditions
9448f6217Selric * are met:
10448f6217Selric * 1. Redistributions of source code must retain the above copyright
11448f6217Selric * notice, this list of conditions and the following disclaimer.
12448f6217Selric * 2. Redistributions in binary form must reproduce the above copyright
13448f6217Selric * notice, this list of conditions and the following disclaimer in the
14448f6217Selric * documentation and/or other materials provided with the distribution.
15eb7c1594Sagc * 3. Neither the name of the University nor the names of its contributors
16448f6217Selric * may be used to endorse or promote products derived from this software
17448f6217Selric * without specific prior written permission.
18448f6217Selric *
19448f6217Selric * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20448f6217Selric * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21448f6217Selric * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22448f6217Selric * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23448f6217Selric * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24448f6217Selric * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25448f6217Selric * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26448f6217Selric * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27448f6217Selric * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28448f6217Selric * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29448f6217Selric * SUCH DAMAGE.
30448f6217Selric */
31448f6217Selric
32448f6217Selric #include <sys/cdefs.h>
33448f6217Selric #ifndef lint
34448f6217Selric #if 0
35448f6217Selric static char sccsid[] = "@(#)dkcksum.c 8.1 (Berkeley) 6/5/93";
36448f6217Selric #else
37*f2b0a446Sthorpej __RCSID("$NetBSD: disklabel_dkcksum.c,v 1.4 2005/05/15 21:01:34 thorpej Exp $");
38448f6217Selric #endif
39448f6217Selric #endif /* not lint */
40448f6217Selric
41448f6217Selric #include <sys/types.h>
42448f6217Selric #include <sys/disklabel.h>
43448f6217Selric
44448f6217Selric #include <util.h>
45448f6217Selric
46*f2b0a446Sthorpej uint16_t
disklabel_dkcksum(struct disklabel * lp)47448f6217Selric disklabel_dkcksum(struct disklabel *lp)
48448f6217Selric {
49*f2b0a446Sthorpej uint16_t *start, *end;
50*f2b0a446Sthorpej uint16_t sum;
51448f6217Selric
52448f6217Selric sum = 0;
53*f2b0a446Sthorpej start = (uint16_t *)(void *)lp;
54*f2b0a446Sthorpej end = (uint16_t *)(void *)&lp->d_partitions[lp->d_npartitions];
55448f6217Selric while (start < end)
56448f6217Selric sum ^= *start++;
57448f6217Selric return (sum);
58448f6217Selric }
59