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 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 static const char copyright[] =
36 "@(#) Copyright (c) 1983, 1993\n\
37 The Regents of the University of California. All rights reserved.\n";
42 static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/4/95";
44 static const char rcsid[] =
45 "$FreeBSD: src/sbin/restore/main.c,v 1.10.2.3 2001/10/02 08:30:17 cjc Exp $";
48 #include <sys/param.h>
51 #include <ufs/ufs/dinode.h>
52 #include <protocols/dumprestore.h>
64 int bflag = 0, cvtflag = 0, dflag = 0, vflag = 0, yflag = 0;
65 int hflag = 1, mflag = 1, Nflag = 0;
79 static void obsolete __P((int *, char **[]));
80 static void usage __P((void));
90 char *symtbl = "./restoresymtable";
91 char *p, name[MAXPATHLEN];
93 /* Temp files should *not* be readable. We set permissions later. */
99 if ((inputdev = getenv("TAPE")) == NULL)
100 inputdev = _PATH_DEFTAPE;
101 obsolete(&argc, &argv);
103 #define optlist "b:cdf:hikmNRrs:tuvxy"
105 #define optlist "b:cdf:himNRrs:tuvxy"
107 while ((ch = getopt(argc, argv, optlist)) != -1)
110 /* Change default tape blocksize. */
112 ntrec = strtol(optarg, &p, 10);
114 errx(1, "illegal blocksize -- %s", optarg);
116 errx(1, "block size must be greater than 0");
142 "%c and %c options are mutually exclusive",
153 /* Dumpnum (skip to) for multifile dump tapes. */
154 dumpnum = strtol(optarg, &p, 10);
156 errx(1, "illegal dump number -- %s", optarg);
158 errx(1, "dump number must be greater than 0");
176 errx(1, "none of i, R, r, t or x options specified");
178 if (signal(SIGINT, onintr) == SIG_IGN)
179 (void) signal(SIGINT, SIG_IGN);
180 if (signal(SIGTERM, onintr) == SIG_IGN)
181 (void) signal(SIGTERM, SIG_IGN);
202 * Incremental restoration of a file system.
208 * This is an incremental dump tape.
210 vprintf(stdout, "Begin incremental restore\n");
211 initsymtable(symtbl);
214 vprintf(stdout, "Calculate node updates.\n");
215 treescan(".", ROOTINO, nodeupdates);
220 * This is a level zero dump tape.
222 vprintf(stdout, "Begin level 0 restore\n");
223 initsymtable((char *)0);
225 vprintf(stdout, "Calculate extraction list.\n");
226 treescan(".", ROOTINO, nodeupdates);
228 createleaves(symtbl);
233 vprintf(stdout, "Verify the directory structure\n");
234 treescan(".", ROOTINO, verifyfile);
236 dumpsymtable(symtbl, (long)1);
239 * Resume an incremental file system restoration.
242 initsymtable(symtbl);
245 createleaves(symtbl);
249 dumpsymtable(symtbl, (long)1);
252 * List contents of tape.
257 initsymtable((char *)0);
259 canon(*argv++, name, sizeof(name));
260 ino = dirlookup(name);
263 treescan(name, ino, listfile);
267 * Batch extraction of tape contents.
272 initsymtable((char *)0);
274 canon(*argv++, name, sizeof(name));
275 ino = dirlookup(name);
280 treescan(name, ino, addfile);
296 (void)fprintf(stderr, "usage:\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n",
297 "restore -i [-cdhkmNuvy] [-b blocksize] [-f file] [-s fileno]",
298 "restore -r [-cdkNuvy] [-b blocksize] [-f file] [-s fileno]",
299 "restore -R [-cdkNuvy] [-b blocksize] [-f file] [-s fileno]",
300 "restore -x [-cdhkmNuvy] [-b blocksize] [-f file] [-s fileno] [file ...]",
301 "restore -t [-cdhkNuvy] [-b blocksize] [-f file] [-s fileno] [file ...]");
307 * Change set of key letters and ordered arguments into something
308 * getopt(3) will like.
311 obsolete(argcp, argvp)
316 char *ap, **argv, *flagsp, **nargv, *p;
322 /* Return if no arguments or first argument has leading dash. */
324 if (argc == 1 || *ap == '-')
327 /* Allocate space for new arguments. */
328 if ((*argvp = nargv = malloc((argc + 1) * sizeof(char *))) == NULL ||
329 (p = flagsp = malloc(strlen(ap) + 2)) == NULL)
333 argv += 2, argc -= 2;
335 for (flags = 0; *ap; ++ap) {
341 warnx("option requires an argument -- %c", *ap);
344 if ((nargv[0] = malloc(strlen(*argv) + 2 + 1)) == NULL)
348 (void)strcpy(&nargv[0][2], *argv);
362 /* Terminate flags. */
368 /* Copy remaining arguments. */
369 while ((*nargv++ = *argv++));
371 /* Update argument count. */
372 *argcp = nargv - *argvp - 1;