]> git.wh0rd.org - dump.git/blobdiff - dump/tape.c
Andreas Dilger fixes (CPP, ext2 features, const char etc).
[dump.git] / dump / tape.c
index 54961a9a1b93dc92c7eef4d177b8e5a881be8b80..f43c3a20a9b3d4aae071afcb90ca90bd3641ebac 100644 (file)
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: tape.c,v 1.32 2001/02/22 10:57:40 stelian Exp $";
+       "$Id: tape.c,v 1.34 2001/03/19 13:22:48 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <stdio.h>
+#include <compaterr.h>
+#ifdef __STDC__
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#else
+int    write(), read();
+#endif
+
 #ifdef __linux__
 #include <sys/types.h>
 #include <time.h>
@@ -56,9 +70,9 @@ static const char rcsid[] =
 #include <sys/wait.h>
 #ifdef __linux__
 #include <linux/ext2_fs.h>
+#include <ext2fs/ext2fs.h>
 #include <bsdcompat.h>
-#else  /* __linux__ */
-#ifdef sunos
+#elif defined sunos
 #include <sys/vnode.h>
 
 #include <ufs/fs.h>
@@ -66,29 +80,10 @@ static const char rcsid[] =
 #else
 #include <ufs/ufs/dinode.h>
 #include <ufs/ffs/fs.h>
-#endif
 #endif /* __linux__ */
 
 #include <protocols/dumprestore.h>
 
-#include <errno.h>
-#include <fcntl.h>
-#include <setjmp.h>
-#include <signal.h>
-#include <stdio.h>
-#include <compaterr.h>
-#ifdef __STDC__
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#else
-int    write(), read();
-#endif
-
-#ifdef __linux__
-#include <ext2fs/ext2fs.h>
-#endif
-
 #ifdef HAVE_ZLIB
 #include <zlib.h>
 #endif /* HAVE_ZLIB */
@@ -1101,6 +1096,7 @@ doslave(int cmd, int slave_number)
                comp_buf = malloc(sizeof(struct tapebuf) + TP_BSIZE + writesize);
                if (comp_buf == NULL)
                        quit("couldn't allocate a compress buffer.\n");
+               comp_buf->flags = 0;
        }
 #endif /* HAVE_ZLIB */
 
@@ -1140,25 +1136,37 @@ doslave(int cmd, int slave_number)
 
 #ifdef HAVE_ZLIB
                /* 
-                * If the data can't be compressed it's written with no
-                * prefix as writesize bytes. If it's compressible, it's
-                * written from struct tapebuf with an 8 byte prefix
-                * followed by the data. This will always be less than
+                * The first NR_SLAVE blocks are not compressed.
+                * When writing a compressed dump, each block is
+                * written from struct tapebuf with an 4 byte prefix
+                * followed by the data. This can be less than
                 * writesize. Restore, on a short read, can compare the
                 * length read to the compressed length in the header
-                * to verify that the read was good.
+                * to verify that the read was good. Blocks which don't
+                * compress well are written uncompressed.
                 */
 
-               if (do_compress) {      /* don't compress the first block */
-                       comp_buf->clen = comp_buf->unclen = bufsize;
+               if (compressed) {
+                       comp_buf->length = bufsize;
                        worklen = TP_BSIZE + writesize;
-                       compresult = compress2(comp_buf->buf, &worklen,
-                               (char *)slp->tblock[0], writesize, complevel);
+                       if (do_compress)
+                               compresult = compress2(comp_buf->buf, &worklen,
+                                       (char *)slp->tblock[0], writesize, complevel);
                        if (compresult == Z_OK && worklen <= writesize-32) {
                                /* write the compressed buffer */
-                               comp_buf->clen = worklen;
+                               comp_buf->length = worklen;
+                               comp_buf->compressed = 1;
+                               buffer = (char *) comp_buf;
+                               returns.clen = bufsize = worklen + sizeof(struct tapebuf);
+                       }
+                       else {
+                               /* write the data uncompressed */
+                               comp_buf->length = writesize;
+                               comp_buf->compressed = 0;
                                buffer = (char *) comp_buf;
-                               returns.clen = bufsize = worklen + 8;
+                               returns.clen = bufsize = writesize + sizeof(struct tapebuf);
+                               returns.unclen = returns.clen;
+                               memcpy(comp_buf->buf, (char *)slp->tblock[0], writesize);
                        }
                }
                /* compress the remaining blocks */