]> git.wh0rd.org - dump.git/blobdiff - dump/tape.c
Relicensed dump/restore under the revised BSD license, as per ftp://ftp.cs.berkeley...
[dump.git] / dump / tape.c
index 54b387eac62559d092a687ab18eca75d7a36a479..6f61210c6da4f0957b31d7c6286a7f408d044fbf 100644 (file)
  * 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.68 2002/05/21 15:48:46 stelian Exp $";
+       "$Id: tape.c,v 1.74 2003/03/30 15:40:37 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -110,13 +106,16 @@ 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 */
 
 static ssize_t dump_atomic_read __P((int, void *, size_t));
 static ssize_t dump_atomic_write __P((int, const void *, size_t));
+#ifdef WRITEDEBUG
 static void doslave __P((int, int, int));
+#else
+static void doslave __P((int, int));
+#endif
 static void enslave __P((void));
 static void flushtape __P((void));
 static void killall __P((void));
@@ -233,14 +232,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;
@@ -311,7 +310,7 @@ tperror(int errnum)
 }
 
 static void
-sigpipe(int signo)
+sigpipe(UNUSED(int signo))
 {
 
        quit("Broken pipe\n");
@@ -332,7 +331,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;
@@ -479,7 +478,7 @@ flushtape(void)
        blocksthisvol += ntrec;
        if (!pipeout && !unlimited) {
                if (blocksperfile) {
-                       if ( compressed ? (bytes_written - tapea_bytes + SLAVES * (writesize + sizeof(struct tapebuf))) >= blocksperfile * 1024
+                       if ( compressed ? (bytes_written - tapea_bytes + SLAVES * (writesize + sizeof(struct tapebuf))) >= (((long long)blocksperfile) * 1024)
                                        : blocksthisvol >= blocksperfile ) {
                                close_rewind();
                                startnewtape(0);
@@ -542,7 +541,7 @@ trewind(void)
 #ifdef RDUMP
                if (host) {
                        rmtclose();
-                       while (rmtopen(tape, "O_RDONLY") < 0)
+                       while (rmtopen(tape, O_RDONLY) < 0)
                                sleep(10);
                        rmtclose();
                }
@@ -556,15 +555,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();
 }
@@ -573,8 +563,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);
@@ -864,7 +865,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
@@ -914,13 +915,13 @@ restore_check_point:
                if (tapeno > 1)
                        msg("Volume %d begins with blocks from inode %d\n",
                                tapeno, slp->inode);
-               if (tapeno < TP_NINOS)
+               if (tapeno < (int)TP_NINOS)
                        volinfo[tapeno] = slp->inode;
        }
 }
 
 void
-dumpabort(int signo)
+dumpabort(UNUSED(int signo))
 {
 
        if (master != 0 && master != getpid())
@@ -950,7 +951,7 @@ Exit(int status)
  * proceed - handler for SIGUSR2, used to synchronize IO between the slaves.
  */
 static void
-proceed(int signo)
+proceed(UNUSED(int signo))
 {
        if (ready)
                siglongjmp(jmpbuf, 1);
@@ -1011,7 +1012,11 @@ enslave(void)
                            != sizeof i)
                                quit("master/slave protocol botched 3\n");
 #endif
-                       doslave(cmd[0], i, (slaves[i].pid == slp->pid));
+                       doslave(cmd[0], 
+#ifdef WRITEDEBUG
+                               i, 
+#endif
+                               (slaves[i].pid == slp->pid));
                        Exit(X_FINOK);
                }
                else
@@ -1057,15 +1062,20 @@ killall(void)
  * slaves.
  */
 static void
-doslave(int cmd, int slave_number, int first)
+doslave(int cmd, 
+#ifdef WRITEDEBUG
+       int slave_number, 
+#endif
+       int first)
 {
        int nread;
-       int nextslave, size, eot_count, bufsize;
-       volatile int wrote = 0;
-       char *buffer;
+       int nextslave;
+       volatile int wrote = 0, size, eot_count, bufsize;
+       char * volatile buffer;
 #if defined(HAVE_ZLIB) || defined(HAVE_BZLIB)
-       struct tapebuf *comp_buf = NULL;
-       int compresult, do_compress = !first;
+       struct tapebuf * volatile comp_buf = NULL;
+       int compresult;
+       volatile int do_compress = !first;
        unsigned long worklen;
 #ifdef HAVE_BZLIB
        unsigned int worklen2;
@@ -1200,7 +1210,7 @@ doslave(int cmd, int slave_number, int first)
                        }
 
 #endif /* HAVE_BZLIB */
-                       if (compresult && worklen <= (writesize - 16)) {
+                       if (compresult && worklen <= ((unsigned long)writesize - 16)) {
                                /* write the compressed buffer */
                                comp_buf->length = worklen;
                                comp_buf->compressed = 1;
@@ -1323,7 +1333,7 @@ dump_atomic_read(int fd, void *buf, size_t count)
                while ((got = read(fd, buf, need)) > 0 && (need -= got) > 0)
                        (char *)buf += got;
        } while (got == -1 && errno == EINTR);
-       return (got < 0 ? got : count - need);
+       return (got < 0 ? got : (ssize_t)count - need);
 }
 
 /*
@@ -1340,7 +1350,7 @@ dump_atomic_write(int fd, const void *buf, size_t count)
                while ((got = write(fd, buf, need)) > 0 && (need -= got) > 0)
                        (char *)buf += got;
        } while (got == -1 && errno == EINTR);
-       return (got < 0 ? got : count - need);
+       return (got < 0 ? got : (ssize_t)count - need);
 }
 
 
@@ -1393,7 +1403,7 @@ MkTapeString(struct s_spcl *spclptr, long long curtapepos) {
                 tapeno, 
                 curtapepos);
        gTps[sizeof(gTps) - 1] = '\0';
-       if (write(gTapeposfd, gTps, strlen(gTps)) != strlen(gTps)) {
+       if (write(gTapeposfd, gTps, strlen(gTps)) != (ssize_t)strlen(gTps)) {
                warn("error writing tapepos file.\n");
        }
 }