Module Name:    othersrc
Committed By:   agc
Date:           Tue Apr 26 15:41:26 UTC 2011

Modified Files:
        othersrc/external/bsd/rs: Makefile
        othersrc/external/bsd/rs/dist: TODO librs.3 rs.c rs.h

Log Message:
add a small rs_parity(3) function, which simply calculates the Reed
Solomon parity - no input copying is involved.


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r1.2 othersrc/external/bsd/rs/Makefile
cvs rdiff -u -r1.1.1.1 -r1.2 othersrc/external/bsd/rs/dist/TODO
cvs rdiff -u -r1.3 -r1.4 othersrc/external/bsd/rs/dist/librs.3
cvs rdiff -u -r1.2 -r1.3 othersrc/external/bsd/rs/dist/rs.c \
    othersrc/external/bsd/rs/dist/rs.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: othersrc/external/bsd/rs/Makefile
diff -u othersrc/external/bsd/rs/Makefile:1.1.1.1 othersrc/external/bsd/rs/Makefile:1.2
--- othersrc/external/bsd/rs/Makefile:1.1.1.1	Sat Mar 12 08:08:29 2011
+++ othersrc/external/bsd/rs/Makefile	Tue Apr 26 15:41:26 2011
@@ -1,10 +1,12 @@
-# $NetBSD: Makefile,v 1.1.1.1 2011/03/12 08:08:29 agc Exp $
+# $NetBSD: Makefile,v 1.2 2011/04/26 15:41:26 agc Exp $
 
 SUBDIR+= librs .WAIT rs
 
+PROCESSOR!= uname -p
+
 .include <bsd.subdir.mk>
 
 t:
-	sudo env USETOOLS=no MAKEOBJDIRPREFIX=/usr/build/obj/x86_64 ${MAKE} includes
-	sudo env USETOOLS=no MAKEOBJDIRPREFIX=/usr/build/obj/x86_64 ${MAKE} install
+	sudo env USETOOLS=no MAKEOBJDIRPREFIX=/usr/build/obj/${PROCESSOR} ${MAKE} includes
+	sudo env USETOOLS=no MAKEOBJDIRPREFIX=/usr/build/obj/${PROCESSOR} ${MAKE} install
 	cd ${.CURDIR}/rs && ${MAKE} t

Index: othersrc/external/bsd/rs/dist/TODO
diff -u othersrc/external/bsd/rs/dist/TODO:1.1.1.1 othersrc/external/bsd/rs/dist/TODO:1.2
--- othersrc/external/bsd/rs/dist/TODO:1.1.1.1	Sat Mar 12 08:08:29 2011
+++ othersrc/external/bsd/rs/dist/TODO	Tue Apr 26 15:41:26 2011
@@ -2,7 +2,6 @@
 =====
 circ
 interleave
-multiple levels
 
 Done
 ====
@@ -18,3 +17,4 @@
 get rid of erasures - need them
 split into lib and main
 man pages
+multiple levels

Index: othersrc/external/bsd/rs/dist/librs.3
diff -u othersrc/external/bsd/rs/dist/librs.3:1.3 othersrc/external/bsd/rs/dist/librs.3:1.4
--- othersrc/external/bsd/rs/dist/librs.3:1.3	Wed Mar 23 06:55:44 2011
+++ othersrc/external/bsd/rs/dist/librs.3	Tue Apr 26 15:41:26 2011
@@ -1,4 +1,4 @@
-.\" $NetBSD: librs.3,v 1.3 2011/03/23 06:55:44 wiz Exp $
+.\" $NetBSD: librs.3,v 1.4 2011/04/26 15:41:26 agc Exp $
 .\"
 .\" Copyright (c) 2011 Alistair Crooks <[email protected]>
 .\" All rights reserved.
@@ -23,7 +23,7 @@
 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"/
-.Dd March 22, 2011
+.Dd April 26, 2011
 .Dt LIBRS 3
 .Os
 .Sh NAME
@@ -47,6 +47,10 @@
 .Fa "rs_t *rs" "const void *input" "size_t insize" "uint8_t *output" "size_t outsize"
 .Fc
 .Ft ssize_t
+.Fo rs_parity
+.Fa "rs_t *rs" "const void *input" "size_t insize" "uint8_t *output" "size_t outsize"
+.Fc
+.Ft ssize_t
 .Fo rs_get_header
 .Fa "rs_t *rs" "void *input" "size_t size"
 .Fc
@@ -96,6 +100,13 @@
 256 bytes.
 .Pp
 The
+.Fn rs_encode
+function will automatically copy the source data to the output,
+whilst the
+.Fn rs_parity
+will simply calculate the parity, placing the result in the output.
+.Pp
+The
 .Fn rs_put_header
 function is used to store information about the encoding in
 the output that is generated.

Index: othersrc/external/bsd/rs/dist/rs.c
diff -u othersrc/external/bsd/rs/dist/rs.c:1.2 othersrc/external/bsd/rs/dist/rs.c:1.3
--- othersrc/external/bsd/rs/dist/rs.c:1.2	Wed Mar 23 03:17:48 2011
+++ othersrc/external/bsd/rs/dist/rs.c	Tue Apr 26 15:41:26 2011
@@ -442,10 +442,11 @@
  * 
  */
 static ssize_t
-encode_chunk(rs_t *rs, const uint8_t *msg, size_t size, uint8_t *dst)
+encode_chunk(rs_t *rs, const uint8_t *msg, size_t size, uint8_t *dst, int include)
 {
 	uint8_t	lfsr[MAX_PARITY + 1];
 	uint8_t	dbyte;
+	size_t	off;
 	size_t	i;
 	int	j;
 
@@ -457,11 +458,16 @@
 		}
 		lfsr[0] = gfmult(rs->genPoly[0], dbyte);
 	}
-	(void) memcpy(dst, msg, size);
+	if (include) {
+		(void) memcpy(dst, msg, size);
+		off = size;
+	} else {
+		off = 0;
+	}
 	for (i = 0; i < rs->header.parityc; i++) {
-		dst[size + i] = lfsr[rs->header.parityc - 1 - i];
+		dst[off + i] = lfsr[rs->header.parityc - 1 - i];
 	}
-	return size + rs->header.parityc;
+	return off + rs->header.parityc;
 }
 
 /* decode one chunk of the input */
@@ -533,6 +539,7 @@
 rs_encode(rs_t *rs, const void *inp, size_t size, uint8_t *out, size_t outsize)
 {
 	const uint8_t	*in = (const uint8_t *)inp;
+	const int	 includemsg = 1;
 	size_t	 	 outcc;
 	size_t		 incc;
 	size_t		 chunk;
@@ -542,7 +549,7 @@
 	}
 	for (outcc = 0, incc = 0 ; incc < size && outcc < outsize ; incc += chunk) {
 		chunk = MIN(size - incc, rs->header.datac);
-		outcc += encode_chunk(rs, &in[incc], chunk, &out[outcc]);
+		outcc += encode_chunk(rs, &in[incc], chunk, &out[outcc], includemsg);
 	}
 	return (ssize_t)outcc;
 }
@@ -593,3 +600,23 @@
 	(void) memcpy(out, &head, sizeof(head));
 	return sizeof(head);
 }
+
+/* Reed Solomon Encoder */
+ssize_t
+rs_parity(rs_t *rs, const void *inp, size_t size, uint8_t *out, size_t outsize)
+{
+	const uint8_t	*in = (const uint8_t *)inp;
+	const int	 nomsg = 0;
+	size_t	 	 outcc;
+	size_t		 incc;
+	size_t		 chunk;
+
+	if (!rs->header.poly) {
+		rs_init(rs, RS_DEFAULT_POLYNOMIAL, RS_DEFAULT_DATA, RS_DEFAULT_PARITY);
+	}
+	for (outcc = 0, incc = 0 ; incc < size && outcc < outsize ; incc += chunk) {
+		chunk = MIN(size - incc, rs->header.datac);
+		outcc += encode_chunk(rs, &in[incc], chunk, &out[outcc], nomsg);
+	}
+	return (ssize_t)outcc;
+}
Index: othersrc/external/bsd/rs/dist/rs.h
diff -u othersrc/external/bsd/rs/dist/rs.h:1.2 othersrc/external/bsd/rs/dist/rs.h:1.3
--- othersrc/external/bsd/rs/dist/rs.h:1.2	Wed Mar 23 03:17:48 2011
+++ othersrc/external/bsd/rs/dist/rs.h	Tue Apr 26 15:41:26 2011
@@ -31,6 +31,8 @@
 #ifndef RS_H_
 #define RS_H_	20110301
 
+#include <sys/types.h>
+
 #include <inttypes.h>
 
 typedef struct rs_header_t {
@@ -74,6 +76,7 @@
 /* Reed Solomon encode/decode routines */
 ssize_t rs_decode(rs_t *, const void *, size_t, uint8_t *, size_t);
 ssize_t rs_encode(rs_t *, const void *, size_t, uint8_t *, size_t);
+ssize_t rs_parity(rs_t *, const void *, size_t, uint8_t *, size_t);
 
 /* Reed Solomon header routines */
 ssize_t rs_get_header(rs_t *, const void *, size_t);

Reply via email to