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