re-read /etc/dumpdates before updating it
[unix-history] / usr / src / sbin / dump / main.c
index 24dd38a..816a56a 100644 (file)
@@ -1,10 +1,12 @@
-static char *sccsid = "@(#)main.c      1.7 (Berkeley) %G%";
+static char *sccsid = "@(#)main.c      1.12 (Berkeley) %G%";
 #include "dump.h"
 
 int    notify = 0;     /* notify operator flag */
 int    blockswritten = 0;      /* number of blocks written on current tape */
 int    tapeno = 0;     /* current tape number */
 #include "dump.h"
 
 int    notify = 0;     /* notify operator flag */
 int    blockswritten = 0;      /* number of blocks written on current tape */
 int    tapeno = 0;     /* current tape number */
-int    density = 160;  /* density in 0.1" units */
+int    density = 0;    /* density in bytes/0.1" */
+int    ntrec = NTREC;  /* # tape blocks in each tape record */
+int    cartridge = 0;  /* Assume non-cartridge tape */
 #ifdef RDUMP
 char   *host;
 #endif
 #ifdef RDUMP
 char   *host;
 #endif
@@ -20,7 +22,7 @@ main(argc, argv)
 
        time(&(spcl.c_date));
 
 
        time(&(spcl.c_date));
 
-       tsize = 2300L*12L*10L;
+       tsize = 0;      /* Default later, based on 'c' option for cart tapes */
        tape = TAPE;
        disk = DISK;
        increm = NINCREM;
        tape = TAPE;
        disk = DISK;
        increm = NINCREM;
@@ -31,16 +33,6 @@ main(argc, argv)
        incno = '9';
        uflag = 0;
        arg = "u";
        incno = '9';
        uflag = 0;
        arg = "u";
-#ifdef RDUMP
-       if (argc < 2) {
-               printf("usage: rdump machine ");
-               Exit(X_ABORT);
-       }
-       host = argv[1];
-       argv++, argc--;
-       if (rmthost(host) == 0)
-               Exit(X_ABORT);
-#endif
        if(argc > 1) {
                argv++;
                argc--;
        if(argc > 1) {
                argv++;
                argc--;
@@ -89,6 +81,18 @@ main(argc, argv)
                }
                break;
 
                }
                break;
 
+       case 'b':                       /* blocks per tape write */
+               if(argc > 1) {
+                       argv++;
+                       argc--;
+                       ntrec = atol(*argv);
+               }
+               break;
+
+       case 'c':                       /* Tape is cart. not 9-track */
+               cartridge++;
+               break;
+
        case '0':                       /* dump level */
        case '1':
        case '2':
        case '0':                       /* dump level */
        case '1':
        case '2':
@@ -111,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) {
@@ -119,7 +123,37 @@ 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
+        *
+        *              density                         tape size
+        * 9-track      1600 bpi (160 bytes/.1")        2300 ft.
+        * 9-track      6250 bpi (625 bytes/.1")        2300 ft.
+        * cartridge    8000 bpi (100 bytes/.1")        4000 ft. (450*9 - slop)
+        */
+       if (density == 0)
+               density = cartridge ? 100 : 160;
+       if (tsize == 0)
+               tsize = cartridge ? 4000L*120L : 2300L*120L;
+
+#ifdef RDUMP
+       { char *index();
+         host = tape;
+         tape = index(host, ':');
+         if (tape == 0) {
+               msg("need keyletter ``f'' and device ``host:tape''");
+               exit(1);
+         }
+         *tape++ = 0;
+         if (rmthost(host) == 0)
+               exit(X_ABORT);
+       }
+#endif
        if (signal(SIGHUP, sighup) == SIG_IGN)
                signal(SIGHUP, SIG_IGN);
        if (signal(SIGTRAP, sigtrap) == SIG_IGN)
        if (signal(SIGHUP, sighup) == SIG_IGN)
                signal(SIGHUP, SIG_IGN);
        if (signal(SIGTRAP, sigtrap) == SIG_IGN)
@@ -156,8 +190,7 @@ main(argc, argv)
        if (dt != 0)
                msgtail("(%s) ", dt->fs_file);
 #ifdef RDUMP
        if (dt != 0)
                msgtail("(%s) ", dt->fs_file);
 #ifdef RDUMP
-       msgtail("to %s", tape);
-       msgtail(" on host %s\n", host);
+       msgtail("to %s on host %s\n", tape, host);
 #else
        msgtail("to %s\n", tape);
 #endif
 #else
        msgtail("to %s\n", tape);
 #endif
@@ -193,16 +226,34 @@ main(argc, argv)
        bmapest(clrmap);
        bmapest(nodmap);
 
        bmapest(clrmap);
        bmapest(nodmap);
 
-       fetapes =
+       if (cartridge) {
+               /* Estimate number of tapes, assuming streaming stops at
+                  the end of each block written, and not in mid-block.
+                  Assume no erroneous blocks; this can be compensated for
+                  with an artificially low tape size. */
+               fetapes = 
+               (         esize         /* blocks */
+                       * TP_BSIZE      /* bytes/block */
+                       * (1.0/density) /* 0.1" / byte */
+                 +
+                         esize         /* blocks */
+                       * (1.0/ntrec)   /* streaming-stops per block */
+                       * 15.48         /* 0.1" / streaming-stop */
+               ) * (1.0 / tsize );     /* tape / 0.1" */
+       } else {
+               /* Estimate number of tapes, for old fashioned 9-track tape */
+               int tenthsperirg = (density == 625) ? 3 : 7;
+               fetapes =
                (         esize         /* blocks */
                        * TP_BSIZE      /* bytes / block */
                        * (1.0/density) /* 0.1" / byte */
                  +
                          esize         /* blocks */
                (         esize         /* blocks */
                        * TP_BSIZE      /* bytes / block */
                        * (1.0/density) /* 0.1" / byte */
                  +
                          esize         /* blocks */
-                       * (1.0/NTREC)   /* IRG's / block */
+                       * (1.0/ntrec)   /* IRG's / block */
+                       * tenthsperirg  /* 0.1" / IRG */
                        * 7             /* 0.1" / IRG */
                        * 7             /* 0.1" / IRG */
-               ) * (1.0 / tsize )      /* tape / 0.1" */
-       ;
+               ) * (1.0 / tsize );     /* tape / 0.1" */
+       }
        etapes = fetapes;               /* truncating assignment */
        etapes++;
        /* count the nodemap on each additional tape */
        etapes = fetapes;               /* truncating assignment */
        etapes++;
        /* count the nodemap on each additional tape */
@@ -211,6 +262,8 @@ main(argc, argv)
        esize += i + 10;        /* headers + 10 trailer blocks */
        msg("estimated %ld tape blocks on %3.2f tape(s).\n", esize, fetapes);
 
        esize += i + 10;        /* headers + 10 trailer blocks */
        msg("estimated %ld tape blocks on %3.2f tape(s).\n", esize, fetapes);
 
+       alloctape();                    /* Allocate tape buffer */
+
        otape();                        /* bitmap is the first to tape write */
        time(&(tstart_writing));
        bitmap(clrmap, TS_CLRI);
        otape();                        /* bitmap is the first to tape write */
        time(&(tstart_writing));
        bitmap(clrmap, TS_CLRI);
@@ -223,7 +276,7 @@ main(argc, argv)
 
        spcl.c_type = TS_END;
 #ifndef RDUMP
 
        spcl.c_type = TS_END;
 #ifndef RDUMP
-       for(i=0; i<NTREC; i++)
+       for(i=0; i<ntrec; i++)
                spclrec();
 #endif
        msg("DUMP: %ld tape blocks on %d tape(s)\n",spcl.c_tapea,spcl.c_volume);
                spclrec();
 #endif
        msg("DUMP: %ld tape blocks on %d tape(s)\n",spcl.c_tapea,spcl.c_volume);
@@ -231,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);
 }
@@ -250,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);