Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/vndcompress Add option -w to vnd(un)compress to spec...



details:   https://anonhg.NetBSD.org/src/rev/57d90810c44a
branches:  trunk
changeset: 326201:57d90810c44a
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Wed Jan 22 06:15:57 2014 +0000

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

diffstat:

 usr.bin/vndcompress/common.h        |   4 +++-
 usr.bin/vndcompress/main.c          |  22 ++++++++++++++++------
 usr.bin/vndcompress/vndcompress.c   |   6 +++---
 usr.bin/vndcompress/vnduncompress.c |  21 +++++++++++++++++----
 4 files changed, 39 insertions(+), 14 deletions(-)

diffs (167 lines):

diff -r a6c8ef99b227 -r 57d90810c44a usr.bin/vndcompress/common.h
--- a/usr.bin/vndcompress/common.h      Wed Jan 22 06:15:48 2014 +0000
+++ b/usr.bin/vndcompress/common.h      Wed Jan 22 06:15:57 2014 +0000
@@ -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 @@
 #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 *);
diff -r a6c8ef99b227 -r 57d90810c44a usr.bin/vndcompress/main.c
--- a/usr.bin/vndcompress/main.c        Wed Jan 22 06:15:48 2014 +0000
+++ b/usr.bin/vndcompress/main.c        Wed Jan 22 06:15:57 2014 +0000
@@ -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 @@
                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 @@
                            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 @@
        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 @@
 
        (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());
diff -r a6c8ef99b227 -r 57d90810c44a usr.bin/vndcompress/vndcompress.c
--- a/usr.bin/vndcompress/vndcompress.c Wed Jan 22 06:15:48 2014 +0000
+++ b/usr.bin/vndcompress/vndcompress.c Wed Jan 22 06:15:57 2014 +0000
@@ -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 @@
        __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.  */
diff -r a6c8ef99b227 -r 57d90810c44a usr.bin/vndcompress/vnduncompress.c
--- a/usr.bin/vndcompress/vnduncompress.c       Wed Jan 22 06:15:48 2014 +0000
+++ b/usr.bin/vndcompress/vnduncompress.c       Wed Jan 22 06:15:57 2014 +0000
@@ -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 @@
                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);
 



Home | Main Index | Thread Index | Old Index