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);
/* Attempt to restart a partial transfer if requested. */
Index: src/usr.bin/vndcompress/vnduncompress.c
diff -u src/usr.bin/vndcompress/vnduncompress.c:1.7 src/usr.bin/vndcompress/vnduncompress.c:1.8
--- src/usr.bin/vndcompress/vnduncompress.c:1.7 Wed Jan 22 06:15:22 2014
+++ src/usr.bin/vndcompress/vnduncompress.c Wed Jan 22 06:15:57 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: vnduncompress.c,v 1.7 2014/01/22 06:15:22 riastradh Exp $ */
+/* $NetBSD: vnduncompress.c,v 1.8 2014/01/22 06:15:57 riastradh Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,12 +30,13 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: vnduncompress.c,v 1.7 2014/01/22 06:15:22 riastradh Exp $");
+__RCSID("$NetBSD: vnduncompress.c,v 1.8 2014/01/22 06:15:57 riastradh Exp $");
#include <sys/endian.h>
#include <assert.h>
#include <err.h>
+#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
@@ -125,11 +126,23 @@ vnduncompress(int argc, char **argv, con
errx(1, "too many blocks: %"PRIu32" (max %"PRIu32")",
n_blocks, (uint32_t)MAX_N_BLOCKS);
- /* Initialize the offset table. */
+ /* Calculate the number of offsets we'll have to handle. */
__CTASSERT(MAX_N_BLOCKS <= (UINT32_MAX - 1));
__CTASSERT((MAX_N_BLOCKS + 1) == MAX_N_OFFSETS);
const uint32_t n_offsets = (n_blocks + 1);
- offtab_init(&offtab, n_offsets, n_offsets, cloop2_fd,
+
+ /* Make sure we can handle it with the requested window size. */
+ if ((O->window_size != 0) && (O->window_size < n_offsets)) {
+ if (lseek(cloop2_fd, 0, SEEK_CUR) == -1) {
+ if (errno == ESPIPE)
+ errx(1, "window too small, nonseekable input");
+ else
+ err(1, "window too small and lseek failed");
+ }
+ }
+
+ /* Initialize the offset table and start reading it in. */
+ offtab_init(&offtab, n_offsets, O->window_size, cloop2_fd,
CLOOP2_OFFSET_TABLE_OFFSET);
offtab_reset_read(&offtab, &err1, &errx1);