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";
42 #include <sys/cdefs.h>
43 __FBSDID("$FreeBSD$");
45 #include <sys/param.h>
48 #include <ufs/ufs/dinode.h>
49 #include <protocols/dumprestore.h>
63 int bflag
= 0, cvtflag
= 0, dflag
= 0, Dflag
= 0, vflag
= 0, yflag
= 0;
64 int hflag
= 1, mflag
= 1, Nflag
= 0;
78 static void obsolete(int *, char **[]);
79 static void usage(void) __dead2
;
82 main(int argc
, char *argv
[])
87 char *symtbl
= "./restoresymtable";
88 char *p
, name
[MAXPATHLEN
];
90 /* Temp files should *not* be readable. We set permissions later. */
96 (void)setlocale(LC_ALL
, "");
99 obsolete(&argc
, &argv
);
100 while ((ch
= getopt(argc
, argv
, "b:dDf:himNP:Rrs:tuvxy")) != -1)
103 /* Change default tape blocksize. */
105 ntrec
= strtol(optarg
, &p
, 10);
107 errx(1, "illegal blocksize -- %s", optarg
);
109 errx(1, "block size must be greater than 0");
120 "-P and -f options are mutually exclusive");
124 if (!pipecmd
&& inputdev
)
126 "-P and -f options are mutually exclusive");
140 "%c and %c options are mutually exclusive",
151 /* Dumpnum (skip to) for multifile dump tapes. */
152 dumpnum
= strtol(optarg
, &p
, 10);
154 errx(1, "illegal dump number -- %s", optarg
);
156 errx(1, "dump number must be greater than 0");
174 errx(1, "none of i, R, r, t or x options specified");
176 if (signal(SIGINT
, onintr
) == SIG_IGN
)
177 (void) signal(SIGINT
, SIG_IGN
);
178 if (signal(SIGTERM
, onintr
) == SIG_IGN
)
179 (void) signal(SIGTERM
, SIG_IGN
);
182 if (inputdev
== NULL
&& (inputdev
= getenv("TAPE")) == NULL
)
183 inputdev
= _PATH_DEFTAPE
;
184 setinput(inputdev
, pipecmd
);
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 const char *const common
=
297 "[-b blocksize] [-f file | -P pipecommand] [-s fileno]";
298 const char *const fileell
= "[file ...]";
300 (void)fprintf(stderr
, "usage:\t%s %s\n\t%s %s\n\t%s %s\n"
301 "\t%s %s %s\n\t%s %s %s\n",
302 "restore -i [-dhmNuvy]", common
,
303 "restore -R [-dNuvy]", common
,
304 "restore -r [-dNuvy]", common
,
305 "restore -t [-dhNuvy]", common
, fileell
,
306 "restore -x [-dhmNuvy]", common
, fileell
);
312 * Change set of key letters and ordered arguments into something
313 * getopt(3) will like.
316 obsolete(int *argcp
, char **argvp
[])
319 char *ap
, **argv
, *flagsp
, **nargv
, *p
;
325 /* Return if no arguments or first argument has leading dash. */
327 if (argc
== 1 || *ap
== '-')
330 /* Allocate space for new arguments. */
331 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
332 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
336 argv
+= 2, argc
-= 2;
338 for (flags
= 0; *ap
; ++ap
) {
344 warnx("option requires an argument -- %c", *ap
);
347 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
351 (void)strcpy(&nargv
[0][2], *argv
);
365 /* Terminate flags. */
371 /* Copy remaining arguments. */
372 while ((*nargv
++ = *argv
++));
374 /* Update argument count. */
375 *argcp
= nargv
- *argvp
- 1;