1 /* $NetBSD: main.c,v 1.32 2006/03/20 01:51:54 christos Exp $ */
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
32 #include <sys/cdefs.h>
34 __COPYRIGHT("@(#) Copyright (c) 1983, 1993\
35 The Regents of the University of California. All rights reserved.");
40 static char sccsid
[] = "@(#)main.c 8.6 (Berkeley) 5/4/95";
42 __RCSID("$NetBSD: main.c,v 1.32 2006/03/20 01:51:54 christos Exp $");
46 #include <sys/param.h>
49 #include <ufs/ufs/dinode.h>
50 #include <ufs/ffs/fs.h>
51 #include <protocols/dumprestore.h>
65 int bflag
= 0, cvtflag
= 0, dflag
= 0, vflag
= 0, yflag
= 0;
66 int hflag
= 1, mflag
= 1, Dflag
= 0, Nflag
= 0;
81 FILE *Mtreefile
= NULL
;
83 static void obsolete(int *, char **[]);
84 static void usage(void);
87 main(int argc
, char *argv
[])
92 const char *symtbl
= "./restoresymtable";
93 char *p
, name
[MAXPATHLEN
];
94 static char dot
[] = ".";
99 if ((inputdev
= getenv("TAPE")) == NULL
)
100 inputdev
= _PATH_DEFTAPE
;
101 if ((tmpdir
= getenv("TMPDIR")) == NULL
)
103 obsolete(&argc
, &argv
);
104 while ((ch
= getopt(argc
, argv
, "b:cD:df:himM:NRrs:tuvxy")) != -1)
107 /* Change default tape blocksize. */
109 ntrec
= strtol(optarg
, &p
, 10);
111 errx(1, "illegal blocksize -- %s", optarg
);
113 errx(1, "block size must be greater than 0");
119 ddesc
= digest_lookup(optarg
);
121 err(1, "unknown digest algorithm: %s", optarg
);
140 "%c and %c options are mutually exclusive",
151 Mtreefile
= fopen(optarg
, "a");
152 if (Mtreefile
== NULL
)
153 err(1, "can't open %s", optarg
);
156 /* Dumpnum (skip to) for multifile dump tapes. */
157 dumpnum
= strtol(optarg
, &p
, 10);
159 errx(1, "illegal dump number -- %s", optarg
);
161 errx(1, "dump number must be greater than 0");
179 errx(1, "none of i, R, r, t or x options specified");
181 if (Nflag
|| command
== 't')
184 if (signal(SIGINT
, onintr
) == SIG_IGN
)
185 (void) signal(SIGINT
, SIG_IGN
);
186 if (signal(SIGTERM
, onintr
) == SIG_IGN
)
187 (void) signal(SIGTERM
, SIG_IGN
);
189 pagesize
= sysconf(_SC_PAGESIZE
);
211 * Incremental restoration of a file system.
217 * This is an incremental dump tape.
219 vprintf(stdout
, "Begin incremental restore\n");
220 initsymtable(symtbl
);
223 vprintf(stdout
, "Calculate node updates.\n");
224 treescan(".", ROOTINO
, nodeupdates
);
229 * This is a level zero dump tape.
231 vprintf(stdout
, "Begin level 0 restore\n");
232 initsymtable((char *)0);
234 vprintf(stdout
, "Calculate extraction list.\n");
235 treescan(".", ROOTINO
, nodeupdates
);
237 createleaves(symtbl
);
242 vprintf(stdout
, "Verify the directory structure\n");
243 treescan(".", ROOTINO
, verifyfile
);
245 dumpsymtable(symtbl
, (long)1);
248 * Resume an incremental file system restoration.
251 initsymtable(symtbl
);
254 createleaves(symtbl
);
258 dumpsymtable(symtbl
, (long)1);
261 * List contents of tape.
266 initsymtable((char *)0);
268 canon(*argv
++, name
);
269 ino
= dirlookup(name
);
272 treescan(name
, ino
, listfile
);
276 * Batch extraction of tape contents.
281 initsymtable((char *)0);
283 canon(*argv
++, name
);
284 ino
= dirlookup(name
);
291 treescan(name
, ino
, addfile
);
307 const char *progname
= getprogname();
309 (void)fprintf(stderr
,
310 "usage: %s -i [-cdhmvyN] [-b bsize] [-D algorithm] "
311 "[-f file] [-M mtreefile] [-s fileno]\n", progname
);
312 (void)fprintf(stderr
,
313 " %s -R [-cdvyN] [-b bsize] [-D algorithm] [-f file] "
314 "[-M mtreefile] [-s fileno]\n", progname
);
315 (void)fprintf(stderr
,
316 " %s -r [-cdvyN] [-b bsize] [-D algorithm] [-f file] "
317 "[-M mtreefile] [-s fileno]\n", progname
);
318 (void)fprintf(stderr
,
319 " %s -t [-cdhvy] [-b bsize] [-D algorithm] [-f file]\n"
320 " [-s fileno] [file ...]\n", progname
);
321 (void)fprintf(stderr
,
322 " %s -x [-cdhmvyN] [-b bsize] [-D algorithm] [-f file]\n"
323 " [-M mtreefile] [-s fileno] [file ...]\n", progname
);
329 * Change set of key letters and ordered arguments into something
330 * getopt(3) will like.
333 obsolete(int *argcp
, char **argvp
[])
336 char *ap
, **argv
, *flagsp
, **nargv
, *p
;
342 /* Return if no arguments or first argument has leading dash. */
344 if (argc
== 1 || *ap
== '-')
347 /* Allocate space for new arguments. */
348 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
349 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
355 for (flags
= 0; *ap
; ++ap
) {
361 warnx("option requires an argument -- %c", *ap
);
364 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
368 (void)strcpy(&nargv
[0][2], *argv
);
382 /* Terminate flags. */
390 /* Copy remaining arguments. */
391 while ((*nargv
++ = *argv
++) != NULL
)
394 /* Update argument count. */
395 *argcp
= nargv
- *argvp
- 1;