]>
git.wh0rd.org - dump.git/blob - restore/main.c
2 * Ported to Linux's Second Extended File System as part of the
3 * dump and restore backup suit
4 * Remy Card <card@Linux.EU.Org>, 1994-1997
5 * Stelian Pop <pop@cybercable.fr>, 1999
10 * Copyright (c) 1983, 1993
11 * The Regents of the University of California. All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgement:
23 * This product includes software developed by the University of
24 * California, Berkeley and its contributors.
25 * 4. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 static const char copyright
[] =
44 "@(#) Copyright (c) 1983, 1993\n\
45 The Regents of the University of California. All rights reserved.\n";
50 static char sccsid
[] = "@(#)main.c 8.6 (Berkeley) 5/4/95";
52 static const char rcsid
[] =
53 "$Id: main.c,v 1.2 1999/10/11 12:53:23 stelian Exp $";
56 #include <sys/param.h>
61 #include <linux/ext2_fs.h>
62 #include <bsdcompat.h>
66 #include <ufs/ufs/dinode.h>
67 #endif /* __linux__ */
68 #include <protocols/dumprestore.h>
76 #include <ext2fs/ext2fs.h>
80 #include "pathnames.h"
84 int bflag
= 0, cvtflag
= 0, dflag
= 0, vflag
= 0, yflag
= 0;
85 int hflag
= 1, mflag
= 1, Nflag
= 0;
98 int compare_ignore_not_found
;
100 char *tmpdir
= _PATH_TMP
;
106 static void obsolete
__P((int *, char **[]));
107 static void usage
__P((void));
117 char *symtbl
= "./restoresymtable";
118 char *p
, name
[MAXPATHLEN
];
120 /* Temp files should *not* be readable. We set permissions later. */
124 __progname
= argv
[0];
130 if ((inputdev
= getenv("TAPE")) == NULL
)
131 inputdev
= _PATH_DEFTAPE
;
132 obsolete(&argc
, &argv
);
134 #define optlist "b:CcdDf:hikmNRrs:tTuvxy"
136 #define optlist "b:CcdDf:himNRrs:tTuvxy"
138 while ((ch
= getopt(argc
, argv
, optlist
)) != -1)
141 /* Change default tape blocksize. */
143 ntrec
= strtol(optarg
, &p
, 10);
145 errx(1, "illegal blocksize -- %s", optarg
);
147 errx(1, "block size must be greater than 0");
180 "%c and %c options are mutually exclusive",
191 /* Dumpnum (skip to) for multifile dump tapes. */
192 dumpnum
= strtol(optarg
, &p
, 10);
194 errx(1, "illegal dump number -- %s", optarg
);
196 errx(1, "dump number must be greater than 0");
214 errx(1, "none of C, i, R, r, t or x options specified");
216 if (signal(SIGINT
, onintr
) == SIG_IGN
)
217 (void) signal(SIGINT
, SIG_IGN
);
218 if (signal(SIGTERM
, onintr
) == SIG_IGN
)
219 (void) signal(SIGTERM
, SIG_IGN
);
231 * Compare contents of tape.
236 vprintf(stdout
, "Begin compare restore\n");
237 compare_ignore_not_found
= 0;
239 printf("filesys = %s\n", filesys
);
240 if (stat(filesys
, &stbuf
) < 0) {
241 fprintf(stderr
, "cannot stat directory %s: %s\n",
242 filesys
, strerror(errno
));
245 if (chdir(filesys
) < 0) {
246 fprintf(stderr
, "cannot cd to %s: %s\n",
247 filesys
, strerror(errno
));
251 compare_ignore_not_found
= dumptime
> 0;
252 initsymtable((char *)0);
254 treescan(".", ROOTINO
, nodeupdates
);
270 * Incremental restoration of a file system.
276 * This is an incremental dump tape.
278 vprintf(stdout
, "Begin incremental restore\n");
279 initsymtable(symtbl
);
282 vprintf(stdout
, "Calculate node updates.\n");
283 treescan(".", ROOTINO
, nodeupdates
);
288 * This is a level zero dump tape.
290 vprintf(stdout
, "Begin level 0 restore\n");
291 initsymtable((char *)0);
293 vprintf(stdout
, "Calculate extraction list.\n");
294 treescan(".", ROOTINO
, nodeupdates
);
296 createleaves(symtbl
);
301 vprintf(stdout
, "Verify the directory structure\n");
302 treescan(".", ROOTINO
, verifyfile
);
304 dumpsymtable(symtbl
, (long)1);
307 * Resume an incremental file system restoration.
310 initsymtable(symtbl
);
313 createleaves(symtbl
);
317 dumpsymtable(symtbl
, (long)1);
320 * List contents of tape.
325 initsymtable((char *)0);
327 canon(*argv
++, name
, sizeof(name
));
328 ino
= dirlookup(name
);
331 treescan(name
, ino
, listfile
);
335 * Batch extraction of tape contents.
340 initsymtable((char *)0);
342 canon(*argv
++, name
, sizeof(name
));
343 ino
= dirlookup(name
);
348 treescan(name
, ino
, addfile
);
359 exit(1); /* gcc shut up */
365 (void)fprintf(stderr
, "usage:\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n",
366 "restore -i [-chkmuvy] [-b blocksize] [-f file] [-s fileno]",
367 "restore -r [-ckuvy] [-b blocksize] [-f file] [-s fileno]",
368 "restore -R [-ckuvy] [-b blocksize] [-f file] [-s fileno]",
369 "restore -x [-chkmuvy] [-b blocksize] [-f file] [-s fileno] [file ...]",
370 "restore -t [-chkuvy] [-b blocksize] [-f file] [-s fileno] [file ...]");
376 * Change set of key letters and ordered arguments into something
377 * getopt(3) will like.
380 obsolete(argcp
, argvp
)
385 char *ap
, **argv
, *flagsp
=NULL
, **nargv
, *p
=NULL
;
391 /* Return if no arguments or first argument has leading dash. */
393 if (argc
== 1 || *ap
== '-')
396 /* Allocate space for new arguments. */
397 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
398 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
402 argv
+= 2, argc
-= 2;
404 for (flags
= 0; *ap
; ++ap
) {
410 warnx("option requires an argument -- %c", *ap
);
413 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
417 (void)strcpy(&nargv
[0][2], *argv
);
431 /* Terminate flags. */
437 /* Copy remaining arguments. */
438 while ((*nargv
++ = *argv
++));
440 /* Update argument count. */
441 *argcp
= nargv
- *argvp
- 1;