new fstab format
[unix-history] / usr / src / sbin / dump / tape.c
index dd5565f..a205703 100644 (file)
@@ -1,19 +1,39 @@
-static char *sccsid = "@(#)tape.c      1.4 (Berkeley) %G%";
+static char *sccsid = "@(#)tape.c      1.7 (Berkeley) %G%";
 #include "dump.h"
 
 #include "dump.h"
 
-char   tblock[NTREC][TP_BSIZE];
+char   (*tblock)[TP_BSIZE];    /* Pointer to malloc()ed buffer for tape */
+int    writesize;              /* Size of malloc()ed buffer for tape */
 int    trecno = 0;
 int    trecno = 0;
+extern int ntrec;              /* blocking factor on tape */
+
+/*
+ * Allocate the buffer for tape operations.
+ *
+ * Depends on global variable ntrec, set from 'b' option in command line.
+ * Returns 1 if successful, 0 if failed.
+ *
+ * For later kernel performance improvement, this buffer should be allocated
+ * on a page boundary.
+ */
+alloctape()
+{
+
+       writesize = ntrec * TP_BSIZE;
+       tblock = (char (*)[TP_BSIZE])malloc(writesize);
+       return (tblock != NULL);
+}
+
 
 taprec(dp)
 
 taprec(dp)
-char *dp;
+       char *dp;
 {
        register i;
 
 {
        register i;
 
-       for(i=0; i<TP_BSIZE; i++)
+       for (i=0; i < TP_BSIZE; i++)
                tblock[trecno][i] = *dp++;
        trecno++;
        spcl.c_tapea++;
                tblock[trecno][i] = *dp++;
        trecno++;
        spcl.c_tapea++;
-       if(trecno >= NTREC)
+       if(trecno >= ntrec)
                flusht();
 }
 
                flusht();
 }
 
@@ -21,24 +41,25 @@ dmpblk(blkno, size)
        daddr_t blkno;
        int size;
 {
        daddr_t blkno;
        int size;
 {
-       int avail, blks;
+       int avail, tpblks, dblkno;
 
 
-       if (size % FRAG != 0)
+       if (size % TP_BSIZE != 0)
                msg("bad size to dmpblk: %d\n", size);
                msg("bad size to dmpblk: %d\n", size);
-       avail = NTREC - trecno;
-       for (blks = size / TP_BSIZE; blks > avail; ) {
-               bread(blkno, tblock[trecno], TP_BSIZE * avail);
+       avail = ntrec - trecno;
+       dblkno = fsbtodb(sblock, blkno);
+       for (tpblks = size / TP_BSIZE; tpblks > avail; ) {
+               bread(dblkno, tblock[trecno], TP_BSIZE * avail);
                trecno += avail;
                spcl.c_tapea += avail;
                flusht();
                trecno += avail;
                spcl.c_tapea += avail;
                flusht();
-               blkno += avail;
-               blks -= avail;
-               avail = NTREC - trecno;
+               dblkno += avail * (TP_BSIZE / DEV_BSIZE);
+               tpblks -= avail;
+               avail = ntrec - trecno;
        }
        }
-       bread(blkno, tblock[trecno], TP_BSIZE * blks);
-       trecno += blks;
-       spcl.c_tapea += blks;
-       if(trecno >= NTREC)
+       bread(dblkno, tblock[trecno], TP_BSIZE * tpblks);
+       trecno += tpblks;
+       spcl.c_tapea += tpblks;
+       if(trecno >= ntrec)
                flusht();
 }
 
                flusht();
 }
 
@@ -50,7 +71,13 @@ flusht()
        daddr_t d;
 
        trecno = 0;
        daddr_t d;
 
        trecno = 0;
-       if (write(to, tblock[0], sizeof(tblock)) != sizeof(tblock) ){
+       if (write(to, tblock[0], writesize) != writesize){
+               if (pipeout) {
+                       msg("Tape write error on %s\n", tape);
+                       msg("Cannot recover\n");
+                       dumpabort();
+                       /* NOTREACHED */
+               }
                msg("Tape write error on tape %d\n", tapeno);
                broadcast("TAPE ERROR!\n");
                if (query("Do you want to restart?")){
                msg("Tape write error on tape %d\n", tapeno);
                broadcast("TAPE ERROR!\n");
                if (query("Do you want to restart?")){
@@ -72,10 +99,10 @@ flusht()
                }
        }
 
                }
        }
 
-       asize += sizeof(tblock)/density;
+       asize += writesize/density;
        asize += 7;
        asize += 7;
-       blockswritten += NTREC;
-       if (asize > tsize) {
+       blockswritten += ntrec;
+       if (!pipeout && asize > tsize) {
                close_rewind();
                otape();
        }
                close_rewind();
                otape();
        }
@@ -86,6 +113,9 @@ rewind()
 {
        int     secs;
        int f;
 {
        int     secs;
        int f;
+
+       if (pipeout)
+               return;
 #ifdef DEBUG
        msg("Waiting 10 seconds to rewind.\n");
        sleep(10);
 #ifdef DEBUG
        msg("Waiting 10 seconds to rewind.\n");
        sleep(10);
@@ -103,6 +133,9 @@ rewind()
 
 close_rewind()
 {
 
 close_rewind()
 {
+
+       if (pipeout)
+               return;
        close(to);
        if (!nogripe){
                rewind();
        close(to);
        if (!nogripe){
                rewind();
@@ -215,7 +248,10 @@ otape()
                        tapeno+1, parentpid, getpid());
 #endif
                do{
                        tapeno+1, parentpid, getpid());
 #endif
                do{
-                       to = creat(tape, 0666);
+                       if (pipeout)
+                               to = 1;
+                       else
+                               to = creat(tape, 0666);
                        if (to < 0) {
                                if (!query("Cannot open tape. Do you want to retry the open?"))
                                        dumpabort();
                        if (to < 0) {
                                if (!query("Cannot open tape. Do you want to retry the open?"))
                                        dumpabort();