2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
36 * The routines in this module are used to fill/check a data buffer
37 * with/against a known pattern.
41 pattern_check(buf, buflen, pat, patlen, patshift)
52 patshift = patshift % patlen;
58 * The following 2 blocks of code are to compare the first patlen
59 * bytes of buf. We need 2 checks if patshift is > 0 since we
60 * must check the last (patlen - patshift) bytes, and then the
61 * first (patshift) bytes.
64 nb = patlen - patshift;
66 return (memcmp(cp, pat + patshift, nleft) ? -1 : 0);
68 if (memcmp(cp, pat + patshift, nb))
78 return (memcmp(cp, pat, nleft) ? -1 : 0);
80 if (memcmp(cp, pat, nb))
89 * Now, verify the rest of the buffer using the algorithm described
90 * in the function header.
94 while (ncmp < buflen) {
95 nb = (ncmp < nleft) ? ncmp : nleft;
96 if (memcmp(buf, cp, nb))
108 pattern_fill(buf, buflen, pat, patlen, patshift)
115 int trans, ncopied, nleft;
119 patshift = patshift % patlen;
125 * The following 2 blocks of code are to fill the first patlen
126 * bytes of buf. We need 2 sections if patshift is > 0 since we
127 * must first copy the last (patlen - patshift) bytes into buf[0]...,
128 * and then the first (patshift) bytes of pattern following them.
131 trans = patlen - patshift;
133 memcpy(cp, pat + patshift, nleft);
136 memcpy(cp, pat + patshift, trans);
144 memcpy(cp, pat, nleft);
147 memcpy(cp, pat, trans);
154 * Now, fill the rest of the buffer using the algorithm described
155 * in the function header comment.
159 while (ncopied < buflen) {
160 trans = (ncopied < nleft) ? ncopied : nleft;
161 memcpy(cp, buf, trans);