add ability to dump to standard output
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Mon, 9 May 1983 10:11:19 +0000 (02:11 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Mon, 9 May 1983 10:11:19 +0000 (02:11 -0800)
SCCS-vsn: sbin/dump/tape.c 1.7
SCCS-vsn: sbin/dump/dump.h 1.8
SCCS-vsn: sbin/dump/main.c 1.12

usr/src/sbin/dump/dump.h
usr/src/sbin/dump/main.c
usr/src/sbin/dump/tape.c

index 748df9d..bef6e47 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * "@(#)dump.h 1.7 (Berkeley) %G%"
+ * "@(#)dump.h 1.8 (Berkeley) %G%"
  */
 #define        NI              16
 #define MAXINOPB       (MAXBSIZE / sizeof(struct dinode))
  */
 #define        NI              16
 #define MAXINOPB       (MAXBSIZE / sizeof(struct dinode))
@@ -41,6 +41,7 @@ char  incno;          /* increment number */
 int    uflag;          /* update flag */
 int    fi;             /* disk file descriptor */
 int    to;             /* tape file descriptor */
 int    uflag;          /* update flag */
 int    fi;             /* disk file descriptor */
 int    to;             /* tape file descriptor */
+int    pipeout;        /* true => output to standard output */
 ino_t  ino;            /* current inumber; used globally */
 int    nsubdir;
 int    newtape;        /* new tape flag */
 ino_t  ino;            /* current inumber; used globally */
 int    nsubdir;
 int    newtape;        /* new tape flag */
index 2eb3a78..816a56a 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)main.c      1.11 (Berkeley) %G%";
+static char *sccsid = "@(#)main.c      1.12 (Berkeley) %G%";
 #include "dump.h"
 
 int    notify = 0;     /* notify operator flag */
 #include "dump.h"
 
 int    notify = 0;     /* notify operator flag */
@@ -115,7 +115,7 @@ main(argc, argv)
                break;
 
        default:
                break;
 
        default:
-               printf("bad key '%c%'\n", arg[-1]);
+               fprintf(stderr, "bad key '%c%'\n", arg[-1]);
                Exit(X_ABORT);
        }
        if(argc > 1) {
                Exit(X_ABORT);
        }
        if(argc > 1) {
@@ -123,6 +123,10 @@ main(argc, argv)
                argc--;
                disk = *argv;
        }
                argc--;
                disk = *argv;
        }
+       if (strcmp(tape, "-") == 0) {
+               pipeout++;
+               tape = "standard output";
+       }
 
        /*
         * Determine how to default tape size and density
 
        /*
         * Determine how to default tape size and density
@@ -280,11 +284,14 @@ main(argc, argv)
 
        putitime();
 #ifndef RDUMP
 
        putitime();
 #ifndef RDUMP
-       close(to);
+       if (!pipeout) {
+               close(to);
+               rewind();
+       }
 #else
        tflush(1);
 #else
        tflush(1);
-#endif
        rewind();
        rewind();
+#endif
        broadcast("DUMP IS DONE!\7\7\n");
        Exit(X_FINOK);
 }
        broadcast("DUMP IS DONE!\7\7\n");
        Exit(X_FINOK);
 }
@@ -299,6 +306,10 @@ int        sigterm(){      msg("SIGTERM()  try rewriting\n"); sigAbort();}
 
 sigAbort()
 {
 
 sigAbort()
 {
+       if (pipeout) {
+               msg("Unknown signal, cannot recover\n");
+               dumpabort();
+       }
        msg("Rewriting attempted as response to unknown signal.\n");
        fflush(stderr);
        fflush(stdout);
        msg("Rewriting attempted as response to unknown signal.\n");
        fflush(stderr);
        fflush(stdout);
index f588c70..a205703 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)tape.c      1.6 (Berkeley) %G%";
+static char *sccsid = "@(#)tape.c      1.7 (Berkeley) %G%";
 #include "dump.h"
 
 char   (*tblock)[TP_BSIZE];    /* Pointer to malloc()ed buffer for tape */
 #include "dump.h"
 
 char   (*tblock)[TP_BSIZE];    /* Pointer to malloc()ed buffer for tape */
@@ -72,6 +72,12 @@ flusht()
 
        trecno = 0;
        if (write(to, tblock[0], writesize) != writesize){
 
        trecno = 0;
        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?")){
@@ -96,7 +102,7 @@ flusht()
        asize += writesize/density;
        asize += 7;
        blockswritten += ntrec;
        asize += writesize/density;
        asize += 7;
        blockswritten += ntrec;
-       if (asize > tsize) {
+       if (!pipeout && asize > tsize) {
                close_rewind();
                otape();
        }
                close_rewind();
                otape();
        }
@@ -107,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);
@@ -124,6 +133,9 @@ rewind()
 
 close_rewind()
 {
 
 close_rewind()
 {
+
+       if (pipeout)
+               return;
        close(to);
        if (!nogripe){
                rewind();
        close(to);
        if (!nogripe){
                rewind();
@@ -236,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();