Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/vndcompress Make partial read/write error messages m...



details:   https://anonhg.NetBSD.org/src/rev/05d765626201
branches:  trunk
changeset: 786674:05d765626201
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon May 06 22:53:24 2013 +0000

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

diffstat:

 usr.bin/vndcompress/vndcompress.c   |  41 ++++++++++++++++++------------------
 usr.bin/vndcompress/vnduncompress.c |  18 +++++++++-------
 2 files changed, 31 insertions(+), 28 deletions(-)

diffs (165 lines):

diff -r e1320dbe65ae -r 05d765626201 usr.bin/vndcompress/vndcompress.c
--- a/usr.bin/vndcompress/vndcompress.c Mon May 06 22:49:27 2013 +0000
+++ b/usr.bin/vndcompress/vndcompress.c Mon May 06 22:53:24 2013 +0000
@@ -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 @@
                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 @@
                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 @@
                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 @@
        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 @@
        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 @@
                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 @@
                        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.  */
diff -r e1320dbe65ae -r 05d765626201 usr.bin/vndcompress/vnduncompress.c
--- a/usr.bin/vndcompress/vnduncompress.c       Mon May 06 22:49:27 2013 +0000
+++ b/usr.bin/vndcompress/vnduncompress.c       Mon May 06 22:53:24 2013 +0000
@@ -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 22:53:24 riastradh Exp $      */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: vnduncompress.c,v 1.1 2013/05/03 23:28:15 riastradh Exp $");
+__RCSID("$NetBSD: vnduncompress.c,v 1.2 2013/05/06 22:53:24 riastradh Exp $");
 
 #include <sys/endian.h>
 
@@ -75,7 +75,8 @@
                err(1, "read header");
        assert(h_read >= 0);
        if ((size_t)h_read != sizeof(header))
-               errx(1, "partial read of header: %zu", (size_t)h_read);
+               errx(1, "partial read of header: %zu != %zu",
+                   (size_t)h_read, sizeof(header));
 
        const uint32_t blocksize = be32toh(header.cl2h_blocksize);
        const uint32_t n_blocks = be32toh(header.cl2h_n_blocks);
@@ -116,7 +117,8 @@
                err(1, "read offset table");
        assert(ot_read >= 0);
        if ((size_t)ot_read != (n_offsets * sizeof(uint64_t)))
-               errx(1, "partial read of offset table: %zu", (size_t)ot_read);
+               errx(1, "partial read of offset table: %zu != %zu",
+                   (size_t)ot_read, (size_t)(n_offsets * sizeof(uint64_t)));
 
        /* Allocate compression buffers.  */
        /* XXX compression ratio bound */
@@ -164,8 +166,8 @@
                        err(1, "read block %"PRIu32, blkno);
                assert(n_read >= 0);
                if ((size_t)n_read != (end - start))
-                       errx(1, "partial read of block %"PRIu32": %zu", blkno,
-                           (size_t)n_read);
+                       errx(1, "partial read of block %"PRIu32": %zu != %zu",
+                           blkno, (size_t)n_read, (size_t)(end - start));
 
                /* Uncompress the block.  */
                const unsigned long complen = (end - start);
@@ -189,8 +191,8 @@
                        err(1, "write block %"PRIu32, blkno);
                assert(n_written >= 0);
                if ((size_t)n_written != uncomplen)
-                       errx(1, "partial write of block %"PRIu32": %zu", blkno,
-                           (size_t)n_written);
+                       errx(1, "partial write of block %"PRIu32": %zu != %lu",
+                           blkno, (size_t)n_written, uncomplen);
 
                /* Advance our position.  */
                assert((size_t)n_read <= (MIN(OFF_MAX, UINT64_MAX) - offset));



Home | Main Index | Thread Index | Old Index