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