minor cleanup, remove vestiges of AT&T wording
[unix-history] / usr / src / sbin / dump / tape.c
index 04b7bbe..129fb36 100644 (file)
@@ -1,11 +1,12 @@
-/*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+/*-
+ * Copyright (c) 1980, 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)tape.c     5.15 (Berkeley) %G%";
+static char sccsid[] = "@(#)tape.c     5.18 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -30,8 +31,10 @@ int  writesize;              /* size of malloc()ed buffer for tape */
 long   lastspclrec = -1;       /* tape block number of last written header */
 int    trecno = 0;             /* next record to write in current block */
 extern long blocksperfile;     /* number of blocks per output file */
 long   lastspclrec = -1;       /* tape block number of last written header */
 int    trecno = 0;             /* next record to write in current block */
 extern long blocksperfile;     /* number of blocks per output file */
-extern int ntrec;              /* blocking factor on tape */
-extern int cartridge;
+long   blocksthisvol;          /* number of blocks on current output file */
+extern int ntrec;              /* blocking factor on tape */
+extern int cartridge;
+char   *nexttape;
 #ifdef RDUMP
 extern char *host;
 int    rmtopen(), rmtwrite();
 #ifdef RDUMP
 extern char *host;
 int    rmtopen(), rmtwrite();
@@ -74,7 +77,9 @@ alloctape()
         * repositioning after stopping, i.e, streaming mode, where the gap is
         * variable, 0.30" to 0.45".  The gap is maximal when the tape stops.
         */
         * repositioning after stopping, i.e, streaming mode, where the gap is
         * variable, 0.30" to 0.45".  The gap is maximal when the tape stops.
         */
-       tenths = writesize/density + (cartridge ? 16 : density == 625 ? 5 : 8);
+       if (blocksperfile == 0)
+               tenths = writesize / density +
+                   (cartridge ? 16 : density == 625 ? 5 : 8);
        /*
         * Allocate tape buffer contiguous with the array of instruction
         * packets, so flushtape() can write them together with one write().
        /*
         * Allocate tape buffer contiguous with the array of instruction
         * packets, so flushtape() can write them together with one write().
@@ -134,7 +139,7 @@ tperror()
                quit("Cannot recover\n");
                /* NOTREACHED */
        }
                quit("Cannot recover\n");
                /* NOTREACHED */
        }
-       msg("write error %d blocks into volume %d\n", blockswritten, tapeno);
+       msg("write error %d blocks into volume %d\n", blocksthisvol, tapeno);
        broadcast("DUMP WRITE ERROR!\n");
        if (!query("Do you want to restart?"))
                dumpabort();
        broadcast("DUMP WRITE ERROR!\n");
        if (!query("Do you want to restart?"))
                dumpabort();
@@ -170,8 +175,9 @@ flushtape()
        trecno = 0;
        asize += tenths;
        blockswritten += ntrec;
        trecno = 0;
        asize += tenths;
        blockswritten += ntrec;
+       blocksthisvol += ntrec;
        if (!pipeout && (blocksperfile ?
        if (!pipeout && (blocksperfile ?
-           (blockswritten >= blocksperfile) : (asize > tsize))) {
+           (blocksthisvol >= blocksperfile) : (asize > tsize))) {
                close_rewind();
                startnewtape();
        }
                close_rewind();
                startnewtape();
        }
@@ -189,7 +195,7 @@ trewind()
                close(slavefd[f]);
        while (wait((int *)NULL) >= 0)  /* wait for any signals from slaves */
                /* void */;
                close(slavefd[f]);
        while (wait((int *)NULL) >= 0)  /* wait for any signals from slaves */
                /* void */;
-       msg("Tape rewinding\n");
+       msg("Closing %s\n", tape);
 #ifdef RDUMP
        if (host) {
                rmtclose();
 #ifdef RDUMP
        if (host) {
                rmtclose();
@@ -209,6 +215,8 @@ void
 close_rewind()
 {
        trewind();
 close_rewind()
 {
        trewind();
+       if (nexttape)
+               return;
        if (!nogripe) {
                msg("Change Volumes: Mount volume #%d\n", tapeno+1);
                broadcast("CHANGE DUMP VOLUMES!\7\7\n");
        if (!nogripe) {
                msg("Change Volumes: Mount volume #%d\n", tapeno+1);
                broadcast("CHANGE DUMP VOLUMES!\7\7\n");
@@ -239,6 +247,7 @@ startnewtape()
        int     waitpid;
        sig_t   interrupt;
        int     blks, i;
        int     waitpid;
        sig_t   interrupt;
        int     blks, i;
+       char    *p;
 
        interrupt = signal(SIGINT, SIG_IGN);
        parentpid = getpid();
 
        interrupt = signal(SIGINT, SIG_IGN);
        parentpid = getpid();
@@ -308,6 +317,22 @@ startnewtape()
                msg("Child on Tape %d has parent %d, my pid = %d\n",
                        tapeno+1, parentpid, getpid());
 #endif TDEBUG
                msg("Child on Tape %d has parent %d, my pid = %d\n",
                        tapeno+1, parentpid, getpid());
 #endif TDEBUG
+               /*
+                * If we have a name like "/dev/rmt0,/dev/rmt1",
+                * use the name before the comma first, and save
+                * the remaining names for subsequent volumes.
+                */
+               tapeno++;               /* current tape sequence */
+               if (nexttape || index(tape, ',')) {
+                       if (nexttape && *nexttape)
+                               tape = nexttape;
+                       if (p = index(tape, ',')) {
+                               *p = '\0';
+                               nexttape = p + 1;
+                       } else
+                               nexttape = NULL;
+                       msg("Dumping volume %d on %s\n", tapeno, tape);
+               }
 #ifdef RDUMP
                while ((tapefd = (host ? rmtopen(tape, 2) :
                        pipeout ? 1 : open(tape, O_WRONLY|O_CREAT, 0666))) < 0)
 #ifdef RDUMP
                while ((tapefd = (host ? rmtopen(tape, 2) :
                        pipeout ? 1 : open(tape, O_WRONLY|O_CREAT, 0666))) < 0)
@@ -324,7 +349,7 @@ startnewtape()
                enslave();  /* Share open tape file descriptor with slaves */
 
                asize = 0;
                enslave();  /* Share open tape file descriptor with slaves */
 
                asize = 0;
-               tapeno++;               /* current tape sequence */
+               blocksthisvol = 0;
                newtape++;              /* new tape signal */
                blks = 0;
                if (spcl.c_type != TS_END)
                newtape++;              /* new tape signal */
                blks = 0;
                if (spcl.c_type != TS_END)
@@ -338,7 +363,7 @@ startnewtape()
                writeheader(curino);
                spcl.c_flags &=~ DR_NEWHEADER;
                if (tapeno > 1)
                writeheader(curino);
                spcl.c_flags &=~ DR_NEWHEADER;
                if (tapeno > 1)
-                       msg("Tape %d begins with blocks from inode %d\n",
+                       msg("Volume %d begins with blocks from inode %d\n",
                                tapeno, curino);
        }
 }
                                tapeno, curino);
        }
 }
@@ -455,6 +480,7 @@ doslave(cmd, prev, next)
        register int cmd, prev[2], next[2];
 {
        register int nread, toggle = 0;
        register int cmd, prev[2], next[2];
 {
        register int nread, toggle = 0;
+       int nwrite;
 #ifndef __STDC__
        int read();
 #endif
 #ifndef __STDC__
        int read();
 #endif
@@ -483,11 +509,17 @@ doslave(cmd, prev, next)
                flock(prev[toggle], LOCK_EX);   /* Wait our turn */
 
 #ifdef RDUMP
                flock(prev[toggle], LOCK_EX);   /* Wait our turn */
 
 #ifdef RDUMP
-               if ((host ? rmtwrite(tblock[0], writesize)
-                       : write(tapefd, tblock[0], writesize)) != writesize) {
+               if ((nwrite = (host ? rmtwrite(tblock[0], writesize)
+                       : write(tapefd, tblock[0], writesize))) != writesize) {
 #else RDUMP
 #else RDUMP
-               if (write(tapefd, tblock[0], writesize) != writesize) {
+               if ((nwrite = write(tapefd, tblock[0], writesize))
+                   != writesize) {
 #endif RDUMP
 #endif RDUMP
+                       if (nwrite == -1) 
+                               perror("write");
+                       else
+                               msg("short write: got %d instead of %d\n",
+                                   nwrite, writesize);
                        kill(master, SIGUSR1);
                        for (;;)
                                sigpause(0);
                        kill(master, SIGUSR1);
                        for (;;)
                                sigpause(0);