2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 static const char copyright[] =
34 "@(#) Copyright (c) 1983, 1993\n\
35 The Regents of the University of California. All rights reserved.\n";
40 static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/4/95";
44 #include <sys/cdefs.h>
45 __FBSDID("$FreeBSD$");
47 #include <sys/param.h>
50 #include <ufs/ufs/dinode.h>
51 #include <protocols/dumprestore.h>
65 int bflag = 0, cvtflag = 0, dflag = 0, Dflag = 0, vflag = 0, yflag = 0;
66 int hflag = 1, mflag = 1, Nflag = 0;
80 static void obsolete(int *, char **[]);
81 static void usage(void) __dead2;
84 main(int argc, char *argv[])
89 char *symtbl = "./restoresymtable";
90 char *p, name[MAXPATHLEN];
92 /* Temp files should *not* be readable. We set permissions later. */
98 (void)setlocale(LC_ALL, "");
101 obsolete(&argc, &argv);
102 while ((ch = getopt(argc, argv, "b:dDf:himNP:Rrs:tuvxy")) != -1)
105 /* Change default tape blocksize. */
107 ntrec = strtol(optarg, &p, 10);
109 errx(1, "illegal blocksize -- %s", optarg);
111 errx(1, "block size must be greater than 0");
122 "-P and -f options are mutually exclusive");
126 if (!pipecmd && inputdev)
128 "-P and -f options are mutually exclusive");
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);
184 if (inputdev == NULL && (inputdev = getenv("TAPE")) == NULL)
185 inputdev = _PATH_DEFTAPE;
186 setinput(inputdev, pipecmd);
204 * Incremental restoration of a file system.
210 * This is an incremental dump tape.
212 vprintf(stdout, "Begin incremental restore\n");
213 initsymtable(symtbl);
216 vprintf(stdout, "Calculate node updates.\n");
217 treescan(".", UFS_ROOTINO, nodeupdates);
222 * This is a level zero dump tape.
224 vprintf(stdout, "Begin level 0 restore\n");
225 initsymtable((char *)0);
227 vprintf(stdout, "Calculate extraction list.\n");
228 treescan(".", UFS_ROOTINO, nodeupdates);
230 createleaves(symtbl);
235 vprintf(stdout, "Verify the directory structure\n");
236 treescan(".", UFS_ROOTINO, verifyfile);
238 dumpsymtable(symtbl, (long)1);
241 * Resume an incremental file system restoration.
244 initsymtable(symtbl);
247 createleaves(symtbl);
251 dumpsymtable(symtbl, (long)1);
254 * List contents of tape.
259 initsymtable((char *)0);
261 canon(*argv++, name, sizeof(name));
262 ino = dirlookup(name);
265 treescan(name, ino, listfile);
269 * Batch extraction of tape contents.
274 initsymtable((char *)0);
276 canon(*argv++, name, sizeof(name));
277 ino = dirlookup(name);
282 treescan(name, ino, addfile);
298 const char *const common =
299 "[-b blocksize] [-f file | -P pipecommand] [-s fileno]";
300 const char *const fileell = "[file ...]";
302 (void)fprintf(stderr, "usage:\t%s %s\n\t%s %s\n\t%s %s\n"
303 "\t%s %s %s\n\t%s %s %s\n",
304 "restore -i [-dhmNuvy]", common,
305 "restore -R [-dNuvy]", common,
306 "restore -r [-dNuvy]", common,
307 "restore -t [-dhNuvy]", common, fileell,
308 "restore -x [-dhmNuvy]", common, fileell);
314 * Change set of key letters and ordered arguments into something
315 * getopt(3) will like.
318 obsolete(int *argcp, char **argvp[])
321 char *ap, **argv, *flagsp, **nargv, *p;
327 /* Return if no arguments or first argument has leading dash. */
329 if (argc == 1 || *ap == '-')
332 /* Allocate space for new arguments. */
333 if ((*argvp = nargv = malloc((argc + 1) * sizeof(char *))) == NULL ||
334 (p = flagsp = malloc(strlen(ap) + 2)) == NULL)
338 argv += 2, argc -= 2;
340 for (flags = 0; *ap; ++ap) {
346 warnx("option requires an argument -- %c", *ap);
349 if ((nargv[0] = malloc(strlen(*argv) + 2 + 1)) == NULL)
353 (void)strcpy(&nargv[0][2], *argv);
367 /* Terminate flags. */
374 /* Copy remaining arguments. */
375 while ((*nargv++ = *argv++));
377 /* Update argument count. */
378 *argcp = nargv - *argvp - 1;