#ifndef lint
static const char rcsid[] =
- "$Id: tape.c,v 1.31 2001/02/21 16:13:05 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>
#include <linux/types.h>
#endif
#include <sys/param.h>
#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>
#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 */
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 */
#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 */