lfs_cksum.c revision 1.10 1 1.10 perseant /* $NetBSD: lfs_cksum.c,v 1.10 1999/03/10 00:20:00 perseant Exp $ */
2 1.2 cgd
3 1.1 mycroft /*-
4 1.10 perseant * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 1.10 perseant * All rights reserved.
6 1.10 perseant *
7 1.10 perseant * This code is derived from software contributed to The NetBSD Foundation
8 1.10 perseant * by Konrad E. Schroder <perseant (at) hhhh.org>.
9 1.10 perseant *
10 1.10 perseant * Redistribution and use in source and binary forms, with or without
11 1.10 perseant * modification, are permitted provided that the following conditions
12 1.10 perseant * are met:
13 1.10 perseant * 1. Redistributions of source code must retain the above copyright
14 1.10 perseant * notice, this list of conditions and the following disclaimer.
15 1.10 perseant * 2. Redistributions in binary form must reproduce the above copyright
16 1.10 perseant * notice, this list of conditions and the following disclaimer in the
17 1.10 perseant * documentation and/or other materials provided with the distribution.
18 1.10 perseant * 3. All advertising materials mentioning features or use of this software
19 1.10 perseant * must display the following acknowledgement:
20 1.10 perseant * This product includes software developed by the NetBSD
21 1.10 perseant * Foundation, Inc. and its contributors.
22 1.10 perseant * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.10 perseant * contributors may be used to endorse or promote products derived
24 1.10 perseant * from this software without specific prior written permission.
25 1.10 perseant *
26 1.10 perseant * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.10 perseant * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.10 perseant * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.10 perseant * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.10 perseant * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.10 perseant * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.10 perseant * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.10 perseant * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.10 perseant * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.10 perseant * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.10 perseant * POSSIBILITY OF SUCH DAMAGE.
37 1.10 perseant */
38 1.10 perseant /*-
39 1.1 mycroft * Copyright (c) 1991, 1993
40 1.1 mycroft * The Regents of the University of California. All rights reserved.
41 1.1 mycroft *
42 1.1 mycroft * Redistribution and use in source and binary forms, with or without
43 1.1 mycroft * modification, are permitted provided that the following conditions
44 1.1 mycroft * are met:
45 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
46 1.1 mycroft * notice, this list of conditions and the following disclaimer.
47 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
48 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
49 1.1 mycroft * documentation and/or other materials provided with the distribution.
50 1.1 mycroft * 3. All advertising materials mentioning features or use of this software
51 1.1 mycroft * must display the following acknowledgement:
52 1.1 mycroft * This product includes software developed by the University of
53 1.1 mycroft * California, Berkeley and its contributors.
54 1.1 mycroft * 4. Neither the name of the University nor the names of its contributors
55 1.1 mycroft * may be used to endorse or promote products derived from this software
56 1.1 mycroft * without specific prior written permission.
57 1.1 mycroft *
58 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 1.1 mycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 1.1 mycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 1.1 mycroft * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 1.1 mycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 1.1 mycroft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 1.1 mycroft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 1.1 mycroft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 1.1 mycroft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 1.1 mycroft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 1.1 mycroft * SUCH DAMAGE.
69 1.1 mycroft *
70 1.4 mycroft * @(#)lfs_cksum.c 8.2 (Berkeley) 10/9/94
71 1.1 mycroft */
72 1.1 mycroft
73 1.1 mycroft #include <sys/types.h>
74 1.9 pk #include <sys/param.h>
75 1.6 christos #ifdef _KERNEL
76 1.8 fvdl #include <sys/systm.h>
77 1.8 fvdl #include <sys/lock.h>
78 1.9 pk #endif
79 1.9 pk #include <sys/mount.h>
80 1.8 fvdl #include <ufs/ufs/quota.h>
81 1.8 fvdl #include <ufs/ufs/inode.h>
82 1.9 pk #include <ufs/lfs/lfs.h>
83 1.5 christos #include <ufs/lfs/lfs_extern.h>
84 1.1 mycroft
85 1.1 mycroft /*
86 1.1 mycroft * Simple, general purpose, fast checksum. Data must be short-aligned.
87 1.1 mycroft * Returns a u_long in case we ever want to do something more rigorous.
88 1.1 mycroft *
89 1.1 mycroft * XXX
90 1.1 mycroft * Use the TCP/IP checksum instead.
91 1.1 mycroft */
92 1.1 mycroft u_long
93 1.1 mycroft cksum(str, len)
94 1.1 mycroft register void *str;
95 1.1 mycroft register size_t len;
96 1.1 mycroft {
97 1.1 mycroft register u_long sum;
98 1.1 mycroft
99 1.1 mycroft len &= ~(sizeof(u_short) - 1);
100 1.1 mycroft for (sum = 0; len; len -= sizeof(u_short)) {
101 1.1 mycroft sum ^= *(u_short *)str;
102 1.3 cgd str = (void *)((u_short *)str + 1);
103 1.1 mycroft }
104 1.1 mycroft return (sum);
105 1.9 pk }
106 1.9 pk
107 1.10 perseant u_long
108 1.9 pk lfs_sb_cksum(fs)
109 1.10 perseant struct dlfs *fs;
110 1.9 pk {
111 1.10 perseant size_t size;
112 1.10 perseant
113 1.10 perseant size = (size_t)&(((struct dlfs *)0)->dlfs_cksum);
114 1.10 perseant return cksum(fs,size);
115 1.1 mycroft }
116