diff options
author | marcel <marcel@FreeBSD.org> | 2013-03-02 05:03:36 +0000 |
---|---|---|
committer | marcel <marcel@FreeBSD.org> | 2013-03-02 05:03:36 +0000 |
commit | 92a73b39ae592cec0fde94aed1f3755d1e1cd9b8 (patch) | |
tree | 28cb8dc157bd230e6a9161d5fee0d7d76277b3e8 /lib/libstand | |
parent | a94abfa9f501e5affb2adf41751ae19fe18a1b36 (diff) | |
download | FreeBSD-src-92a73b39ae592cec0fde94aed1f3755d1e1cd9b8.zip FreeBSD-src-92a73b39ae592cec0fde94aed1f3755d1e1cd9b8.tar.gz |
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.
Diffstat (limited to 'lib/libstand')
-rw-r--r-- | lib/libstand/nandfs.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/libstand/nandfs.c b/lib/libstand/nandfs.c index d5fcb9d..2ddf8c3 100644 --- a/lib/libstand/nandfs.c +++ b/lib/libstand/nandfs.c @@ -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; |