2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 static const char copyright[] =
32 "@(#) Copyright (c) 1983, 1993\n\
33 The Regents of the University of California. All rights reserved.\n";
38 static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/4/95";
40 static const char rcsid[] =
44 #include <sys/param.h>
47 #include <ufs/ufs/dinode.h>
48 #include <protocols/dumprestore.h>
62 int bflag = 0, cvtflag = 0, dflag = 0, vflag = 0, yflag = 0;
63 int hflag = 1, mflag = 1, Nflag = 0;
77 static void obsolete(int *, char **[]);
78 static void usage(void) __dead2;
81 main(int argc, char *argv[])
86 char *symtbl = "./restoresymtable";
87 char *p, name[MAXPATHLEN];
89 /* Temp files should *not* be readable. We set permissions later. */
95 (void)setlocale(LC_ALL, "");
98 obsolete(&argc, &argv);
99 while ((ch = getopt(argc, argv, "b:df:himNP:Rrs:tuvxy")) != -1)
102 /* Change default tape blocksize. */
104 ntrec = strtol(optarg, &p, 10);
106 errx(1, "illegal blocksize -- %s", optarg);
108 errx(1, "block size must be greater than 0");
116 "-P and -f options are mutually exclusive");
120 if (!pipecmd && inputdev)
122 "-P and -f options are mutually exclusive");
136 "%c and %c options are mutually exclusive",
147 /* Dumpnum (skip to) for multifile dump tapes. */
148 dumpnum = strtol(optarg, &p, 10);
150 errx(1, "illegal dump number -- %s", optarg);
152 errx(1, "dump number must be greater than 0");
170 errx(1, "none of i, R, r, t or x options specified");
172 if (signal(SIGINT, onintr) == SIG_IGN)
173 (void) signal(SIGINT, SIG_IGN);
174 if (signal(SIGTERM, onintr) == SIG_IGN)
175 (void) signal(SIGTERM, SIG_IGN);
178 if (inputdev == NULL && (inputdev = getenv("TAPE")) == NULL)
179 inputdev = _PATH_DEFTAPE;
180 setinput(inputdev, pipecmd);
198 * Incremental restoration of a file system.
204 * This is an incremental dump tape.
206 vprintf(stdout, "Begin incremental restore\n");
207 initsymtable(symtbl);
210 vprintf(stdout, "Calculate node updates.\n");
211 treescan(".", ROOTINO, nodeupdates);
216 * This is a level zero dump tape.
218 vprintf(stdout, "Begin level 0 restore\n");
219 initsymtable((char *)0);
221 vprintf(stdout, "Calculate extraction list.\n");
222 treescan(".", ROOTINO, nodeupdates);
224 createleaves(symtbl);
229 vprintf(stdout, "Verify the directory structure\n");
230 treescan(".", ROOTINO, verifyfile);
232 dumpsymtable(symtbl, (long)1);
235 * Resume an incremental file system restoration.
238 initsymtable(symtbl);
241 createleaves(symtbl);
245 dumpsymtable(symtbl, (long)1);
248 * List contents of tape.
253 initsymtable((char *)0);
255 canon(*argv++, name, sizeof(name));
256 ino = dirlookup(name);
259 treescan(name, ino, listfile);
263 * Batch extraction of tape contents.
268 initsymtable((char *)0);
270 canon(*argv++, name, sizeof(name));
271 ino = dirlookup(name);
276 treescan(name, ino, addfile);
292 const char *const common =
293 "[-b blocksize] [-P pipecmd | -f file] [-s fileno]";
294 const char *const fileell = "[file ...]";
296 (void)fprintf(stderr, "usage:\t%s %s\n\t%s %s\n\t%s %s\n"
297 "\t%s %s %s\n\t%s %s %s\n",
298 "restore -i [-cdhmNuvy]", common,
299 "restore -r [-cdNuvy]", common,
300 "restore -R [-cdNuvy]", common,
301 "restore -x [-cdhmNuvy]", common, fileell,
302 "restore -t [-cdhNuvy]", common, fileell);
308 * Change set of key letters and ordered arguments into something
309 * getopt(3) will like.
312 obsolete(int *argcp, char **argvp[])
315 char *ap, **argv, *flagsp, **nargv, *p;
321 /* Return if no arguments or first argument has leading dash. */
323 if (argc == 1 || *ap == '-')
326 /* Allocate space for new arguments. */
327 if ((*argvp = nargv = malloc((argc + 1) * sizeof(char *))) == NULL ||
328 (p = flagsp = malloc(strlen(ap) + 2)) == NULL)
332 argv += 2, argc -= 2;
334 for (flags = 0; *ap; ++ap) {
340 warnx("option requires an argument -- %c", *ap);
343 if ((nargv[0] = malloc(strlen(*argv) + 2 + 1)) == NULL)
347 (void)strcpy(&nargv[0][2], *argv);
361 /* Terminate flags. */
367 /* Copy remaining arguments. */
368 while ((*nargv++ = *argv++));
370 /* Update argument count. */
371 *argcp = nargv - *argvp - 1;