151185Sbostic /*- 251185Sbostic * Copyright (c) 1991 The Regents of the University of California. 351185Sbostic * All rights reserved. 451185Sbostic * 551185Sbostic * %sccs.include.redist.c% 651185Sbostic * 7*53353Sbostic * @(#)lfs_cksum.c 7.3 (Berkeley) 05/04/92 851185Sbostic */ 951185Sbostic 1051487Sbostic #include <sys/param.h> 1151185Sbostic 1251495Sbostic #include <ufs/lfs/lfs.h> 1351495Sbostic #include <ufs/lfs/lfs_extern.h> 1451487Sbostic 1551185Sbostic /* 1651215Sbostic * Simple, general purpose, fast checksum. Data must be short-aligned. 1751215Sbostic * Returns a u_long in case we ever want to do something more rigorous. 1851487Sbostic * 1951487Sbostic * XXX 2051487Sbostic * Use the TCP/IP checksum instead. 2151185Sbostic */ 2251185Sbostic u_long 2351185Sbostic cksum(str, len) 2451185Sbostic register void *str; 2551185Sbostic register size_t len; 2651185Sbostic { 2751185Sbostic register u_long sum; 2851185Sbostic 2951185Sbostic len &= ~(sizeof(u_short) - 1); 30*53353Sbostic for (sum = 0; len; len -= sizeof(u_short)) { 31*53353Sbostic sum ^= *(u_short *)str; 32*53353Sbostic ++(u_short *)str; 33*53353Sbostic } 3451185Sbostic return (sum); 3551185Sbostic } 36