|
|
1.1 root 1: /*
2: * Copyright (c) 1983 The Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that: (1) source distributions retain this entire copyright
7: * notice and comment, and (2) distributions including binaries display
8: * the following acknowledgement: ``This product includes software
9: * developed by the University of California, Berkeley and its contributors''
10: * in the documentation or other materials provided with the distribution
11: * and in all advertising materials mentioning features or use of this
12: * software. Neither the name of the University nor the names of its
13: * contributors may be used to endorse or promote products derived
14: * from this software without specific prior written permission.
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18: */
19:
20: #ifndef lint
21: char copyright[] =
22: "@(#) Copyright (c) 1983 The Regents of the University of California.\n\
23: All rights reserved.\n";
24: #endif /* not lint */
25:
26: #ifndef lint
27: static char sccsid[] = "@(#)main.c 5.8 (Berkeley) 6/1/90";
28: #endif /* not lint */
29:
30: /*
31: * Modified to recursively extract all files within a subtree
32: * (supressed by the h option) and recreate the heirarchical
33: * structure of that subtree and move extracted files to their
34: * proper homes (supressed by the m option).
35: * Includes the s (skip files) option for use with multiple
36: * dumps on a single tape.
37: * 8/29/80 by Mike Litzkow
38: *
39: * Modified to work on the new file system and to recover from
40: * tape read errors.
41: * 1/19/82 by Kirk McKusick
42: *
43: * Full incremental restore running entirely in user code and
44: * interactive tape browser.
45: * 1/19/83 by Kirk McKusick
46: */
47:
48: #include "restore.h"
49: #include <protocols/dumprestore.h>
50: #include <sys/signal.h>
51: #include "pathnames.h"
52:
53: int bflag = 0, cvtflag = 0, dflag = 0, vflag = 0, yflag = 0;
54: int hflag = 1, mflag = 1, Nflag = 0;
55: char command = '\0';
56: long dumpnum = 1;
57: long volno = 0;
58: long ntrec;
59: char *dumpmap;
60: char *clrimap;
61: ino_t maxino;
62: time_t dumptime;
63: time_t dumpdate;
64: FILE *terminal;
65:
66: main(argc, argv)
67: int argc;
68: char *argv[];
69: {
70: register char *cp;
71: ino_t ino;
72: char *inputdev = _PATH_DEFTAPE;
73: char *symtbl = "./restoresymtable";
74: char name[MAXPATHLEN];
75: void onintr();
76:
77: if (signal(SIGINT, onintr) == SIG_IGN)
78: (void) signal(SIGINT, SIG_IGN);
79: if (signal(SIGTERM, onintr) == SIG_IGN)
80: (void) signal(SIGTERM, SIG_IGN);
81: setlinebuf(stderr);
82: if (argc < 2) {
83: usage:
84: fprintf(stderr, "Usage:\n%s%s%s%s%s",
85: "\trestore tfhsvy [file file ...]\n",
86: "\trestore xfhmsvy [file file ...]\n",
87: "\trestore ifhmsvy\n",
88: "\trestore rfsvy\n",
89: "\trestore Rfsvy\n");
90: done(1);
91: }
92: argv++;
93: argc -= 2;
94: command = '\0';
95: for (cp = *argv++; *cp; cp++) {
96: switch (*cp) {
97: case '-':
98: break;
99: case 'c':
100: cvtflag++;
101: break;
102: case 'd':
103: dflag++;
104: break;
105: case 'h':
106: hflag = 0;
107: break;
108: case 'm':
109: mflag = 0;
110: break;
111: case 'N':
112: Nflag++;
113: break;
114: case 'v':
115: vflag++;
116: break;
117: case 'y':
118: yflag++;
119: break;
120: case 'f':
121: if (argc < 1) {
122: fprintf(stderr, "missing device specifier\n");
123: done(1);
124: }
125: inputdev = *argv++;
126: argc--;
127: break;
128: case 'b':
129: /*
130: * change default tape blocksize
131: */
132: bflag++;
133: if (argc < 1) {
134: fprintf(stderr, "missing block size\n");
135: done(1);
136: }
137: ntrec = atoi(*argv++);
138: if (ntrec <= 0) {
139: fprintf(stderr, "Block size must be a positive integer\n");
140: done(1);
141: }
142: argc--;
143: break;
144: case 's':
145: /*
146: * dumpnum (skip to) for multifile dump tapes
147: */
148: if (argc < 1) {
149: fprintf(stderr, "missing dump number\n");
150: done(1);
151: }
152: dumpnum = atoi(*argv++);
153: if (dumpnum <= 0) {
154: fprintf(stderr, "Dump number must be a positive integer\n");
155: done(1);
156: }
157: argc--;
158: break;
159: case 't':
160: case 'R':
161: case 'r':
162: case 'x':
163: case 'i':
164: if (command != '\0') {
165: fprintf(stderr,
166: "%c and %c are mutually exclusive\n",
167: *cp, command);
168: goto usage;
169: }
170: command = *cp;
171: break;
172: default:
173: fprintf(stderr, "Bad key character %c\n", *cp);
174: goto usage;
175: }
176: }
177: if (command == '\0') {
178: fprintf(stderr, "must specify i, t, r, R, or x\n");
179: goto usage;
180: }
181: setinput(inputdev);
182: if (argc == 0) {
183: argc = 1;
184: *--argv = ".";
185: }
186: switch (command) {
187: /*
188: * Interactive mode.
189: */
190: case 'i':
191: setup();
192: extractdirs(1);
193: initsymtable((char *)0);
194: runcmdshell();
195: done(0);
196: /*
197: * Incremental restoration of a file system.
198: */
199: case 'r':
200: setup();
201: if (dumptime > 0) {
202: /*
203: * This is an incremental dump tape.
204: */
205: vprintf(stdout, "Begin incremental restore\n");
206: initsymtable(symtbl);
207: extractdirs(1);
208: removeoldleaves();
209: vprintf(stdout, "Calculate node updates.\n");
210: treescan(".", ROOTINO, nodeupdates);
211: findunreflinks();
212: removeoldnodes();
213: } else {
214: /*
215: * This is a level zero dump tape.
216: */
217: vprintf(stdout, "Begin level 0 restore\n");
218: initsymtable((char *)0);
219: extractdirs(1);
220: vprintf(stdout, "Calculate extraction list.\n");
221: treescan(".", ROOTINO, nodeupdates);
222: }
223: createleaves(symtbl);
224: createlinks();
225: setdirmodes();
226: checkrestore();
227: if (dflag) {
228: vprintf(stdout, "Verify the directory structure\n");
229: treescan(".", ROOTINO, verifyfile);
230: }
231: dumpsymtable(symtbl, (long)1);
232: done(0);
233: /*
234: * Resume an incremental file system restoration.
235: */
236: case 'R':
237: initsymtable(symtbl);
238: skipmaps();
239: skipdirs();
240: createleaves(symtbl);
241: createlinks();
242: setdirmodes();
243: checkrestore();
244: dumpsymtable(symtbl, (long)1);
245: done(0);
246: /*
247: * List contents of tape.
248: */
249: case 't':
250: setup();
251: extractdirs(0);
252: initsymtable((char *)0);
253: while (argc--) {
254: canon(*argv++, name);
255: ino = dirlookup(name);
256: if (ino == 0)
257: continue;
258: treescan(name, ino, listfile);
259: }
260: done(0);
261: /*
262: * Batch extraction of tape contents.
263: */
264: case 'x':
265: setup();
266: extractdirs(1);
267: initsymtable((char *)0);
268: while (argc--) {
269: canon(*argv++, name);
270: ino = dirlookup(name);
271: if (ino == 0)
272: continue;
273: if (mflag)
274: pathcheck(name);
275: treescan(name, ino, addfile);
276: }
277: createfiles();
278: createlinks();
279: setdirmodes();
280: if (dflag)
281: checkrestore();
282: done(0);
283: }
284: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.