]>
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@noos.fr>, 1999-2000
6 * Stelian Pop <pop@noos.fr> - AlcĂ´ve <www.alcove.fr>, 2000
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 rcsid
[] =
44 "$Id: main.c,v 1.19 2001/03/23 14:40:12 stelian Exp $";
48 #include <sys/param.h>
53 #ifdef HAVE_EXT2FS_EXT2_FS_H
54 #include <ext2fs/ext2_fs.h>
56 #include <linux/ext2_fs.h>
58 #include <bsdcompat.h>
62 #include <ufs/ufs/dinode.h>
63 #endif /* __linux__ */
64 #include <protocols/dumprestore.h>
66 #include <compaterr.h>
72 #include <ext2fs/ext2fs.h>
76 #include "pathnames.h"
80 int bflag
= 0, cvtflag
= 0, dflag
= 0, vflag
= 0, yflag
= 0;
81 int hflag
= 1, mflag
= 1, Nflag
= 0, zflag
= 0;
95 int compare_ignore_not_found
;
97 char filesys
[NAMELEN
];
98 static const char *stdin_opt
= NULL
;
104 static void obsolete
__P((int *, char **[]));
105 static void usage
__P((void));
106 static void use_stdin
__P((const char *));
109 main(int argc
, char *argv
[])
113 char *inputdev
= _PATH_DEFTAPE
;
114 char *symtbl
= "./restoresymtable";
115 char *p
, name
[MAXPATHLEN
];
116 FILE *filelist
= NULL
;
117 char fname
[MAXPATHLEN
];
119 /* Temp files should *not* be readable. We set permissions later. */
123 __progname
= argv
[0];
129 if ((inputdev
= getenv("TAPE")) == NULL
)
130 inputdev
= _PATH_DEFTAPE
;
131 if ((tmpdir
= getenv("TMPDIR")) == NULL
)
133 if ((tmpdir
= strdup(tmpdir
)) == NULL
)
134 err(1, "malloc tmpdir");
135 for (p
= tmpdir
+ strlen(tmpdir
) - 1; p
>= tmpdir
&& *p
== '/'; p
--)
137 obsolete(&argc
, &argv
);
139 #define optlist "b:CcdD:f:hikmMNRrs:tT:uvxX:y"
141 #define optlist "b:CcdD:f:himMNRrs:tT:uvxX:y"
143 while ((ch
= getopt(argc
, argv
, optlist
)) != -1)
146 /* Change default tape blocksize. */
148 ntrec
= strtol(optarg
, &p
, 10);
150 errx(1, "illegal blocksize -- %s", optarg
);
152 errx(1, "block size must be greater than 0");
158 strncpy(filesys
, optarg
, NAMELEN
);
159 filesys
[NAMELEN
- 1] = '\0';
168 if( !strcmp(optarg
,"-") )
188 "%c and %c options are mutually exclusive",
202 /* Dumpnum (skip to) for multifile dump tapes. */
203 dumpnum
= strtol(optarg
, &p
, 10);
205 errx(1, "illegal dump number -- %s", optarg
);
207 errx(1, "dump number must be greater than 0");
216 if( !strcmp(optarg
,"-") ) {
221 if ( !(filelist
= fopen(optarg
,"r")) )
222 errx(1, "can't open file for reading -- %s", optarg
);
234 errx(1, "none of C, i, R, r, t or x options specified");
236 if (signal(SIGINT
, onintr
) == SIG_IGN
)
237 (void) signal(SIGINT
, SIG_IGN
);
238 if (signal(SIGTERM
, onintr
) == SIG_IGN
)
239 (void) signal(SIGTERM
, SIG_IGN
);
246 if (argc
== 0 && !filelist
) {
253 * Compare contents of tape.
258 Vprintf(stdout
, "Begin compare restore\n");
259 compare_ignore_not_found
= 0;
262 printf("filesys = %s\n", filesys
);
263 if (stat(filesys
, &stbuf
) < 0)
264 err(1, "cannot stat directory %s", filesys
);
265 if (chdir(filesys
) < 0)
266 err(1, "cannot cd to %s", filesys
);
267 compare_ignore_not_found
= dumptime
> 0;
268 initsymtable((char *)0);
270 treescan(".", ROOTINO
, nodeupdates
);
273 if (compare_errors
) {
274 printf("Some files were modified!\n");
290 * Incremental restoration of a file system.
296 * This is an incremental dump tape.
298 Vprintf(stdout
, "Begin incremental restore\n");
299 initsymtable(symtbl
);
302 Vprintf(stdout
, "Calculate node updates.\n");
303 treescan(".", ROOTINO
, nodeupdates
);
308 * This is a level zero dump tape.
310 Vprintf(stdout
, "Begin level 0 restore\n");
311 initsymtable((char *)0);
313 Vprintf(stdout
, "Calculate extraction list.\n");
314 treescan(".", ROOTINO
, nodeupdates
);
316 createleaves(symtbl
);
321 Vprintf(stdout
, "Verify the directory structure\n");
322 treescan(".", ROOTINO
, verifyfile
);
324 dumpsymtable(symtbl
, (long)1);
327 * Resume an incremental file system restoration.
330 initsymtable(symtbl
);
333 createleaves(symtbl
);
337 dumpsymtable(symtbl
, (long)1);
340 /* handle file names from either text file (-X) or the command line */
341 #define NEXTFILE(p) \
347 else if (filelist) { \
348 if ((p = fgets(fname, MAXPATHLEN, filelist))) { \
349 if ( *p && *(p + strlen(p) - 1) == '\n' ) /* possible null string */ \
350 *(p + strlen(p) - 1) = '\0'; \
351 if ( !*p ) /* skip empty lines */ \
357 * List contents of tape.
362 initsymtable((char *)0);
367 canon(p
, name
, sizeof(name
));
368 ino
= dirlookup(name
);
371 treescan(name
, ino
, listfile
);
375 * Batch extraction of tape contents.
380 initsymtable((char *)0);
385 canon(p
, name
, sizeof(name
));
386 ino
= dirlookup(name
);
391 treescan(name
, ino
, addfile
);
402 return 0; /* gcc shut up */
409 const char *ext2ver
, *ext2date
;
411 ext2fs_get_library_version(&ext2ver
, &ext2date
);
412 (void)fprintf(stderr
, "%s %s (using libext2fs %s of %s)\n",
413 __progname
, _DUMP_VERSION
, ext2ver
, ext2date
);
415 (void)fprintf(stderr
, "%s %s\n", __progname
, _DUMP_VERSION
);
423 (void)fprintf(stderr
,
424 "usage:\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n",
425 __progname
, " -C [-c" kerbflag
"Mvy] [-b blocksize] [-D filesystem] [-f file] [-s fileno]",
426 __progname
, " -i [-ch" kerbflag
"mMuvy] [-b blocksize] [-f file] [-s fileno]",
427 __progname
, " -r [-c" kerbflag
"Muvy] [-b blocksize] [-f file] [-s fileno] [-T directory]",
428 __progname
, " -R [-c" kerbflag
"Muvy] [-b blocksize] [-f file] [-s fileno] [-T directory]",
429 __progname
, " -t [-ch" kerbflag
"Muvy] [-b blocksize] [-f file] [-s fileno] [-X filelist] [file ...]",
430 __progname
, " -x [-ch" kerbflag
"mMuvy] [-b blocksize] [-f file] [-s fileno] [-X filelist] [file ...]");
436 * Change set of key letters and ordered arguments into something
437 * getopt(3) will like.
440 obsolete(int *argcp
, char **argvp
[])
443 char *ap
, **argv
, *flagsp
= NULL
, **nargv
, *p
= NULL
;
449 /* Return if no arguments or first argument has leading dash. */
451 if (argc
== 1 || *ap
== '-')
454 /* Allocate space for new arguments. */
455 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
456 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
457 err(1, "malloc args");
460 argv
+= 2, argc
-= 2;
462 for (flags
= 0; *ap
; ++ap
) {
471 warnx("option requires an argument -- %c", *ap
);
474 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
475 err(1, "malloc arg");
478 (void)strcpy(&nargv
[0][2], *argv
);
492 /* Terminate flags. */
498 /* Copy remaining arguments. */
499 while ((*nargv
++ = *argv
++));
501 /* Update argument count. */
502 *argcp
= nargv
- *argvp
- 1;
507 * reserve stdin for opt (avoid conflicts)
510 use_stdin(const char *opt
)
513 errx(1, "can't handle standard input for both %s and %s",