put in key words
[unix-history] / usr / src / sbin / restore / main.c
CommitLineData
8c5eec2f 1/*
b42768a6
KB
2 * Copyright (c) 1983 The Regents of the University of California.
3 * All rights reserved.
4 *
70ab3c27 5 * %sccs.include.redist.c%
8c5eec2f
DF
6 */
7
e9039e39 8#ifndef lint
8c5eec2f 9char copyright[] =
b42768a6 10"@(#) Copyright (c) 1983 The Regents of the University of California.\n\
8c5eec2f 11 All rights reserved.\n";
b42768a6 12#endif /* not lint */
7d4dda01 13
8c5eec2f 14#ifndef lint
70ab3c27 15static char sccsid[] = "@(#)main.c 5.8 (Berkeley) %G%";
b42768a6 16#endif /* not lint */
ebd1f727 17
e0519353
KM
18/*
19 * Modified to recursively extract all files within a subtree
20 * (supressed by the h option) and recreate the heirarchical
21 * structure of that subtree and move extracted files to their
22 * proper homes (supressed by the m option).
23 * Includes the s (skip files) option for use with multiple
24 * dumps on a single tape.
7d4dda01
KM
25 * 8/29/80 by Mike Litzkow
26 *
e0519353
KM
27 * Modified to work on the new file system and to recover from
28 * tape read errors.
e9039e39
KM
29 * 1/19/82 by Kirk McKusick
30 *
7432ff81
KM
31 * Full incremental restore running entirely in user code and
32 * interactive tape browser.
e0519353 33 * 1/19/83 by Kirk McKusick
7d4dda01
KM
34 */
35
e0519353 36#include "restore.h"
d9127117 37#include <protocols/dumprestore.h>
7abf8d65
KB
38#include <sys/signal.h>
39#include "pathnames.h"
7d4dda01 40
b97e998a 41int bflag = 0, cvtflag = 0, dflag = 0, vflag = 0, yflag = 0;
414c4f09 42int hflag = 1, mflag = 1, Nflag = 0;
e0519353
KM
43char command = '\0';
44long dumpnum = 1;
a08c9679 45long volno = 0;
b97e998a 46long ntrec;
b6407c9d
KM
47char *dumpmap;
48char *clrimap;
e0519353
KM
49ino_t maxino;
50time_t dumptime;
2cb5dabb 51time_t dumpdate;
7432ff81 52FILE *terminal;
7d4dda01 53
e9039e39 54main(argc, argv)
003a2a9e
KM
55 int argc;
56 char *argv[];
7d4dda01
KM
57{
58 register char *cp;
9f13f26d 59 ino_t ino;
7abf8d65 60 char *inputdev = _PATH_DEFTAPE;
9f13f26d 61 char *symtbl = "./restoresymtable";
7432ff81 62 char name[MAXPATHLEN];
62492bc2 63 void onintr();
7d4dda01 64
e0519353 65 if (signal(SIGINT, onintr) == SIG_IGN)
a08c9679 66 (void) signal(SIGINT, SIG_IGN);
e0519353 67 if (signal(SIGTERM, onintr) == SIG_IGN)
a08c9679 68 (void) signal(SIGTERM, SIG_IGN);
9f13f26d 69 setlinebuf(stderr);
7d4dda01
KM
70 if (argc < 2) {
71usage:
7432ff81
KM
72 fprintf(stderr, "Usage:\n%s%s%s%s%s",
73 "\trestore tfhsvy [file file ...]\n",
74 "\trestore xfhmsvy [file file ...]\n",
75 "\trestore ifhmsvy\n",
76 "\trestore rfsvy\n",
77 "\trestore Rfsvy\n");
003a2a9e 78 done(1);
7d4dda01
KM
79 }
80 argv++;
81 argc -= 2;
097c918f 82 command = '\0';
7d4dda01
KM
83 for (cp = *argv++; *cp; cp++) {
84 switch (*cp) {
85 case '-':
86 break;
d8cbdd8d
KM
87 case 'c':
88 cvtflag++;
89 break;
e0519353
KM
90 case 'd':
91 dflag++;
7d4dda01
KM
92 break;
93 case 'h':
097c918f 94 hflag = 0;
7d4dda01
KM
95 break;
96 case 'm':
097c918f 97 mflag = 0;
7d4dda01 98 break;
414c4f09
KM
99 case 'N':
100 Nflag++;
101 break;
f99961a3
KM
102 case 'v':
103 vflag++;
104 break;
105 case 'y':
106 yflag++;
107 break;
e0519353 108 case 'f':
5c5f44c7
KM
109 if (argc < 1) {
110 fprintf(stderr, "missing device specifier\n");
111 done(1);
112 }
e0519353
KM
113 inputdev = *argv++;
114 argc--;
115 break;
19230a53
KM
116 case 'b':
117 /*
118 * change default tape blocksize
119 */
b97e998a 120 bflag++;
19230a53
KM
121 if (argc < 1) {
122 fprintf(stderr, "missing block size\n");
123 done(1);
124 }
125 ntrec = atoi(*argv++);
126 if (ntrec <= 0) {
127 fprintf(stderr, "Block size must be a positive integer\n");
128 done(1);
129 }
130 argc--;
131 break;
e0519353
KM
132 case 's':
133 /*
134 * dumpnum (skip to) for multifile dump tapes
135 */
5c5f44c7
KM
136 if (argc < 1) {
137 fprintf(stderr, "missing dump number\n");
138 done(1);
139 }
e0519353
KM
140 dumpnum = atoi(*argv++);
141 if (dumpnum <= 0) {
142 fprintf(stderr, "Dump number must be a positive integer\n");
143 done(1);
144 }
145 argc--;
146 break;
7d4dda01 147 case 't':
e0519353
KM
148 case 'R':
149 case 'r':
150 case 'x':
7432ff81 151 case 'i':
097c918f 152 if (command != '\0') {
e0519353 153 fprintf(stderr,
5c5f44c7
KM
154 "%c and %c are mutually exclusive\n",
155 *cp, command);
097c918f
KM
156 goto usage;
157 }
5c5f44c7 158 command = *cp;
7d4dda01
KM
159 break;
160 default:
003a2a9e 161 fprintf(stderr, "Bad key character %c\n", *cp);
7d4dda01
KM
162 goto usage;
163 }
164 }
097c918f 165 if (command == '\0') {
7432ff81 166 fprintf(stderr, "must specify i, t, r, R, or x\n");
097c918f
KM
167 goto usage;
168 }
e0519353 169 setinput(inputdev);
097c918f 170 if (argc == 0) {
e0519353 171 argc = 1;
097c918f
KM
172 *--argv = ".";
173 }
e0519353 174 switch (command) {
7432ff81
KM
175 /*
176 * Interactive mode.
177 */
178 case 'i':
e0519353 179 setup();
7432ff81 180 extractdirs(1);
a08c9679 181 initsymtable((char *)0);
7432ff81 182 runcmdshell();
e0519353 183 done(0);
7432ff81
KM
184 /*
185 * Incremental restoration of a file system.
186 */
e0519353
KM
187 case 'r':
188 setup();
189 if (dumptime > 0) {
a08c9679
KM
190 /*
191 * This is an incremental dump tape.
192 */
193 vprintf(stdout, "Begin incremental restore\n");
e0519353 194 initsymtable(symtbl);
7432ff81 195 extractdirs(1);
a08c9679
KM
196 removeoldleaves();
197 vprintf(stdout, "Calculate node updates.\n");
198 treescan(".", ROOTINO, nodeupdates);
199 findunreflinks();
200 removeoldnodes();
e0519353 201 } else {
a08c9679
KM
202 /*
203 * This is a level zero dump tape.
204 */
205 vprintf(stdout, "Begin level 0 restore\n");
206 initsymtable((char *)0);
7432ff81 207 extractdirs(1);
a08c9679
KM
208 vprintf(stdout, "Calculate extraction list.\n");
209 treescan(".", ROOTINO, nodeupdates);
e0519353
KM
210 }
211 createleaves(symtbl);
212 createlinks();
7432ff81 213 setdirmodes();
e0519353
KM
214 checkrestore();
215 if (dflag) {
216 vprintf(stdout, "Verify the directory structure\n");
217 treescan(".", ROOTINO, verifyfile);
218 }
219 dumpsymtable(symtbl, (long)1);
220 done(0);
7432ff81
KM
221 /*
222 * Resume an incremental file system restoration.
223 */
e0519353
KM
224 case 'R':
225 initsymtable(symtbl);
38bbfe41
KM
226 skipmaps();
227 skipdirs();
e0519353
KM
228 createleaves(symtbl);
229 createlinks();
7432ff81 230 setdirmodes();
e0519353
KM
231 checkrestore();
232 dumpsymtable(symtbl, (long)1);
233 done(0);
7432ff81
KM
234 /*
235 * List contents of tape.
236 */
237 case 't':
238 setup();
239 extractdirs(0);
329dd5fb 240 initsymtable((char *)0);
7432ff81
KM
241 while (argc--) {
242 canon(*argv++, name);
243 ino = dirlookup(name);
244 if (ino == 0)
245 continue;
246 treescan(name, ino, listfile);
247 }
248 done(0);
249 /*
250 * Batch extraction of tape contents.
251 */
252 case 'x':
253 setup();
254 extractdirs(1);
255 initsymtable((char *)0);
256 while (argc--) {
257 canon(*argv++, name);
258 ino = dirlookup(name);
259 if (ino == 0)
260 continue;
261 if (mflag)
262 pathcheck(name);
263 treescan(name, ino, addfile);
264 }
265 createfiles();
266 createlinks();
267 setdirmodes();
268 if (dflag)
269 checkrestore();
270 done(0);
271 }
272}