date and time created 89/04/02 12:30:51 by bostic
[unix-history] / usr / src / sbin / dump / main.c
index 816a56a..541d302 100644 (file)
@@ -1,4 +1,13 @@
-static char *sccsid = "@(#)main.c      1.12 (Berkeley) %G%";
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)main.c     5.6 (Berkeley) %G%";
+#endif not lint
+
 #include "dump.h"
 
 int    notify = 0;     /* notify operator flag */
 #include "dump.h"
 
 int    notify = 0;     /* notify operator flag */
@@ -7,16 +16,19 @@ int  tapeno = 0;     /* current tape number */
 int    density = 0;    /* density in bytes/0.1" */
 int    ntrec = NTREC;  /* # tape blocks in each tape record */
 int    cartridge = 0;  /* Assume non-cartridge tape */
 int    density = 0;    /* density in bytes/0.1" */
 int    ntrec = NTREC;  /* # tape blocks in each tape record */
 int    cartridge = 0;  /* Assume non-cartridge tape */
+long   dev_bsize = 1;  /* recalculated below */
 #ifdef RDUMP
 char   *host;
 #endif
 #ifdef RDUMP
 char   *host;
 #endif
+int    anydskipped;    /* set true in mark() if any directories are skipped */
+                       /* this lets us avoid map pass 2 in some cases */
 
 main(argc, argv)
        int     argc;
        char    *argv[];
 {
        char            *arg;
 
 main(argc, argv)
        int     argc;
        char    *argv[];
 {
        char            *arg;
-       int             i;
+       int             bflag = 0, i;
        float           fetapes;
        register        struct  fstab   *dt;
 
        float           fetapes;
        register        struct  fstab   *dt;
 
@@ -26,6 +38,7 @@ main(argc, argv)
        tape = TAPE;
        disk = DISK;
        increm = NINCREM;
        tape = TAPE;
        disk = DISK;
        increm = NINCREM;
+       temp = TEMP;
        if (TP_BSIZE / DEV_BSIZE == 0 || TP_BSIZE % DEV_BSIZE != 0) {
                msg("TP_BSIZE must be a multiple of DEV_BSIZE\n");
                dumpabort();
        if (TP_BSIZE / DEV_BSIZE == 0 || TP_BSIZE % DEV_BSIZE != 0) {
                msg("TP_BSIZE must be a multiple of DEV_BSIZE\n");
                dumpabort();
@@ -51,11 +64,6 @@ main(argc, argv)
                exit(0);                /* do nothing else */
                break;
 
                exit(0);                /* do nothing else */
                break;
 
-       case 'J':                       /* update old to new */
-               o_nconvert();
-               exit(0);                /* do nothing else */
-               break;
-
        case 'f':                       /* output file */
                if(argc > 1) {
                        argv++;
        case 'f':                       /* output file */
                if(argc > 1) {
                        argv++;
@@ -69,6 +77,8 @@ main(argc, argv)
                        argv++;
                        argc--;
                        density = atoi(*argv) / 10;
                        argv++;
                        argc--;
                        density = atoi(*argv) / 10;
+                       if (density >= 625 && !bflag)
+                               ntrec = HIGHDENSITYTREC;
                }
                break;
 
                }
                break;
 
@@ -85,6 +95,7 @@ main(argc, argv)
                if(argc > 1) {
                        argv++;
                        argc--;
                if(argc > 1) {
                        argv++;
                        argc--;
+                       bflag++;
                        ntrec = atol(*argv);
                }
                break;
                        ntrec = atol(*argv);
                }
                break;
@@ -134,25 +145,26 @@ main(argc, argv)
         *              density                         tape size
         * 9-track      1600 bpi (160 bytes/.1")        2300 ft.
         * 9-track      6250 bpi (625 bytes/.1")        2300 ft.
         *              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)
+        * cartridge    8000 bpi (100 bytes/.1")        1700 ft. (450*4 - slop)
         */
        if (density == 0)
                density = cartridge ? 100 : 160;
        if (tsize == 0)
         */
        if (density == 0)
                density = cartridge ? 100 : 160;
        if (tsize == 0)
-               tsize = cartridge ? 4000L*120L : 2300L*120L;
+               tsize = cartridge ? 1700L*120L : 2300L*120L;
 
 #ifdef RDUMP
        { char *index();
          host = tape;
          tape = index(host, ':');
          if (tape == 0) {
 
 #ifdef RDUMP
        { char *index();
          host = tape;
          tape = index(host, ':');
          if (tape == 0) {
-               msg("need keyletter ``f'' and device ``host:tape''");
+               msg("need keyletter ``f'' and device ``host:tape''\n");
                exit(1);
          }
          *tape++ = 0;
          if (rmthost(host) == 0)
                exit(X_ABORT);
        }
                exit(1);
          }
          *tape++ = 0;
          if (rmthost(host) == 0)
                exit(X_ABORT);
        }
+       setuid(getuid());       /* rmthost() is the only reason to be setuid */
 #endif
        if (signal(SIGHUP, sighup) == SIG_IGN)
                signal(SIGHUP, SIG_IGN);
 #endif
        if (signal(SIGHUP, sighup) == SIG_IGN)
                signal(SIGHUP, SIG_IGN);
@@ -180,12 +192,23 @@ main(argc, argv)
         *      the file system name with or without the leading '/'.
         */
        dt = fstabsearch(disk);
         *      the file system name with or without the leading '/'.
         */
        dt = fstabsearch(disk);
-       if (dt != 0)
+       if (dt != 0) {
                disk = rawname(dt->fs_spec);
                disk = rawname(dt->fs_spec);
+               strncpy(spcl.c_dev, dt->fs_spec, NAMELEN);
+               strncpy(spcl.c_filesys, dt->fs_file, NAMELEN);
+       } else {
+               strncpy(spcl.c_dev, disk, NAMELEN);
+               strncpy(spcl.c_filesys, "an unlisted file system", NAMELEN);
+       }
+       strcpy(spcl.c_label, "none");
+       gethostname(spcl.c_host, NAMELEN);
+       spcl.c_level = incno - '0';
+       spcl.c_type = TS_TAPE;
        getitime();             /* /etc/dumpdates snarfed */
 
        msg("Date of this level %c dump: %s\n", incno, prdate(spcl.c_date));
        getitime();             /* /etc/dumpdates snarfed */
 
        msg("Date of this level %c dump: %s\n", incno, prdate(spcl.c_date));
-       msg("Date of last level %c dump: %s\n", incno, prdate(spcl.c_ddate));
+       msg("Date of last level %c dump: %s\n",
+               lastincno, prdate(spcl.c_ddate));
        msg("Dumping %s ", disk);
        if (dt != 0)
                msgtail("(%s) ", dt->fs_file);
        msg("Dumping %s ", disk);
        if (dt != 0)
                msgtail("(%s) ", dt->fs_file);
@@ -203,25 +226,30 @@ main(argc, argv)
        esize = 0;
        sblock = (struct fs *)buf;
        sync();
        esize = 0;
        sblock = (struct fs *)buf;
        sync();
-       bread(SBLOCK, sblock, SBSIZE);
+       bread(SBOFF, sblock, SBSIZE);
        if (sblock->fs_magic != FS_MAGIC) {
                msg("bad sblock magic number\n");
                dumpabort();
        }
        if (sblock->fs_magic != FS_MAGIC) {
                msg("bad sblock magic number\n");
                dumpabort();
        }
+       dev_bsize = sblock->fs_fsize / fsbtodb(sblock, 1);
        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));
 
        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));
 
+       anydskipped = 0;
        msg("mapping (Pass I) [regular files]\n");
        pass(mark, (char *)NULL);               /* mark updates esize */
 
        msg("mapping (Pass I) [regular files]\n");
        pass(mark, (char *)NULL);               /* mark updates esize */
 
-       do {
+       if (anydskipped) {
+               do {
+                       msg("mapping (Pass II) [directories]\n");
+                       nadded = 0;
+                       pass(add, dirmap);
+               } while(nadded);
+       } else                          /* keep the operators happy */
                msg("mapping (Pass II) [directories]\n");
                msg("mapping (Pass II) [directories]\n");
-               nadded = 0;
-               pass(add, dirmap);
-       } while(nadded);
 
        bmapest(clrmap);
        bmapest(nodmap);
 
        bmapest(clrmap);
        bmapest(nodmap);
@@ -251,7 +279,6 @@ main(argc, argv)
                          esize         /* blocks */
                        * (1.0/ntrec)   /* IRG's / block */
                        * tenthsperirg  /* 0.1" / IRG */
                          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 */
                ) * (1.0 / tsize );     /* tape / 0.1" */
        }
        etapes = fetapes;               /* truncating assignment */
@@ -269,7 +296,7 @@ main(argc, argv)
        bitmap(clrmap, TS_CLRI);
 
        msg("dumping (Pass III) [directories]\n");
        bitmap(clrmap, TS_CLRI);
 
        msg("dumping (Pass III) [directories]\n");
-       pass(dump, dirmap);
+       pass(dirdump, dirmap);
 
        msg("dumping (Pass IV) [regular files]\n");
        pass(dump, nodmap);
 
        msg("dumping (Pass IV) [regular files]\n");
        pass(dump, nodmap);