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
29 * @(#) Copyright (c) 1983, 1993 The Regents of the University of California. All rights reserved.
30 * @(#)main.c 8.6 (Berkeley) 5/4/95
31 * $FreeBSD: src/sbin/restore/main.c,v 1.10.2.3 2001/10/02 08:30:17 cjc Exp $
32 * $DragonFly: src/sbin/restore/main.c,v 1.8 2005/11/06 12:49:25 swildner Exp $
35 #include <sys/param.h>
38 #include <vfs/ufs/dinode.h>
39 #include <protocols/dumprestore.h>
51 int bflag = 0, cvtflag = 0, dflag = 0, vflag = 0, yflag = 0;
52 int hflag = 1, mflag = 1, Nflag = 0;
66 static void obsolete(int *, char **[]);
67 static void usage(void);
70 main(int argc, char **argv)
75 char *symtbl = "./restoresymtable";
76 char *p, name[MAXPATHLEN];
78 /* Temp files should *not* be readable. We set permissions later. */
84 if ((inputdev = getenv("TAPE")) == NULL)
85 inputdev = _PATH_DEFTAPE;
86 obsolete(&argc, &argv);
88 #define optlist "b:cdf:hikmNRrs:tuvxy"
90 #define optlist "b:cdf:himNRrs:tuvxy"
92 while ((ch = getopt(argc, argv, optlist)) != -1)
95 /* Change default tape blocksize. */
97 ntrec = strtol(optarg, &p, 10);
99 errx(1, "illegal blocksize -- %s", optarg);
101 errx(1, "block size must be greater than 0");
127 "%c and %c options are mutually exclusive",
138 /* Dumpnum (skip to) for multifile dump tapes. */
139 dumpnum = strtol(optarg, &p, 10);
141 errx(1, "illegal dump number -- %s", optarg);
143 errx(1, "dump number must be greater than 0");
161 errx(1, "none of i, R, r, t or x options specified");
163 if (signal(SIGINT, onintr) == SIG_IGN)
164 signal(SIGINT, SIG_IGN);
165 if (signal(SIGTERM, onintr) == SIG_IGN)
166 signal(SIGTERM, SIG_IGN);
187 * Incremental restoration of a file system.
193 * This is an incremental dump tape.
195 vprintf(stdout, "Begin incremental restore\n");
196 initsymtable(symtbl);
199 vprintf(stdout, "Calculate node updates.\n");
200 treescan(".", ROOTINO, nodeupdates);
205 * This is a level zero dump tape.
207 vprintf(stdout, "Begin level 0 restore\n");
210 vprintf(stdout, "Calculate extraction list.\n");
211 treescan(".", ROOTINO, nodeupdates);
213 createleaves(symtbl);
218 vprintf(stdout, "Verify the directory structure\n");
219 treescan(".", ROOTINO, verifyfile);
221 dumpsymtable(symtbl, (long)1);
224 * Resume an incremental file system restoration.
227 initsymtable(symtbl);
230 createleaves(symtbl);
234 dumpsymtable(symtbl, (long)1);
237 * List contents of tape.
244 canon(*argv++, name, sizeof(name));
245 ino = dirlookup(name);
248 treescan(name, ino, listfile);
252 * Batch extraction of tape contents.
259 canon(*argv++, name, sizeof(name));
260 ino = dirlookup(name);
265 treescan(name, ino, addfile);
281 fprintf(stderr, "usage:\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n",
282 "restore -i [-cdhkmNuvy] [-b blocksize] [-f file] [-s fileno]",
283 "restore -r [-cdkNuvy] [-b blocksize] [-f file] [-s fileno]",
284 "restore -R [-cdkNuvy] [-b blocksize] [-f file] [-s fileno]",
285 "restore -x [-cdhkmNuvy] [-b blocksize] [-f file] [-s fileno] [file ...]",
286 "restore -t [-cdhkNuvy] [-b blocksize] [-f file] [-s fileno] [file ...]");
292 * Change set of key letters and ordered arguments into something
293 * getopt(3) will like.
296 obsolete(int *argcp, char **argvp[])
299 char *ap, **argv, *flagsp, **nargv, *p;
305 /* Return if no arguments or first argument has leading dash. */
307 if (argc == 1 || *ap == '-')
310 /* Allocate space for new arguments. */
311 if ((*argvp = nargv = malloc((argc + 1) * sizeof(char *))) == NULL ||
312 (p = flagsp = malloc(strlen(ap) + 2)) == NULL)
316 argv += 2, argc -= 2;
318 for (flags = 0; *ap; ++ap) {
324 warnx("option requires an argument -- %c", *ap);
327 if ((nargv[0] = malloc(strlen(*argv) + 2 + 1)) == NULL)
331 strcpy(&nargv[0][2], *argv);
345 /* Terminate flags. */
351 /* Copy remaining arguments. */
352 while ((*nargv++ = *argv++));
354 /* Update argument count. */
355 *argcp = nargv - *argvp - 1;