+
+ /* Try to write the data... */
+ wrote = 0;
+ eot_count = 0;
+ size = 0;
+ buffer = (char *) slp->tblock[0]; /* set write pointer */
+ bufsize = writesize; /* length to write */
+ returns.clen = returns.unclen = bufsize;
+
+#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO)
+ /*
+ * When writing a compressed dump, each block except
+ * the first one on each tape 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. Blocks which don't
+ * compress well are written uncompressed.
+ * The first block written by each slave is not compressed
+ * and does not have a prefix.
+ */
+
+ if (compressed && do_compress) {
+ comp_buf->length = bufsize;
+ worklen = TP_BSIZE + writesize;
+ compresult = 1;
+#ifdef HAVE_ZLIB
+ if (zipflag == COMPRESS_ZLIB) {
+ compresult = compress2(comp_buf->buf,
+ &worklen,
+ (char *)slp->tblock[0],
+ writesize,
+ compressed);
+ if (compresult == Z_OK)
+ compresult = 1;
+ else
+ compresult = 0;
+ }
+#endif /* HAVE_ZLIB */
+#ifdef HAVE_BZLIB
+ if (zipflag == COMPRESS_BZLIB) {
+ worklen2 = worklen;
+ compresult = BZ2_bzBuffToBuffCompress(
+ comp_buf->buf,
+ &worklen2,
+ (char *)slp->tblock[0],
+ writesize,
+ compressed,
+ 0, 30);
+ worklen = worklen2;
+ if (compresult == BZ_OK)
+ compresult = 1;
+ else
+ compresult = 0;
+ }
+
+#endif /* HAVE_BZLIB */
+#ifdef HAVE_LZO
+ if (zipflag == COMPRESS_LZO) {
+ compresult = lzo1x_1_compress((char *)slp->tblock[0],writesize,
+ comp_buf->buf,
+ (lzo_uintp)&worklen,
+ LZO_WorkMem);
+ if (compresult == LZO_E_OK)
+ compresult = 1;
+ else
+ compresult = 0;
+ }
+#endif /* HAVE_LZO */
+ if (compresult && worklen <= ((unsigned long)writesize - 16)) {
+ /* write the compressed buffer */
+ 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 = writesize + sizeof(struct tapebuf);
+ returns.unclen = returns.clen;
+ memcpy(comp_buf->buf, (char *)slp->tblock[0], writesize);
+ }
+ }
+ /* compress the remaining blocks if we're compressing */
+ do_compress = compressed;
+#endif /* HAVE_ZLIB || HAVE_BZLIB || HAVE_LZO */
+