Commit | Line | Data |
---|---|---|
e4c3f0d8 KB |
1 | /*- |
2 | * Copyright (c) 1991 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * %sccs.include.redist.c% | |
6 | * | |
d5cb0372 | 7 | * @(#)lfs_cksum.c 7.4 (Berkeley) %G% |
e4c3f0d8 KB |
8 | */ |
9 | ||
f6437c6d | 10 | #include <sys/param.h> |
dcde5f10 | 11 | #include <sys/vnode.h> |
f6437c6d | 12 | |
7688a3ec KB |
13 | #include <ufs/lfs/lfs.h> |
14 | #include <ufs/lfs/lfs_extern.h> | |
e4c3f0d8 KB |
15 | |
16 | /* | |
275ca4f0 KB |
17 | * Simple, general purpose, fast checksum. Data must be short-aligned. |
18 | * Returns a u_long in case we ever want to do something more rigorous. | |
f6437c6d KB |
19 | * |
20 | * XXX | |
21 | * Use the TCP/IP checksum instead. | |
e4c3f0d8 KB |
22 | */ |
23 | u_long | |
24 | cksum(str, len) | |
25 | register void *str; | |
26 | register size_t len; | |
27 | { | |
28 | register u_long sum; | |
29 | ||
30 | len &= ~(sizeof(u_short) - 1); | |
aac71cb6 KB |
31 | for (sum = 0; len; len -= sizeof(u_short)) { |
32 | sum ^= *(u_short *)str; | |
33 | ++(u_short *)str; | |
34 | } | |
e4c3f0d8 KB |
35 | return (sum); |
36 | } |