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