new fstab format
[unix-history] / usr / src / sbin / dump / tape.c
index 6042d61..a205703 100644 (file)
@@ -1,34 +1,65 @@
-static char *sccsid = "@(#)tape.c      1.3 (Berkeley) %G%";
+static char *sccsid = "@(#)tape.c      1.7 (Berkeley) %G%";
 #include "dump.h"
 
 #include "dump.h"
 
-char   tblock[NTREC][BSIZE];
-daddr_t        tdaddr[NTREC];
-int    trecno;
+char   (*tblock)[TP_BSIZE];    /* Pointer to malloc()ed buffer for tape */
+int    writesize;              /* Size of malloc()ed buffer for tape */
+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<BSIZE; i++)
+       for (i=0; i < TP_BSIZE; i++)
                tblock[trecno][i] = *dp++;
                tblock[trecno][i] = *dp++;
-       tdaddr[trecno] = 0;
        trecno++;
        spcl.c_tapea++;
        trecno++;
        spcl.c_tapea++;
-       if(trecno >= NTREC)
+       if(trecno >= ntrec)
                flusht();
 }
 
                flusht();
 }
 
-tapsrec(d)
-daddr_t d;
+dmpblk(blkno, size)
+       daddr_t blkno;
+       int size;
 {
 {
+       int avail, tpblks, dblkno;
 
 
-       if(d == 0)
-               return;
-       tdaddr[trecno] = d;
-       trecno++;
-       spcl.c_tapea++;
-       if(trecno >= NTREC)
+       if (size % TP_BSIZE != 0)
+               msg("bad size to dmpblk: %d\n", size);
+       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();
+               dblkno += avail * (TP_BSIZE / DEV_BSIZE);
+               tpblks -= avail;
+               avail = ntrec - trecno;
+       }
+       bread(dblkno, tblock[trecno], TP_BSIZE * tpblks);
+       trecno += tpblks;
+       spcl.c_tapea += tpblks;
+       if(trecno >= ntrec)
                flusht();
 }
 
                flusht();
 }
 
@@ -39,24 +70,14 @@ flusht()
        register i, si;
        daddr_t d;
 
        register i, si;
        daddr_t d;
 
-       while(trecno < NTREC)
-               tdaddr[trecno++] = 1;
-
-loop:
-       d = 0;
-       for(i=0; i<NTREC; i++)
-               if(tdaddr[i] != 0)
-               if(d == 0 || tdaddr[i] < d) {
-                       si = i;
-                       d = tdaddr[i];
-               }
-       if(d != 0) {
-               bread(d, tblock[si], BSIZE);
-               tdaddr[si] = 0;
-               goto loop;
-       }
        trecno = 0;
        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?")){
@@ -78,10 +99,10 @@ loop:
                }
        }
 
                }
        }
 
-       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();
        }
@@ -92,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);
@@ -109,6 +133,9 @@ rewind()
 
 close_rewind()
 {
 
 close_rewind()
 {
+
+       if (pipeout)
+               return;
        close(to);
        if (!nogripe){
                rewind();
        close(to);
        if (!nogripe){
                rewind();
@@ -221,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();