add Kerberos info
[unix-history] / usr / src / sbin / restore / main.c
index dfbb58e..fe9d358 100644 (file)
@@ -1,8 +1,19 @@
-/* Copyright (c) 1983 Regents of the University of California */
+/*
+ * Copyright (c) 1983 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1983 The Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
 
 #ifndef lint
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     3.3     (Berkeley)      83/02/27";
-#endif
+static char sccsid[] = "@(#)main.c     5.8 (Berkeley) %G%";
+#endif /* not lint */
 
 /*
  *     Modified to recursively extract all files within a subtree
 
 /*
  *     Modified to recursively extract all files within a subtree
@@ -17,24 +28,28 @@ static char sccsid[] = "@(#)main.c  3.3     (Berkeley)      83/02/27";
  *     tape read errors.
  *     1/19/82         by Kirk McKusick
  *
  *     tape read errors.
  *     1/19/82         by Kirk McKusick
  *
- *     Full incremental restore running entirely in user code.
+ *     Full incremental restore running entirely in user code and
+ *     interactive tape browser.
  *     1/19/83         by Kirk McKusick
  */
 
 #include "restore.h"
  *     1/19/83         by Kirk McKusick
  */
 
 #include "restore.h"
-#include <signal.h>
+#include <protocols/dumprestore.h>
+#include <sys/signal.h>
+#include "pathnames.h"
 
 
-int    cvtflag = 0, dflag = 0, vflag = 0, yflag = 0;
-int    hflag = 1, mflag = 1;
+int    bflag = 0, cvtflag = 0, dflag = 0, vflag = 0, yflag = 0;
+int    hflag = 1, mflag = 1, Nflag = 0;
 char   command = '\0';
 long   dumpnum = 1;
 char   command = '\0';
 long   dumpnum = 1;
-long   volno = 1;
+long   volno = 0;
+long   ntrec;
 char   *dumpmap;
 char   *clrimap;
 ino_t  maxino;
 time_t dumptime;
 time_t dumpdate;
 char   *dumpmap;
 char   *clrimap;
 ino_t  maxino;
 time_t dumptime;
 time_t dumpdate;
-struct entry **entry;
+FILE   *terminal;
 
 main(argc, argv)
        int argc;
 
 main(argc, argv)
        int argc;
@@ -42,20 +57,24 @@ main(argc, argv)
 {
        register char *cp;
        ino_t ino;
 {
        register char *cp;
        ino_t ino;
-       char *inputdev = "/dev/rmt8";
+       char *inputdev = _PATH_DEFTAPE;
        char *symtbl = "./restoresymtable";
        char *symtbl = "./restoresymtable";
-       char *dirmodefile = "./dirmodes";
-       int (*signal())();
-       extern int onintr();
+       char name[MAXPATHLEN];
+       void onintr();
 
        if (signal(SIGINT, onintr) == SIG_IGN)
 
        if (signal(SIGINT, onintr) == SIG_IGN)
-               signal(SIGINT, SIG_IGN);
+               (void) signal(SIGINT, SIG_IGN);
        if (signal(SIGTERM, onintr) == SIG_IGN)
        if (signal(SIGTERM, onintr) == SIG_IGN)
-               signal(SIGTERM, SIG_IGN);
+               (void) signal(SIGTERM, SIG_IGN);
        setlinebuf(stderr);
        if (argc < 2) {
 usage:
        setlinebuf(stderr);
        if (argc < 2) {
 usage:
-               fprintf(stderr, "Usage: restor xtfhmsvy file file... or restor rRfsvy\n");
+               fprintf(stderr, "Usage:\n%s%s%s%s%s",
+                       "\trestore tfhsvy [file file ...]\n",
+                       "\trestore xfhmsvy [file file ...]\n",
+                       "\trestore ifhmsvy\n",
+                       "\trestore rfsvy\n",
+                       "\trestore Rfsvy\n");
                done(1);
        }
        argv++;
                done(1);
        }
        argv++;
@@ -77,6 +96,9 @@ usage:
                case 'm':
                        mflag = 0;
                        break;
                case 'm':
                        mflag = 0;
                        break;
+               case 'N':
+                       Nflag++;
+                       break;
                case 'v':
                        vflag++;
                        break;
                case 'v':
                        vflag++;
                        break;
@@ -84,13 +106,37 @@ usage:
                        yflag++;
                        break;
                case 'f':
                        yflag++;
                        break;
                case 'f':
+                       if (argc < 1) {
+                               fprintf(stderr, "missing device specifier\n");
+                               done(1);
+                       }
                        inputdev = *argv++;
                        argc--;
                        break;
                        inputdev = *argv++;
                        argc--;
                        break;
+               case 'b':
+                       /*
+                        * change default tape blocksize
+                        */
+                       bflag++;
+                       if (argc < 1) {
+                               fprintf(stderr, "missing block size\n");
+                               done(1);
+                       }
+                       ntrec = atoi(*argv++);
+                       if (ntrec <= 0) {
+                               fprintf(stderr, "Block size must be a positive integer\n");
+                               done(1);
+                       }
+                       argc--;
+                       break;
                case 's':
                        /*
                         * dumpnum (skip to) for multifile dump tapes
                         */
                case 's':
                        /*
                         * dumpnum (skip to) for multifile dump tapes
                         */
+                       if (argc < 1) {
+                               fprintf(stderr, "missing dump number\n");
+                               done(1);
+                       }
                        dumpnum = atoi(*argv++);
                        if (dumpnum <= 0) {
                                fprintf(stderr, "Dump number must be a positive integer\n");
                        dumpnum = atoi(*argv++);
                        if (dumpnum <= 0) {
                                fprintf(stderr, "Dump number must be a positive integer\n");
@@ -99,40 +145,17 @@ usage:
                        argc--;
                        break;
                case 't':
                        argc--;
                        break;
                case 't':
-                       if (command != '\0') {
-                               fprintf(stderr,
-                                       "t and %c are mutually exclusive\n",
-                                       command);
-                               goto usage;
-                       }
-                       command = 't';
-                       break;
                case 'R':
                case 'R':
-                       if (command != '\0') {
-                               fprintf(stderr,
-                                       "R and %c are mutually exclusive\n",
-                                       command);
-                               goto usage;
-                       }
-                       command = 'R';
-                       break;
                case 'r':
                case 'r':
-                       if (command != '\0') {
-                               fprintf(stderr,
-                                       "r and %c are mutually exclusive\n",
-                                       command);
-                               goto usage;
-                       }
-                       command = 'r';
-                       break;
                case 'x':
                case 'x':
+               case 'i':
                        if (command != '\0') {
                                fprintf(stderr,
                        if (command != '\0') {
                                fprintf(stderr,
-                                       "x and %c are mutually exclusive\n",
-                                       command);
+                                       "%c and %c are mutually exclusive\n",
+                                       *cp, command);
                                goto usage;
                        }
                                goto usage;
                        }
-                       command = 'x';
+                       command = *cp;
                        break;
                default:
                        fprintf(stderr, "Bad key character %c\n", *cp);
                        break;
                default:
                        fprintf(stderr, "Bad key character %c\n", *cp);
@@ -140,7 +163,7 @@ usage:
                }
        }
        if (command == '\0') {
                }
        }
        if (command == '\0') {
-               fprintf(stderr, "must specify t, r, R, or x\n");
+               fprintf(stderr, "must specify i, t, r, R, or x\n");
                goto usage;
        }
        setinput(inputdev);
                goto usage;
        }
        setinput(inputdev);
@@ -149,75 +172,45 @@ usage:
                *--argv = ".";
        }
        switch (command) {
                *--argv = ".";
        }
        switch (command) {
-
-       case 't':
+       /*
+        * Interactive mode.
+        */
+       case 'i':
                setup();
                setup();
-               extractdirs((char *)0);
-               while (argc--) {
-                       if ((ino = psearch(*argv)) == 0 ||
-                           BIT(ino, dumpmap) == 0) {
-                               fprintf(stderr, "%s: not on tape\n", *argv++);
-                               continue;
-                       }
-                       treescan(*argv++, ino, listfile);
-               }
+               extractdirs(1);
+               initsymtable((char *)0);
+               runcmdshell();
                done(0);
                done(0);
-
-       case 'x':
-               setup();
-               extractdirs(dirmodefile);
-               entry = (struct entry **)
-                       calloc((int)maxino, sizeof(struct entry *));
-               if (entry == (struct entry **)NIL)
-                       panic("no memory for entry table\n");
-               (void)addentry(".", ROOTINO, NODE);
-               while (argc--) {
-                       if ((ino = psearch(*argv)) == 0 ||
-                           BIT(ino, dumpmap) == 0) {
-                               fprintf(stderr, "%s: not on tape\n", *argv++);
-                               continue;
-                       }
-                       if (mflag)
-                               pathcheck(*argv, NEW);
-                       if (hflag)
-                               treescan(*argv++, ino, addfile);
-                       else
-                               addfile(*argv++, ino, LEAF);
-               }
-               createnodes();
-               createfiles();
-               createlinks();
-               setdirmodes(dirmodefile);
-               if (dflag)
-                       checkrestore();
-               done(0);
-
+       /*
+        * Incremental restoration of a file system.
+        */
        case 'r':
                setup();
                if (dumptime > 0) {
        case 'r':
                setup();
                if (dumptime > 0) {
+                       /*
+                        * This is an incremental dump tape.
+                        */
+                       vprintf(stdout, "Begin incremental restore\n");
                        initsymtable(symtbl);
                        initsymtable(symtbl);
+                       extractdirs(1);
+                       removeoldleaves();
+                       vprintf(stdout, "Calculate node updates.\n");
+                       treescan(".", ROOTINO, nodeupdates);
+                       findunreflinks();
+                       removeoldnodes();
                } else {
                } else {
-                       entry = (struct entry **)
-                               calloc((int)maxino, sizeof(struct entry *));
-                       if (entry == (struct entry **)NIL)
-                               panic("no memory for entry table\n");
-                       (void)addentry(".", ROOTINO, NODE);
+                       /*
+                        * This is a level zero dump tape.
+                        */
+                       vprintf(stdout, "Begin level 0 restore\n");
+                       initsymtable((char *)0);
+                       extractdirs(1);
+                       vprintf(stdout, "Calculate extraction list.\n");
+                       treescan(".", ROOTINO, nodeupdates);
                }
                }
-               extractdirs(dirmodefile);
-               markremove();
-               if ((ino = psearch(".")) == 0 || BIT(ino, dumpmap) == 0)
-                       panic("Root directory is not on tape\n");
-               vprintf(stdout, "Calculate extraction list.\n");
-               treescan(".", ino, markfile);
-               findunref();
-               removeleaves();
-               renamenodes();
-               createnodes();
-               renameleaves();
-               removenodes();
                createleaves(symtbl);
                createlinks();
                createleaves(symtbl);
                createlinks();
-               setdirmodes(dirmodefile);
+               setdirmodes();
                checkrestore();
                if (dflag) {
                        vprintf(stdout, "Verify the directory structure\n");
                checkrestore();
                if (dflag) {
                        vprintf(stdout, "Verify the directory structure\n");
@@ -225,14 +218,55 @@ usage:
                }
                dumpsymtable(symtbl, (long)1);
                done(0);
                }
                dumpsymtable(symtbl, (long)1);
                done(0);
-
+       /*
+        * Resume an incremental file system restoration.
+        */
        case 'R':
                initsymtable(symtbl);
        case 'R':
                initsymtable(symtbl);
+               skipmaps();
+               skipdirs();
                createleaves(symtbl);
                createlinks();
                createleaves(symtbl);
                createlinks();
-               setdirmodes(dirmodefile);
+               setdirmodes();
                checkrestore();
                dumpsymtable(symtbl, (long)1);
                done(0);
                checkrestore();
                dumpsymtable(symtbl, (long)1);
                done(0);
+       /*
+        * List contents of tape.
+        */
+       case 't':
+               setup();
+               extractdirs(0);
+               initsymtable((char *)0);
+               while (argc--) {
+                       canon(*argv++, name);
+                       ino = dirlookup(name);
+                       if (ino == 0)
+                               continue;
+                       treescan(name, ino, listfile);
+               }
+               done(0);
+       /*
+        * Batch extraction of tape contents.
+        */
+       case 'x':
+               setup();
+               extractdirs(1);
+               initsymtable((char *)0);
+               while (argc--) {
+                       canon(*argv++, name);
+                       ino = dirlookup(name);
+                       if (ino == 0)
+                               continue;
+                       if (mflag)
+                               pathcheck(name);
+                       treescan(name, ino, addfile);
+               }
+               createfiles();
+               createlinks();
+               setdirmodes();
+               if (dflag)
+                       checkrestore();
+               done(0);
        }
 }
        }
 }