/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#ifndef _KERNEL
#include <meta.h>
#include <assert.h>
#else /* _KERNEL */
#endif /* ! _KERNEL */
static uint_t *
crcgentab(void)
{
int b, i;
uint_t v;
for (b = 0; b < 256; b++) {
for (v = b << (24), i = 0; i < 8; i++) {
if (v & ((unsigned int)1 << 31)) {
v = (v << 1) ^ poly;
} else {
v = v << 1;
}
}
crctab[b] = v;
}
return (crctab);
}
/*
* crc function that allows a number of areas to be skipped (ignored)
* during the crc computation. The result area of the record is also ignored
* during the crc computation. Ignored areas are used for data that may
* be changed after record has been crcgen'd, but before the data has been
* written to disk or for when a multi-owner diskset may have multiple
* nodes writing the same record data with the exception of the timestamp field.
* The list of skip areas must be in ascending order of offset and if any
* areas overlap, the list will be modified.
*/
)
{
crc_skip_t *s, *p;
/*
* Check skip areas to see if they overlap (this should never happen,
* but is handled just in case something changes in the future).
* Also the skip list must be in ascending order of offset, assert
* error if this is not the case.
* If any 2 adjacent skip areas overlap, then the skip areas will
* be merged into 1 skip area and the other skip area is freed.
* If any 2 adjacent skip areas abut (border) each other, then skip
* areas are not merged, but are left as 2 independent skip areas.
* If the skip areas are identical, no change is made to either skip
* area since this is handled later.
*/
if (skip) {
p = NULL;
if (p == NULL) {
p = s;
continue;
}
#ifdef _KERNEL
#else
#endif
/*
* Current area overlaps previous, modify
* previous area and release current
*/
+ p->skip_size - s->skip_offset);
MD_FREE(s, sizeof (crc_skip_t));
s = p;
}
p = s;
}
}
if (! mddb_crctab)
mddb_crctab = crcgentab();
s = skip;
while (size--) {
/* Skip the result pointer */
continue;
}
/*
* Skip over next skip area if non-null
*/
s = s->skip_next;
continue;
}
}
/* If we are checking, we either get a 0 - OK, or 1 - Not OK result */
if (check) {
return (0);
return (1);
}
/*
* If we are generating, we stuff the result, if we have a result
* pointer, and return the value.
*/
return (newcrc);
}
void
crcfreetab(void)
{
if (mddb_crctab) {
mddb_crctab = NULL;
}
}