CVS commit: src/usr.bin/vndcompress

2020-01-24 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Fri Jan 24 20:20:35 UTC 2020

Modified Files:
src/usr.bin/vndcompress: vndcompress.1

Log Message:
Since vnconfig(8) was renamed (many years ago), update some cross-refs
in vndcompress(1) man page.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/vndcompress/vndcompress.1

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

Modified files:

Index: src/usr.bin/vndcompress/vndcompress.1
diff -u src/usr.bin/vndcompress/vndcompress.1:1.14 src/usr.bin/vndcompress/vndcompress.1:1.15
--- src/usr.bin/vndcompress/vndcompress.1:1.14	Wed Jan 22 06:18:17 2014
+++ src/usr.bin/vndcompress/vndcompress.1	Fri Jan 24 20:20:35 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: vndcompress.1,v 1.14 2014/01/22 06:18:17 riastradh Exp $
+.\"	$NetBSD: vndcompress.1,v 1.15 2020/01/24 20:20:35 pgoyette Exp $
 .\"
 .\" Copyright (c) 2013 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd January 21, 2014
+.Dd January 24, 2020
 .Dt VNDCOMPRESS 1
 .Os
 .Sh NAME
@@ -59,7 +59,7 @@ utility compresses disk images in cloop2
 device can interpret as read-only disk devices using the
 .Fl z
 option to
-.Xr vnconfig 8 .
+.Xr vndconfig 8 .
 .Pp
 By default,
 .Nm vndcompress
@@ -203,7 +203,7 @@ assuming your kernel was built with the
 .Dv VND_COMPRESSION
 option enabled:
 .Bd -literal -offset indent
-# vnconfig -z vnd0 disk.cloop2
+# vndconfig -z vnd0 disk.cloop2
 # mount /dev/vnd0d /mnt
 .Ed
 .Sh SIGNALS
@@ -246,7 +246,7 @@ may be truncated if the uncompressed ima
 the compression block size.
 .Sh SEE ALSO
 .Xr vnd 4 ,
-.Xr vnconfig 8
+.Xr vndconfig 8
 .Sh HISTORY
 The
 .Nm



CVS commit: src/usr.bin/vndcompress

2017-07-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jul 29 21:04:07 UTC 2017

Modified Files:
src/usr.bin/vndcompress: common.h offtab.c vndcompress.c
vnduncompress.c

Log Message:
Clarify compile-time and run-time arithmetic safety assertions.

This is an experiment with a handful of macros for writing the
checks, most of which are compile-time:

MUL_OK(t, a, b) Does a*b avoid overflow in type t?
ADD_OK(t, a, b) Does a + b avoid overflow in type t?
TOOMANY(t, x, b, m) Are there more than m b-element blocks in x in type t?
(I.e., does ceiling(x/b) > m?)

Addenda that might make sense but are not needed here:

MUL(t, a, b, )Set p = a*b and return 0, or return ERANGE if overflow.
ADD(t, a, b, )Set s = a+b and return 0, or return ERANGE if overflow.

Example:

uint32_t a = ..., b = ..., y = ..., z = ..., x, w;

/* input validation */
error = MUL(size_t, a, b, );
if (error)
fail;
if (TOOMANY(uint32_t, x, BLKSIZ, MAX_NBLK))
fail;
y = HOWMANY(x, BLKSIZ);
if (z > Z_MAX)
fail;
...
/* internal computation */
__CTASSERT(MUL_OK(uint32_t, Z_MAX, MAX_NBLK));
w = z*y;

Obvious shortcomings:

1. Nothing checks your ctassert matches your subsequent arithmetic.
   (Maybe we could have BOUNDED_MUL(t, x, xmax, y, ymax) with a
   ctassert inside.)

2. Nothing flows the bounds needed by the arithmetic you use back
   into candidate definitions of X_MAX/Y_MAX.

But at least the reviewer's job is only to make sure that (a) the
MUL_OK matches the *, and (b) the bounds in the assertion match the
bounds on the inputs -- in particular, the reviewer need not derive
the bounds from the context, only confirm they are supported by the
paths to it.

This is not meant to be a general-purpose proof assistant, or even a
special-purpose one like gfverif .
Rather, it is an experiment in adding a modicum of compile-time
verification with a simple C API change.

This also is not intended to serve as trapping arithmetic on
overflow.  The goal here is to enable writing the program with
explicit checks on input and compile-time annotations on computation
to gain confident that overflow won't happen in the computation.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/vndcompress/common.h
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/vndcompress/offtab.c
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/vndcompress/vndcompress.c
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/vndcompress/vnduncompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/common.h
diff -u src/usr.bin/vndcompress/common.h:1.7 src/usr.bin/vndcompress/common.h:1.8
--- src/usr.bin/vndcompress/common.h:1.7	Sun Apr 16 23:43:57 2017
+++ src/usr.bin/vndcompress/common.h	Sat Jul 29 21:04:07 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: common.h,v 1.7 2017/04/16 23:43:57 riastradh Exp $	*/
+/*	$NetBSD: common.h,v 1.8 2017/07/29 21:04:07 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -83,6 +83,16 @@
 #define	ISSET(t, f)	((t) & (f))
 
 /*
+ * Bounds checks for arithmetic.
+ */
+#define	ADD_OK(T, A, B)	((A) <= __type_max(T) - (B))
+
+#define	MUL_OK(T, A, B)	((A) <= __type_max(T)/(B))
+
+#define	HOWMANY(X, N)		(((X) + ((N) - 1))/(N))
+#define	TOOMANY(T, X, N, M)	(!ADD_OK(T, X, (N) - 1) || HOWMANY(X, N) > (M))
+
+/*
  * We require:
  *
  *   0 < blocksize			(duh)

Index: src/usr.bin/vndcompress/offtab.c
diff -u src/usr.bin/vndcompress/offtab.c:1.14 src/usr.bin/vndcompress/offtab.c:1.15
--- src/usr.bin/vndcompress/offtab.c:1.14	Sun Apr 16 23:50:40 2017
+++ src/usr.bin/vndcompress/offtab.c	Sat Jul 29 21:04:07 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: offtab.c,v 1.14 2017/04/16 23:50:40 riastradh Exp $	*/
+/*	$NetBSD: offtab.c,v 1.15 2017/07/29 21:04:07 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: offtab.c,v 1.14 2017/04/16 23:50:40 riastradh Exp $");
+__RCSID("$NetBSD: offtab.c,v 1.15 2017/07/29 21:04:07 riastradh Exp $");
 
 #include 
 #include 
@@ -95,18 +95,18 @@ offtab_compute_window_position(struct of
 	const uint32_t window_size = offtab_compute_window_size(offtab,
 	window_start);
 
-	__CTASSERT(MAX_WINDOW_SIZE <= (SIZE_MAX / sizeof(uint64_t)));
+	__CTASSERT(MUL_OK(size_t, MAX_WINDOW_SIZE, sizeof(uint64_t)));
 	*bytes = (window_size * sizeof(uint64_t));
 
 	assert(window_start <= offtab->ot_n_offsets);
-	__CTASSERT(MAX_N_OFFSETS <= (OFF_MAX / sizeof(uint64_t)));
+	__CTASSERT(MUL_OK(off_t, MAX_N_OFFSETS, sizeof(uint64_t)));
 	const off_t window_offset = ((off_t)window_start *
 	(off_t)sizeof(uint64_t));
 
 	assert(offtab->ot_fdpos <= OFFTAB_MAX_FDPOS);
-	__CTASSERT(OFFTAB_MAX_FDPOS <=
-	(OFF_MAX - 

CVS commit: src/usr.bin/vndcompress

2017-04-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Apr 17 00:03:34 UTC 2017

Modified Files:
src/usr.bin/vndcompress: vnduncompress.c

Log Message:
Omit needless XXX comment.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/vndcompress/vnduncompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/vnduncompress.c
diff -u src/usr.bin/vndcompress/vnduncompress.c:1.12 src/usr.bin/vndcompress/vnduncompress.c:1.13
--- src/usr.bin/vndcompress/vnduncompress.c:1.12	Sun Apr 16 23:50:40 2017
+++ src/usr.bin/vndcompress/vnduncompress.c	Mon Apr 17 00:03:33 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vnduncompress.c,v 1.12 2017/04/16 23:50:40 riastradh Exp $	*/
+/*	$NetBSD: vnduncompress.c,v 1.13 2017/04/17 00:03:33 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: vnduncompress.c,v 1.12 2017/04/16 23:50:40 riastradh Exp $");
+__RCSID("$NetBSD: vnduncompress.c,v 1.13 2017/04/17 00:03:33 riastradh Exp $");
 
 #include 
 
@@ -70,7 +70,6 @@ vnduncompress(int argc, char **argv, con
 		err(1, "open(%s)", cloop2_pathname);
 
 	const int image_fd = open(image_pathname,
-	/* XXX O_EXCL, not O_TRUNC */
 	(O_WRONLY | O_CREAT | O_TRUNC), 0777);
 	if (image_fd == -1)
 		err(1, "open(%s)", image_pathname);



CVS commit: src/usr.bin/vndcompress

2017-04-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Apr 17 00:02:45 UTC 2017

Modified Files:
src/usr.bin/vndcompress: vndcompress.c

Log Message:
Omit needless XXX comment.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/usr.bin/vndcompress/vndcompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/vndcompress.c
diff -u src/usr.bin/vndcompress/vndcompress.c:1.27 src/usr.bin/vndcompress/vndcompress.c:1.28
--- src/usr.bin/vndcompress/vndcompress.c:1.27	Sun Apr 16 23:50:40 2017
+++ src/usr.bin/vndcompress/vndcompress.c	Mon Apr 17 00:02:45 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vndcompress.c,v 1.27 2017/04/16 23:50:40 riastradh Exp $	*/
+/*	$NetBSD: vndcompress.c,v 1.28 2017/04/17 00:02:45 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: vndcompress.c,v 1.27 2017/04/16 23:50:40 riastradh Exp $");
+__RCSID("$NetBSD: vndcompress.c,v 1.28 2017/04/17 00:02:45 riastradh Exp $");
 
 #include 
 #include 
@@ -438,7 +438,7 @@ compress_init(int argc, char **argv, con
 
 	int oflags;
 	if (!ISSET(O->flags, FLAG_r))
-		oflags = (O_WRONLY | O_TRUNC | O_CREAT); /* XXX O_EXCL?  */
+		oflags = (O_WRONLY | O_TRUNC | O_CREAT);
 	else if (!ISSET(O->flags, FLAG_R))
 		oflags = (O_RDWR | O_CREAT);
 	else



CVS commit: src/usr.bin/vndcompress

2017-04-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Apr 16 23:50:40 UTC 2017

Modified Files:
src/usr.bin/vndcompress: offtab.c offtab.h vndcompress.c
vnduncompress.c

Log Message:
Justify the last unjustified assertion here.

Sprinkle a few more assertions to help along the way.

(Actually, it was justified; I just hadn't made explicit the relation
to the value of fdpos that all two callers specify.)


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/vndcompress/offtab.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/vndcompress/offtab.h
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/vndcompress/vndcompress.c
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/vndcompress/vnduncompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/offtab.c
diff -u src/usr.bin/vndcompress/offtab.c:1.13 src/usr.bin/vndcompress/offtab.c:1.14
--- src/usr.bin/vndcompress/offtab.c:1.13	Sat Jan 25 16:38:15 2014
+++ src/usr.bin/vndcompress/offtab.c	Sun Apr 16 23:50:40 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: offtab.c,v 1.13 2014/01/25 16:38:15 riastradh Exp $	*/
+/*	$NetBSD: offtab.c,v 1.14 2017/04/16 23:50:40 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: offtab.c,v 1.13 2014/01/25 16:38:15 riastradh Exp $");
+__RCSID("$NetBSD: offtab.c,v 1.14 2017/04/16 23:50:40 riastradh Exp $");
 
 #include 
 #include 
@@ -103,7 +103,9 @@ offtab_compute_window_position(struct of
 	const off_t window_offset = ((off_t)window_start *
 	(off_t)sizeof(uint64_t));
 
-	/* XXX This assertion is not justified.  */
+	assert(offtab->ot_fdpos <= OFFTAB_MAX_FDPOS);
+	__CTASSERT(OFFTAB_MAX_FDPOS <=
+	(OFF_MAX - (off_t)MAX_N_OFFSETS*sizeof(uint64_t)));
 	assert(offtab->ot_fdpos <= (OFF_MAX - window_offset));
 	*pos = (offtab->ot_fdpos + window_offset);
 }
@@ -209,6 +211,7 @@ offtab_init(struct offtab *offtab, uint3
 	assert(0 < n_offsets);
 	assert(0 <= fd);
 	assert(0 <= fdpos);
+	assert(fdpos <= OFFTAB_MAX_FDPOS);
 
 	offtab->ot_n_offsets = n_offsets;
 	if ((window_size == 0) || (n_offsets < window_size))
@@ -293,6 +296,9 @@ offtab_reset_read(struct offtab *offtab,
 		__CTASSERT(MAX_N_OFFSETS <= (OFF_MAX / sizeof(uint64_t)));
 		const off_t offtab_bytes = ((off_t)offtab->ot_n_offsets *
 		(off_t)sizeof(uint64_t));
+		assert(offtab->ot_fdpos <= OFFTAB_MAX_FDPOS);
+		__CTASSERT(OFFTAB_MAX_FDPOS <=
+		(OFF_MAX - (off_t)MAX_N_OFFSETS*sizeof(uint64_t)));
 		assert(offtab->ot_fdpos <= (OFF_MAX - offtab_bytes));
 		const off_t first_offset = (offtab->ot_fdpos + offtab_bytes);
 		if (lseek(offtab->ot_fd, first_offset, SEEK_SET) == -1) {
@@ -367,9 +373,11 @@ offtab_reset_write(struct offtab *offtab
 	__CTASSERT(MAX_N_OFFSETS <= UINT32_MAX);
 	assert(offtab->ot_n_offsets > 0);
 
+	/* Initialize window of all ones.  */
 	for (i = 0; i < offtab->ot_window_size; i++)
 		offtab->ot_window[i] = ~(uint64_t)0;
 
+	/* Write the window to every position in the table.  */
 	const uint32_t n_windows =
 	howmany(offtab->ot_n_offsets, offtab->ot_window_size);
 	for (i = 1; i < n_windows; i++) {
@@ -378,15 +386,25 @@ offtab_reset_write(struct offtab *offtab
 		offtab_write_window(offtab);
 	}
 
-	offtab->ot_window_start = 0;
-	__CTASSERT(MAX_N_OFFSETS <=
-	(MIN(OFF_MAX, UINT64_MAX) / sizeof(uint64_t)));
+	/* Compute the number of bytes in the offset table.  */
+	__CTASSERT(MAX_N_OFFSETS <= OFF_MAX/sizeof(uint64_t));
 	const off_t offtab_bytes = ((off_t)offtab->ot_n_offsets *
 	sizeof(uint64_t));
-	assert(offtab->ot_fdpos <=
-	((off_t)MIN(OFF_MAX, UINT64_MAX) - offtab_bytes));
+
+	/* Compute the offset of the first block.  */
+	assert(offtab->ot_fdpos <= OFFTAB_MAX_FDPOS);
+	__CTASSERT(OFFTAB_MAX_FDPOS <=
+	(OFF_MAX - (off_t)MAX_N_OFFSETS*sizeof(uint64_t)));
+	assert(offtab->ot_fdpos <= (OFF_MAX - offtab_bytes));
 	const off_t first_offset = (offtab->ot_fdpos + offtab_bytes);
-	assert(first_offset <= (off_t)MIN(OFF_MAX, UINT64_MAX));
+
+	/* Assert that it fits in 64 bits.  */
+	__CTASSERT(MAX_N_OFFSETS <= UINT64_MAX/sizeof(uint64_t));
+	__CTASSERT(OFFTAB_MAX_FDPOS <=
+	(UINT64_MAX - (uint64_t)MAX_N_OFFSETS*sizeof(uint64_t)));
+
+	/* Write out the first window with the first offset.  */
+	offtab->ot_window_start = 0;
 	offtab->ot_window[0] = htobe64((uint64_t)first_offset);
 	offtab_write_window(offtab);
 

Index: src/usr.bin/vndcompress/offtab.h
diff -u src/usr.bin/vndcompress/offtab.h:1.2 src/usr.bin/vndcompress/offtab.h:1.3
--- src/usr.bin/vndcompress/offtab.h:1.2	Wed Jan 22 06:15:22 2014
+++ src/usr.bin/vndcompress/offtab.h	Sun Apr 16 23:50:40 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: offtab.h,v 1.2 2014/01/22 06:15:22 riastradh Exp $	*/
+/*	$NetBSD: offtab.h,v 1.3 2017/04/16 23:50:40 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -37,6 +37,8 @@
 #include 
 #include 
 
+#include "common.h"
+
 

CVS commit: src/usr.bin/vndcompress

2017-04-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Apr 16 23:43:57 UTC 2017

Modified Files:
src/usr.bin/vndcompress: common.h

Log Message:
Emphasize that MAX_WINDOW_SIZE is bounded by the maximum uint32_t.

Since we store window sizes in uint32_t, the maximum had better fit
in uint32_t!


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/vndcompress/common.h

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

Modified files:

Index: src/usr.bin/vndcompress/common.h
diff -u src/usr.bin/vndcompress/common.h:1.6 src/usr.bin/vndcompress/common.h:1.7
--- src/usr.bin/vndcompress/common.h:1.6	Wed Jan 22 06:18:00 2014
+++ src/usr.bin/vndcompress/common.h	Sun Apr 16 23:43:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: common.h,v 1.6 2014/01/22 06:18:00 riastradh Exp $	*/
+/*	$NetBSD: common.h,v 1.7 2017/04/16 23:43:57 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -111,13 +111,13 @@
 #define	MAX_N_OFFSETS		(MAX_N_BLOCKS + 1)
 
 /*
- * The window size is at most the number of offsets, so it has the same
- * maximum bound.  The default window size is chosen so that windows
+ * The window size is at most the number of offsets, or the largest
+ * uint32_t value.  The default window size is chosen so that windows
  * fit in one 4096-byte page of memory.  We could use 64k bytes, or
  * st_blksize, to maximize I/O transfer size, but the transfers won't
  * be aligned without a lot of extra work.
  */
-#define	MAX_WINDOW_SIZE		MAX_N_OFFSETS
+#define	MAX_WINDOW_SIZE		MIN(UINT32_MAX, MAX_N_OFFSETS)
 #define	DEF_WINDOW_SIZE		512
 
 struct cloop2_header {



CVS commit: src/usr.bin/vndcompress

2017-03-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Mar 21 13:56:38 UTC 2017

Modified Files:
src/usr.bin/vndcompress: utils.c

Log Message:
Simplify.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/vndcompress/utils.c

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

Modified files:

Index: src/usr.bin/vndcompress/utils.c
diff -u src/usr.bin/vndcompress/utils.c:1.5 src/usr.bin/vndcompress/utils.c:1.6
--- src/usr.bin/vndcompress/utils.c:1.5	Thu Apr  7 23:29:59 2016
+++ src/usr.bin/vndcompress/utils.c	Tue Mar 21 13:56:38 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: utils.c,v 1.5 2016/04/07 23:29:59 riastradh Exp $	*/
+/*	$NetBSD: utils.c,v 1.6 2017/03/21 13:56:38 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: utils.c,v 1.5 2016/04/07 23:29:59 riastradh Exp $");
+__RCSID("$NetBSD: utils.c,v 1.6 2017/03/21 13:56:38 riastradh Exp $");
 
 #include 
 
@@ -59,31 +59,23 @@ int	vsnprintf_ss(char *restrict, size_t,
  * Read, returning partial data only at end of file.
  */
 ssize_t
-read_block(int fd, void *buffer, size_t n)
+read_block(int fd, void *buf, size_t len)
 {
-	char *p = buffer, *const end __diagused = (p + n);
-	size_t total_read = 0;
+	char *p = buf;
+	size_t n = len;
+	const char *const end __diagused = p + n;
+	ssize_t nread = 0;
 
-	while (n > 0) {
-		const ssize_t n_read = read(fd, p, n);
-		if (n_read == -1)
+	while (0 < n && (nread = read(fd, p, n)) != 0) {
+		if (nread == -1)
 			return -1;
-		assert(n_read >= 0);
-		if (n_read == 0)
-			break;
-
-		assert((size_t)n_read <= n);
-		n -= (size_t)n_read;
-
-		assert(p <= end);
-		assert(n_read <= (end - p));
-		p += (size_t)n_read;
-
-		assert((size_t)n_read <= (SIZE_MAX - total_read));
-		total_read += (size_t)n_read;
+		p += MIN(n, (size_t)nread);
+		n -= MIN(n, (size_t)nread);
+		assert(p + n == end);
 	}
 
-	return total_read;
+	assert(n == 0 || nread == 0); /* complete read or EOF */
+	return len - n;
 }
 
 /*
@@ -91,35 +83,29 @@ read_block(int fd, void *buffer, size_t 
  * of file.
  */
 ssize_t
-pread_block(int fd, void *buffer, size_t n, off_t fdpos)
+pread_block(int fd, void *buf, size_t len, off_t fdpos)
 {
-	char *p = buffer, *const end __diagused = (p + n);
-	size_t total_read = 0;
+	char *p = buf;
+	size_t n = len;
+	const char *const end __diagused = p + n;
+	ssize_t nread = 0;
 
 	assert(0 <= fdpos);
-	assert(n <= (OFF_MAX - (uintmax_t)fdpos));
+	assert(n <= OFF_MAX - (uintmax_t)fdpos);
+	const off_t endpos __diagused = fdpos + n;
 
-	while (n > 0) {
-		assert(total_read <= n);
-		const ssize_t n_read = pread(fd, p, n, (fdpos + total_read));
-		if (n_read == -1)
+	while (0 < n && (nread = pread(fd, p, n, fdpos)) != 0) {
+		if (nread == -1)
 			return -1;
-		assert(n_read >= 0);
-		if (n_read == 0)
-			break;
-
-		assert((size_t)n_read <= n);
-		n -= (size_t)n_read;
-
-		assert(p <= end);
-		assert(n_read <= (end - p));
-		p += (size_t)n_read;
-
-		assert((size_t)n_read <= (SIZE_MAX - total_read));
-		total_read += (size_t)n_read;
+		fdpos += MIN(n, (size_t)nread);
+		p += MIN(n, (size_t)nread);
+		n -= MIN(n, (size_t)nread);
+		assert(p + n == end);
+		assert(fdpos + (off_t)n == endpos);
 	}
 
-	return total_read;
+	assert(n == 0 || nread == 0); /* complete read or EOF */
+	return len - n;
 }
 
 /*



CVS commit: src/usr.bin/vndcompress

2017-01-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Jan 10 21:15:54 UTC 2017

Modified Files:
src/usr.bin/vndcompress: vndcompress.c

Log Message:
need 


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/vndcompress/vndcompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/vndcompress.c
diff -u src/usr.bin/vndcompress/vndcompress.c:1.25 src/usr.bin/vndcompress/vndcompress.c:1.26
--- src/usr.bin/vndcompress/vndcompress.c:1.25	Mon Nov 17 22:48:17 2014
+++ src/usr.bin/vndcompress/vndcompress.c	Tue Jan 10 16:15:54 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vndcompress.c,v 1.25 2014/11/18 03:48:17 riastradh Exp $	*/
+/*	$NetBSD: vndcompress.c,v 1.26 2017/01/10 21:15:54 christos Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,9 +30,10 @@
  */
 
 #include 
-__RCSID("$NetBSD: vndcompress.c,v 1.25 2014/11/18 03:48:17 riastradh Exp $");
+__RCSID("$NetBSD: vndcompress.c,v 1.26 2017/01/10 21:15:54 christos Exp $");
 
 #include 
+#include 
 
 #include 
 #include 



CVS commit: src/usr.bin/vndcompress

2016-04-07 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Apr  7 23:29:59 UTC 2016

Modified Files:
src/usr.bin/vndcompress: utils.c

Log Message:
__diagused, not __unused -- used in an assert.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/vndcompress/utils.c

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

Modified files:

Index: src/usr.bin/vndcompress/utils.c
diff -u src/usr.bin/vndcompress/utils.c:1.4 src/usr.bin/vndcompress/utils.c:1.5
--- src/usr.bin/vndcompress/utils.c:1.4	Wed Jan 22 06:15:31 2014
+++ src/usr.bin/vndcompress/utils.c	Thu Apr  7 23:29:59 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: utils.c,v 1.4 2014/01/22 06:15:31 riastradh Exp $	*/
+/*	$NetBSD: utils.c,v 1.5 2016/04/07 23:29:59 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: utils.c,v 1.4 2014/01/22 06:15:31 riastradh Exp $");
+__RCSID("$NetBSD: utils.c,v 1.5 2016/04/07 23:29:59 riastradh Exp $");
 
 #include 
 
@@ -61,7 +61,7 @@ int	vsnprintf_ss(char *restrict, size_t,
 ssize_t
 read_block(int fd, void *buffer, size_t n)
 {
-	char *p = buffer, *const end __unused = (p + n);
+	char *p = buffer, *const end __diagused = (p + n);
 	size_t total_read = 0;
 
 	while (n > 0) {
@@ -93,7 +93,7 @@ read_block(int fd, void *buffer, size_t 
 ssize_t
 pread_block(int fd, void *buffer, size_t n, off_t fdpos)
 {
-	char *p = buffer, *const end __unused = (p + n);
+	char *p = buffer, *const end __diagused = (p + n);
 	size_t total_read = 0;
 
 	assert(0 <= fdpos);



CVS commit: src/usr.bin/vndcompress

2014-11-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Nov 18 03:48:17 UTC 2014

Modified Files:
src/usr.bin/vndcompress: Makefile vndcompress.c

Log Message:
Fix vndcompress restart failure fallback when input is a pipe.

Defer seeking the *input* image, or winding it forward, until we are
certain we all ready in the cloop2 output, because when the input
image is a pipe, we don't get a chance to seek back to the beginning
and start from the top instead of restarting.

If restart does fail, don't try to seek the input image back to the
beginning unless we had already tried to seek or wind it forward.

Add some automatic tests for this and related cases.

XXX pullup to netbsd-7, netbsd-6


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/vndcompress/Makefile
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/vndcompress/vndcompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/Makefile
diff -u src/usr.bin/vndcompress/Makefile:1.13 src/usr.bin/vndcompress/Makefile:1.14
--- src/usr.bin/vndcompress/Makefile:1.13	Wed Jan 22 06:18:00 2014
+++ src/usr.bin/vndcompress/Makefile	Tue Nov 18 03:48:17 2014
@@ -77,6 +77,7 @@ tentinyblock.in:
 	head -c 5120  /usr/share/dict/words  ${.TARGET}.tmp \
 	 mv -f ${.TARGET}.tmp ${.TARGET}
 
+# Make sure we can restart from a pipe.
 CHECKS+=	check-pipe-restart
 CLEANFILES+=	piperestart.in piperestart.in.tmp
 CLEANFILES+=	piperestart.cl2 piperestart.cl2.tmp
@@ -87,7 +88,7 @@ check-pipe-restart: .PHONY piperestart.c
 piperestart.cl2restart: piperestart.cl2part vndcompress
 	cp piperestart.cl2part ${.TARGET}.tmp \
 	 head -c 70  /usr/share/dict/words \
-	| ./vndcompress -l 655360 -k 1 -rR /dev/stdin ${.TARGET}.tmp \
+	| ./vndcompress -l 655360 -k 1 -r -R /dev/stdin ${.TARGET}.tmp \
 	 mv -f ${.TARGET}.tmp ${.TARGET}
 # The following rule uses ; and not  on purpose: vndcompress is
 # supposed to fail (and it is even OK to interrupt!) so we can restart
@@ -100,13 +101,53 @@ piperestart.in:
 	head -c 655360  /usr/share/dict/words  ${.TARGET}.tmp \
 	 mv -f ${.TARGET}.tmp ${.TARGET}
 
+# Make sure we can restart from a pipe even if the original start was
+# corrupted, as long as we don't pass -R.
+CHECKS+=	check-pipe-badstart
+CLEANFILES+=	pipebadstart.in pipebadstart.in.tmp
+CLEANFILES+=	pipebadstart.cl2 pipebadstart.cl2.tmp
+CLEANFILES+=	pipebadstart.cl2restart pipebadstart.cl2restart.tmp
+CLEANFILES+=	pipebadstart.cl2part pipebadstart.cl2part.tmp
+check-pipe-badstart: .PHONY pipebadstart.cl2 pipebadstart.cl2restart
+	cmp ${.ALLSRC}
+pipebadstart.cl2restart: pipebadstart.cl2part vndcompress
+	cp pipebadstart.cl2part ${.TARGET}.tmp \
+	 head -c 70  /usr/share/dict/words \
+	| ./vndcompress -l 655360 -k 1 -r /dev/stdin ${.TARGET}.tmp \
+	 mv -f ${.TARGET}.tmp ${.TARGET}
+pipebadstart.cl2part:
+	touch ${.TARGET}
+pipebadstart.in:
+	head -c 655360  /usr/share/dict/words  ${.TARGET}.tmp \
+	 mv -f ${.TARGET}.tmp ${.TARGET}
+
+# Make sure we can `restart' even if there's nothing there.
+CHECKS+=	check-pipe-falsestart
+CLEANFILES+=	pipefalsestart.in pipefalsestart.in.tmp
+CLEANFILES+=	pipefalsestart.cl2 pipefalsestart.cl2.tmp
+CLEANFILES+=	pipefalsestart.cl2restart pipefalsestart.cl2restart.tmp
+check-pipe-falsestart: .PHONY pipefalsestart.cl2 pipefalsestart.cl2restart
+	cmp ${.ALLSRC}
+pipefalsestart.cl2restart: vndcompress
+	rm -f ${.TARGET}.tmp \
+	 head -c 70  /usr/share/dict/words \
+	| ./vndcompress -l 655360 -k 1 -r /dev/stdin ${.TARGET}.tmp \
+	 mv -f ${.TARGET}.tmp ${.TARGET}
+pipefalsestart.in:
+	head -c 655360  /usr/share/dict/words  ${.TARGET}.tmp \
+	 mv -f ${.TARGET}.tmp ${.TARGET}
+
+# Make sure we can restart from a file, simulated with `-p'.
 CHECKS+=	check-part
-CLEANFILES+=	part.orig part.cl2part part.cl2 part.out
+CLEANFILES+=	part.orig part.orig.tmp
+CLEANFILES+=	part.cl2part part.cl2part.tmp
+CLEANFILES+=	part.cl2 part.cl2.tmp
+CLEANFILES+=	part.out part.out.tmp
 check-part: .PHONY part.orig part.out
 	cmp part.orig part.out
 part.cl2: part.orig part.cl2part vndcompress
 	cp part.cl2part ${.TARGET}.tmp \
-	 ./vndcompress -b 512 -rR part.orig ${.TARGET}.tmp \
+	 ./vndcompress -b 512 -r -R part.orig ${.TARGET}.tmp \
 	 mv -f ${.TARGET}.tmp ${.TARGET}
 part.cl2part: part.orig vndcompress
 	./vndcompress -b 512 -p 10 part.orig ${.TARGET}.tmp \
@@ -115,6 +156,21 @@ part.orig:
 	head -c 12345  /usr/share/dict/words  ${.TARGET}.tmp \
 	 mv -f ${.TARGET}.tmp ${.TARGET}
 
+# Make sure we can `restart' even if there's nothing there.
+CHECKS+=	check-falsestart
+CLEANFILES+=	falsestart.in falsestart.in.tmp
+CLEANFILES+=	falsestart.cl2 falsestart.cl2.tmp
+CLEANFILES+=	falsestart.cl2restart falsestart.cl2restart.tmp
+check-falsestart: .PHONY falsestart.cl2 falsestart.cl2restart
+	cmp ${.ALLSRC}
+falsestart.cl2restart: vndcompress falsestart.in
+	rm -f ${.TARGET}.tmp \
+	 ./vndcompress -r falsestart.in ${.TARGET}.tmp \
+	 mv 

CVS commit: src/usr.bin/vndcompress

2014-01-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan 24 17:30:18 UTC 2014

Modified Files:
src/usr.bin/vndcompress: vndcompress.c

Log Message:
CID 1164169: integer overflow


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/vndcompress/vndcompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/vndcompress.c
diff -u src/usr.bin/vndcompress/vndcompress.c:1.22 src/usr.bin/vndcompress/vndcompress.c:1.23
--- src/usr.bin/vndcompress/vndcompress.c:1.22	Wed Jan 22 01:18:00 2014
+++ src/usr.bin/vndcompress/vndcompress.c	Fri Jan 24 12:30:18 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: vndcompress.c,v 1.22 2014/01/22 06:18:00 riastradh Exp $	*/
+/*	$NetBSD: vndcompress.c,v 1.23 2014/01/24 17:30:18 christos Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: vndcompress.c,v 1.22 2014/01/22 06:18:00 riastradh Exp $);
+__RCSID($NetBSD: vndcompress.c,v 1.23 2014/01/24 17:30:18 christos Exp $);
 
 #include sys/endian.h
 
@@ -598,11 +598,11 @@ compress_restart(struct compress_state *
 	if (!offtab_prepare_get(S-offtab, 0))
 		return false;
 	const uint64_t first_offset = offtab_get(S-offtab, 0);
-	if (first_offset != (sizeof(struct cloop2_header) +
-		(S-n_offsets * sizeof(uint64_t {
+	const uint64_t expected = sizeof(struct cloop2_header) + 
+	((uint64_t)S-n_offsets * sizeof(uint64_t));
+	if (first_offset != expected) {
 		warnx(first offset is not 0x%PRIx64: 0x%PRIx64,
-		((uint64_t)S-n_offsets * sizeof(uint64_t)),
-		first_offset);
+		expected, first_offset);
 		return false;
 	}
 



CVS commit: src/usr.bin/vndcompress

2014-01-23 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Jan 23 14:17:05 UTC 2014

Modified Files:
src/usr.bin/vndcompress: offtab.c

Log Message:
Mark offtab_bug[x] as dead.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/vndcompress/offtab.c

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

Modified files:

Index: src/usr.bin/vndcompress/offtab.c
diff -u src/usr.bin/vndcompress/offtab.c:1.9 src/usr.bin/vndcompress/offtab.c:1.10
--- src/usr.bin/vndcompress/offtab.c:1.9	Wed Jan 22 14:25:07 2014
+++ src/usr.bin/vndcompress/offtab.c	Thu Jan 23 14:17:05 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: offtab.c,v 1.9 2014/01/22 14:25:07 riastradh Exp $	*/
+/*	$NetBSD: offtab.c,v 1.10 2014/01/23 14:17:05 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: offtab.c,v 1.9 2014/01/22 14:25:07 riastradh Exp $);
+__RCSID($NetBSD: offtab.c,v 1.10 2014/01/23 14:17:05 joerg Exp $);
 
 #include sys/types.h
 #include sys/endian.h
@@ -49,14 +49,14 @@ __RCSID($NetBSD: offtab.c,v 1.9 2014/01
 
 #include offtab.h
 
-static void __printflike(1,2)
+static void __printflike(1,2) __dead
 offtab_bug(const char *fmt, ...)
 {
 
 	errx(1, bug in offtab, please report);
 }
 
-static void __printflike(1,2)
+static void __printflike(1,2) __dead
 offtab_bugx(const char *fmt, ...)
 {
 



CVS commit: src/usr.bin/vndcompress

2014-01-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 14:25:07 UTC 2014

Modified Files:
src/usr.bin/vndcompress: offtab.c

Log Message:
Fix $NetBSD$ tag.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/vndcompress/offtab.c

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

Modified files:

Index: src/usr.bin/vndcompress/offtab.c
diff -u src/usr.bin/vndcompress/offtab.c:1.8 src/usr.bin/vndcompress/offtab.c:1.9
--- src/usr.bin/vndcompress/offtab.c:1.8	Wed Jan 22 06:17:16 2014
+++ src/usr.bin/vndcompress/offtab.c	Wed Jan 22 14:25:07 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: offtab.c,v 1.8 2014/01/22 06:17:16 riastradh Exp $	*/
+/*	$NetBSD: offtab.c,v 1.9 2014/01/22 14:25:07 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD);
+__RCSID($NetBSD: offtab.c,v 1.9 2014/01/22 14:25:07 riastradh Exp $);
 
 #include sys/types.h
 #include sys/endian.h



CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:14:03 UTC 2014

Modified Files:
src/usr.bin/vndcompress: vnduncompress.c

Log Message:
Fail if malloc can't allocate offset table.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/vndcompress/vnduncompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/vnduncompress.c
diff -u src/usr.bin/vndcompress/vnduncompress.c:1.2 src/usr.bin/vndcompress/vnduncompress.c:1.3
--- src/usr.bin/vndcompress/vnduncompress.c:1.2	Mon May  6 22:53:24 2013
+++ src/usr.bin/vndcompress/vnduncompress.c	Wed Jan 22 06:14:03 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: vnduncompress.c,v 1.2 2013/05/06 22:53:24 riastradh Exp $	*/
+/*	$NetBSD: vnduncompress.c,v 1.3 2014/01/22 06:14:03 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: vnduncompress.c,v 1.2 2013/05/06 22:53:24 riastradh Exp $);
+__RCSID($NetBSD: vnduncompress.c,v 1.3 2014/01/22 06:14:03 riastradh Exp $);
 
 #include sys/endian.h
 
@@ -109,6 +109,8 @@ vnduncompress(int argc, char **argv, con
 
 	__CTASSERT(MAX_N_OFFSETS = (SIZE_MAX / sizeof(uint64_t)));
 	uint64_t *const offset_table = malloc(n_offsets * sizeof(uint64_t));
+	if (offset_table == NULL)
+		err(1, malloc offset table);
 
 	/* Read the offset table in.  */
 	const ssize_t ot_read = read(cloop2_fd, offset_table,



CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:14:20 UTC 2014

Modified Files:
src/usr.bin/vndcompress: Makefile vndcompress.c
Added Files:
src/usr.bin/vndcompress: utils.c utils.h

Log Message:
Move vndcompress utilities to utils.c.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/vndcompress/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/vndcompress/utils.c \
src/usr.bin/vndcompress/utils.h
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/vndcompress/vndcompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/Makefile
diff -u src/usr.bin/vndcompress/Makefile:1.4 src/usr.bin/vndcompress/Makefile:1.5
--- src/usr.bin/vndcompress/Makefile:1.4	Sun Aug 11 06:33:30 2013
+++ src/usr.bin/vndcompress/Makefile	Wed Jan 22 06:14:20 2014
@@ -1,5 +1,5 @@
 PROG=	vndcompress
-SRCS=	main.c vndcompress.c vnduncompress.c
+SRCS=	main.c utils.c vndcompress.c vnduncompress.c
 
 LINKS=	${BINDIR}/vndcompress ${BINDIR}/vnduncompress
 MLINKS=	vndcompress.1 vnduncompress.1

Index: src/usr.bin/vndcompress/vndcompress.c
diff -u src/usr.bin/vndcompress/vndcompress.c:1.13 src/usr.bin/vndcompress/vndcompress.c:1.14
--- src/usr.bin/vndcompress/vndcompress.c:1.13	Mon May  6 22:53:24 2013
+++ src/usr.bin/vndcompress/vndcompress.c	Wed Jan 22 06:14:20 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: vndcompress.c,v 1.13 2013/05/06 22:53:24 riastradh Exp $	*/
+/*	$NetBSD: vndcompress.c,v 1.14 2014/01/22 06:14:20 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: vndcompress.c,v 1.13 2013/05/06 22:53:24 riastradh Exp $);
+__RCSID($NetBSD: vndcompress.c,v 1.14 2014/01/22 06:14:20 riastradh Exp $);
 
 #include sys/endian.h
 
@@ -49,13 +49,8 @@ __RCSID($NetBSD: vndcompress.c,v 1.13 2
 #include unistd.h
 #include zlib.h
 
-/* XXX Seems to be missing from stdio.h...  */
-int	snprintf_ss(char *restrict, size_t, const char *restrict, ...)
-	__printflike(3, 4);
-int	vsnprintf_ss(char *restrict, size_t, const char *restrict, va_list)
-	__printflike(3, 0);
-
 #include common.h
+#include utils.h
 
 /*
  * XXX Switch to control bug-for-bug byte-for-byte compatibility with
@@ -116,12 +111,6 @@ static uint32_t	compress_block(int, int,
 static void	compress_maybe_checkpoint(struct compress_state *);
 static void	compress_checkpoint(struct compress_state *);
 static void	compress_exit(struct compress_state *);
-static ssize_t	read_block(int, void *, size_t);
-static void	err_ss(int, const char *) __dead;
-static void	errx_ss(int, const char *, ...) __printflike(2, 3) __dead;
-static void	warn_ss(const char *);
-static void	warnx_ss(const char *, ...) __printflike(1, 2);
-static void	vwarnx_ss(const char *, va_list) __printflike(1, 0);
 
 /*
  * Compression entry point.
@@ -949,97 +938,3 @@ compress_exit(struct compress_state *S)
 	if (close(S-image_fd) == -1)
 		warn(close(image fd));
 }
-
-/*
- * Read, returning partial data only at end of file.
- */
-static ssize_t
-read_block(int fd, void *buffer, size_t n)
-{
-	char *p = buffer, *const end __unused = (p + n);
-	size_t total_read = 0;
-
-	while (n  0) {
-		const ssize_t n_read = read(fd, p, n);
-		if (n_read == -1)
-			return -1;
-		assert(n_read = 0);
-		if (n_read == 0)
-			break;
-
-		assert((size_t)n_read = n);
-		n -= (size_t)n_read;
-
-		assert(p = end);
-		assert(n_read = (end - p));
-		p += (size_t)n_read;
-
-		assert((size_t)n_read = (SIZE_MAX - total_read));
-		total_read += (size_t)n_read;
-	}
-
-	return total_read;
-}
-
-/*
- * Signal-safe err/warn utilities.  The errno varieties are limited to
- * having no format arguments for reasons of laziness.
- */
-
-static void
-err_ss(int exit_value, const char *msg)
-{
-	warn_ss(msg);
-	_Exit(exit_value);
-}
-
-static void
-errx_ss(int exit_value, const char *format, ...)
-{
-	va_list va;
-
-	va_start(va, format);
-	vwarnx_ss(format, va);
-	va_end(va);
-	_Exit(exit_value);
-}
-
-static void
-warn_ss(const char *msg)
-{
-	int error = errno;
-
-	warnx_ss(%s: %s, msg, strerror(error));
-
-	errno = error;
-}
-
-static void
-warnx_ss(const char *format, ...)
-{
-	va_list va;
-
-	va_start(va, format);
-	vwarnx_ss(format, va);
-	va_end(va);
-}
-
-static void
-vwarnx_ss(const char *format, va_list va)
-{
-	char buf[128];
-
-	(void)strlcpy(buf, getprogname(), sizeof(buf));
-	(void)strlcat(buf, : , sizeof(buf));
-
-	const int n = vsnprintf_ss(buf[strlen(buf)], (sizeof(buf) -
-		strlen(buf)), format, va);
-	if (n = 0) {
-		const char fallback[] =
-		vndcompress: Help!  I'm trapped in a signal handler!\n;
-		(void)write(STDERR_FILENO, fallback, __arraycount(fallback));
-	} else {
-		(void)strlcat(buf, \n, sizeof(buf));
-		(void)write(STDERR_FILENO, buf, strlen(buf));
-	}
-}

Added files:

Index: src/usr.bin/vndcompress/utils.c
diff -u /dev/null src/usr.bin/vndcompress/utils.c:1.1
--- /dev/null	Wed Jan 

CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:14:28 UTC 2014

Modified Files:
src/usr.bin/vndcompress: vnduncompress.c

Log Message:
Use read_block instead of read in vnduncompress.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/vndcompress/vnduncompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/vnduncompress.c
diff -u src/usr.bin/vndcompress/vnduncompress.c:1.3 src/usr.bin/vndcompress/vnduncompress.c:1.4
--- src/usr.bin/vndcompress/vnduncompress.c:1.3	Wed Jan 22 06:14:03 2014
+++ src/usr.bin/vndcompress/vnduncompress.c	Wed Jan 22 06:14:28 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: vnduncompress.c,v 1.3 2014/01/22 06:14:03 riastradh Exp $	*/
+/*	$NetBSD: vnduncompress.c,v 1.4 2014/01/22 06:14:28 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: vnduncompress.c,v 1.3 2014/01/22 06:14:03 riastradh Exp $);
+__RCSID($NetBSD: vnduncompress.c,v 1.4 2014/01/22 06:14:28 riastradh Exp $);
 
 #include sys/endian.h
 
@@ -46,6 +46,7 @@ __RCSID($NetBSD: vnduncompress.c,v 1.3 
 #include zlib.h
 
 #include common.h
+#include utils.h
 
 int
 vnduncompress(int argc, char **argv, const struct options *O __unused)
@@ -70,7 +71,7 @@ vnduncompress(int argc, char **argv, con
 
 	/* Read the header.  */
 	struct cloop2_header header;
-	const ssize_t h_read = read(cloop2_fd, header, sizeof(header));
+	const ssize_t h_read = read_block(cloop2_fd, header, sizeof(header));
 	if (h_read == -1)
 		err(1, read header);
 	assert(h_read = 0);
@@ -113,7 +114,7 @@ vnduncompress(int argc, char **argv, con
 		err(1, malloc offset table);
 
 	/* Read the offset table in.  */
-	const ssize_t ot_read = read(cloop2_fd, offset_table,
+	const ssize_t ot_read = read_block(cloop2_fd, offset_table,
 	(n_offsets * sizeof(uint64_t)));
 	if (ot_read == -1)
 		err(1, read offset table);
@@ -163,7 +164,8 @@ vnduncompress(int argc, char **argv, con
 			blkno, offset, (end - start));
 
 		/* Read the compressed block.  */
-		const ssize_t n_read = read(cloop2_fd, compbuf, (end - start));
+		const ssize_t n_read = read_block(cloop2_fd, compbuf,
+		(end - start));
 		if (n_read == -1)
 			err(1, read block %PRIu32, blkno);
 		assert(n_read = 0);



CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:14:55 UTC 2014

Modified Files:
src/usr.bin/vndcompress: Makefile

Log Message:
Use write-to-temporary/rename-to-permanent pattern in Makefile.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/vndcompress/Makefile

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

Modified files:

Index: src/usr.bin/vndcompress/Makefile
diff -u src/usr.bin/vndcompress/Makefile:1.6 src/usr.bin/vndcompress/Makefile:1.7
--- src/usr.bin/vndcompress/Makefile:1.6	Wed Jan 22 06:14:46 2014
+++ src/usr.bin/vndcompress/Makefile	Wed Jan 22 06:14:55 2014
@@ -145,13 +145,17 @@ check: .PHONY ${CHECKS}
 .SUFFIXES: .cl2 .cl2x .in .out .outx
 
 .in.cl2: vndcompress
-	./vndcompress ${.IMPSRC} ${.TARGET} ${BLOCKSIZE.${.PREFIX}}
+	./vndcompress ${.IMPSRC} ${.TARGET}.tmp ${BLOCKSIZE.${.PREFIX}} \
+	 mv -f ${.TARGET}.tmp ${.TARGET}
 
 .in.cl2x:
-	vndcompress ${.IMPSRC} ${.TARGET} ${BLOCKSIZE.${.PREFIX}}
+	vndcompress ${.IMPSRC} ${.TARGET}.tmp ${BLOCKSIZE.${.PREFIX}} \
+	 mv -f ${.TARGET}.tmp ${.TARGET}
 
 .cl2.out: vndcompress
-	./vndcompress -d ${.IMPSRC} ${.TARGET}
+	./vndcompress -d ${.IMPSRC} ${.TARGET}.tmp \
+	 mv -f ${.TARGET}.tmp ${.TARGET}
 
 .cl2.outx:
-	vnduncompress ${.IMPSRC} ${.TARGET}
+	vnduncompress ${.IMPSRC} ${.TARGET}.tmp \
+	 mv -f ${.TARGET}.tmp ${.TARGET}



CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:14:46 UTC 2014

Modified Files:
src/usr.bin/vndcompress: Makefile vndcompress.c vnduncompress.c
Added Files:
src/usr.bin/vndcompress: offtab.c offtab.h

Log Message:
Abstract handling of the cloop2 offset table.

Preparation for converting it to use a fixed-size window.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/vndcompress/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/vndcompress/offtab.c \
src/usr.bin/vndcompress/offtab.h
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/vndcompress/vndcompress.c
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/vndcompress/vnduncompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/Makefile
diff -u src/usr.bin/vndcompress/Makefile:1.5 src/usr.bin/vndcompress/Makefile:1.6
--- src/usr.bin/vndcompress/Makefile:1.5	Wed Jan 22 06:14:20 2014
+++ src/usr.bin/vndcompress/Makefile	Wed Jan 22 06:14:46 2014
@@ -1,5 +1,5 @@
 PROG=	vndcompress
-SRCS=	main.c utils.c vndcompress.c vnduncompress.c
+SRCS=	main.c offtab.c utils.c vndcompress.c vnduncompress.c
 
 LINKS=	${BINDIR}/vndcompress ${BINDIR}/vnduncompress
 MLINKS=	vndcompress.1 vnduncompress.1

Index: src/usr.bin/vndcompress/vndcompress.c
diff -u src/usr.bin/vndcompress/vndcompress.c:1.14 src/usr.bin/vndcompress/vndcompress.c:1.15
--- src/usr.bin/vndcompress/vndcompress.c:1.14	Wed Jan 22 06:14:20 2014
+++ src/usr.bin/vndcompress/vndcompress.c	Wed Jan 22 06:14:46 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: vndcompress.c,v 1.14 2014/01/22 06:14:20 riastradh Exp $	*/
+/*	$NetBSD: vndcompress.c,v 1.15 2014/01/22 06:14:46 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: vndcompress.c,v 1.14 2014/01/22 06:14:20 riastradh Exp $);
+__RCSID($NetBSD: vndcompress.c,v 1.15 2014/01/22 06:14:46 riastradh Exp $);
 
 #include sys/endian.h
 
@@ -50,6 +50,7 @@ __RCSID($NetBSD: vndcompress.c,v 1.14 2
 #include zlib.h
 
 #include common.h
+#include offtab.h
 #include utils.h
 
 /*
@@ -72,7 +73,7 @@ struct compress_state {
 	uint32_t	checkpoint_blocks;	/* blocks before checkpoint */
 	int		image_fd;
 	int		cloop2_fd;
-	uint64_t	*offset_table;
+	struct offtab	offtab;
 	uint32_t	n_checkpointed_blocks;
 	volatile sig_atomic_t
 			initialized;	/* everything above initialized?  */
@@ -133,10 +134,6 @@ vndcompress(int argc, char **argv, const
 	compress_init(argc, argv, O, S);
 	assert(MIN_BLOCKSIZE = S-blocksize);
 	assert(S-blocksize = MAX_BLOCKSIZE);
-	assert(S-offset_table != NULL);
-	assert(S-n_offsets  0);
-	assert(S-offset_table[0] == htobe64(sizeof(struct cloop2_header) +
-		(S-n_offsets * sizeof(uint64_t;
 
 	/*
 	 * Allocate compression buffers.
@@ -172,6 +169,7 @@ vndcompress(int argc, char **argv, const
 
 		/* Checkpoint if appropriate.  */
 		compress_maybe_checkpoint(S);
+		offtab_prepare_put(S-offtab, (S-blkno + 1));
 
 		/* Choose read size: partial if last block, full if not.  */
 		const uint32_t readsize = (S-blkno == S-n_full_blocks?
@@ -208,7 +206,7 @@ vndcompress(int argc, char **argv, const
 		block_signals(old_sigmask);
 		S-blkno += 1;	/* (a) */
 		S-offset += complen;/* (b) */
-		S-offset_table[S-blkno] = htobe64(S-offset);	/* (c) */
+		offtab_put(S-offtab, S-blkno, S-offset);	/* (c) */
 		restore_sigmask(old_sigmask);
 	}
 	}
@@ -244,7 +242,7 @@ vndcompress(int argc, char **argv, const
 	}
 
 out:
-	/* Commit the offset table.  */
+	/* One last checkpoint to commit the offset table.  */
 	assert(S-offset = OFF_MAX);
 	assert((off_t)S-offset == lseek(S-cloop2_fd, 0, SEEK_CUR));
 	compress_checkpoint(S);
@@ -405,7 +403,6 @@ static void
 compress_init(int argc, char **argv, const struct options *O,
 struct compress_state *S)
 {
-	uint32_t i;
 
 	if (!((argc == 2) || (argc == 3)))
 		usage();
@@ -494,14 +491,13 @@ compress_init(int argc, char **argv, con
 		S-blocksize, S-size);
 	assert(S-n_blocks = MAX_N_BLOCKS);
 
-	/* Allocate an offset table for the blocks; one extra for the end.  */
+	/* Create an offset table for the blocks; one extra for the end.  */
 	__CTASSERT(MAX_N_BLOCKS = (UINT32_MAX - 1));
 	S-n_offsets = (S-n_blocks + 1);
 	__CTASSERT(MAX_N_OFFSETS == (MAX_N_BLOCKS + 1));
 	__CTASSERT(MAX_N_OFFSETS = (SIZE_MAX / sizeof(uint64_t)));
-	S-offset_table = malloc(S-n_offsets * sizeof(uint64_t));
-	if (S-offset_table == NULL)
-		err(1, malloc offset table);
+	offtab_init(S-offtab, S-n_offsets, S-cloop2_fd,
+	CLOOP2_OFFSET_TABLE_OFFSET);
 
 	/* Attempt to restart a partial transfer if requested.  */
 	if (ISSET(O-flags, FLAG_r)) {
@@ -534,18 +530,6 @@ compress_init(int argc, char **argv, con
 		}
 	}
 
-	/*
-	 * Initialize the offset table to all ones (except for the
-	 * fixed first offset) so that we can easily detect where we
-	 * were interrupted if we want to restart.
-	 */
-	

CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:15:48 UTC 2014

Modified Files:
src/usr.bin/vndcompress: common.h

Log Message:
Add some leading zero digits to the flags.  Cosmetic change only.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/vndcompress/common.h

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

Modified files:

Index: src/usr.bin/vndcompress/common.h
diff -u src/usr.bin/vndcompress/common.h:1.2 src/usr.bin/vndcompress/common.h:1.3
--- src/usr.bin/vndcompress/common.h:1.2	Wed Jan 22 06:15:22 2014
+++ src/usr.bin/vndcompress/common.h	Wed Jan 22 06:15:48 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: common.h,v 1.2 2014/01/22 06:15:22 riastradh Exp $	*/
+/*	$NetBSD: common.h,v 1.3 2014/01/22 06:15:48 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -121,14 +121,14 @@ struct cloop2_header {
 
 struct options {
 	int		flags;
-#define	FLAG_c	0x01	/* Compress */
-#define	FLAG_d	0x02	/* Decompress */
-#define	FLAG_p	0x04	/* Partial */
-#define	FLAG_r	0x08	/* Restart */
-#define	FLAG_s	0x10	/* block Size */
-#define	FLAG_R	0x20	/* abort on Restart failure */
-#define	FLAG_k	0x40	/* checKpoint blocks */
-#define	FLAG_l	0x80	/* Length of input */
+#define	FLAG_c	0x0001	/* Compress */
+#define	FLAG_d	0x0002	/* Decompress */
+#define	FLAG_p	0x0004	/* Partial */
+#define	FLAG_r	0x0008	/* Restart */
+#define	FLAG_s	0x0010	/* block Size */
+#define	FLAG_R	0x0020	/* abort on Restart failure */
+#define	FLAG_k	0x0040	/* checKpoint blocks */
+#define	FLAG_l	0x0080	/* Length of input */
 	uint32_t	blocksize;
 	uint32_t	end_block;	/* end for partial transfer */
 	uint32_t	checkpoint_blocks;	/* blocks before checkpoint */



CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:15:04 UTC 2014

Modified Files:
src/usr.bin/vndcompress: utils.c utils.h vndcompress.c

Log Message:
Move block_signals/restore_sigmask to utils.c


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/vndcompress/utils.c \
src/usr.bin/vndcompress/utils.h
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/vndcompress/vndcompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/utils.c
diff -u src/usr.bin/vndcompress/utils.c:1.1 src/usr.bin/vndcompress/utils.c:1.2
--- src/usr.bin/vndcompress/utils.c:1.1	Wed Jan 22 06:14:20 2014
+++ src/usr.bin/vndcompress/utils.c	Wed Jan 22 06:15:04 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: utils.c,v 1.1 2014/01/22 06:14:20 riastradh Exp $	*/
+/*	$NetBSD: utils.c,v 1.2 2014/01/22 06:15:04 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: utils.c,v 1.1 2014/01/22 06:14:20 riastradh Exp $);
+__RCSID($NetBSD: utils.c,v 1.2 2014/01/22 06:15:04 riastradh Exp $);
 
 #include sys/types.h
 
@@ -39,6 +39,7 @@ __RCSID($NetBSD: utils.c,v 1.1 2014/01/
 #include errno.h
 #include inttypes.h
 #include limits.h
+#include signal.h
 #include stdio.h
 #include stdlib.h
 #include string.h
@@ -145,3 +146,19 @@ vwarnx_ss(const char *format, va_list va
 		(void)write(STDERR_FILENO, buf, strlen(buf));
 	}
 }
+
+void
+block_signals(sigset_t *old_sigmask)
+{
+	sigset_t block;
+
+	(void)sigfillset(block);
+	(void)sigprocmask(SIG_BLOCK, block, old_sigmask);
+}
+
+void
+restore_sigmask(const sigset_t *sigmask)
+{
+
+	(void)sigprocmask(SIG_SETMASK, sigmask, NULL);
+}
Index: src/usr.bin/vndcompress/utils.h
diff -u src/usr.bin/vndcompress/utils.h:1.1 src/usr.bin/vndcompress/utils.h:1.2
--- src/usr.bin/vndcompress/utils.h:1.1	Wed Jan 22 06:14:20 2014
+++ src/usr.bin/vndcompress/utils.h	Wed Jan 22 06:15:04 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: utils.h,v 1.1 2014/01/22 06:14:20 riastradh Exp $	*/
+/*	$NetBSD: utils.h,v 1.2 2014/01/22 06:15:04 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -47,5 +47,7 @@ void	errx_ss(int, const char *, ...) __p
 void	warn_ss(const char *);
 void	warnx_ss(const char *, ...) __printflike(1, 2);
 void	vwarnx_ss(const char *, va_list) __printflike(1, 0);
+void	block_signals(sigset_t *);
+void	restore_sigmask(const sigset_t *);
 
 #endif	/* VNDCOMPRESS_UTILS_H */

Index: src/usr.bin/vndcompress/vndcompress.c
diff -u src/usr.bin/vndcompress/vndcompress.c:1.15 src/usr.bin/vndcompress/vndcompress.c:1.16
--- src/usr.bin/vndcompress/vndcompress.c:1.15	Wed Jan 22 06:14:46 2014
+++ src/usr.bin/vndcompress/vndcompress.c	Wed Jan 22 06:15:04 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: vndcompress.c,v 1.15 2014/01/22 06:14:46 riastradh Exp $	*/
+/*	$NetBSD: vndcompress.c,v 1.16 2014/01/22 06:15:04 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: vndcompress.c,v 1.15 2014/01/22 06:14:46 riastradh Exp $);
+__RCSID($NetBSD: vndcompress.c,v 1.16 2014/01/22 06:15:04 riastradh Exp $);
 
 #include sys/endian.h
 
@@ -101,8 +101,6 @@ static void	init_signal_handler(int, con
 		void (*)(int));
 static void	info_signal_handler(int);
 static void	checkpoint_signal_handler(int);
-static void	block_signals(sigset_t *);
-static void	restore_sigmask(const sigset_t *);
 static void	compress_progress(struct compress_state *);
 static void	compress_init(int, char **, const struct options *,
 		struct compress_state *);
@@ -370,22 +368,6 @@ out:
 	errno = error;
 }
 
-static void
-block_signals(sigset_t *old_sigmask)
-{
-	sigset_t block;
-
-	(void)sigfillset(block);
-	(void)sigprocmask(SIG_BLOCK, block, old_sigmask);
-}
-
-static void
-restore_sigmask(const sigset_t *sigmask)
-{
-
-	(void)sigprocmask(SIG_SETMASK, sigmask, NULL);
-}
-
 /*
  * Report progress.
  *



CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:15:57 UTC 2014

Modified Files:
src/usr.bin/vndcompress: common.h main.c vndcompress.c vnduncompress.c

Log Message:
Add option -w to vnd(un)compress to specify the window size.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/vndcompress/common.h
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/vndcompress/main.c
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/vndcompress/vndcompress.c
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/vndcompress/vnduncompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/common.h
diff -u src/usr.bin/vndcompress/common.h:1.3 src/usr.bin/vndcompress/common.h:1.4
--- src/usr.bin/vndcompress/common.h:1.3	Wed Jan 22 06:15:48 2014
+++ src/usr.bin/vndcompress/common.h	Wed Jan 22 06:15:57 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: common.h,v 1.3 2014/01/22 06:15:48 riastradh Exp $	*/
+/*	$NetBSD: common.h,v 1.4 2014/01/22 06:15:57 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -129,10 +129,12 @@ struct options {
 #define	FLAG_R	0x0020	/* abort on Restart failure */
 #define	FLAG_k	0x0040	/* checKpoint blocks */
 #define	FLAG_l	0x0080	/* Length of input */
+#define	FLAG_w	0x0100	/* Window size */
 	uint32_t	blocksize;
 	uint32_t	end_block;	/* end for partial transfer */
 	uint32_t	checkpoint_blocks;	/* blocks before checkpoint */
 	uint64_t	length;			/* length of image in bytes */
+	uint32_t	window_size;	/* size of window into offset table */
 };
 
 int	vndcompress(int, char **, const struct options *);

Index: src/usr.bin/vndcompress/main.c
diff -u src/usr.bin/vndcompress/main.c:1.1 src/usr.bin/vndcompress/main.c:1.2
--- src/usr.bin/vndcompress/main.c:1.1	Fri May  3 23:28:15 2013
+++ src/usr.bin/vndcompress/main.c	Wed Jan 22 06:15:57 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.1 2013/05/03 23:28:15 riastradh Exp $	*/
+/*	$NetBSD: main.c,v 1.2 2014/01/22 06:15:57 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: main.c,v 1.1 2013/05/03 23:28:15 riastradh Exp $);
+__RCSID($NetBSD: main.c,v 1.2 2014/01/22 06:15:57 riastradh Exp $);
 
 #include assert.h
 #include err.h
@@ -60,7 +60,7 @@ main(int argc, char **argv)
 		warnx(unknown program name, defaulting to vndcompress: %s,
 		getprogname());
 
-	while ((ch = getopt(argc, argv, cdk:l:p:rRs:)) != -1) {
+	while ((ch = getopt(argc, argv, cdk:l:p:rRs:w:)) != -1) {
 		switch (ch) {
 		case 'c':
 			if (ISSET(O-flags, FLAG_d)) {
@@ -128,6 +128,16 @@ main(int argc, char **argv)
 			MIN_BLOCKSIZE, MAX_BLOCKSIZE);
 			break;
 
+		case 'w':
+			if (ISSET(O-flags, FLAG_w)) {
+warnx(-w may be supplied only once);
+usage();
+			}
+			O-flags |= FLAG_w;
+			O-window_size = strsuftoll(window size, optarg,
+			0, MAX_WINDOW_SIZE);
+			break;
+
 		case '?':
 		default:
 			usage();
@@ -138,12 +148,12 @@ main(int argc, char **argv)
 	argv += optind;
 
 	if (operation == vnduncompress) {
-		if (ISSET(O-flags, ~FLAG_d))
+		if (ISSET(O-flags, ~(FLAG_d | FLAG_w)))
 			usage();
 	} else {
 		assert(operation == vndcompress);
 		if (ISSET(O-flags, ~(FLAG_c | FLAG_k | FLAG_l | FLAG_p |
-			FLAG_r | FLAG_s | FLAG_R)))
+			FLAG_r | FLAG_s | FLAG_R | FLAG_w)))
 			usage();
 		if (ISSET(O-flags, FLAG_R)  !ISSET(O-flags, FLAG_r)) {
 			warnx(-R makes no sense without -r);
@@ -160,7 +170,7 @@ usage(void)
 
 	(void)fprintf(stderr,
 	Usage: %s -c [-rR] [-k checkpoint-blocks] [-l length]\n
-	  [-p partial-offset] [-s blocksize]\n
+	  [-p partial-offset] [-s blocksize] [-w winsize]\n
 	  image compressed-image [blocksize]\n
 	   %s -d compressed-image image\n,
 	getprogname(), getprogname());

Index: src/usr.bin/vndcompress/vndcompress.c
diff -u src/usr.bin/vndcompress/vndcompress.c:1.18 src/usr.bin/vndcompress/vndcompress.c:1.19
--- src/usr.bin/vndcompress/vndcompress.c:1.18	Wed Jan 22 06:15:22 2014
+++ src/usr.bin/vndcompress/vndcompress.c	Wed Jan 22 06:15:57 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: vndcompress.c,v 1.18 2014/01/22 06:15:22 riastradh Exp $	*/
+/*	$NetBSD: vndcompress.c,v 1.19 2014/01/22 06:15:57 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: vndcompress.c,v 1.18 2014/01/22 06:15:22 riastradh Exp $);
+__RCSID($NetBSD: vndcompress.c,v 1.19 2014/01/22 06:15:57 riastradh Exp $);
 
 #include sys/endian.h
 
@@ -479,7 +479,7 @@ compress_init(int argc, char **argv, con
 	__CTASSERT(MAX_N_OFFSETS == (MAX_N_BLOCKS + 1));
 	__CTASSERT(MAX_N_OFFSETS = (SIZE_MAX / sizeof(uint64_t)));
 	/* XXX Make the window size an option.  */
-	offtab_init(S-offtab, S-n_offsets, S-n_offsets, S-cloop2_fd,
+	offtab_init(S-offtab, S-n_offsets, O-window_size, S-cloop2_fd,
 	CLOOP2_OFFSET_TABLE_OFFSET);
 
 	

CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:15:13 UTC 2014

Modified Files:
src/usr.bin/vndcompress: vndcompress.c vnduncompress.c

Log Message:
Write offsets in hexadecimal, not decimal.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/vndcompress/vndcompress.c
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/vndcompress/vnduncompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/vndcompress.c
diff -u src/usr.bin/vndcompress/vndcompress.c:1.16 src/usr.bin/vndcompress/vndcompress.c:1.17
--- src/usr.bin/vndcompress/vndcompress.c:1.16	Wed Jan 22 06:15:04 2014
+++ src/usr.bin/vndcompress/vndcompress.c	Wed Jan 22 06:15:12 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: vndcompress.c,v 1.16 2014/01/22 06:15:04 riastradh Exp $	*/
+/*	$NetBSD: vndcompress.c,v 1.17 2014/01/22 06:15:12 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: vndcompress.c,v 1.16 2014/01/22 06:15:04 riastradh Exp $);
+__RCSID($NetBSD: vndcompress.c,v 1.17 2014/01/22 06:15:12 riastradh Exp $);
 
 #include sys/endian.h
 
@@ -596,7 +596,7 @@ compress_restart(struct compress_state *
 	const uint64_t first_offset = offtab_get(S-offtab, 0);
 	if (first_offset != (sizeof(struct cloop2_header) +
 		(S-n_offsets * sizeof(uint64_t {
-		warnx(first offset is not %PRIu64: %PRIu64,
+		warnx(first offset is not 0x%PRIx64: 0x%PRIx64,
 		((uint64_t)S-n_offsets * sizeof(uint64_t)),
 		first_offset);
 		return false;
@@ -625,8 +625,9 @@ compress_restart(struct compress_state *
 			__CTASSERT(MAX_BLOCKSIZE = (SIZE_MAX / 2));
 			if ((2 * (size_t)S-blocksize) = (end - start)) {
 warnx(block %PRIu32 too large:
- %PRIu64 bytes,
-blkno, (end - start));
+ %PRIu64 bytes
+ from 0x%PRIx64 to 0x%PRIx64,
+blkno, (end - start), start, end);
 return false;
 			}
 		}
@@ -649,7 +650,7 @@ compress_restart(struct compress_state *
 			const uint64_t offset = offtab_get(S-offtab, nblkno);
 			if (offset != ~(uint64_t)0) {
 warnx(bad partial offset table entry
- at %PRIu32: %PRIu64,
+ at %PRIu32: 0x%PRIx64,
 nblkno, offset);
 return false;
 			}

Index: src/usr.bin/vndcompress/vnduncompress.c
diff -u src/usr.bin/vndcompress/vnduncompress.c:1.5 src/usr.bin/vndcompress/vnduncompress.c:1.6
--- src/usr.bin/vndcompress/vnduncompress.c:1.5	Wed Jan 22 06:14:46 2014
+++ src/usr.bin/vndcompress/vnduncompress.c	Wed Jan 22 06:15:12 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: vnduncompress.c,v 1.5 2014/01/22 06:14:46 riastradh Exp $	*/
+/*	$NetBSD: vnduncompress.c,v 1.6 2014/01/22 06:15:12 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: vnduncompress.c,v 1.5 2014/01/22 06:14:46 riastradh Exp $);
+__RCSID($NetBSD: vnduncompress.c,v 1.6 2014/01/22 06:15:12 riastradh Exp $);
 
 #include sys/endian.h
 
@@ -163,17 +163,19 @@ vnduncompress(int argc, char **argv, con
 
 		/* Sanity-check the offsets.  */
 		if (start != offset)
-			errx(1, strange offset for block %PRIu32: %PRIu64,
+			errx(1, strange offset for block %PRIu32
+			: 0x%PRIx64,
 			blkno, start);
 		/* XXX compression ratio bound */
 		__CTASSERT(MAX_BLOCKSIZE = (SIZE_MAX / 2));
 		if ((2 * (size_t)blocksize) = (end - start))
-			errx(1, block %PRIu32 too large: %PRIu64 bytes,
-			blkno, (end - start));
+			errx(1, block %PRIu32 too large
+			: %PRIu64 bytes from 0x%PRIx64 to 0x%PRIx64,
+			blkno, (end - start), start, end);
 		assert(offset = MIN(OFF_MAX, UINT64_MAX));
 		if ((MIN(OFF_MAX, UINT64_MAX) - offset)  (end - start))
 			errx(1, block %PRIu32 overflows offset:
-			 %PRIu64 + %PRIu64,
+			 0x%PRIx64 + %PRIu64,
 			blkno, offset, (end - start));
 
 		/* Read the compressed block.  */



CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:15:22 UTC 2014

Modified Files:
src/usr.bin/vndcompress: common.h offtab.c offtab.h utils.c utils.h
vndcompress.c vnduncompress.c

Log Message:
Implement machinery for fixed-size windows into the offset table.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/vndcompress/common.h \
src/usr.bin/vndcompress/offtab.c src/usr.bin/vndcompress/offtab.h
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/vndcompress/utils.c \
src/usr.bin/vndcompress/utils.h
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/vndcompress/vndcompress.c
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/vndcompress/vnduncompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/common.h
diff -u src/usr.bin/vndcompress/common.h:1.1 src/usr.bin/vndcompress/common.h:1.2
--- src/usr.bin/vndcompress/common.h:1.1	Fri May  3 23:28:15 2013
+++ src/usr.bin/vndcompress/common.h	Wed Jan 22 06:15:22 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: common.h,v 1.1 2013/05/03 23:28:15 riastradh Exp $	*/
+/*	$NetBSD: common.h,v 1.2 2014/01/22 06:15:22 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -109,6 +109,7 @@
 #define	MAX_N_BLOCKS			\
 	(MIN(UINT32_MAX, (SIZE_MAX / sizeof(uint64_t))) - 1)
 #define	MAX_N_OFFSETS		(MAX_N_BLOCKS + 1)
+#define	MAX_WINDOW_SIZE		MAX_N_OFFSETS
 
 struct cloop2_header {
 	char		cl2h_magic[128];
Index: src/usr.bin/vndcompress/offtab.c
diff -u src/usr.bin/vndcompress/offtab.c:1.1 src/usr.bin/vndcompress/offtab.c:1.2
--- src/usr.bin/vndcompress/offtab.c:1.1	Wed Jan 22 06:14:46 2014
+++ src/usr.bin/vndcompress/offtab.c	Wed Jan 22 06:15:22 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: offtab.c,v 1.1 2014/01/22 06:14:46 riastradh Exp $	*/
+/*	$NetBSD: offtab.c,v 1.2 2014/01/22 06:15:22 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -62,13 +62,137 @@ offtab_bugx(const char *fmt, ...)
 
 	errx(1, bug in offtab, please report);
 }
+
+static uint32_t
+offtab_compute_window_size(struct offtab *offtab, uint32_t start,
+uint32_t end)
+{
+
+	if (end == 0)
+		end = offtab-ot_n_offsets;
+
+	assert(end = offtab-ot_n_offsets);
+	assert(start  end);
+	return MIN(offtab-ot_window_size, (end - start));
+}
+
+static uint32_t
+offtab_current_window_size(struct offtab *offtab)
+{
+
+	return offtab_compute_window_size(offtab, offtab-ot_window_start, 0);
+}
+
+static uint32_t
+offtab_current_window_end(struct offtab *offtab)
+{
+
+	assert(offtab-ot_window_start  offtab-ot_n_offsets);
+	assert(offtab_current_window_size(offtab) =
+	(offtab-ot_n_offsets - offtab-ot_window_start));
+	return (offtab-ot_window_start + offtab_current_window_size(offtab));
+}
+
+#define	OFFTAB_READ_SEEK	0x01
+#define	OFFTAB_READ_NOSEEK	0x00
+
+static bool
+offtab_read_window(struct offtab *offtab, uint32_t blkno, int read_flags)
+{
+
+	assert(offtab-ot_mode == OFFTAB_MODE_READ);
+
+	const uint32_t window_start = rounddown(blkno, offtab-ot_window_size);
+	const uint32_t window_size = offtab_compute_window_size(offtab,
+	window_start, 0);
+
+	__CTASSERT(MAX_WINDOW_SIZE = (SIZE_MAX / sizeof(uint64_t)));
+	__CTASSERT(MAX_N_OFFSETS = (OFF_MAX / sizeof(uint64_t)));
+	assert(window_start  offtab-ot_n_offsets);
+	assert(offtab-ot_fdpos =
+	(OFF_MAX - (window_start * sizeof(uint64_t;
+	assert(ISSET(read_flags, OFFTAB_READ_SEEK) ||
+	(lseek(offtab-ot_fd, 0, SEEK_CUR) == offtab-ot_fdpos) ||
+	((lseek(offtab-ot_fd, 0, SEEK_CUR) == -1)  (errno == ESPIPE)));
+	const size_t n_req = (window_size * sizeof(uint64_t));
+	const ssize_t n_read = (ISSET(read_flags, OFFTAB_READ_SEEK)
+	? pread_block(offtab-ot_fd, offtab-ot_window, n_req,
+		(offtab-ot_fdpos + (window_start * sizeof(uint64_t
+	: read_block(offtab-ot_fd, offtab-ot_window, n_req));
+	if (n_read == -1) {
+		(*offtab-ot_report)(read offset table at %PRIuMAX,
+		(uintmax_t)(offtab-ot_fdpos +
+			(window_start * sizeof(uint64_t;
+		return false;
+	}
+	assert(n_read = 0);
+	if ((size_t)n_read != (window_size * sizeof(uint64_t))) {
+		(*offtab-ot_reportx)(partial read of offset table
+		 at %PRIuMAX: %zu != %zu,
+		(uintmax_t)(offtab-ot_fdpos +
+			(window_start * sizeof(uint64_t))),
+		(size_t)n_read,
+		(size_t)(window_size * sizeof(uint64_t)));
+		return false;
+	}
+	offtab-ot_window_start = window_start;
+
+	return true;
+}
+
+static bool
+offtab_maybe_read_window(struct offtab *offtab, uint32_t blkno, int read_flags)
+{
+
+	/* Don't bother if blkno is already in the window.  */
+	if ((offtab-ot_window_start = blkno) 
+	(blkno  offtab_current_window_end(offtab)))
+		return true;
+
+	if (!offtab_read_window(offtab, blkno, read_flags))
+		return false;
+
+	return true;
+}
+
+static void
+offtab_write_window(struct offtab *offtab, uint32_t start, uint32_t end)
+{
+
+	assert(offtab-ot_mode == OFFTAB_MODE_WRITE);
+
+	/* Don't 

CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:16:05 UTC 2014

Modified Files:
src/usr.bin/vndcompress: offtab.c

Log Message:
Seek if necessary at end of offtab_reset_read.

Fixes vnduncompress with a small window, and makes offtab_reset_read
symmetric with offtab_reset_write.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/vndcompress/offtab.c

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

Modified files:

Index: src/usr.bin/vndcompress/offtab.c
diff -u src/usr.bin/vndcompress/offtab.c:1.3 src/usr.bin/vndcompress/offtab.c:1.4
--- src/usr.bin/vndcompress/offtab.c:1.3	Wed Jan 22 06:15:31 2014
+++ src/usr.bin/vndcompress/offtab.c	Wed Jan 22 06:16:05 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: offtab.c,v 1.3 2014/01/22 06:15:31 riastradh Exp $	*/
+/*	$NetBSD: offtab.c,v 1.4 2014/01/22 06:16:05 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -279,6 +279,19 @@ offtab_reset_read(struct offtab *offtab,
 	if (!offtab_read_window(offtab, 0, OFFTAB_READ_NOSEEK))
 		return false;
 
+	if (offtab-ot_window_size  offtab-ot_n_offsets) {
+		__CTASSERT(MAX_N_OFFSETS = (OFF_MAX / sizeof(uint64_t)));
+		assert(offtab-ot_fdpos = (OFF_MAX -
+			(off_t)(offtab-ot_n_offsets * sizeof(uint64_t;
+		const off_t first_offset = (offtab-ot_fdpos +
+		(offtab-ot_n_offsets * sizeof(uint64_t)));
+		if (lseek(offtab-ot_fd, first_offset, SEEK_SET) == -1) {
+			(*offtab-ot_report)(lseek to first offset 0x%PRIx64,
+			first_offset);
+			return false;
+		}
+	}
+
 	return true;
 }
 



CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:15:31 UTC 2014

Modified Files:
src/usr.bin/vndcompress: offtab.c utils.c

Log Message:
Judicious (and justified) casts to avoid signed/unsigned comparisons.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/vndcompress/offtab.c
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/vndcompress/utils.c

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

Modified files:

Index: src/usr.bin/vndcompress/offtab.c
diff -u src/usr.bin/vndcompress/offtab.c:1.2 src/usr.bin/vndcompress/offtab.c:1.3
--- src/usr.bin/vndcompress/offtab.c:1.2	Wed Jan 22 06:15:22 2014
+++ src/usr.bin/vndcompress/offtab.c	Wed Jan 22 06:15:31 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: offtab.c,v 1.2 2014/01/22 06:15:22 riastradh Exp $	*/
+/*	$NetBSD: offtab.c,v 1.3 2014/01/22 06:15:31 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -110,7 +110,7 @@ offtab_read_window(struct offtab *offtab
 	__CTASSERT(MAX_N_OFFSETS = (OFF_MAX / sizeof(uint64_t)));
 	assert(window_start  offtab-ot_n_offsets);
 	assert(offtab-ot_fdpos =
-	(OFF_MAX - (window_start * sizeof(uint64_t;
+	(OFF_MAX - (off_t)(window_start * sizeof(uint64_t;
 	assert(ISSET(read_flags, OFFTAB_READ_SEEK) ||
 	(lseek(offtab-ot_fd, 0, SEEK_CUR) == offtab-ot_fdpos) ||
 	((lseek(offtab-ot_fd, 0, SEEK_CUR) == -1)  (errno == ESPIPE)));
@@ -172,7 +172,7 @@ offtab_write_window(struct offtab *offta
 	__CTASSERT(MAX_N_OFFSETS = (OFF_MAX / sizeof(uint64_t)));
 	assert(offtab-ot_window_start  offtab-ot_n_offsets);
 	assert(offtab-ot_fdpos =
-	(OFF_MAX - (offtab-ot_window_start * sizeof(uint64_t;
+	(OFF_MAX - (off_t)(offtab-ot_window_start * sizeof(uint64_t;
 	const ssize_t n_written = pwrite(offtab-ot_fd, offtab-ot_window,
 	(window_size * sizeof(uint64_t)),
 	(offtab-ot_fdpos +
@@ -358,10 +358,10 @@ offtab_reset_write(struct offtab *offtab
 	offtab-ot_window_start = 0;
 	__CTASSERT(MAX_N_OFFSETS = (OFF_MAX / sizeof(uint64_t)));
 	assert(offtab-ot_fdpos =
-	(OFF_MAX - (offtab-ot_n_offsets * sizeof(uint64_t;
-	const off_t first_offset = (offtab-ot_fdpos +
+	(OFF_MAX - (off_t)(offtab-ot_n_offsets * sizeof(uint64_t;
+	const uint64_t first_offset = (offtab-ot_fdpos +
 	(offtab-ot_n_offsets * sizeof(uint64_t)));
-	assert(first_offset = UINT64_MAX);
+	assert(first_offset = OFF_MAX);
 	offtab-ot_window[0] = htobe64(first_offset);
 	offtab_write_window(offtab, 0, offtab-ot_n_offsets);
 
@@ -404,7 +404,7 @@ offtab_checkpoint(struct offtab *offtab,
 	if (ISSET(flags, OFFTAB_CHECKPOINT_SYNC)) {
 		__CTASSERT(MAX_N_OFFSETS = (OFF_MAX / sizeof(uint64_t)));
 		assert(offtab-ot_fdpos
-		= (OFF_MAX - (n_offsets * sizeof(uint64_t;
+		= (OFF_MAX - (off_t)(n_offsets * sizeof(uint64_t;
 		if (fsync_range(offtab-ot_fd, (FFILESYNC | FDISKSYNC),
 			offtab-ot_fdpos,
 			(offtab-ot_fdpos + (n_offsets * sizeof(uint64_t

Index: src/usr.bin/vndcompress/utils.c
diff -u src/usr.bin/vndcompress/utils.c:1.3 src/usr.bin/vndcompress/utils.c:1.4
--- src/usr.bin/vndcompress/utils.c:1.3	Wed Jan 22 06:15:22 2014
+++ src/usr.bin/vndcompress/utils.c	Wed Jan 22 06:15:31 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: utils.c,v 1.3 2014/01/22 06:15:22 riastradh Exp $	*/
+/*	$NetBSD: utils.c,v 1.4 2014/01/22 06:15:31 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: utils.c,v 1.3 2014/01/22 06:15:22 riastradh Exp $);
+__RCSID($NetBSD: utils.c,v 1.4 2014/01/22 06:15:31 riastradh Exp $);
 
 #include sys/types.h
 
@@ -96,7 +96,8 @@ pread_block(int fd, void *buffer, size_t
 	char *p = buffer, *const end __unused = (p + n);
 	size_t total_read = 0;
 
-	assert(n = (OFF_MAX - fdpos));
+	assert(0 = fdpos);
+	assert(n = (OFF_MAX - (uintmax_t)fdpos));
 
 	while (n  0) {
 		assert(total_read = n);



CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:15:40 UTC 2014

Modified Files:
src/usr.bin/vndcompress: Makefile

Log Message:
Add WARNS=5.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/vndcompress/Makefile

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

Modified files:

Index: src/usr.bin/vndcompress/Makefile
diff -u src/usr.bin/vndcompress/Makefile:1.7 src/usr.bin/vndcompress/Makefile:1.8
--- src/usr.bin/vndcompress/Makefile:1.7	Wed Jan 22 06:14:55 2014
+++ src/usr.bin/vndcompress/Makefile	Wed Jan 22 06:15:39 2014
@@ -7,6 +7,8 @@ MLINKS=	vndcompress.1 vnduncompress.1
 DPADD+=	${LIBZ}
 LDADD+=	-lz
 
+WARNS=	5
+
 .include bsd.prog.mk
 
 TESTFILES+=	oneblock



CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:16:23 UTC 2014

Modified Files:
src/usr.bin/vndcompress: Makefile

Log Message:
Add comment explaining why piperestart.cl2part is allowed to fail.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/vndcompress/Makefile

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

Modified files:

Index: src/usr.bin/vndcompress/Makefile
diff -u src/usr.bin/vndcompress/Makefile:1.8 src/usr.bin/vndcompress/Makefile:1.9
--- src/usr.bin/vndcompress/Makefile:1.8	Wed Jan 22 06:15:39 2014
+++ src/usr.bin/vndcompress/Makefile	Wed Jan 22 06:16:23 2014
@@ -89,6 +89,9 @@ piperestart.cl2restart: piperestart.cl2p
 	 head -c 70  /usr/share/dict/words \
 	| ./vndcompress -l 655360 -k 1 -rR /dev/stdin ${.TARGET}.tmp \
 	 mv -f ${.TARGET}.tmp ${.TARGET}
+# The following rule uses ; and not  on purpose: vndcompress is
+# supposed to fail (and it is even OK to interrupt!) so we can restart
+# and fill in the rest.
 piperestart.cl2part: vndcompress
 	head -c 60  /usr/share/dict/words \
 	| ./vndcompress -l 655360 -k 1 /dev/stdin ${.TARGET}.tmp; \



CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:16:32 UTC 2014

Modified Files:
src/usr.bin/vndcompress: vndcompress.c

Log Message:
Window size is now an option; remove XXX comment to the contrary.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/vndcompress/vndcompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/vndcompress.c
diff -u src/usr.bin/vndcompress/vndcompress.c:1.19 src/usr.bin/vndcompress/vndcompress.c:1.20
--- src/usr.bin/vndcompress/vndcompress.c:1.19	Wed Jan 22 06:15:57 2014
+++ src/usr.bin/vndcompress/vndcompress.c	Wed Jan 22 06:16:32 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: vndcompress.c,v 1.19 2014/01/22 06:15:57 riastradh Exp $	*/
+/*	$NetBSD: vndcompress.c,v 1.20 2014/01/22 06:16:32 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: vndcompress.c,v 1.19 2014/01/22 06:15:57 riastradh Exp $);
+__RCSID($NetBSD: vndcompress.c,v 1.20 2014/01/22 06:16:32 riastradh Exp $);
 
 #include sys/endian.h
 
@@ -478,7 +478,6 @@ compress_init(int argc, char **argv, con
 	S-n_offsets = (S-n_blocks + 1);
 	__CTASSERT(MAX_N_OFFSETS == (MAX_N_BLOCKS + 1));
 	__CTASSERT(MAX_N_OFFSETS = (SIZE_MAX / sizeof(uint64_t)));
-	/* XXX Make the window size an option.  */
 	offtab_init(S-offtab, S-n_offsets, O-window_size, S-cloop2_fd,
 	CLOOP2_OFFSET_TABLE_OFFSET);
 



CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:16:14 UTC 2014

Modified Files:
src/usr.bin/vndcompress: offtab.c

Log Message:
Split guard in offtab_write_window into offtab_maybe_write_window.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/vndcompress/offtab.c

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

Modified files:

Index: src/usr.bin/vndcompress/offtab.c
diff -u src/usr.bin/vndcompress/offtab.c:1.4 src/usr.bin/vndcompress/offtab.c:1.5
--- src/usr.bin/vndcompress/offtab.c:1.4	Wed Jan 22 06:16:05 2014
+++ src/usr.bin/vndcompress/offtab.c	Wed Jan 22 06:16:14 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: offtab.c,v 1.4 2014/01/22 06:16:05 riastradh Exp $	*/
+/*	$NetBSD: offtab.c,v 1.5 2014/01/22 06:16:14 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -156,17 +156,11 @@ offtab_maybe_read_window(struct offtab *
 }
 
 static void
-offtab_write_window(struct offtab *offtab, uint32_t start, uint32_t end)
+offtab_write_window(struct offtab *offtab)
 {
 
 	assert(offtab-ot_mode == OFFTAB_MODE_WRITE);
 
-	/* Don't bother if [start, end) does not cover our window.  */
-	if (end = offtab-ot_window_start)
-		return;
-	if (offtab_current_window_end(offtab)  start)
-		return;
-
 	const uint32_t window_size = offtab_current_window_size(offtab);
 	__CTASSERT(MAX_WINDOW_SIZE = (SIZE_MAX / sizeof(uint64_t)));
 	__CTASSERT(MAX_N_OFFSETS = (OFF_MAX / sizeof(uint64_t)));
@@ -185,6 +179,19 @@ offtab_write_window(struct offtab *offta
 		(size_t)n_written,
 		(size_t)(window_size * sizeof(uint64_t)));
 }
+
+static void
+offtab_maybe_write_window(struct offtab *offtab, uint32_t start, uint32_t end)
+{
+
+	/* Don't bother if [start, end) does not cover our window.  */
+	if (end = offtab-ot_window_start)
+		return;
+	if (offtab_current_window_end(offtab)  start)
+		return;
+
+	offtab_write_window(offtab);
+}
 
 /*
  * Initialize an offtab to support the specified number of offsets read
@@ -365,7 +372,7 @@ offtab_reset_write(struct offtab *offtab
 	for (i = 1; i  n_windows; i++) {
 		/* Change the start but reuse the all-ones buffer.  */
 		offtab-ot_window_start = (i * offtab-ot_window_size);
-		offtab_write_window(offtab, 0, offtab-ot_n_offsets);
+		offtab_write_window(offtab);
 	}
 
 	offtab-ot_window_start = 0;
@@ -376,7 +383,7 @@ offtab_reset_write(struct offtab *offtab
 	(offtab-ot_n_offsets * sizeof(uint64_t)));
 	assert(first_offset = OFF_MAX);
 	offtab-ot_window[0] = htobe64(first_offset);
-	offtab_write_window(offtab, 0, offtab-ot_n_offsets);
+	offtab_write_window(offtab);
 
 	/*
 	 * We could adapt offtab_write_window to use pwrite instead of
@@ -412,7 +419,7 @@ offtab_checkpoint(struct offtab *offtab,
 	 * interrupted before we could move the window.
 	 */
 	if (offtab-ot_window != NULL)
-		offtab_write_window(offtab, 0, n_offsets);
+		offtab_maybe_write_window(offtab, 0, n_offsets);
 
 	if (ISSET(flags, OFFTAB_CHECKPOINT_SYNC)) {
 		__CTASSERT(MAX_N_OFFSETS = (OFF_MAX / sizeof(uint64_t)));
@@ -452,7 +459,7 @@ offtab_prepare_put(struct offtab *offtab
 		goto win;
 
 	/* Otherwise, write out the current window and choose a new one.  */
-	offtab_write_window(offtab, 0, offtab-ot_n_offsets);
+	offtab_write_window(offtab);
 
 	assert(offtab-ot_window_size = blkno);
 	assert(offtab-ot_window_start == (blkno - offtab-ot_window_size));



CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:16:41 UTC 2014

Modified Files:
src/usr.bin/vndcompress: offtab.c

Log Message:
Remove silly comment in offtab_reset_write.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/vndcompress/offtab.c

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

Modified files:

Index: src/usr.bin/vndcompress/offtab.c
diff -u src/usr.bin/vndcompress/offtab.c:1.5 src/usr.bin/vndcompress/offtab.c:1.6
--- src/usr.bin/vndcompress/offtab.c:1.5	Wed Jan 22 06:16:14 2014
+++ src/usr.bin/vndcompress/offtab.c	Wed Jan 22 06:16:41 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: offtab.c,v 1.5 2014/01/22 06:16:14 riastradh Exp $	*/
+/*	$NetBSD: offtab.c,v 1.6 2014/01/22 06:16:41 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -385,12 +385,6 @@ offtab_reset_write(struct offtab *offtab
 	offtab-ot_window[0] = htobe64(first_offset);
 	offtab_write_window(offtab);
 
-	/*
-	 * We could adapt offtab_write_window to use pwrite instead of
-	 * write in order to avoid this lseek, but we require lseek on
-	 * the output anyway, and this avoids conditionalization of
-	 * offtab_write_window.
-	 */
 	if (lseek(offtab-ot_fd, first_offset, SEEK_SET) == -1)
 		err(1, lseek to first offset failed);
 }



CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:17:07 UTC 2014

Modified Files:
src/usr.bin/vndcompress: offtab.c

Log Message:
Fix typo in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/vndcompress/offtab.c

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

Modified files:

Index: src/usr.bin/vndcompress/offtab.c
diff -u src/usr.bin/vndcompress/offtab.c:1.6 src/usr.bin/vndcompress/offtab.c:1.7
--- src/usr.bin/vndcompress/offtab.c:1.6	Wed Jan 22 06:16:41 2014
+++ src/usr.bin/vndcompress/offtab.c	Wed Jan 22 06:17:07 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: offtab.c,v 1.6 2014/01/22 06:16:41 riastradh Exp $	*/
+/*	$NetBSD: offtab.c,v 1.7 2014/01/22 06:17:07 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -466,7 +466,7 @@ offtab_prepare_put(struct offtab *offtab
 
 	/*
 	 * Mark the window as being updated so nobody tries to write it
-	 * (since we just write it) while we fill it with ones.
+	 * (since we just wrote it) while we fill it with ones.
 	 */
 	block_signals(sigmask);
 	window = offtab-ot_window;



CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:17:16 UTC 2014

Modified Files:
src/usr.bin/vndcompress: offtab.c

Log Message:
Simplify vndcompress offtab_compute_window_size.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/vndcompress/offtab.c

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

Modified files:

Index: src/usr.bin/vndcompress/offtab.c
diff -u src/usr.bin/vndcompress/offtab.c:1.7 src/usr.bin/vndcompress/offtab.c:1.8
--- src/usr.bin/vndcompress/offtab.c:1.7	Wed Jan 22 06:17:07 2014
+++ src/usr.bin/vndcompress/offtab.c	Wed Jan 22 06:17:16 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: offtab.c,v 1.7 2014/01/22 06:17:07 riastradh Exp $	*/
+/*	$NetBSD: offtab.c,v 1.8 2014/01/22 06:17:16 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -64,23 +64,18 @@ offtab_bugx(const char *fmt, ...)
 }
 
 static uint32_t
-offtab_compute_window_size(struct offtab *offtab, uint32_t start,
-uint32_t end)
+offtab_compute_window_size(struct offtab *offtab, uint32_t start)
 {
 
-	if (end == 0)
-		end = offtab-ot_n_offsets;
-
-	assert(end = offtab-ot_n_offsets);
-	assert(start  end);
-	return MIN(offtab-ot_window_size, (end - start));
+	assert(start  offtab-ot_n_offsets);
+	return MIN(offtab-ot_window_size, (offtab-ot_n_offsets - start));
 }
 
 static uint32_t
 offtab_current_window_size(struct offtab *offtab)
 {
 
-	return offtab_compute_window_size(offtab, offtab-ot_window_start, 0);
+	return offtab_compute_window_size(offtab, offtab-ot_window_start);
 }
 
 static uint32_t
@@ -104,7 +99,7 @@ offtab_read_window(struct offtab *offtab
 
 	const uint32_t window_start = rounddown(blkno, offtab-ot_window_size);
 	const uint32_t window_size = offtab_compute_window_size(offtab,
-	window_start, 0);
+	window_start);
 
 	__CTASSERT(MAX_WINDOW_SIZE = (SIZE_MAX / sizeof(uint64_t)));
 	__CTASSERT(MAX_N_OFFSETS = (OFF_MAX / sizeof(uint64_t)));



CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:16:59 UTC 2014

Modified Files:
src/usr.bin/vndcompress: Makefile

Log Message:
Fix up ulimited vndcompress tests and explain what's up with them.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/vndcompress/Makefile

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

Modified files:

Index: src/usr.bin/vndcompress/Makefile
diff -u src/usr.bin/vndcompress/Makefile:1.10 src/usr.bin/vndcompress/Makefile:1.11
--- src/usr.bin/vndcompress/Makefile:1.10	Wed Jan 22 06:16:50 2014
+++ src/usr.bin/vndcompress/Makefile	Wed Jan 22 06:16:59 2014
@@ -134,23 +134,42 @@ check-pipewindow: smallwindow.cl2
 	  echo 'unexpected pass!'  exit 1; \
 	fi
 
-# These checks don't work unless RLIMIT_AS (i.e., ulimit -v) actually
-# works!  Apparently it doesn't...
-
-# CHECKS+=	check-ulimit
-# check-ulimit:
-# 	@echo '# expecting failure...'
-# 	if head -c 1073741824  /dev/zero \
-# 	| (ulimit -v 2  \
-# 	./vndcompress -l 1g -s 512 /dev/stdin /dev/null); then \
-# 	  echo 'unexpected pass!'  exit 0; \
-# 	fi
-
-# CHECKS+=	check-ulimit-window
-# check-ulimit-window:
-# 	head -c 1073741824  /dev/zero \
-# 	| (ulimit -v 2  \
-# 	./vndcompress -w 1 -l 1g -s 512 /dev/stdin /dev/null)
+# The following two tests try to ensure a limited window size means
+# limited memory allocation.  They don't work very well.  The virtual
+# address space rlimit (ulimit -v, RLIMIT_AS) must cover the stack size
+# that is allocated automatically for the process, which varies from
+# machine architecture to machine architecture (the kernel's MAXSSIZ
+# parameter), as well as any shared libraries that get loaded in and
+# other auxiliary crud the loader or libc might allocate.
+#
+# In principle, the overhead from that and the program image should be
+# constant, and the only substantial memory allocation performed by
+# vndcompress should be w*8 bytes or (n/b)*8, where w is the window
+# size if specified, n is the size of the input, and b is the block
+# size.
+#
+# We could perhaps do an exponential growth and then binary search on
+# the virtual address space limit to determine the overhead, but that's
+# more trouble than I care to do in a makefile right now.  Currently
+# this is calibrated for NetBSD/amd64 6, where 128 MB of virtual
+# address space is allocated for the stack.  (Note `ulimit -v' takes a
+# number of kilobytes, not a number of bytes.)  Since this is not
+# reliable, however, these are commented out.
+
+#CHECKS+=	check-ulimit
+#check-ulimit:
+#	@echo '# expecting failure...'
+#	if head -c $$((64 * 1024 * 1024))  /dev/zero \
+#	| (ulimit -v $$((139 * 1024))  \
+#	./vndcompress -l 64m -s 512 /dev/stdin /dev/null); then \
+#	  echo 'unexpected pass!'  exit 1; \
+#	fi
+#
+#CHECKS+=	check-ulimit-window
+#check-ulimit-window:
+#	head -c $$((64 * 1024 * 1024))  /dev/zero \
+#	| (ulimit -v $$((139 * 1024))  \
+#	./vndcompress -w 8192 -l 64m -s 512 /dev/stdin /dev/null)
 
 TESTSUFFIXES+=	in cl2 cl2x out outx
 



CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:16:50 UTC 2014

Modified Files:
src/usr.bin/vndcompress: Makefile

Log Message:
Add some simple automatic tests for window sizes.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/vndcompress/Makefile

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

Modified files:

Index: src/usr.bin/vndcompress/Makefile
diff -u src/usr.bin/vndcompress/Makefile:1.9 src/usr.bin/vndcompress/Makefile:1.10
--- src/usr.bin/vndcompress/Makefile:1.9	Wed Jan 22 06:16:23 2014
+++ src/usr.bin/vndcompress/Makefile	Wed Jan 22 06:16:50 2014
@@ -115,6 +115,43 @@ part.orig:
 	head -c 12345  /usr/share/dict/words  ${.TARGET}.tmp \
 	 mv -f ${.TARGET}.tmp ${.TARGET}
 
+TESTFILES+=	smallwindow
+smallwindow.in:
+	head -c 655360  /usr/share/dict/words  ${.TARGET}.tmp \
+	 mv -f ${.TARGET}.tmp ${.TARGET}
+smallwindow.cl2: smallwindow.in
+	./vndcompress -w 1 ${.IMPSRC} ${.TARGET}.tmp \
+	 mv -f ${.TARGET}.tmp ${.TARGET}
+smallwindow.out: smallwindow.cl2
+	./vndcompress -w 1 -d ${.IMPSRC} ${.TARGET}.tmp \
+	 mv -f ${.TARGET}.tmp ${.TARGET}
+
+CHECKS+=	check-pipewindow
+check-pipewindow: smallwindow.cl2
+	@echo '# expecting failure...'
+	if cat smallwindow.cl2 | ./vndcompress -w 1 -d /dev/stdin /dev/null; \
+	then \
+	  echo 'unexpected pass!'  exit 1; \
+	fi
+
+# These checks don't work unless RLIMIT_AS (i.e., ulimit -v) actually
+# works!  Apparently it doesn't...
+
+# CHECKS+=	check-ulimit
+# check-ulimit:
+# 	@echo '# expecting failure...'
+# 	if head -c 1073741824  /dev/zero \
+# 	| (ulimit -v 2  \
+# 	./vndcompress -l 1g -s 512 /dev/stdin /dev/null); then \
+# 	  echo 'unexpected pass!'  exit 0; \
+# 	fi
+
+# CHECKS+=	check-ulimit-window
+# check-ulimit-window:
+# 	head -c 1073741824  /dev/zero \
+# 	| (ulimit -v 2  \
+# 	./vndcompress -w 1 -l 1g -s 512 /dev/stdin /dev/null)
+
 TESTSUFFIXES+=	in cl2 cl2x out outx
 
 TESTFORMS+=	cl2 cl2x
@@ -149,6 +186,9 @@ check: .PHONY ${CHECKS}
 
 .SUFFIXES: .cl2 .cl2x .in .out .outx
 
+# XXX These tests should automatically try different window sizes, but
+# that is tricky to express in make.
+
 .in.cl2: vndcompress
 	./vndcompress ${.IMPSRC} ${.TARGET}.tmp ${BLOCKSIZE.${.PREFIX}} \
 	 mv -f ${.TARGET}.tmp ${.TARGET}



CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:17:34 UTC 2014

Modified Files:
src/usr.bin/vndcompress: vnduncompress.c

Log Message:
Move err1  errx1 to the end of vnduncompress.c; add __printflike.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/vndcompress/vnduncompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/vnduncompress.c
diff -u src/usr.bin/vndcompress/vnduncompress.c:1.8 src/usr.bin/vndcompress/vnduncompress.c:1.9
--- src/usr.bin/vndcompress/vnduncompress.c:1.8	Wed Jan 22 06:15:57 2014
+++ src/usr.bin/vndcompress/vnduncompress.c	Wed Jan 22 06:17:34 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: vnduncompress.c,v 1.8 2014/01/22 06:15:57 riastradh Exp $	*/
+/*	$NetBSD: vnduncompress.c,v 1.9 2014/01/22 06:17:34 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: vnduncompress.c,v 1.8 2014/01/22 06:15:57 riastradh Exp $);
+__RCSID($NetBSD: vnduncompress.c,v 1.9 2014/01/22 06:17:34 riastradh Exp $);
 
 #include sys/endian.h
 
@@ -50,25 +50,8 @@ __RCSID($NetBSD: vnduncompress.c,v 1.8 
 #include offtab.h
 #include utils.h
 
-static void __dead
-err1(const char *fmt, ...)
-{
-	va_list va;
-
-	va_start(va, fmt);
-	verr(1, fmt, va);
-	va_end(va);
-}
-
-static void __dead
-errx1(const char *fmt, ...)
-{
-	va_list va;
-
-	va_start(va, fmt);
-	verrx(1, fmt, va);
-	va_end(va);
-}
+static void	err1(const char *, ...) __printflike(1,2) __dead;
+static void	errx1(const char *, ...) __printflike(1,2) __dead;
 
 int
 vnduncompress(int argc, char **argv, const struct options *O __unused)
@@ -246,3 +229,23 @@ vnduncompress(int argc, char **argv, con
 
 	return 0;
 }
+
+static void __printflike(1,2) __dead
+err1(const char *fmt, ...)
+{
+	va_list va;
+
+	va_start(va, fmt);
+	verr(1, fmt, va);
+	va_end(va);
+}
+
+static void __printflike(1,2) __dead
+errx1(const char *fmt, ...)
+{
+	va_list va;
+
+	va_start(va, fmt);
+	verrx(1, fmt, va);
+	va_end(va);
+}



CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:17:42 UTC 2014

Modified Files:
src/usr.bin/vndcompress: vndcompress.1

Log Message:
Reflect rename of `-s' to `-b' in the vndcompress man page.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/vndcompress/vndcompress.1

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

Modified files:

Index: src/usr.bin/vndcompress/vndcompress.1
diff -u src/usr.bin/vndcompress/vndcompress.1:1.10 src/usr.bin/vndcompress/vndcompress.1:1.11
--- src/usr.bin/vndcompress/vndcompress.1:1.10	Sat May  4 14:34:13 2013
+++ src/usr.bin/vndcompress/vndcompress.1	Wed Jan 22 06:17:42 2014
@@ -1,4 +1,4 @@
-.\	$NetBSD: vndcompress.1,v 1.10 2013/05/04 14:34:13 riastradh Exp $
+.\	$NetBSD: vndcompress.1,v 1.11 2014/01/22 06:17:42 riastradh Exp $
 .\
 .\ Copyright (c) 2013 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -38,10 +38,10 @@
 .Nm
 .Op Fl c
 .Op Fl rR
+.Op Fl b Ar blocksize
 .Op Fl k Ar checkpoint-blocks
 .Op Fl l Ar length
 .Op Fl p Ar partial-offset
-.Op Fl s Ar blocksize
 .Ar image
 .Ar compressed-image
 .Op Ar blocksize
@@ -71,6 +71,18 @@ options can control whether either utili
 .Pp
 The following options are available for the compression operation:
 .Bl -tag -width indent
+.It Fl b Ar blocksize
+Set the compression block size to
+.Ar blocksize ,
+which must be a multiple of 512 and must be no more than 4294966784, or
+0xfe00.
+(On 32-bit systems, the limit may be smaller, limited by the available
+virtual address space.)
+.Pp
+For compatibility with the old version of
+.Nm ,
+the compression block size may instead be specified at the end of the
+command line.
 .It Fl k Ar checkpoint-blocks
 Write a checkpoint after every
 .Ar checkpoint-blocks
@@ -113,18 +125,6 @@ Restarting may fail for various reasons:
 checkpoints, or if the output file has been corrupted in some easily
 recognizable ways, or if the input file's size has changed, or if the
 block size does not match, and so on.
-.It Fl s Ar blocksize
-Set the compression block size to
-.Ar blocksize ,
-which must be a multiple of 512 and must be no more than 4294966784, or
-0xfe00.
-(On 32-bit systems, the limit may be smaller, limited by the available
-virtual address space.)
-.Pp
-For compatibility with the old version of
-.Nm ,
-the compression block size may instead be specified at the end of the
-command line.
 .El
 .Sh EXIT STATUS
 .Ex -std



CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:17:25 UTC 2014

Modified Files:
src/usr.bin/vndcompress: Makefile common.h main.c vndcompress.c

Log Message:
Rename block size option from `-s' to `-b'.

Makes more sense and makes it consistent with other utilities such as
pax and pigz.  This vndcompress has never gone out in a release, so
changing the name of the option shouldn't cause too many problems...


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/vndcompress/Makefile
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/vndcompress/common.h
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/vndcompress/main.c
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/vndcompress/vndcompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/Makefile
diff -u src/usr.bin/vndcompress/Makefile:1.11 src/usr.bin/vndcompress/Makefile:1.12
--- src/usr.bin/vndcompress/Makefile:1.11	Wed Jan 22 06:16:59 2014
+++ src/usr.bin/vndcompress/Makefile	Wed Jan 22 06:17:25 2014
@@ -106,10 +106,10 @@ check-part: .PHONY part.orig part.out
 	cmp part.orig part.out
 part.cl2: part.orig part.cl2part vndcompress
 	cp part.cl2part ${.TARGET}.tmp \
-	 ./vndcompress -s 512 -rR part.orig ${.TARGET}.tmp \
+	 ./vndcompress -b 512 -rR part.orig ${.TARGET}.tmp \
 	 mv -f ${.TARGET}.tmp ${.TARGET}
 part.cl2part: part.orig vndcompress
-	./vndcompress -s 512 -p 10 part.orig ${.TARGET}.tmp \
+	./vndcompress -b 512 -p 10 part.orig ${.TARGET}.tmp \
 	 mv -f ${.TARGET}.tmp ${.TARGET}
 part.orig:
 	head -c 12345  /usr/share/dict/words  ${.TARGET}.tmp \
@@ -161,7 +161,7 @@ check-pipewindow: smallwindow.cl2
 #	@echo '# expecting failure...'
 #	if head -c $$((64 * 1024 * 1024))  /dev/zero \
 #	| (ulimit -v $$((139 * 1024))  \
-#	./vndcompress -l 64m -s 512 /dev/stdin /dev/null); then \
+#	./vndcompress -l 64m -b 512 /dev/stdin /dev/null); then \
 #	  echo 'unexpected pass!'  exit 1; \
 #	fi
 #
@@ -169,7 +169,7 @@ check-pipewindow: smallwindow.cl2
 #check-ulimit-window:
 #	head -c $$((64 * 1024 * 1024))  /dev/zero \
 #	| (ulimit -v $$((139 * 1024))  \
-#	./vndcompress -w 8192 -l 64m -s 512 /dev/stdin /dev/null)
+#	./vndcompress -w 8192 -l 64m -b 512 /dev/stdin /dev/null)
 
 TESTSUFFIXES+=	in cl2 cl2x out outx
 

Index: src/usr.bin/vndcompress/common.h
diff -u src/usr.bin/vndcompress/common.h:1.4 src/usr.bin/vndcompress/common.h:1.5
--- src/usr.bin/vndcompress/common.h:1.4	Wed Jan 22 06:15:57 2014
+++ src/usr.bin/vndcompress/common.h	Wed Jan 22 06:17:25 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: common.h,v 1.4 2014/01/22 06:15:57 riastradh Exp $	*/
+/*	$NetBSD: common.h,v 1.5 2014/01/22 06:17:25 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -125,7 +125,7 @@ struct options {
 #define	FLAG_d	0x0002	/* Decompress */
 #define	FLAG_p	0x0004	/* Partial */
 #define	FLAG_r	0x0008	/* Restart */
-#define	FLAG_s	0x0010	/* block Size */
+#define	FLAG_b	0x0010	/* Block size */
 #define	FLAG_R	0x0020	/* abort on Restart failure */
 #define	FLAG_k	0x0040	/* checKpoint blocks */
 #define	FLAG_l	0x0080	/* Length of input */

Index: src/usr.bin/vndcompress/main.c
diff -u src/usr.bin/vndcompress/main.c:1.2 src/usr.bin/vndcompress/main.c:1.3
--- src/usr.bin/vndcompress/main.c:1.2	Wed Jan 22 06:15:57 2014
+++ src/usr.bin/vndcompress/main.c	Wed Jan 22 06:17:25 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.2 2014/01/22 06:15:57 riastradh Exp $	*/
+/*	$NetBSD: main.c,v 1.3 2014/01/22 06:17:25 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: main.c,v 1.2 2014/01/22 06:15:57 riastradh Exp $);
+__RCSID($NetBSD: main.c,v 1.3 2014/01/22 06:17:25 riastradh Exp $);
 
 #include assert.h
 #include err.h
@@ -60,8 +60,20 @@ main(int argc, char **argv)
 		warnx(unknown program name, defaulting to vndcompress: %s,
 		getprogname());
 
-	while ((ch = getopt(argc, argv, cdk:l:p:rRs:w:)) != -1) {
+	while ((ch = getopt(argc, argv, b:cdk:l:p:rRw:)) != -1) {
 		switch (ch) {
+		case 'b':
+			if (ISSET(O-flags, FLAG_b)) {
+warnx(-b may be supplied only once);
+usage();
+			}
+			O-flags |= FLAG_b;
+			__CTASSERT(MIN_BLOCKSIZE = MAX_BLOCKSIZE);
+			__CTASSERT(MAX_BLOCKSIZE = LLONG_MAX);
+			O-blocksize = strsuftoll(block size, optarg,
+			MIN_BLOCKSIZE, MAX_BLOCKSIZE);
+			break;
+
 		case 'c':
 			if (ISSET(O-flags, FLAG_d)) {
 warnx(-c and -d are mutually exclusive);
@@ -116,18 +128,6 @@ main(int argc, char **argv)
 			O-flags |= FLAG_R;
 			break;
 
-		case 's':
-			if (ISSET(O-flags, FLAG_s)) {
-warnx(-s may be supplied only once);
-usage();
-			}
-			O-flags |= FLAG_s;
-			__CTASSERT(MIN_BLOCKSIZE = MAX_BLOCKSIZE);
-			__CTASSERT(MAX_BLOCKSIZE = LLONG_MAX);
-			O-blocksize = strsuftoll(block size, optarg,
-			MIN_BLOCKSIZE, MAX_BLOCKSIZE);
-			break;
-
 		case 'w':
 			if (ISSET(O-flags, 

CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:17:51 UTC 2014

Modified Files:
src/usr.bin/vndcompress: vndcompress.1

Log Message:
Document the new vndcompress -w option and nuke BUGS section.

Perhaps vndcompress and vnduncompress ought by default to choose a
limited window size (say, 8192 entries, i.e. 64k bytes, the default
MAXPHYS), and vnduncompress should fall back to an unlimited window
only if the input is nonseekable.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/vndcompress/vndcompress.1

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

Modified files:

Index: src/usr.bin/vndcompress/vndcompress.1
diff -u src/usr.bin/vndcompress/vndcompress.1:1.11 src/usr.bin/vndcompress/vndcompress.1:1.12
--- src/usr.bin/vndcompress/vndcompress.1:1.11	Wed Jan 22 06:17:42 2014
+++ src/usr.bin/vndcompress/vndcompress.1	Wed Jan 22 06:17:51 2014
@@ -1,4 +1,4 @@
-.\	$NetBSD: vndcompress.1,v 1.11 2014/01/22 06:17:42 riastradh Exp $
+.\	$NetBSD: vndcompress.1,v 1.12 2014/01/22 06:17:51 riastradh Exp $
 .\
 .\ Copyright (c) 2013 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -42,11 +42,13 @@
 .Op Fl k Ar checkpoint-blocks
 .Op Fl l Ar length
 .Op Fl p Ar partial-offset
+.Op Fl w Ar winsize
 .Ar image
 .Ar compressed-image
 .Op Ar blocksize
 .Nm vnduncompress
 .Op Fl d
+.Op Fl w Ar winsize
 .Ar compressed-image
 .Ar image
 .Sh DESCRIPTION
@@ -126,6 +128,39 @@ checkpoints, or if the output file has b
 recognizable ways, or if the input file's size has changed, or if the
 block size does not match, and so on.
 .El
+.Pp
+The following option is available for both compression and
+decompression:
+.Bl -tag -width indent
+.It Fl w Ar winsize
+Use an in-memory window of
+.Ar winsize
+entries into the table of compressed block offsets.
+If
+.Fl w
+is not supplied or
+.Ar winsize
+is zero,
+.Nm
+will use memory proportional to the number of blocks in the
+uncompressed image, namely 64 bits or 8 bytes per block.
+If
+.Ar winsize
+is nonzero,
+.Nm
+will use memory proportional to
+.Ar winsize ,
+and independent of the size of the uncompressed image.
+.Pp
+A nonzero
+.Ar winsize
+requires the compressed image to be a seekable file, which compression
+requires anyway, in order to record the offsets of compressed blocks
+once they are compressed and written, but which is a limitation for
+decompression.
+Thus, decompressing from a pipe is incompatible with a nonzero
+.Ar winsize .
+.El
 .Sh EXIT STATUS
 .Ex -std
 .Sh EXAMPLES
@@ -215,14 +250,6 @@ The
 .Nm
 command first appeared in
 .Nx 3.0 .
-It was rewritten to be more robust and to support restarting partial
-transfers in
+It was rewritten to be more robust, to support restarting partial
+transfers, and to support bounded memory usage in
 .Nx 7.0 .
-.Sh BUGS
-The amount of memory consumed by
-.Nm
-and
-.Nm vnduncompress
-is proportional to the number of compression blocks they process,
-because they store the whole offset table in memory at once.
-Instead, they should use a limited-size window into the offset table.



CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:18:09 UTC 2014

Modified Files:
src/usr.bin/vndcompress: vndcompress.1

Log Message:
Fix vndcompress man page to reflect default window size.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/vndcompress/vndcompress.1

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

Modified files:

Index: src/usr.bin/vndcompress/vndcompress.1
diff -u src/usr.bin/vndcompress/vndcompress.1:1.12 src/usr.bin/vndcompress/vndcompress.1:1.13
--- src/usr.bin/vndcompress/vndcompress.1:1.12	Wed Jan 22 06:17:51 2014
+++ src/usr.bin/vndcompress/vndcompress.1	Wed Jan 22 06:18:09 2014
@@ -1,4 +1,4 @@
-.\	$NetBSD: vndcompress.1,v 1.12 2014/01/22 06:17:51 riastradh Exp $
+.\	$NetBSD: vndcompress.1,v 1.13 2014/01/22 06:18:09 riastradh Exp $
 .\
 .\ Copyright (c) 2013 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -137,8 +137,6 @@ Use an in-memory window of
 .Ar winsize
 entries into the table of compressed block offsets.
 If
-.Fl w
-is not supplied or
 .Ar winsize
 is zero,
 .Nm
@@ -160,6 +158,10 @@ once they are compressed and written, bu
 decompression.
 Thus, decompressing from a pipe is incompatible with a nonzero
 .Ar winsize .
+.Pp
+By default,
+.Nm
+uses a fixed window size, unless decompressing with nonseekable input.
 .El
 .Sh EXIT STATUS
 .Ex -std



CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:18:01 UTC 2014

Modified Files:
src/usr.bin/vndcompress: Makefile common.h vndcompress.c
vnduncompress.c

Log Message:
Change vndcompress to use a default window size of 512.

For vnduncompress on nonseekable input, the window size is as large
as it needs to be by default, as before.  Not clear that this is the
right choice -- by default vnduncompress on nonseekable input will
just use unbounded memory unsolicited.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/vndcompress/Makefile
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/vndcompress/common.h
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/vndcompress/vndcompress.c
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/vndcompress/vnduncompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/Makefile
diff -u src/usr.bin/vndcompress/Makefile:1.12 src/usr.bin/vndcompress/Makefile:1.13
--- src/usr.bin/vndcompress/Makefile:1.12	Wed Jan 22 06:17:25 2014
+++ src/usr.bin/vndcompress/Makefile	Wed Jan 22 06:18:00 2014
@@ -161,7 +161,7 @@ check-pipewindow: smallwindow.cl2
 #	@echo '# expecting failure...'
 #	if head -c $$((64 * 1024 * 1024))  /dev/zero \
 #	| (ulimit -v $$((139 * 1024))  \
-#	./vndcompress -l 64m -b 512 /dev/stdin /dev/null); then \
+#	./vndcompress -w 0 -l 64m -b 512 /dev/stdin /dev/null); then \
 #	  echo 'unexpected pass!'  exit 1; \
 #	fi
 #

Index: src/usr.bin/vndcompress/common.h
diff -u src/usr.bin/vndcompress/common.h:1.5 src/usr.bin/vndcompress/common.h:1.6
--- src/usr.bin/vndcompress/common.h:1.5	Wed Jan 22 06:17:25 2014
+++ src/usr.bin/vndcompress/common.h	Wed Jan 22 06:18:00 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: common.h,v 1.5 2014/01/22 06:17:25 riastradh Exp $	*/
+/*	$NetBSD: common.h,v 1.6 2014/01/22 06:18:00 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -109,7 +109,16 @@
 #define	MAX_N_BLOCKS			\
 	(MIN(UINT32_MAX, (SIZE_MAX / sizeof(uint64_t))) - 1)
 #define	MAX_N_OFFSETS		(MAX_N_BLOCKS + 1)
+
+/*
+ * The window size is at most the number of offsets, so it has the same
+ * maximum bound.  The default window size is chosen so that windows
+ * fit in one 4096-byte page of memory.  We could use 64k bytes, or
+ * st_blksize, to maximize I/O transfer size, but the transfers won't
+ * be aligned without a lot of extra work.
+ */
 #define	MAX_WINDOW_SIZE		MAX_N_OFFSETS
+#define	DEF_WINDOW_SIZE		512
 
 struct cloop2_header {
 	char		cl2h_magic[128];

Index: src/usr.bin/vndcompress/vndcompress.c
diff -u src/usr.bin/vndcompress/vndcompress.c:1.21 src/usr.bin/vndcompress/vndcompress.c:1.22
--- src/usr.bin/vndcompress/vndcompress.c:1.21	Wed Jan 22 06:17:25 2014
+++ src/usr.bin/vndcompress/vndcompress.c	Wed Jan 22 06:18:00 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: vndcompress.c,v 1.21 2014/01/22 06:17:25 riastradh Exp $	*/
+/*	$NetBSD: vndcompress.c,v 1.22 2014/01/22 06:18:00 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: vndcompress.c,v 1.21 2014/01/22 06:17:25 riastradh Exp $);
+__RCSID($NetBSD: vndcompress.c,v 1.22 2014/01/22 06:18:00 riastradh Exp $);
 
 #include sys/endian.h
 
@@ -473,12 +473,16 @@ compress_init(int argc, char **argv, con
 		S-blocksize, S-size);
 	assert(S-n_blocks = MAX_N_BLOCKS);
 
+	/* Choose a window size.  */
+	const uint32_t window_size = (ISSET(O-flags, FLAG_w)? O-window_size :
+	DEF_WINDOW_SIZE);
+
 	/* Create an offset table for the blocks; one extra for the end.  */
 	__CTASSERT(MAX_N_BLOCKS = (UINT32_MAX - 1));
 	S-n_offsets = (S-n_blocks + 1);
 	__CTASSERT(MAX_N_OFFSETS == (MAX_N_BLOCKS + 1));
 	__CTASSERT(MAX_N_OFFSETS = (SIZE_MAX / sizeof(uint64_t)));
-	offtab_init(S-offtab, S-n_offsets, O-window_size, S-cloop2_fd,
+	offtab_init(S-offtab, S-n_offsets, window_size, S-cloop2_fd,
 	CLOOP2_OFFSET_TABLE_OFFSET);
 
 	/* Attempt to restart a partial transfer if requested.  */

Index: src/usr.bin/vndcompress/vnduncompress.c
diff -u src/usr.bin/vndcompress/vnduncompress.c:1.9 src/usr.bin/vndcompress/vnduncompress.c:1.10
--- src/usr.bin/vndcompress/vnduncompress.c:1.9	Wed Jan 22 06:17:34 2014
+++ src/usr.bin/vndcompress/vnduncompress.c	Wed Jan 22 06:18:00 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: vnduncompress.c,v 1.9 2014/01/22 06:17:34 riastradh Exp $	*/
+/*	$NetBSD: vnduncompress.c,v 1.10 2014/01/22 06:18:00 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: vnduncompress.c,v 1.9 2014/01/22 06:17:34 riastradh Exp $);
+__RCSID($NetBSD: vnduncompress.c,v 1.10 2014/01/22 06:18:00 riastradh Exp $);
 
 #include sys/endian.h
 
@@ -114,18 +114,28 @@ vnduncompress(int argc, char **argv, con
 	__CTASSERT((MAX_N_BLOCKS + 1) == MAX_N_OFFSETS);
 	const uint32_t n_offsets = (n_blocks + 1);
 

CVS commit: src/usr.bin/vndcompress

2014-01-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jan 22 06:18:17 UTC 2014

Modified Files:
src/usr.bin/vndcompress: vndcompress.1

Log Message:
Bump date on vndcompress(1) man page.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/vndcompress/vndcompress.1

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

Modified files:

Index: src/usr.bin/vndcompress/vndcompress.1
diff -u src/usr.bin/vndcompress/vndcompress.1:1.13 src/usr.bin/vndcompress/vndcompress.1:1.14
--- src/usr.bin/vndcompress/vndcompress.1:1.13	Wed Jan 22 06:18:09 2014
+++ src/usr.bin/vndcompress/vndcompress.1	Wed Jan 22 06:18:17 2014
@@ -1,4 +1,4 @@
-.\	$NetBSD: vndcompress.1,v 1.13 2014/01/22 06:18:09 riastradh Exp $
+.\	$NetBSD: vndcompress.1,v 1.14 2014/01/22 06:18:17 riastradh Exp $
 .\
 .\ Copyright (c) 2013 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -27,7 +27,7 @@
 .\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\ POSSIBILITY OF SUCH DAMAGE.
 .\
-.Dd April 27, 2013
+.Dd January 21, 2014
 .Dt VNDCOMPRESS 1
 .Os
 .Sh NAME



CVS commit: src/usr.bin/vndcompress

2013-08-11 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Aug 11 06:33:30 UTC 2013

Modified Files:
src/usr.bin/vndcompress: Makefile

Log Message:
Remove redundant WARNS=5.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/vndcompress/Makefile

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

Modified files:

Index: src/usr.bin/vndcompress/Makefile
diff -u src/usr.bin/vndcompress/Makefile:1.3 src/usr.bin/vndcompress/Makefile:1.4
--- src/usr.bin/vndcompress/Makefile:1.3	Fri May  3 23:28:15 2013
+++ src/usr.bin/vndcompress/Makefile	Sun Aug 11 06:33:30 2013
@@ -7,8 +7,6 @@ MLINKS=	vndcompress.1 vnduncompress.1
 DPADD+=	${LIBZ}
 LDADD+=	-lz
 
-WARNS=	5
-
 .include bsd.prog.mk
 
 TESTFILES+=	oneblock



CVS commit: src/usr.bin/vndcompress

2013-05-06 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May  6 22:53:24 UTC 2013

Modified Files:
src/usr.bin/vndcompress: vndcompress.c vnduncompress.c

Log Message:
Make partial read/write error messages more consistent in vndcompress.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/vndcompress/vndcompress.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/vndcompress/vnduncompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/vndcompress.c
diff -u src/usr.bin/vndcompress/vndcompress.c:1.12 src/usr.bin/vndcompress/vndcompress.c:1.13
--- src/usr.bin/vndcompress/vndcompress.c:1.12	Sat May  4 15:37:39 2013
+++ src/usr.bin/vndcompress/vndcompress.c	Mon May  6 22:53:24 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: vndcompress.c,v 1.12 2013/05/04 15:37:39 riastradh Exp $	*/
+/*	$NetBSD: vndcompress.c,v 1.13 2013/05/06 22:53:24 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: vndcompress.c,v 1.12 2013/05/04 15:37:39 riastradh Exp $);
+__RCSID($NetBSD: vndcompress.c,v 1.13 2013/05/06 22:53:24 riastradh Exp $);
 
 #include sys/endian.h
 
@@ -241,8 +241,8 @@ vndcompress(int argc, char **argv, const
 		assert(n_written = 0);
 		if ((size_t)n_written != n_padding)
 			errx(1, partial write of final padding bytes
-			: %zd = %PRIu32,
-			n_written, n_padding);
+			: %zu != %PRIu32,
+			(size_t)n_written, n_padding);
 
 		/* Account for the extra bytes in the output file.  */
 		assert(n_padding = (MIN(UINT64_MAX, OFF_MAX) - S-offset));
@@ -565,8 +565,8 @@ compress_init(int argc, char **argv, con
 		err(1, write header);
 	assert(h_written = 0);
 	if ((size_t)h_written != sizeof(zero_header))
-		errx(1, partial write of header: %zd = %zu, h_written,
-		sizeof(zero_header));
+		errx(1, partial write of header: %zu != %zu,
+		(size_t)h_written, sizeof(zero_header));
 
 	/* Write the initial (empty) offset table.  */
 	const ssize_t ot_written = write(S-cloop2_fd, S-offset_table,
@@ -575,8 +575,9 @@ compress_init(int argc, char **argv, con
 		err(1, write initial offset table);
 	assert(ot_written = 0);
 	if ((size_t)ot_written != (S-n_offsets * sizeof(uint64_t)))
-		errx(1, partial write of initial offset bytes: %zd = %zu,
-		ot_written, (size_t)(S-n_offsets * sizeof(uint64_t)));
+		errx(1, partial write of initial offset bytes: %zu = %zu,
+		(size_t)ot_written,
+		(size_t)(S-n_offsets * sizeof(uint64_t)));
 
 	/* Start at the beginning of the image.  */
 	S-blkno = 0;
@@ -792,10 +793,9 @@ compress_block(int in_fd, int out_fd, ui
 	if (n_read == -1)
 		err(1, read block %PRIu32, blkno);
 	assert(n_read = 0);
-	assert((uintmax_t)n_read = (uintmax_t)readsize);
-	if ((uint32_t)n_read  readsize)
-		errx(1, partial read of block %PRIu32: %zd = %PRIu32,
-		blkno, n_read, readsize);
+	if ((size_t)n_read != readsize)
+		errx(1, partial read of block %PRIu32: %zu != %PRIu32,
+		blkno, (size_t)n_read, readsize);
 
 	/* Compress the block.  */
 	/* XXX compression ratio bound */
@@ -815,11 +815,11 @@ compress_block(int in_fd, int out_fd, ui
 	if (n_written == -1)
 		err(1, write block %PRIu32, blkno);
 	assert(n_written = 0);
-	if ((uint32_t)n_written != complen)
-		errx(1, partial write of block %PRIu32: %zd = %lu, blkno,
-		n_written, complen);
+	if ((size_t)n_written != complen)
+		errx(1, partial write of block %PRIu32: %zu != %lu,
+		blkno, (size_t)n_written, complen);
 
-	return n_written;
+	return (size_t)n_written;
 }
 
 /*
@@ -882,8 +882,9 @@ compress_checkpoint(struct compress_stat
 		err_ss(1, write partial offset table);
 	assert(n_written = 0);
 	if ((size_t)n_written != (n_offsets * sizeof(uint64_t)))
-		errx_ss(1, partial write of partial offset table: %zd = %zu,
-		n_written, (size_t)(n_offsets * sizeof(uint64_t)));
+		errx_ss(1, partial write of partial offset table: %zu != %zu,
+		(size_t)n_written,
+		(size_t)(n_offsets * sizeof(uint64_t)));
 
 	/*
 	 * If this is the first checkpoint, initialize the header.
@@ -919,8 +920,8 @@ compress_checkpoint(struct compress_stat
 			err_ss(1, write header);
 		assert(h_written = 0);
 		if ((size_t)h_written != sizeof(header))
-			errx_ss(1, partial write of header: %zd = %zu,
-			h_written, sizeof(header));
+			errx_ss(1, partial write of header: %zu != %zu,
+			(size_t)h_written, sizeof(header));
 	}
 
 	/* Record how many blocks we've checkpointed.  */

Index: src/usr.bin/vndcompress/vnduncompress.c
diff -u src/usr.bin/vndcompress/vnduncompress.c:1.1 src/usr.bin/vndcompress/vnduncompress.c:1.2
--- src/usr.bin/vndcompress/vnduncompress.c:1.1	Fri May  3 23:28:15 2013
+++ src/usr.bin/vndcompress/vnduncompress.c	Mon May  6 22:53:24 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: vnduncompress.c,v 1.1 2013/05/03 23:28:15 riastradh Exp $	*/
+/*	$NetBSD: vnduncompress.c,v 1.2 2013/05/06 

CVS commit: src/usr.bin/vndcompress

2013-05-04 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat May  4 07:13:24 UTC 2013

Modified Files:
src/usr.bin/vndcompress: vndcompress.1

Log Message:
Sort. Add EXIT STATUS section.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/vndcompress/vndcompress.1

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

Modified files:

Index: src/usr.bin/vndcompress/vndcompress.1
diff -u src/usr.bin/vndcompress/vndcompress.1:1.8 src/usr.bin/vndcompress/vndcompress.1:1.9
--- src/usr.bin/vndcompress/vndcompress.1:1.8	Fri May  3 23:28:15 2013
+++ src/usr.bin/vndcompress/vndcompress.1	Sat May  4 07:13:23 2013
@@ -1,4 +1,4 @@
-.\	$NetBSD: vndcompress.1,v 1.8 2013/05/03 23:28:15 riastradh Exp $
+.\	$NetBSD: vndcompress.1,v 1.9 2013/05/04 07:13:23 wiz Exp $
 .\
 .\ Copyright (c) 2013 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -38,9 +38,9 @@
 .Nm
 .Op Fl c
 .Op Fl rR
-.Op Fl s Ar blocksize
-.Op Fl p Ar partial-offset
 .Op Fl k Ar checkpoint-blocks
+.Op Fl p Ar partial-offset
+.Op Fl s Ar blocksize
 .Ar image
 .Ar compressed-image
 .Op Ar blocksize
@@ -97,6 +97,11 @@ Stop after writing
 .Ar partial-blocks
 blocks of output.
 This option is mainly useful for automatic testing of restarts.
+.It Fl R
+With the
+.Fl r
+option, if restarting fails, then abort right now and don't touch the
+output file.
 .It Fl r
 Try to restart a partial compression from the last checkpoint.
 If restarting fails, and the
@@ -107,11 +112,6 @@ Restarting may fail for various reasons:
 checkpoints, or if the output file has been corrupted in some easily
 recognizable ways, or if the input file's size has changed, or if the
 block size does not match, and so on.
-.It Fl R
-With the
-.Fl r
-option, if restarting fails, then abort right now and don't touch the
-output file.
 .It Fl s Ar blocksize
 Set the compression block size to
 .Ar blocksize ,
@@ -125,7 +125,7 @@ For compatibility with the old version o
 the compression block size may instead be specified at the end of the
 command line.
 .El
-.Pp
+.Sh EXIT STATUS
 .Ex -std
 .Sh EXAMPLES
 Compress an ISO 9660 CD-ROM image:



CVS commit: src/usr.bin/vndcompress

2013-05-04 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sat May  4 10:21:28 UTC 2013

Modified Files:
src/usr.bin/vndcompress: vndcompress.c

Log Message:
__printflike for vwarnx_ss, __dead for err_ss and errx_ss.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/vndcompress/vndcompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/vndcompress.c
diff -u src/usr.bin/vndcompress/vndcompress.c:1.8 src/usr.bin/vndcompress/vndcompress.c:1.9
--- src/usr.bin/vndcompress/vndcompress.c:1.8	Fri May  3 23:28:15 2013
+++ src/usr.bin/vndcompress/vndcompress.c	Sat May  4 10:21:27 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: vndcompress.c,v 1.8 2013/05/03 23:28:15 riastradh Exp $	*/
+/*	$NetBSD: vndcompress.c,v 1.9 2013/05/04 10:21:27 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: vndcompress.c,v 1.8 2013/05/03 23:28:15 riastradh Exp $);
+__RCSID($NetBSD: vndcompress.c,v 1.9 2013/05/04 10:21:27 joerg Exp $);
 
 #include sys/endian.h
 
@@ -116,11 +116,11 @@ static void	compress_maybe_checkpoint(st
 static void	compress_checkpoint(struct compress_state *);
 static void	compress_exit(struct compress_state *);
 static ssize_t	read_block(int, void *, size_t);
-static void	err_ss(int, const char *);
-static void	errx_ss(int, const char *, ...) __printflike(2, 3);
+static void	err_ss(int, const char *) __dead;
+static void	errx_ss(int, const char *, ...) __printflike(2, 3) __dead;
 static void	warn_ss(const char *);
 static void	warnx_ss(const char *, ...) __printflike(1, 2);
-static void	vwarnx_ss(const char *, va_list);
+static void	vwarnx_ss(const char *, va_list) __printflike(1, 0);
 
 /*
  * Compression entry point.



CVS commit: src/usr.bin/vndcompress

2013-05-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat May  4 14:29:48 UTC 2013

Modified Files:
src/usr.bin/vndcompress: vndcompress.c

Log Message:
Fix sign-compare in compress_blocks.

Not sure why my builds didn't reveal this one -- they revealed
several others during development.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/vndcompress/vndcompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/vndcompress.c
diff -u src/usr.bin/vndcompress/vndcompress.c:1.9 src/usr.bin/vndcompress/vndcompress.c:1.10
--- src/usr.bin/vndcompress/vndcompress.c:1.9	Sat May  4 10:21:27 2013
+++ src/usr.bin/vndcompress/vndcompress.c	Sat May  4 14:29:48 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: vndcompress.c,v 1.9 2013/05/04 10:21:27 joerg Exp $	*/
+/*	$NetBSD: vndcompress.c,v 1.10 2013/05/04 14:29:48 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: vndcompress.c,v 1.9 2013/05/04 10:21:27 joerg Exp $);
+__RCSID($NetBSD: vndcompress.c,v 1.10 2013/05/04 14:29:48 riastradh Exp $);
 
 #include sys/endian.h
 
@@ -792,7 +792,7 @@ compress_block(int in_fd, int out_fd, ui
 		err(1, read block %PRIu32, blkno);
 	assert(n_read = 0);
 	assert((uintmax_t)n_read = (uintmax_t)readsize);
-	if (n_read  readsize)
+	if ((uint32_t)n_read  readsize)
 		errx(1, partial read of block %PRIu32: %zd = %PRIu32,
 		blkno, n_read, readsize);
 



CVS commit: src/usr.bin/vndcompress

2013-05-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat May  4 14:34:13 UTC 2013

Modified Files:
src/usr.bin/vndcompress: vndcompress.1

Log Message:
Add -l option to synopsis for vndcompress(1) man page.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/vndcompress/vndcompress.1

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

Modified files:

Index: src/usr.bin/vndcompress/vndcompress.1
diff -u src/usr.bin/vndcompress/vndcompress.1:1.9 src/usr.bin/vndcompress/vndcompress.1:1.10
--- src/usr.bin/vndcompress/vndcompress.1:1.9	Sat May  4 07:13:23 2013
+++ src/usr.bin/vndcompress/vndcompress.1	Sat May  4 14:34:13 2013
@@ -1,4 +1,4 @@
-.\	$NetBSD: vndcompress.1,v 1.9 2013/05/04 07:13:23 wiz Exp $
+.\	$NetBSD: vndcompress.1,v 1.10 2013/05/04 14:34:13 riastradh Exp $
 .\
 .\ Copyright (c) 2013 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -39,6 +39,7 @@
 .Op Fl c
 .Op Fl rR
 .Op Fl k Ar checkpoint-blocks
+.Op Fl l Ar length
 .Op Fl p Ar partial-offset
 .Op Fl s Ar blocksize
 .Ar image



CVS commit: src/usr.bin/vndcompress

2013-05-04 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Sat May  4 15:27:40 UTC 2013

Modified Files:
src/usr.bin/vndcompress: vndcompress.c

Log Message:
'unsigned long' prints with %lu, not %zu.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/vndcompress/vndcompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/vndcompress.c
diff -u src/usr.bin/vndcompress/vndcompress.c:1.10 src/usr.bin/vndcompress/vndcompress.c:1.11
--- src/usr.bin/vndcompress/vndcompress.c:1.10	Sat May  4 14:29:48 2013
+++ src/usr.bin/vndcompress/vndcompress.c	Sat May  4 15:27:39 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: vndcompress.c,v 1.10 2013/05/04 14:29:48 riastradh Exp $	*/
+/*	$NetBSD: vndcompress.c,v 1.11 2013/05/04 15:27:39 riz Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: vndcompress.c,v 1.10 2013/05/04 14:29:48 riastradh Exp $);
+__RCSID($NetBSD: vndcompress.c,v 1.11 2013/05/04 15:27:39 riz Exp $);
 
 #include sys/endian.h
 
@@ -815,7 +815,7 @@ compress_block(int in_fd, int out_fd, ui
 		err(1, write block %PRIu32, blkno);
 	assert(n_written = 0);
 	if ((uint32_t)n_written != complen)
-		errx(1, partial write of block %PRIu32: %zd = %zu, blkno,
+		errx(1, partial write of block %PRIu32: %zd = %lu, blkno,
 		n_written, complen);
 
 	return n_written;



CVS commit: src/usr.bin/vndcompress

2013-05-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat May  4 15:37:39 UTC 2013

Modified Files:
src/usr.bin/vndcompress: vndcompress.c

Log Message:
Add __printflike to vsnprintf_ss.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/vndcompress/vndcompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/vndcompress.c
diff -u src/usr.bin/vndcompress/vndcompress.c:1.11 src/usr.bin/vndcompress/vndcompress.c:1.12
--- src/usr.bin/vndcompress/vndcompress.c:1.11	Sat May  4 15:27:39 2013
+++ src/usr.bin/vndcompress/vndcompress.c	Sat May  4 15:37:39 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: vndcompress.c,v 1.11 2013/05/04 15:27:39 riz Exp $	*/
+/*	$NetBSD: vndcompress.c,v 1.12 2013/05/04 15:37:39 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: vndcompress.c,v 1.11 2013/05/04 15:27:39 riz Exp $);
+__RCSID($NetBSD: vndcompress.c,v 1.12 2013/05/04 15:37:39 riastradh Exp $);
 
 #include sys/endian.h
 
@@ -52,7 +52,8 @@ __RCSID($NetBSD: vndcompress.c,v 1.11 2
 /* XXX Seems to be missing from stdio.h...  */
 int	snprintf_ss(char *restrict, size_t, const char *restrict, ...)
 	__printflike(3, 4);
-int	vsnprintf_ss(char *restrict, size_t, const char *restrict, va_list);
+int	vsnprintf_ss(char *restrict, size_t, const char *restrict, va_list)
+	__printflike(3, 0);
 
 #include common.h
 



CVS commit: src/usr.bin/vndcompress

2012-07-08 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Jul  8 22:48:32 UTC 2012

Modified Files:
src/usr.bin/vndcompress: vndcompress.1

Log Message:
Improve wording, fix typo, bump date.
From Bug Hunting.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/vndcompress/vndcompress.1

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

Modified files:

Index: src/usr.bin/vndcompress/vndcompress.1
diff -u src/usr.bin/vndcompress/vndcompress.1:1.6 src/usr.bin/vndcompress/vndcompress.1:1.7
--- src/usr.bin/vndcompress/vndcompress.1:1.6	Sat Mar 24 23:16:11 2007
+++ src/usr.bin/vndcompress/vndcompress.1	Sun Jul  8 22:48:32 2012
@@ -1,4 +1,4 @@
-.\	$NetBSD: vndcompress.1,v 1.6 2007/03/24 23:16:11 dillo Exp $
+.\	$NetBSD: vndcompress.1,v 1.7 2012/07/08 22:48:32 wiz Exp $
 .\
 .\ Copyright (c) 2005 Florian Stoehr net...@wolfnode.de
 .\ All rights reserved.
@@ -30,7 +30,7 @@
 .\ SUCH DAMAGE.
 .\
 .\
-.Dd December 12, 2005
+.Dd July 8, 2012
 .Dt VNDCOMPRESS 1
 .Os
 .Sh NAME
@@ -57,7 +57,7 @@ If omitted, the default of 64kB is used.
 .Pp
 The
 .Nm vnduncompress
-command decompress a cloop2-compressed file system image back into a
+command decompress a cloop2 compressed file system image back into a
 regular image.
 .Pp
 The
@@ -141,7 +141,7 @@ was compiled with
 .Dv VND_COMPRESSION ,
 you can use
 .Xr vnconfig 8
-to access the cloop-compressed image directly, e.g.,
+to access the cloop2 compressed image directly, e.g.,
 .Bd -literal -offset indent
 # vnconfig vnd0 KNOPPIX.iso
 # mount -t cd9660 -o ro /dev/vnd0d /mnt



CVS commit: src/usr.bin/vndcompress

2011-09-06 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Sep  6 18:45:04 UTC 2011

Modified Files:
src/usr.bin/vndcompress: vndcompress.c vndcompress.h

Log Message:
Use static and __dead


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/vndcompress/vndcompress.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/vndcompress/vndcompress.h

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

Modified files:

Index: src/usr.bin/vndcompress/vndcompress.c
diff -u src/usr.bin/vndcompress/vndcompress.c:1.6 src/usr.bin/vndcompress/vndcompress.c:1.7
--- src/usr.bin/vndcompress/vndcompress.c:1.6	Tue Apr 14 07:36:16 2009
+++ src/usr.bin/vndcompress/vndcompress.c	Tue Sep  6 18:45:04 2011
@@ -1,4 +1,4 @@
-/* $Id: vndcompress.c,v 1.6 2009/04/14 07:36:16 lukem Exp $ */
+/* $Id: vndcompress.c,v 1.7 2011/09/06 18:45:04 joerg Exp $ */
 
 /*
  * Copyright (c) 2005 by Florian Stoehr net...@wolfnode.de
@@ -60,12 +60,12 @@
  */
 static const char *cloop_sh = #!/bin/sh\n #V2.0 Format\n insmod cloop.o file=$0  mount -r -t iso9660 /dev/cloop $1\n exit $?\n;
 
-int opmode;
+static int opmode;
 
 /*
  * Print usage information, then exit program
  */
-void
+__dead static void
 usage(void)
 {
 	if (opmode == OM_COMPRESS) {
@@ -80,7 +80,7 @@
 /*
  * Compress a given file system
  */
-void
+static void
 vndcompress(const char *fs, const char *comp, uint32_t blocksize)
 {
 	int fd_in, fd_out;
@@ -243,7 +243,7 @@
 /*
  * Read in header and offset table from compressed image
  */
-uint64_t *
+static uint64_t *
 readheader(int fd, struct cloop_header *clh, off_t *dstart)
 {
 	uint32_t offtable_size;
@@ -273,7 +273,7 @@
 /*
  * Decompress a given file system image
  */
-void
+static void
 vnduncompress(const char *comp, const char *fs)
 {
 	int fd_in, fd_out;

Index: src/usr.bin/vndcompress/vndcompress.h
diff -u src/usr.bin/vndcompress/vndcompress.h:1.2 src/usr.bin/vndcompress/vndcompress.h:1.3
--- src/usr.bin/vndcompress/vndcompress.h:1.2	Mon Feb 18 03:34:04 2008
+++ src/usr.bin/vndcompress/vndcompress.h	Tue Sep  6 18:45:04 2011
@@ -1,4 +1,4 @@
-/* $Id: vndcompress.h,v 1.2 2008/02/18 03:34:04 dyoung Exp $ */
+/* $Id: vndcompress.h,v 1.3 2011/09/06 18:45:04 joerg Exp $ */
 
 /*
  * Copyright (c) 2005 by Florian Stoehr
@@ -51,11 +51,6 @@
 
 struct cloop_header;
 
-void usage(void);
-void vndcompress(const char *, const char *, uint32_t);
-uint64_t * readheader(int, struct cloop_header *, off_t *);
-void vnduncompress(const char *, const char *);
-
 /* Size of the shell command (Linux compatibility) */
 #define CLOOP_SH_SIZE 128
 



CVS commit: src/usr.bin/vndcompress

2009-04-14 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Tue Apr 14 07:28:23 UTC 2009

Modified Files:
src/usr.bin/vndcompress: vndcompress.c

Log Message:
fix sign-compare issues


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/vndcompress/vndcompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/vndcompress.c
diff -u src/usr.bin/vndcompress/vndcompress.c:1.4 src/usr.bin/vndcompress/vndcompress.c:1.5
--- src/usr.bin/vndcompress/vndcompress.c:1.4	Mon Feb 18 03:34:04 2008
+++ src/usr.bin/vndcompress/vndcompress.c	Tue Apr 14 07:28:23 2009
@@ -1,4 +1,4 @@
-/* $Id: vndcompress.c,v 1.4 2008/02/18 03:34:04 dyoung Exp $ */
+/* $Id: vndcompress.c,v 1.5 2009/04/14 07:28:23 lukem Exp $ */
 
 /*
  * Copyright (c) 2005 by Florian Stoehr net...@wolfnode.de
@@ -39,6 +39,7 @@
  */
 #include err.h
 #include fcntl.h
+#include inttypes.h
 #include stdarg.h
 #include stdio.h
 #include stdlib.h
@@ -157,8 +158,8 @@
 	 * blocks block-by-block to disk. After that, we overwrite the offset
 	 * table in the image file with the real offset table.
 	 */
-	if (write(fd_out, clh, sizeof(struct cloop_header)) 
-		 sizeof(struct cloop_header))
+	if ((size_t)write(fd_out, clh, sizeof(struct cloop_header)) 
+		!= sizeof(struct cloop_header))
 		err(EXIT_FAILURE, Cannot write to output file \%s\, comp);
 		/* NOTREACHED */
 		
@@ -200,7 +201,7 @@
 			errx(EXIT_FAILURE, Compression failed in block %d, i);
 			/* NOTREACHED */
 
-		if (write(fd_out, cb, complen)  complen)
+		if ((unsigned long)write(fd_out, cb, complen) != complen)
 			err(EXIT_FAILURE, Cannot write to output file \%s\, comp);
 			/* NOTREACHED */
 		
@@ -248,8 +249,8 @@
 	uint32_t offtable_size;
 	uint64_t *offt;
 
-	if (read(fd, clh, sizeof(struct cloop_header)) 
-		 sizeof(struct cloop_header))
+	if ((size_t)read(fd, clh, sizeof(struct cloop_header)) 
+		!= sizeof(struct cloop_header))
 		return NULL;
 		
 	/* Convert endianness */
@@ -276,7 +277,7 @@
 vnduncompress(const char *comp, const char *fs)
 {
 	int fd_in, fd_out;
-	int i;
+	uint32_t i;
 	struct cloop_header clh;
 	uint64_t *offtable;
 	off_t imgofs, datastart;
@@ -321,14 +322,14 @@
 		complen = SWAPPER(*(offtable + i + 1))
 		   - SWAPPER(*(offtable + i));
 		
-		if (read(fd_in, cb, complen)  complen)
-			err(EXIT_FAILURE, Cannot read compressed block %d from \%s\, i, comp);
+		if ((unsigned long)read(fd_in, cb, complen) != complen)
+			err(EXIT_FAILURE, Cannot read compressed block %PRIu32 from \%s\, i, comp);
 			/* NOTREACHED */
 
 		uncomplen = clh.block_size;
 		rc = uncompress(ucb, uncomplen, cb, complen);
 		if (rc != Z_OK)
-			errx(EXIT_FAILURE, Cannot decompress block %d from \%s\ (rc=%d),
+			errx(EXIT_FAILURE, Cannot decompress block %PRIu32 from \%s\ (rc=%d),
 			i, comp, rc);
 			/* NOTREACHED */
 			



CVS commit: src/usr.bin/vndcompress

2009-04-14 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Tue Apr 14 07:36:16 UTC 2009

Modified Files:
src/usr.bin/vndcompress: vndcompress.c

Log Message:
Fix another sign-compare issue


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/vndcompress/vndcompress.c

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

Modified files:

Index: src/usr.bin/vndcompress/vndcompress.c
diff -u src/usr.bin/vndcompress/vndcompress.c:1.5 src/usr.bin/vndcompress/vndcompress.c:1.6
--- src/usr.bin/vndcompress/vndcompress.c:1.5	Tue Apr 14 07:28:23 2009
+++ src/usr.bin/vndcompress/vndcompress.c	Tue Apr 14 07:36:16 2009
@@ -1,4 +1,4 @@
-/* $Id: vndcompress.c,v 1.5 2009/04/14 07:28:23 lukem Exp $ */
+/* $Id: vndcompress.c,v 1.6 2009/04/14 07:36:16 lukem Exp $ */
 
 /*
  * Copyright (c) 2005 by Florian Stoehr net...@wolfnode.de
@@ -260,7 +260,7 @@
 	offtable_size = (clh-num_blocks + 1) * sizeof(uint64_t);
 	offt = (uint64_t *)malloc(offtable_size);
 	
-	if (read(fd, offt, offtable_size)  offtable_size) {
+	if ((uint32_t)read(fd, offt, offtable_size) != offtable_size) {
 		free(offt);
 		return NULL;
 	}