]>
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-2000
9 * Copyright (c) 1983, 1993
10 * The Regents of the University of California. All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 static const char rcsid
[] =
43 "$Id: main.c,v 1.12 2000/05/28 16:52:21 stelian Exp $";
46 #include <sys/param.h>
51 #include <linux/ext2_fs.h>
52 #include <bsdcompat.h>
56 #include <ufs/ufs/dinode.h>
57 #endif /* __linux__ */
58 #include <protocols/dumprestore.h>
60 #include <compaterr.h>
66 #include <ext2fs/ext2fs.h>
70 #include "pathnames.h"
74 int bflag
= 0, cvtflag
= 0, dflag
= 0, vflag
= 0, yflag
= 0;
75 int hflag
= 1, mflag
= 1, Nflag
= 0;
89 int compare_ignore_not_found
;
91 char filesys
[NAMELEN
];
92 static const char *stdin_opt
= NULL
;
98 static void obsolete
__P((int *, char **[]));
99 static void usage
__P((void));
100 static void use_stdin
__P((const char *));
103 main(int argc
, char *argv
[])
107 char *inputdev
= _PATH_DEFTAPE
;
108 char *symtbl
= "./restoresymtable";
109 char *p
, name
[MAXPATHLEN
];
110 FILE *filelist
= NULL
;
111 char fname
[MAXPATHLEN
];
113 /* Temp files should *not* be readable. We set permissions later. */
117 __progname
= argv
[0];
123 if ((inputdev
= getenv("TAPE")) == NULL
)
124 inputdev
= _PATH_DEFTAPE
;
125 if ((tmpdir
= getenv("TMPDIR")) == NULL
)
127 if ((tmpdir
= strdup(tmpdir
)) == NULL
)
128 err(1, "malloc tmpdir");
129 for (p
= tmpdir
+ strlen(tmpdir
) - 1; p
>= tmpdir
&& *p
== '/'; p
--)
131 obsolete(&argc
, &argv
);
133 #define optlist "b:CcdD:f:hikmMNRrs:tT:uvxX:y"
135 #define optlist "b:CcdD:f:himMNRrs:tT:uvxX:y"
137 while ((ch
= getopt(argc
, argv
, optlist
)) != -1)
140 /* Change default tape blocksize. */
142 ntrec
= strtol(optarg
, &p
, 10);
144 errx(1, "illegal blocksize -- %s", optarg
);
146 errx(1, "block size must be greater than 0");
152 strncpy(filesys
, optarg
, NAMELEN
);
153 filesys
[NAMELEN
- 1] = '\0';
162 if( !strcmp(optarg
,"-") )
182 "%c and %c options are mutually exclusive",
196 /* Dumpnum (skip to) for multifile dump tapes. */
197 dumpnum
= strtol(optarg
, &p
, 10);
199 errx(1, "illegal dump number -- %s", optarg
);
201 errx(1, "dump number must be greater than 0");
210 if( !strcmp(optarg
,"-") ) {
215 if ( !(filelist
= fopen(optarg
,"r")) )
216 errx(1, "can't open file for reading -- %s", optarg
);
228 errx(1, "none of C, i, R, r, t or x options specified");
230 if (signal(SIGINT
, onintr
) == SIG_IGN
)
231 (void) signal(SIGINT
, SIG_IGN
);
232 if (signal(SIGTERM
, onintr
) == SIG_IGN
)
233 (void) signal(SIGTERM
, SIG_IGN
);
240 if (argc
== 0 && !filelist
) {
247 * Compare contents of tape.
252 Vprintf(stdout
, "Begin compare restore\n");
253 compare_ignore_not_found
= 0;
256 printf("filesys = %s\n", filesys
);
257 if (stat(filesys
, &stbuf
) < 0)
258 err(1, "cannot stat directory %s", filesys
);
259 if (chdir(filesys
) < 0)
260 err(1, "cannot cd to %s", filesys
);
261 compare_ignore_not_found
= dumptime
> 0;
262 initsymtable((char *)0);
264 treescan(".", ROOTINO
, nodeupdates
);
267 if (compare_errors
) {
268 printf("Some files were modified!\n");
284 * Incremental restoration of a file system.
290 * This is an incremental dump tape.
292 Vprintf(stdout
, "Begin incremental restore\n");
293 initsymtable(symtbl
);
296 Vprintf(stdout
, "Calculate node updates.\n");
297 treescan(".", ROOTINO
, nodeupdates
);
302 * This is a level zero dump tape.
304 Vprintf(stdout
, "Begin level 0 restore\n");
305 initsymtable((char *)0);
307 Vprintf(stdout
, "Calculate extraction list.\n");
308 treescan(".", ROOTINO
, nodeupdates
);
310 createleaves(symtbl
);
315 Vprintf(stdout
, "Verify the directory structure\n");
316 treescan(".", ROOTINO
, verifyfile
);
318 dumpsymtable(symtbl
, (long)1);
321 * Resume an incremental file system restoration.
324 initsymtable(symtbl
);
327 createleaves(symtbl
);
331 dumpsymtable(symtbl
, (long)1);
334 /* handle file names from either text file (-X) or the command line */
335 #define NEXTFILE(p) \
341 else if (filelist) { \
342 if ((p = fgets(fname, MAXPATHLEN, filelist))) { \
343 if ( *p && *(p + strlen(p) - 1) == '\n' ) /* possible null string */ \
344 *(p + strlen(p) - 1) = '\0'; \
345 if ( !*p ) /* skip empty lines */ \
351 * List contents of tape.
356 initsymtable((char *)0);
361 canon(p
, name
, sizeof(name
));
362 ino
= dirlookup(name
);
365 treescan(name
, ino
, listfile
);
369 * Batch extraction of tape contents.
374 initsymtable((char *)0);
379 canon(p
, name
, sizeof(name
));
380 ino
= dirlookup(name
);
385 treescan(name
, ino
, addfile
);
396 return 0; /* gcc shut up */
407 (void)fprintf(stderr
,
408 "%s %s\n", __progname
, _DUMP_VERSION
);
409 (void)fprintf(stderr
,
410 "usage:\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n",
411 __progname
, " -i [-ch" kerbflag
"mMuvy] [-b blocksize] [-f file] [-s fileno]",
412 __progname
, " -r [-c" kerbflag
"Muvy] [-b blocksize] [-f file] [-s fileno]",
413 __progname
, " -R [-c" kerbflag
"Muvy] [-b blocksize] [-f file] [-s fileno]",
414 __progname
, " -x [-ch" kerbflag
"mMuvy] [-b blocksize] [-f file] [-s fileno] [-X filelist] [file ...]",
415 __progname
, " -t [-ch" kerbflag
"Muvy] [-b blocksize] [-f file] [-s fileno] [-X filelist] [file ...]");
421 * Change set of key letters and ordered arguments into something
422 * getopt(3) will like.
425 obsolete(int *argcp
, char **argvp
[])
428 char *ap
, **argv
, *flagsp
= NULL
, **nargv
, *p
= NULL
;
434 /* Return if no arguments or first argument has leading dash. */
436 if (argc
== 1 || *ap
== '-')
439 /* Allocate space for new arguments. */
440 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
441 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
442 err(1, "malloc args");
445 argv
+= 2, argc
-= 2;
447 for (flags
= 0; *ap
; ++ap
) {
456 warnx("option requires an argument -- %c", *ap
);
459 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
460 err(1, "malloc arg");
463 (void)strcpy(&nargv
[0][2], *argv
);
477 /* Terminate flags. */
483 /* Copy remaining arguments. */
484 while ((*nargv
++ = *argv
++));
486 /* Update argument count. */
487 *argcp
= nargv
- *argvp
- 1;
492 * reserve stdin for opt (avoid conflicts)
495 use_stdin(const char *opt
)
498 errx(1, "can't handle standard input for both %s and %s",