Module Name:    othersrc
Committed By:   agc
Date:           Thu May 12 04:11:15 UTC 2011

Modified Files:
        othersrc/external/bsd/circa/dist: circa.c circa.h main.c

Log Message:
move c1 and c3 data arrays into the circa struct, and allocate them
dynamically once at initialisation time.

add a separate function to free up this space at finalisation time.

this allows use of dynamic sector sizes, if desired


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r1.2 othersrc/external/bsd/circa/dist/circa.c \
    othersrc/external/bsd/circa/dist/circa.h \
    othersrc/external/bsd/circa/dist/main.c

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/circa/dist/circa.c
diff -u othersrc/external/bsd/circa/dist/circa.c:1.1.1.1 othersrc/external/bsd/circa/dist/circa.c:1.2
--- othersrc/external/bsd/circa/dist/circa.c:1.1.1.1	Sat May  7 02:31:24 2011
+++ othersrc/external/bsd/circa/dist/circa.c	Thu May 12 04:11:15 2011
@@ -103,6 +103,11 @@
 	}
 	circa->maxframes = (uint32_t)(sectorsize / C1_FRAME_SIZE);
 	circa->datasize = (uint32_t)((sectorsize * 3 / 4) - sizeof(uint32_t));
+	if ((circa->c1data = calloc(1, sectorsize)) == NULL ||
+	    (circa->c3data = calloc(1, circa->datasize + C3_FRAME_SIZE)) == NULL) {
+		(void) fprintf(stderr, "can't allocate c1data/c3data\n");
+		return 0;
+	}
 	return circa->init = 1;
 }
 
@@ -111,8 +116,6 @@
 circa_encode(circa_t *circa, const void *inp, size_t insize, uint8_t *out, size_t outsize)
 {
 	uint32_t	isize;
-	uint8_t		in[CIRCA_DATA_SIZE + 24];
-	uint8_t		c1work[CIRCA_SECTOR_SIZE * 2];
 	uint8_t		qparity[C1_FRAME_SIZE];
 	int		f;
 	int		b;
@@ -125,51 +128,51 @@
 		circa_init(circa, outsize);
 	}
 	isize = le32((uint32_t)insize);
-	(void) memcpy(in, &isize, sizeof(isize));
-	(void) memcpy(&in[sizeof(isize)], inp, insize);
-	(void) memset(c1work, 0x0, sizeof(c1work));
+	(void) memcpy(circa->c3data, &isize, sizeof(isize));
+	(void) memcpy(&circa->c3data[sizeof(isize)], inp, insize);
+	(void) memset(circa->c1data, 0x0, sizeof(circa->c1data));
 	/* C3 even nybbles delayed 2 frames */
 	for (f = 0 ; f < (int)circa->maxframes ; f++) {
 		for (b = 0 ; b < C3_FRAME_SIZE ; b++) {
 			if (((b / 4) & 1) == 0) {
-				c1work[C1OFF(f + 2, b)] = in[C3OFF(f, b)];
+				circa->c1data[C1OFF(f + 2, b)] = circa->c3data[C3OFF(f, b)];
 			} else {
-				c1work[C1OFF(f, b)] = in[C3OFF(f, b)];
+				circa->c1data[C1OFF(f, b)] = circa->c3data[C3OFF(f, b)];
 			}
 		}
 	}
 	/* intra-frame scramble */
 	for (f = 0 ; f < (int)circa->maxframes ; f++) {
-		PERMUTE5(c1work, f, C1OFF, 2, 8, 10, 18, 6);
-		PERMUTE5(c1work, f, C1OFF, 3, 9, 11, 19, 7);
-		PERMUTE5(c1work, f, C1OFF, 4, 16, 20, 14, 12);
-		PERMUTE5(c1work, f, C1OFF, 5, 17, 21, 15, 13);
+		PERMUTE5(circa->c1data, f, C1OFF, 2, 8, 10, 18, 6);
+		PERMUTE5(circa->c1data, f, C1OFF, 3, 9, 11, 19, 7);
+		PERMUTE5(circa->c1data, f, C1OFF, 4, 16, 20, 14, 12);
+		PERMUTE5(circa->c1data, f, C1OFF, 5, 17, 21, 15, 13);
 	}
 	/* C2 Q parity RS encoding */
 	for (f = 0 ; f < (int)circa->maxframes ; f++) {
-		rs_parity(&circa->c2, &c1work[C1OFF(f, 0)], C3_FRAME_SIZE, qparity, Q_PARITY_SIZE);
-		(void) memmove(&c1work[C1OFF(f, Q_PARITY_OFF + Q_PARITY_SIZE)],
-			&c1work[C1OFF(f, Q_PARITY_OFF)], C3_FRAME_SIZE / 2);
-		(void) memcpy(&c1work[C1OFF(f, Q_PARITY_OFF)], qparity, Q_PARITY_SIZE); 
+		rs_parity(&circa->c2, &circa->c1data[C1OFF(f, 0)], C3_FRAME_SIZE, qparity, Q_PARITY_SIZE);
+		(void) memmove(&circa->c1data[C1OFF(f, Q_PARITY_OFF + Q_PARITY_SIZE)],
+			&circa->c1data[C1OFF(f, Q_PARITY_OFF)], C3_FRAME_SIZE / 2);
+		(void) memcpy(&circa->c1data[C1OFF(f, Q_PARITY_OFF)], qparity, Q_PARITY_SIZE); 
 	}
 	/* sector disperse */
 	for (f = 0 ; f < (int)circa->maxframes ; f++) {
 		for (b = 1 ; b < C2_FRAME_SIZE ; b++) {
-			SWAP(c1work, C1OFF(f, b), C1OFF(f + b, b));
+			SWAP(circa->c1data, C1OFF(f, b), C1OFF(f + b, b));
 		}
 	}
 	/* C1 P parity rs encoding */
 	for (f = 0 ; f < (int)circa->maxframes ; f++) {
-		rs_parity(&circa->c1, &c1work[C1OFF(f, 0)], C2_FRAME_SIZE,
-			&c1work[C1OFF(f, C2_FRAME_SIZE)], P_PARITY_SIZE);
+		rs_parity(&circa->c1, &circa->c1data[C1OFF(f, 0)], C2_FRAME_SIZE,
+			&circa->c1data[C1OFF(f, C2_FRAME_SIZE)], P_PARITY_SIZE);
 	}
 	/* C1 even bytes delayed 1 frame */
 	for (f = (int)circa->maxframes - 1 ; f >= 0 ; --f) {
 		for (b = C1_FRAME_SIZE - 1 ; b >= 0 ; --b) {
 			if ((b & 1) == 0) {
-				out[C1OFF(f + 1, b)] = c1work[C1OFF(f, b)];
+				out[C1OFF(f + 1, b)] = circa->c1data[C1OFF(f, b)];
 			} else {
-				out[C1OFF(f, b)] = c1work[C1OFF(f, b)];
+				out[C1OFF(f, b)] = circa->c1data[C1OFF(f, b)];
 			}
 		}
 	}
@@ -183,8 +186,6 @@
 	const uint8_t	*in = (const uint8_t *)inp;
 	unsigned	 b;
 	uint32_t	 isize;
-	uint8_t		 c1work[CIRCA_SECTOR_SIZE * 2];
-	uint8_t		 c3work[CIRCA_SECTOR_SIZE * 2];
 	uint8_t		 qparity[C2_FRAME_SIZE];
 	uint8_t		 qcalc[C2_FRAME_SIZE];
 	uint8_t		 f1[C1_FRAME_SIZE];
@@ -199,17 +200,13 @@
 	/* C1 even bytes delayed 1 frame */
 	for (f = 0 ; f < (int)circa->maxframes ; f++) {
 		for (b = 0 ; b < C1_FRAME_SIZE ; b++) {
-			if ((b & 1) == 0) {
-				c1work[C1OFF(f, b)] = in[C1OFF(f + 1, b)];
-			} else {
-				c1work[C1OFF(f, b)] = in[C1OFF(f, b)];
-			}
+			circa->c1data[C1OFF(f, b)] = ((b & 1) == 0) ? in[C1OFF(f + 1, b)] : in[C1OFF(f, b)];
 		}
 	}
 	/* P parity C1 rs decoding */
 	for (f = 0 ; f < (int)circa->maxframes ; f++) {
-		(void) memcpy(f1, &c1work[C1OFF(f, 0)], C1_FRAME_SIZE);
-		cc = rs_decode(&circa->c1, f1, C1_FRAME_SIZE, &c1work[C1OFF(f, 0)], C1_FRAME_SIZE);
+		(void) memcpy(f1, &circa->c1data[C1OFF(f, 0)], C1_FRAME_SIZE);
+		cc = rs_decode(&circa->c1, f1, C1_FRAME_SIZE, &circa->c1data[C1OFF(f, 0)], C1_FRAME_SIZE);
 		if (cc != C2_FRAME_SIZE) {
 			circa->c1errc += 1;
 		}
@@ -217,38 +214,38 @@
 	/* sector disperse */
 	for (f = circa->maxframes - 1 ; f >= 0 ; --f) {
 		for (b = C2_FRAME_SIZE - 1 ; b > 0 ; --b) {
-			SWAP(c1work, C1OFF(f, b), C1OFF(f + b, b));
+			SWAP(circa->c1data, C1OFF(f, b), C1OFF(f + b, b));
 		}
 	}
 	/* Q parity C2 rs decoding */
 	for (f = 0 ; f < (int)circa->maxframes ; f++) {
-		(void) memcpy(qparity, &c1work[C1OFF(f, 0)], C3_FRAME_SIZE / 2);
-		(void) memcpy(&qparity[C3_FRAME_SIZE / 2], &c1work[C1OFF(f, (C3_FRAME_SIZE / 2) + Q_PARITY_SIZE)],
+		(void) memcpy(qparity, &circa->c1data[C1OFF(f, 0)], C3_FRAME_SIZE / 2);
+		(void) memcpy(&qparity[C3_FRAME_SIZE / 2], &circa->c1data[C1OFF(f, (C3_FRAME_SIZE / 2) + Q_PARITY_SIZE)],
 				C3_FRAME_SIZE / 2);
-		(void) memcpy(&qparity[C3_FRAME_SIZE], &c1work[C1OFF(f, C3_FRAME_SIZE / 2)], Q_PARITY_SIZE);
+		(void) memcpy(&qparity[C3_FRAME_SIZE], &circa->c1data[C1OFF(f, C3_FRAME_SIZE / 2)], Q_PARITY_SIZE);
 		cc = rs_decode(&circa->c2, qparity, C2_FRAME_SIZE, qcalc, sizeof(qcalc));
 		if (cc != C3_FRAME_SIZE) {
 			circa->c2errc += 1;
 		}
-		(void) memcpy(&c3work[C3OFF(f, 0)], qcalc, C3_FRAME_SIZE);
+		(void) memcpy(&circa->c3data[C3OFF(f, 0)], qcalc, C3_FRAME_SIZE);
 	}
 	/* intra-frame scramble */
 	for (f = 0 ; f < (int)circa->maxframes ; f++) {
-		PERMUTE5(c3work, f, C3OFF, 2, 6, 18, 10, 8);
-		PERMUTE5(c3work, f, C3OFF, 3, 7, 19, 11, 9);
-		PERMUTE5(c3work, f, C3OFF, 4, 12, 14, 20, 16);
-		PERMUTE5(c3work, f, C3OFF, 5, 13, 15, 21, 17);
+		PERMUTE5(circa->c3data, f, C3OFF, 2, 6, 18, 10, 8);
+		PERMUTE5(circa->c3data, f, C3OFF, 3, 7, 19, 11, 9);
+		PERMUTE5(circa->c3data, f, C3OFF, 4, 12, 14, 20, 16);
+		PERMUTE5(circa->c3data, f, C3OFF, 5, 13, 15, 21, 17);
 	}
 	/* C3 even nybbles delayed 2 frames */
 	for (f = 0 ; f < (int)circa->maxframes ; f++) {
 		for (b = 0 ; b < C3_FRAME_SIZE ; b++) {
-			c1work[C3OFF(f, b)] = (((b / 4) & 1) == 0) ?
-				c3work[C3OFF(f + 2, b)] : c3work[C3OFF(f, b)];
+			circa->c1data[C3OFF(f, b)] = (((b / 4) & 1) == 0) ?
+				circa->c3data[C3OFF(f + 2, b)] : circa->c3data[C3OFF(f, b)];
 		}
 	}
-	(void) memcpy(&isize, c1work, sizeof(isize));
+	(void) memcpy(&isize, circa->c1data, sizeof(isize));
 	isize = le32(isize);
-	(void) memcpy(out, &c1work[sizeof(isize)], outsize);
+	(void) memcpy(out, &circa->c1data[sizeof(isize)], outsize);
 	return isize;
 }
 
@@ -282,3 +279,18 @@
 	(void) memcpy(out, &head, sizeof(head));
 	return sizeof(head);
 }
+
+/* finalise things */
+int
+circa_end(circa_t *circa)
+{
+	if (circa->c1data) {
+		free(circa->c1data);
+		circa->c1data = NULL;
+	}
+	if (circa->c3data) {
+		free(circa->c3data);
+		circa->c3data = NULL;
+	}
+	return 1;
+}
Index: othersrc/external/bsd/circa/dist/circa.h
diff -u othersrc/external/bsd/circa/dist/circa.h:1.1.1.1 othersrc/external/bsd/circa/dist/circa.h:1.2
--- othersrc/external/bsd/circa/dist/circa.h:1.1.1.1	Sat May  7 02:31:24 2011
+++ othersrc/external/bsd/circa/dist/circa.h	Thu May 12 04:11:15 2011
@@ -23,7 +23,7 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 #ifndef CIRCA_H_
-#define CIRCA_H_	20110428
+#define CIRCA_H_	20110511
 
 #include <sys/types.h>
 
@@ -55,18 +55,21 @@
 } res_header_t;
 
 typedef struct circa_t {
-	uint64_t	c2errc;		/* # of C2 errors corrected */
-	uint64_t	c1errc;		/* # of C1 errors corrected */
-	rs_t		c2;		/* Q parity */
-	rs_t		c1;		/* P parity */
-	uint8_t		init;		/* initialised */
-	res_header_t	header;		/* header */
-	uint32_t	maxframes;	/* number of frames in sector */
-	uint32_t	datasize;	/* data size (for input) */
+	uint64_t	 c2errc;	/* # of C2 errors corrected */
+	uint64_t	 c1errc;	/* # of C1 errors corrected */
+	rs_t		 c2;		/* Q parity */
+	rs_t		 c1;		/* P parity */
+	uint8_t		 init;		/* initialised */
+	res_header_t	 header;	/* header */
+	uint32_t	 maxframes;	/* number of frames in sector */
+	uint32_t	 datasize;	/* data size (for input) */
+	uint8_t		*c1data;	/* work array for c1 data */
+	uint8_t		*c3data;	/* work space for c3 data */
 } circa_t;
 
 /* initialise resiliency vectors etc */
 int circa_init(circa_t */*circa*/, size_t /*sectorsize*/);
+int circa_end(circa_t */*circa*/);
 
 /* encode and decode in a resilient way */
 ssize_t circa_encode(circa_t */*circa*/, const void */*in*/, size_t /*insize*/, uint8_t */*out*/, size_t /*outsize*/);
Index: othersrc/external/bsd/circa/dist/main.c
diff -u othersrc/external/bsd/circa/dist/main.c:1.1.1.1 othersrc/external/bsd/circa/dist/main.c:1.2
--- othersrc/external/bsd/circa/dist/main.c:1.1.1.1	Sat May  7 02:31:24 2011
+++ othersrc/external/bsd/circa/dist/main.c	Thu May 12 04:11:15 2011
@@ -34,7 +34,7 @@
 
 #include "circa.h"
 
-#define PKG_VERSION	"20110428"
+#define PKG_VERSION	"20110511"
 #define PKG_AUTHOR	"Alistair Crooks ([email protected])"
 
 /* process a file - encoding or decoding */

Reply via email to