date and time created 89/04/02 12:30:51 by bostic
[unix-history] / usr / src / sbin / dump / main.c
index e7ddfef..541d302 100644 (file)
@@ -1,4 +1,13 @@
-static char *sccsid = "@(#)main.c      1.16 (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;
 
@@ -65,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;
 
@@ -81,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;
@@ -142,13 +157,14 @@ main(argc, argv)
          host = tape;
          tape = index(host, ':');
          if (tape == 0) {
          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);
@@ -176,8 +192,18 @@ 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));
@@ -200,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);
@@ -265,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);