1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000 Silicon Graphics, Inc.
10 * The routines in this module are used to fill/check a data buffer
11 * with/against a known pattern.
15 pattern_check(buf, buflen, pat, patlen, patshift)
26 patshift = patshift % patlen;
32 * The following 2 blocks of code are to compare the first patlen
33 * bytes of buf. We need 2 checks if patshift is > 0 since we
34 * must check the last (patlen - patshift) bytes, and then the
35 * first (patshift) bytes.
38 nb = patlen - patshift;
40 return (memcmp(cp, pat + patshift, nleft) ? -1 : 0);
42 if (memcmp(cp, pat + patshift, nb))
52 return (memcmp(cp, pat, nleft) ? -1 : 0);
54 if (memcmp(cp, pat, nb))
63 * Now, verify the rest of the buffer using the algorithm described
64 * in the function header.
68 while (ncmp < buflen) {
69 nb = (ncmp < nleft) ? ncmp : nleft;
70 if (memcmp(buf, cp, nb))
82 pattern_fill(buf, buflen, pat, patlen, patshift)
89 int trans, ncopied, nleft;
93 patshift = patshift % patlen;
99 * The following 2 blocks of code are to fill the first patlen
100 * bytes of buf. We need 2 sections if patshift is > 0 since we
101 * must first copy the last (patlen - patshift) bytes into buf[0]...,
102 * and then the first (patshift) bytes of pattern following them.
105 trans = patlen - patshift;
107 memcpy(cp, pat + patshift, nleft);
110 memcpy(cp, pat + patshift, trans);
118 memcpy(cp, pat, nleft);
121 memcpy(cp, pat, trans);
128 * Now, fill the rest of the buffer using the algorithm described
129 * in the function header comment.
133 while (ncopied < buflen) {
134 trans = (ncopied < nleft) ? ncopied : nleft;
135 memcpy(cp, buf, trans);