2 * Copyright (c) 2000 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * The routines in this module are used to fill/check a data buffer
23 * with/against a known pattern.
27 pattern_check(buf, buflen, pat, patlen, patshift)
38 patshift = patshift % patlen;
44 * The following 2 blocks of code are to compare the first patlen
45 * bytes of buf. We need 2 checks if patshift is > 0 since we
46 * must check the last (patlen - patshift) bytes, and then the
47 * first (patshift) bytes.
50 nb = patlen - patshift;
52 return (memcmp(cp, pat + patshift, nleft) ? -1 : 0);
54 if (memcmp(cp, pat + patshift, nb))
64 return (memcmp(cp, pat, nleft) ? -1 : 0);
66 if (memcmp(cp, pat, nb))
75 * Now, verify the rest of the buffer using the algorithm described
76 * in the function header.
80 while (ncmp < buflen) {
81 nb = (ncmp < nleft) ? ncmp : nleft;
82 if (memcmp(buf, cp, nb))
94 pattern_fill(buf, buflen, pat, patlen, patshift)
101 int trans, ncopied, nleft;
105 patshift = patshift % patlen;
111 * The following 2 blocks of code are to fill the first patlen
112 * bytes of buf. We need 2 sections if patshift is > 0 since we
113 * must first copy the last (patlen - patshift) bytes into buf[0]...,
114 * and then the first (patshift) bytes of pattern following them.
117 trans = patlen - patshift;
119 memcpy(cp, pat + patshift, nleft);
122 memcpy(cp, pat + patshift, trans);
130 memcpy(cp, pat, nleft);
133 memcpy(cp, pat, trans);
140 * Now, fill the rest of the buffer using the algorithm described
141 * in the function header comment.
145 while (ncopied < buflen) {
146 trans = (ncopied < nleft) ? ncopied : nleft;
147 memcpy(cp, buf, trans);