Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/vndcompress Rewrite vndcompress to support SIGINFO a...



details:   https://anonhg.NetBSD.org/src/rev/5ba924925389
branches:  trunk
changeset: 786626:5ba924925389
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Fri May 03 23:28:15 2013 +0000

description:
Rewrite vndcompress to support SIGINFO and restart after interrupt.

Make it generally more robust in the process.

No objection (or comment) on tech-userlevel.

ok christos

diffstat:

 usr.bin/vndcompress/Makefile        |   159 ++++-
 usr.bin/vndcompress/common.h        |   148 +++
 usr.bin/vndcompress/main.c          |   168 ++++
 usr.bin/vndcompress/vndcompress.1   |   363 +++++----
 usr.bin/vndcompress/vndcompress.c   |  1298 ++++++++++++++++++++++++++--------
 usr.bin/vndcompress/vndcompress.h   |    83 --
 usr.bin/vndcompress/vnduncompress.c |   212 +++++
 7 files changed, 1840 insertions(+), 591 deletions(-)

diffs (truncated from 2571 to 300 lines):

diff -r 5852439d3254 -r 5ba924925389 usr.bin/vndcompress/Makefile
--- a/usr.bin/vndcompress/Makefile      Fri May 03 21:33:06 2013 +0000
+++ b/usr.bin/vndcompress/Makefile      Fri May 03 23:28:15 2013 +0000
@@ -1,8 +1,159 @@
-# $Id: Makefile,v 1.2 2009/04/14 22:15:28 lukem Exp $
+PROG=  vndcompress
+SRCS=  main.c vndcompress.c vnduncompress.c
 
-PROG=  vndcompress
-LINKS=   ${BINDIR}/vndcompress ${BINDIR}/vnduncompress
-MLINKS=  vndcompress.1 vnduncompress.1
+LINKS= ${BINDIR}/vndcompress ${BINDIR}/vnduncompress
+MLINKS=        vndcompress.1 vnduncompress.1
+
+DPADD+=        ${LIBZ}
 LDADD+=        -lz
 
+WARNS= 5
+
 .include <bsd.prog.mk>
+
+TESTFILES+=    oneblock
+XFAIL+=                oneblock.in-outx
+XFAIL+=                oneblock.cl2-cl2x
+oneblock.in:
+       head -c 512 < /usr/share/dict/words > ${.TARGET}.tmp \
+       && mv -f ${.TARGET}.tmp ${.TARGET}
+
+TESTFILES+=    tenblock
+XFAIL+=                tenblock.in-outx
+XFAIL+=                tenblock.cl2-cl2x
+tenblock.in:
+       head -c 5120 < /usr/share/dict/words > ${.TARGET}.tmp \
+       && mv -f ${.TARGET}.tmp ${.TARGET}
+
+TESTFILES+=    smallfile
+XFAIL+=                smallfile.in-outx
+XFAIL+=                smallfile.cl2-cl2x
+smallfile.in:
+       head -c 12345 < /usr/share/dict/words > ${.TARGET}.tmp \
+       && mv -f ${.TARGET}.tmp ${.TARGET}
+
+CHECKS+=       check-pipe
+CLEANFILES+=   smallfile.cl2pipe
+check-pipe: .PHONY smallfile.cl2 smallfile.cl2pipe
+       cmp ${.ALLSRC}
+smallfile.cl2pipe: smallfile.in vndcompress
+       head -c 54321 < /usr/share/dict/words \
+       | ./vndcompress -l 12345 /dev/stdin ${.TARGET}.tmp \
+       && mv -f ${.TARGET}.tmp ${.TARGET}
+
+TESTFILES+=    onechunk
+onechunk.in:
+       head -c 65536 < /usr/share/dict/words > ${.TARGET}.tmp \
+       && mv -f ${.TARGET}.tmp ${.TARGET}
+
+TESTFILES+=    tenchunk
+tenchunk.in:
+       head -c 655360 < /usr/share/dict/words > ${.TARGET}.tmp \
+       && mv -f ${.TARGET}.tmp ${.TARGET}
+
+TESTFILES+=    extrablock
+XFAIL+=                extrablock.in-outx
+XFAIL+=                extrablock.cl2-cl2x
+extrablock.in:
+       head -c $$((65536 + 512)) < /usr/share/dict/words > ${.TARGET}.tmp \
+       && mv -f ${.TARGET}.tmp ${.TARGET}
+
+TESTFILES+=    medfile
+XFAIL+=                medfile.in-outx
+XFAIL+=                medfile.cl2-cl2x
+medfile.in:
+       head -c 123456 < /usr/share/dict/words > ${.TARGET}.tmp \
+       && mv -f ${.TARGET}.tmp ${.TARGET}
+
+TESTFILES+=            onetinyblock
+BLOCKSIZE.onetinyblock=        512
+onetinyblock.in:
+       head -c 512 < /usr/share/dict/words > ${.TARGET}.tmp \
+       && mv -f ${.TARGET}.tmp ${.TARGET}
+
+TESTFILES+=            tentinyblock
+BLOCKSIZE.tentinyblock=        512
+tentinyblock.in:
+       head -c 5120 < /usr/share/dict/words > ${.TARGET}.tmp \
+       && mv -f ${.TARGET}.tmp ${.TARGET}
+
+CHECKS+=       check-pipe-restart
+CLEANFILES+=   piperestart.in piperestart.in.tmp
+CLEANFILES+=   piperestart.cl2 piperestart.cl2.tmp
+CLEANFILES+=   piperestart.cl2restart piperestart.cl2restart.tmp
+CLEANFILES+=   piperestart.cl2part piperestart.cl2part.tmp
+check-pipe-restart: .PHONY piperestart.cl2 piperestart.cl2restart
+       cmp ${.ALLSRC}
+piperestart.cl2restart: piperestart.cl2part vndcompress
+       cp piperestart.cl2part ${.TARGET}.tmp \
+       && head -c 700000 < /usr/share/dict/words \
+       | ./vndcompress -l 655360 -k 1 -rR /dev/stdin ${.TARGET}.tmp \
+       && mv -f ${.TARGET}.tmp ${.TARGET}
+piperestart.cl2part: vndcompress
+       head -c 600000 < /usr/share/dict/words \
+       | ./vndcompress -l 655360 -k 1 /dev/stdin ${.TARGET}.tmp; \
+       mv -f ${.TARGET}.tmp ${.TARGET}
+piperestart.in:
+       head -c 655360 < /usr/share/dict/words > ${.TARGET}.tmp \
+       && mv -f ${.TARGET}.tmp ${.TARGET}
+
+CHECKS+=       check-part
+CLEANFILES+=   part.orig part.cl2part part.cl2 part.out
+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 \
+       && mv -f ${.TARGET}.tmp ${.TARGET}
+part.cl2part: part.orig vndcompress
+       ./vndcompress -s 512 -p 10 part.orig ${.TARGET}.tmp \
+       && mv -f ${.TARGET}.tmp ${.TARGET}
+part.orig:
+       head -c 12345 < /usr/share/dict/words > ${.TARGET}.tmp \
+       && mv -f ${.TARGET}.tmp ${.TARGET}
+
+TESTSUFFIXES+= in cl2 cl2x out outx
+
+TESTFORMS+=    cl2 cl2x
+TESTFORMS+=    in out
+TESTFORMS+=    in outx
+
+.for testfile in ${TESTFILES}
+.  for suffix in ${TESTSUFFIXES}
+CLEANFILES+=   ${testfile}.${suffix}
+CLEANFILES+=   ${testfile}.${suffix}.tmp
+.  endfor
+.  for left right in ${TESTFORMS}
+CHECKS.${testfile}+=   check-${testfile}.${left}-${right}
+check-${testfile}.${left}-${right}: .PHONY \
+  ${testfile}.${left} ${testfile}.${right}
+.    if empty(XFAIL:M${testfile}.${left}-${right})
+       cmp ${testfile}.${left} ${testfile}.${right}
+.    else
+       @echo '# expecting failure...' \
+       && echo 'cmp ${testfile}.${left} ${testfile}.${right}' \
+       && if cmp ${testfile}.${left} ${testfile}.${right}; then \
+         echo 'unexpected pass!' \
+         && exit 1; \
+       fi
+.    endif
+.  endfor
+check-${testfile}: ${CHECKS.${testfile}}
+CHECKS+=       check-${testfile}
+.endfor
+
+check: .PHONY ${CHECKS}
+
+.SUFFIXES: .cl2 .cl2x .in .out .outx
+
+.in.cl2: vndcompress
+       ./vndcompress ${.IMPSRC} ${.TARGET} ${BLOCKSIZE.${.PREFIX}}
+
+.in.cl2x:
+       vndcompress ${.IMPSRC} ${.TARGET} ${BLOCKSIZE.${.PREFIX}}
+
+.cl2.out: vndcompress
+       ./vndcompress -d ${.IMPSRC} ${.TARGET}
+
+.cl2.outx:
+       vnduncompress ${.IMPSRC} ${.TARGET}
diff -r 5852439d3254 -r 5ba924925389 usr.bin/vndcompress/common.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/vndcompress/common.h      Fri May 03 23:28:15 2013 +0000
@@ -0,0 +1,148 @@
+/*     $NetBSD: common.h,v 1.1 2013/05/03 23:28:15 riastradh Exp $     */
+
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef        VNDCOMPRESS_COMMON_H
+#define        VNDCOMPRESS_COMMON_H
+
+#include <sys/cdefs.h>
+#include <sys/param.h>
+
+#include <limits.h>
+#include <stdint.h>
+
+#ifndef __type_fit
+
+/* XXX Cruft from HEAD.  */
+
+#define __type_mask(t) (/*LINTED*/sizeof(t) < sizeof(intmax_t) ? \
+    (~((1ULL << (sizeof(t) * NBBY)) - 1)) : 0ULL)
+
+#define __zeroll() (0LL)
+#define __negative_p(x) ((x) < 0)
+
+#define __type_min_s(t) ((t)((1ULL << (sizeof(t) * NBBY - 1))))
+#define __type_max_s(t) ((t)~((1ULL << (sizeof(t) * NBBY - 1))))
+#define __type_min_u(t) ((t)0ULL)
+#define __type_max_u(t) ((t)~0ULL)
+#define __type_is_signed(t) (/*LINTED*/__type_min_s(t) + (t)1 < (t)1)
+#define __type_min(t) (__type_is_signed(t) ? __type_min_s(t) : __type_min_u(t))
+#define __type_max(t) (__type_is_signed(t) ? __type_max_s(t) : __type_max_u(t))
+
+
+#define __type_fit_u(t, a) (/*LINTED*/sizeof(t) < sizeof(intmax_t) ? \
+    (((a) & __type_mask(t)) == 0) : !__negative_p(a))
+
+#define __type_fit_s(t, a) (/*LINTED*/__negative_p(a) ? \
+    ((intmax_t)((a) + __zeroll()) >= (intmax_t)__type_min_s(t)) : \
+    ((intmax_t)((a) + __zeroll()) <= (intmax_t)__type_max_s(t)))
+
+/*
+ * return true if value 'a' fits in type 't'
+ */
+#define __type_fit(t, a) (__type_is_signed(t) ? \
+    __type_fit_s(t, a) : __type_fit_u(t, a))
+
+#endif
+
+/* XXX urk */
+#ifndef OFF_MAX
+#define        OFF_MAX                 __type_max(off_t)
+#endif
+
+/* XXX Why is this kernel-only?  */
+#define        SET(t, f)       ((t) |= (f))
+#define        CLR(t, f)       ((t) &= ~(f))
+#define        ISSET(t, f)     ((t) & (f))
+
+/*
+ * We require:
+ *
+ *   0 < blocksize                     (duh)
+ *   blocksize % DEV_BSIZE == 0                (for kernel use)
+ *
+ *   blocksize <= UINT32_MAX           (per the format)
+ *   blocksize*2 <= SIZE_MAX           (for a compression buffer)
+ *   blocksize*2 <= ULONG_MAX          (for zlib API)
+ */
+#define        MIN_BLOCKSIZE           DEV_BSIZE
+#define        DEF_BLOCKSIZE           0x10000
+#define        MAX_BLOCKSIZE                                                   \
+       rounddown(MIN(UINT32_MAX, (MIN(SIZE_MAX, ULONG_MAX) / 2)),      \
+           MIN_BLOCKSIZE)
+
+/*
+ * We require:
+ *
+ *   n_offsets * sizeof(uint64_t) <= SIZE_MAX  (array of 64-bit offsets)
+ *   n_blocks = (n_offsets + 1)                (extra offset to set last block end)
+ *   n_blocks <= UINT32_MAX            (per the format)
+ *   n_offsets <= UINT32_MAX           (for the sake of simplicity)
+ */
+#define        MAX_N_BLOCKS                                                    \
+       (MIN(UINT32_MAX, (SIZE_MAX / sizeof(uint64_t))) - 1)
+#define        MAX_N_OFFSETS           (MAX_N_BLOCKS + 1)
+
+struct cloop2_header {
+       char            cl2h_magic[128];
+       uint32_t        cl2h_blocksize;
+       uint32_t        cl2h_n_blocks;
+} __packed;
+
+#define        CLOOP2_OFFSET_TABLE_OFFSET      136
+
+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 */



Home | Main Index | Thread Index | Old Index