svn commit: r247611 - head/lib/libstand

Marcel Moolenaar marcel at FreeBSD.org
Sat Mar 2 05:03:36 UTC 2013


Author: marcel
Date: Sat Mar  2 05:03:36 2013
New Revision: 247611
URL: http://svnweb.freebsd.org/changeset/base/247611

Log:
  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.

Modified:
  head/lib/libstand/nandfs.c

Modified: head/lib/libstand/nandfs.c
==============================================================================
--- head/lib/libstand/nandfs.c	Sat Mar  2 05:02:29 2013	(r247610)
+++ head/lib/libstand/nandfs.c	Sat Mar  2 05:03:36 2013	(r247611)
@@ -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_fs
 
 	/* 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 nandf
 
 	/* 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;


More information about the svn-src-all mailing list