X-Git-Url: https://git.wh0rd.org/?p=dump.git;a=blobdiff_plain;f=dump%2Ftape.c;h=1990be91bbb952a43c767f985abb3df27ab01775;hp=70c1d1d7f1de944af1a6f99f530b34f88fe90fd3;hb=aa2fe29bc559dfbf17805267f10f7bf0b112750f;hpb=a18d599791e977f3e3d26123031e6ed4e64d6d08 diff --git a/dump/tape.c b/dump/tape.c index 70c1d1d..1990be9 100644 --- a/dump/tape.c +++ b/dump/tape.c @@ -18,11 +18,7 @@ * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,7 +37,7 @@ #ifndef lint static const char rcsid[] = - "$Id: tape.c,v 1.70 2002/07/19 14:57:39 stelian Exp $"; + "$Id: tape.c,v 1.77 2003/04/18 07:47:57 stelian Exp $"; #endif /* not lint */ #include @@ -99,6 +95,10 @@ int write(), read(); #include #endif /* HAVE_BZLIB */ +#ifdef HAVE_LZO +#include +#endif /* HAVE_LZO */ + #include "dump.h" int writesize; /* size of malloc()ed buffer for tape */ @@ -110,7 +110,6 @@ extern int ntrec; /* blocking factor on tape */ extern int cartridge; char *nexttape; extern pid_t rshpid; -int eot_code = 1; long long tapea_bytes = 0; /* bytes_written at start of current volume */ static int magtapeout; /* output is really a tape */ @@ -237,14 +236,14 @@ writerec(const void *dp, int isspcl) *(union u_spcl *)(*(nextblock)) = *(union u_spcl *)dp; /* Need to write it to the archive file */ - if (Afile < 0 && isspcl && (spcl.c_type == TS_END)) - Afile = -Afile; - if (Afile > 0) { + if (! AfileActive && isspcl && (spcl.c_type == TS_END)) + AfileActive = 1; + if (AfileActive && Afile >= 0) { /* When we dump an inode which is not a directory, * it means we ended the archive contents */ if (isspcl && (spcl.c_type == TS_INODE) && ((spcl.c_dinode.di_mode & S_IFMT) != IFDIR)) - Afile = -Afile; + AfileActive = 0; else { union u_spcl tmp; tmp = *(union u_spcl *)dp; @@ -336,7 +335,7 @@ do_stats(void) blocks = spcl.c_tapea - tapea_volume; msg("Volume %d completed at: %s", tapeno, ctime(&tnow)); if (! compressed) - msg("Volume %d %ld tape blocks (%.2fMB)\n", tapeno, + msg("Volume %d %ld blocks (%.2fMB)\n", tapeno, blocks, ((double)blocks * TP_BSIZE / 1048576)); if (ttaken > 0) { long volkb = (bytes_written - tapea_bytes) / 1024; @@ -546,7 +545,7 @@ trewind(void) #ifdef RDUMP if (host) { rmtclose(); - while (rmtopen(tape, "O_RDONLY") < 0) + while (rmtopen(tape, O_RDONLY) < 0) sleep(10); rmtclose(); } @@ -560,15 +559,6 @@ trewind(void) (void) close(f); } } - eot_code = 1; - if (eot_script && spcl.c_type != TS_END) { - msg("Launching %s\n", eot_script); - eot_code = system_command(eot_script, tape, tapeno); - } - if (eot_code != 0 && eot_code != 1) { - msg("Dump aborted by the end of tape script\n"); - dumpabort(0); - } } return do_stats(); } @@ -577,8 +567,19 @@ trewind(void) void close_rewind(void) { + int eot_code = 1; (void)trewind(); - if (nexttape || Mflag || (eot_code == 0) ) + if (nexttape || Mflag) + return; + if (eot_script) { + msg("Launching %s\n", eot_script); + eot_code = system_command(eot_script, tape, tapeno); + } + if (eot_code != 0 && eot_code != 1) { + msg("Dump aborted by the end of tape script\n"); + dumpabort(0); + } + if (eot_code == 0) return; if (!nogripe) { msg("Change Volumes: Mount volume #%d\n", tapeno+1); @@ -868,7 +869,7 @@ restore_check_point: msg("Dumping volume %d on %s\n", tapeno, tape); } #ifdef RDUMP - while ((tapefd = (host ? rmtopen(tape, "O_WRONLY|O_CREAT|O_TRUNC") : pipeout ? + while ((tapefd = (host ? rmtopen(tape, O_WRONLY|O_CREAT|O_TRUNC) : pipeout ? fileno(stdout) : OPEN(tape, O_WRONLY|O_CREAT|O_TRUNC, 0666))) < 0) #else @@ -1075,7 +1076,7 @@ doslave(int cmd, int nextslave; volatile int wrote = 0, size, eot_count, bufsize; char * volatile buffer; -#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) +#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO) struct tapebuf * volatile comp_buf = NULL; int compresult; volatile int do_compress = !first; @@ -1083,7 +1084,10 @@ doslave(int cmd, #ifdef HAVE_BZLIB unsigned int worklen2; #endif -#endif /* HAVE_ZLIB || HAVE_BZLIB */ +#ifdef HAVE_LZO + lzo_align_t __LZO_MMODEL *LZO_WorkMem; +#endif +#endif /* HAVE_ZLIB || HAVE_BZLIB || HAVE_LZO */ struct slave_results returns; #ifdef __linux__ errcode_t retval; @@ -1124,18 +1128,34 @@ doslave(int cmd, quit("master/slave protocol botched - didn't get pid of next slave.\n"); } -#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) +#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) || defined(HAVE_LZO) /* if we're doing a compressed dump, allocate the compress buffer */ if (compressed) { - comp_buf = malloc(sizeof(struct tapebuf) + TP_BSIZE + writesize); + int bsiz = sizeof(struct tapebuf) + writesize; + /* Add extra space to deal with compression enlarging the buffer */ + if (TP_BSIZE > writesize/16 + 67) + bsiz += TP_BSIZE; + else + bsiz += writesize/16 + 67; + comp_buf = malloc(bsiz); if (comp_buf == NULL) quit("couldn't allocate a compress buffer.\n"); - if (bzipflag) - comp_buf->flags = COMPRESS_BZLIB; - else + if (zipflag == COMPRESS_ZLIB) comp_buf->flags = COMPRESS_ZLIB; + else if (zipflag == COMPRESS_BZLIB) + comp_buf->flags = COMPRESS_BZLIB; + else if (zipflag == COMPRESS_LZO) { + comp_buf->flags = COMPRESS_LZO; + if (lzo_init() != LZO_E_OK) quit("lzo_init failed\n"); + } else + quit("internal error - unknown compression method: %d\n", zipflag); } -#endif /* HAVE_ZLIB || HAVE_BZLIB */ +#ifdef HAVE_LZO + LZO_WorkMem = malloc(LZO1X_1_MEM_COMPRESS); + if (!LZO_WorkMem) + quit("couldn't allocate a compress buffer.\n"); +#endif +#endif /* HAVE_ZLIB || HAVE_BZLIB || HAVE_LZO */ /* * Get list of blocks to dump, read the blocks into tape buffer @@ -1164,7 +1184,7 @@ doslave(int cmd, bufsize = writesize; /* length to write */ returns.clen = returns.unclen = bufsize; -#if defined(HAVE_ZLIB) || defined(HAVE_BZLIB) +#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 @@ -1183,7 +1203,7 @@ doslave(int cmd, worklen = TP_BSIZE + writesize; compresult = 1; #ifdef HAVE_ZLIB - if (!bzipflag) { + if (zipflag == COMPRESS_ZLIB) { compresult = compress2(comp_buf->buf, &worklen, (char *)slp->tblock[0], @@ -1196,7 +1216,7 @@ doslave(int cmd, } #endif /* HAVE_ZLIB */ #ifdef HAVE_BZLIB - if (bzipflag) { + if (zipflag == COMPRESS_BZLIB) { worklen2 = worklen; compresult = BZ2_bzBuffToBuffCompress( comp_buf->buf, @@ -1213,6 +1233,18 @@ doslave(int cmd, } #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; @@ -1232,7 +1264,7 @@ doslave(int cmd, } /* compress the remaining blocks if we're compressing */ do_compress = compressed; -#endif /* HAVE_ZLIB || HAVE_BZLIB */ +#endif /* HAVE_ZLIB || HAVE_BZLIB || HAVE_LZO */ if (sigsetjmp(jmpbuf, 1) == 0) { ready = 1; @@ -1277,11 +1309,12 @@ doslave(int cmd, #ifdef WRITEDEBUG printf("slave %d wrote %d\n", slave_number, wrote); #endif - if (wrote < 0) + if (wrote < 0 && errno != ENOSPC) break; - if (wrote == 0) + if (wrote == 0 || (wrote < 0 && errno == ENOSPC)) eot_count++; - size += wrote; + else + size += wrote; } #ifdef WRITEDEBUG