1*58567fe6Smiod /* $OpenBSD: dkcksum.c,v 1.6 2014/11/19 20:28:56 miod Exp $ */
221c66822Sderaadt /* $NetBSD: disklabel.c,v 1.3 1994/10/26 05:44:42 cgd Exp $ */
321c66822Sderaadt
421c66822Sderaadt /*-
521c66822Sderaadt * Copyright (c) 1993
621c66822Sderaadt * The Regents of the University of California. All rights reserved.
721c66822Sderaadt *
821c66822Sderaadt * Redistribution and use in source and binary forms, with or without
921c66822Sderaadt * modification, are permitted provided that the following conditions
1021c66822Sderaadt * are met:
1121c66822Sderaadt * 1. Redistributions of source code must retain the above copyright
1221c66822Sderaadt * notice, this list of conditions and the following disclaimer.
1321c66822Sderaadt * 2. Redistributions in binary form must reproduce the above copyright
1421c66822Sderaadt * notice, this list of conditions and the following disclaimer in the
1521c66822Sderaadt * documentation and/or other materials provided with the distribution.
1629295d1cSmillert * 3. Neither the name of the University nor the names of its contributors
1721c66822Sderaadt * may be used to endorse or promote products derived from this software
1821c66822Sderaadt * without specific prior written permission.
1921c66822Sderaadt *
2021c66822Sderaadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2121c66822Sderaadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2221c66822Sderaadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2321c66822Sderaadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2421c66822Sderaadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2521c66822Sderaadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2621c66822Sderaadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2721c66822Sderaadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2821c66822Sderaadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2921c66822Sderaadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3021c66822Sderaadt * SUCH DAMAGE.
3121c66822Sderaadt *
3221c66822Sderaadt * @(#)disklabel.c 8.1 (Berkeley) 6/11/93
3321c66822Sderaadt */
3421c66822Sderaadt
3521c66822Sderaadt #include <sys/param.h>
3621c66822Sderaadt #include <sys/disklabel.h>
3721c66822Sderaadt #include "stand.h"
3821c66822Sderaadt
3921c66822Sderaadt /*
4021c66822Sderaadt * Compute checksum for disk label.
4121c66822Sderaadt */
4292c155deSmickey u_int
dkcksum(const struct disklabel * lp)43*58567fe6Smiod dkcksum(const struct disklabel *lp)
4421c66822Sderaadt {
45599546b3Sderaadt u_short *start, *end;
46599546b3Sderaadt u_short sum = 0;
4721c66822Sderaadt
4821c66822Sderaadt start = (u_short *)lp;
4921c66822Sderaadt end = (u_short *)&lp->d_partitions[lp->d_npartitions];
5021c66822Sderaadt while (start < end)
5121c66822Sderaadt sum ^= *start++;
5221c66822Sderaadt return (sum);
5321c66822Sderaadt }
54