Fix nandfs support by providing the same crc32 function as is used

in newfs_nandfs. In libstand we get crc32 from libz. The polynomial
is not the same as used for nandfs, which is the crc32 used in the
kernel.
This commit is contained in:
Marcel Moolenaar 2013-03-02 05:03:36 +00:00
parent e40f53aa44
commit 9b6799ad6b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=247611

View File

@ -125,6 +125,27 @@ struct fs_ops nandfs_fsops = {
#define NINDIR(fs) ((fs)->nf_blocksize / sizeof(nandfs_daddr_t))
/* from NetBSD's src/sys/net/if_ethersubr.c */
static uint32_t
nandfs_crc32(uint32_t crc, const uint8_t *buf, size_t len)
{
static const uint32_t crctab[] = {
0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
};
size_t i;
crc = crc ^ ~0U;
for (i = 0; i < len; i++) {
crc ^= buf[i];
crc = (crc >> 4) ^ crctab[crc & 0xf];
crc = (crc >> 4) ^ crctab[crc & 0xf];
}
return (crc ^ ~0U);
}
static int
nandfs_check_fsdata_crc(struct nandfs_fsdata *fsdata)
{
@ -138,7 +159,7 @@ nandfs_check_fsdata_crc(struct nandfs_fsdata *fsdata)
/* Calculate */
fsdata->f_sum = (0);
comp_crc = crc32(0, (uint8_t *)fsdata, fsdata->f_bytes);
comp_crc = nandfs_crc32(0, (uint8_t *)fsdata, fsdata->f_bytes);
/* Restore */
fsdata->f_sum = fsdata_crc;
@ -162,7 +183,7 @@ nandfs_check_superblock_crc(struct nandfs_fsdata *fsdata,
/* Calculate */
super->s_sum = (0);
comp_crc = crc32(0, (uint8_t *)super, fsdata->f_sbbytes);
comp_crc = nandfs_crc32(0, (uint8_t *)super, fsdata->f_sbbytes);
/* Restore */
super->s_sum = super_crc;