add rps and minfree arguments
[unix-history] / usr / src / sbin / dump / main.c
index 3e4f8d0..2eb3a78 100644 (file)
@@ -1,27 +1,35 @@
-static char *sccsid = "@(#)main.c      1.1 (Berkeley) %G%";
+static char *sccsid = "@(#)main.c      1.11 (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
 
 main(argc, argv)
        int     argc;
        char    *argv[];
 {
        char            *arg;
 
 main(argc, argv)
        int     argc;
        char    *argv[];
 {
        char            *arg;
-       register        i;
+       int             i;
        float           fetapes;
        register        struct  fstab   *dt;
 
        time(&(spcl.c_date));
 
        float           fetapes;
        register        struct  fstab   *dt;
 
        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;
-
+       if (TP_BSIZE / DEV_BSIZE == 0 || TP_BSIZE % DEV_BSIZE != 0) {
+               msg("TP_BSIZE must be a multiple of DEV_BSIZE\n");
+               dumpabort();
+       }
        incno = '9';
        uflag = 0;
        arg = "u";
        incno = '9';
        uflag = 0;
        arg = "u";
@@ -34,8 +42,12 @@ main(argc, argv)
        }
        while(*arg)
        switch (*arg++) {
        }
        while(*arg)
        switch (*arg++) {
+       case 'w':
+               lastdump('w');          /* tell us only what has to be done */
+               exit(0);
+               break;
        case 'W':                       /* what to do */
        case 'W':                       /* what to do */
-               lastdump();
+               lastdump('W');          /* tell us the current state of what has been done */
                exit(0);                /* do nothing else */
                break;
 
                exit(0);                /* do nothing else */
                break;
 
@@ -69,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':
@@ -100,6 +124,32 @@ main(argc, argv)
                disk = *argv;
        }
 
                disk = *argv;
        }
 
+       /*
+        * 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)
@@ -135,20 +185,33 @@ main(argc, argv)
        msg("Dumping %s ", disk);
        if (dt != 0)
                msgtail("(%s) ", dt->fs_file);
        msg("Dumping %s ", disk);
        if (dt != 0)
                msgtail("(%s) ", dt->fs_file);
+#ifdef RDUMP
+       msgtail("to %s on host %s\n", tape, host);
+#else
        msgtail("to %s\n", tape);
        msgtail("to %s\n", tape);
+#endif
 
        fi = open(disk, 0);
        if (fi < 0) {
                msg("Cannot open %s\n", disk);
                Exit(X_ABORT);
        }
 
        fi = open(disk, 0);
        if (fi < 0) {
                msg("Cannot open %s\n", disk);
                Exit(X_ABORT);
        }
-       CLR(clrmap);
-       CLR(dirmap);
-       CLR(nodmap);
        esize = 0;
        esize = 0;
+       sblock = (struct fs *)buf;
+       sync();
+       bread(SBLOCK, sblock, SBSIZE);
+       if (sblock->fs_magic != FS_MAGIC) {
+               msg("bad sblock magic number\n");
+               dumpabort();
+       }
+       msiz = roundup(howmany(sblock->fs_ipg * sblock->fs_ncg, NBBY),
+               TP_BSIZE);
+       clrmap = (char *)calloc(msiz, sizeof(char));
+       dirmap = (char *)calloc(msiz, sizeof(char));
+       nodmap = (char *)calloc(msiz, sizeof(char));
 
        msg("mapping (Pass I) [regular files]\n");
 
        msg("mapping (Pass I) [regular files]\n");
-       pass(mark, (short *)NULL);              /* mark updates esize */
+       pass(mark, (char *)NULL);               /* mark updates esize */
 
        do {
                msg("mapping (Pass II) [directories]\n");
 
        do {
                msg("mapping (Pass II) [directories]\n");
@@ -159,24 +222,44 @@ main(argc, argv)
        bmapest(clrmap);
        bmapest(nodmap);
 
        bmapest(clrmap);
        bmapest(nodmap);
 
-       fetapes =
-               (        esize          /* blocks */
-                       *BSIZE          /* bytes / block */
-                       *(1.0/density)  /* 0.1" / byte */
+       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)    /* IRG's / block */
-                       *7              /* 0.1" / IRG */
-               ) * (1.0 / tsize )      /* tape / 0.1" */
-       ;
+                         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 */
+                       * (1.0/ntrec)   /* IRG's / block */
+                       * tenthsperirg  /* 0.1" / IRG */
+                       * 7             /* 0.1" / IRG */
+               ) * (1.0 / tsize );     /* tape / 0.1" */
+       }
        etapes = fetapes;               /* truncating assignment */
        etapes++;
        etapes = fetapes;               /* truncating assignment */
        etapes++;
-       /*
-        *      esize is typically about 5% too low; we frob it here
-        */
-       esize += ((5*esize)/100);
+       /* count the nodemap on each additional tape */
+       for (i = 1; i < etapes; i++)
+               bmapest(nodmap);
+       esize += i + 10;        /* headers + 10 trailer blocks */
        msg("estimated %ld tape blocks on %3.2f tape(s).\n", esize, fetapes);
 
        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);
@@ -188,13 +271,19 @@ main(argc, argv)
        pass(dump, nodmap);
 
        spcl.c_type = TS_END;
        pass(dump, nodmap);
 
        spcl.c_type = TS_END;
-       for(i=0; i<NTREC; i++)
+#ifndef RDUMP
+       for(i=0; i<ntrec; i++)
                spclrec();
                spclrec();
+#endif
        msg("DUMP: %ld tape blocks on %d tape(s)\n",spcl.c_tapea,spcl.c_volume);
        msg("DUMP IS DONE\n");
 
        putitime();
        msg("DUMP: %ld tape blocks on %d tape(s)\n",spcl.c_tapea,spcl.c_volume);
        msg("DUMP IS DONE\n");
 
        putitime();
+#ifndef RDUMP
        close(to);
        close(to);
+#else
+       tflush(1);
+#endif
        rewind();
        broadcast("DUMP IS DONE!\7\7\n");
        Exit(X_FINOK);
        rewind();
        broadcast("DUMP IS DONE!\7\7\n");
        Exit(X_FINOK);
@@ -221,6 +310,7 @@ char *rawname(cp)
        char *cp;
 {
        static char rawbuf[32];
        char *cp;
 {
        static char rawbuf[32];
+       char *rindex();
        char *dp = rindex(cp, '/');
 
        if (dp == 0)
        char *dp = rindex(cp, '/');
 
        if (dp == 0)