Home | History | Annotate | Line # | Download | only in restore
main.c revision 1.2
      1  1.1      cgd /*
      2  1.1      cgd  * Copyright (c) 1983 The Regents of the University of California.
      3  1.1      cgd  * All rights reserved.
      4  1.1      cgd  *
      5  1.1      cgd  * Redistribution and use in source and binary forms, with or without
      6  1.1      cgd  * modification, are permitted provided that the following conditions
      7  1.1      cgd  * are met:
      8  1.1      cgd  * 1. Redistributions of source code must retain the above copyright
      9  1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     10  1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     11  1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     12  1.1      cgd  *    documentation and/or other materials provided with the distribution.
     13  1.1      cgd  * 3. All advertising materials mentioning features or use of this software
     14  1.1      cgd  *    must display the following acknowledgement:
     15  1.1      cgd  *	This product includes software developed by the University of
     16  1.1      cgd  *	California, Berkeley and its contributors.
     17  1.1      cgd  * 4. Neither the name of the University nor the names of its contributors
     18  1.1      cgd  *    may be used to endorse or promote products derived from this software
     19  1.1      cgd  *    without specific prior written permission.
     20  1.1      cgd  *
     21  1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  1.1      cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  1.1      cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  1.1      cgd  * SUCH DAMAGE.
     32  1.1      cgd  */
     33  1.1      cgd 
     34  1.1      cgd #ifndef lint
     35  1.1      cgd char copyright[] =
     36  1.1      cgd "@(#) Copyright (c) 1983 The Regents of the University of California.\n\
     37  1.1      cgd  All rights reserved.\n";
     38  1.1      cgd #endif /* not lint */
     39  1.1      cgd 
     40  1.1      cgd #ifndef lint
     41  1.2  mycroft /*static char sccsid[] = "from: @(#)main.c	5.8 (Berkeley) 6/1/90";*/
     42  1.2  mycroft static char rcsid[] = "$Id: main.c,v 1.2 1993/08/01 18:25:18 mycroft Exp $";
     43  1.1      cgd #endif /* not lint */
     44  1.1      cgd 
     45  1.1      cgd /*
     46  1.1      cgd  *	Modified to recursively extract all files within a subtree
     47  1.1      cgd  *	(supressed by the h option) and recreate the heirarchical
     48  1.1      cgd  *	structure of that subtree and move extracted files to their
     49  1.1      cgd  *	proper homes (supressed by the m option).
     50  1.1      cgd  *	Includes the s (skip files) option for use with multiple
     51  1.1      cgd  *	dumps on a single tape.
     52  1.1      cgd  *	8/29/80		by Mike Litzkow
     53  1.1      cgd  *
     54  1.1      cgd  *	Modified to work on the new file system and to recover from
     55  1.1      cgd  *	tape read errors.
     56  1.1      cgd  *	1/19/82		by Kirk McKusick
     57  1.1      cgd  *
     58  1.1      cgd  *	Full incremental restore running entirely in user code and
     59  1.1      cgd  *	interactive tape browser.
     60  1.1      cgd  *	1/19/83		by Kirk McKusick
     61  1.1      cgd  */
     62  1.1      cgd 
     63  1.1      cgd #include "restore.h"
     64  1.1      cgd #include <protocols/dumprestore.h>
     65  1.1      cgd #include <sys/signal.h>
     66  1.1      cgd #include "pathnames.h"
     67  1.1      cgd 
     68  1.1      cgd int	bflag = 0, cvtflag = 0, dflag = 0, vflag = 0, yflag = 0;
     69  1.1      cgd int	hflag = 1, mflag = 1, Nflag = 0;
     70  1.1      cgd char	command = '\0';
     71  1.1      cgd long	dumpnum = 1;
     72  1.1      cgd long	volno = 0;
     73  1.1      cgd long	ntrec;
     74  1.1      cgd char	*dumpmap;
     75  1.1      cgd char	*clrimap;
     76  1.1      cgd ino_t	maxino;
     77  1.1      cgd time_t	dumptime;
     78  1.1      cgd time_t	dumpdate;
     79  1.1      cgd FILE 	*terminal;
     80  1.1      cgd 
     81  1.1      cgd main(argc, argv)
     82  1.1      cgd 	int argc;
     83  1.1      cgd 	char *argv[];
     84  1.1      cgd {
     85  1.1      cgd 	register char *cp;
     86  1.1      cgd 	ino_t ino;
     87  1.1      cgd 	char *inputdev = _PATH_DEFTAPE;
     88  1.1      cgd 	char *symtbl = "./restoresymtable";
     89  1.1      cgd 	char name[MAXPATHLEN];
     90  1.1      cgd 	void onintr();
     91  1.1      cgd 
     92  1.1      cgd 	if (signal(SIGINT, onintr) == SIG_IGN)
     93  1.1      cgd 		(void) signal(SIGINT, SIG_IGN);
     94  1.1      cgd 	if (signal(SIGTERM, onintr) == SIG_IGN)
     95  1.1      cgd 		(void) signal(SIGTERM, SIG_IGN);
     96  1.1      cgd 	setlinebuf(stderr);
     97  1.1      cgd 	if (argc < 2) {
     98  1.1      cgd usage:
     99  1.1      cgd 		fprintf(stderr, "Usage:\n%s%s%s%s%s",
    100  1.1      cgd 			"\trestore tfhsvy [file file ...]\n",
    101  1.1      cgd 			"\trestore xfhmsvy [file file ...]\n",
    102  1.1      cgd 			"\trestore ifhmsvy\n",
    103  1.1      cgd 			"\trestore rfsvy\n",
    104  1.1      cgd 			"\trestore Rfsvy\n");
    105  1.1      cgd 		done(1);
    106  1.1      cgd 	}
    107  1.1      cgd 	argv++;
    108  1.1      cgd 	argc -= 2;
    109  1.1      cgd 	command = '\0';
    110  1.1      cgd 	for (cp = *argv++; *cp; cp++) {
    111  1.1      cgd 		switch (*cp) {
    112  1.1      cgd 		case '-':
    113  1.1      cgd 			break;
    114  1.1      cgd 		case 'c':
    115  1.1      cgd 			cvtflag++;
    116  1.1      cgd 			break;
    117  1.1      cgd 		case 'd':
    118  1.1      cgd 			dflag++;
    119  1.1      cgd 			break;
    120  1.1      cgd 		case 'h':
    121  1.1      cgd 			hflag = 0;
    122  1.1      cgd 			break;
    123  1.1      cgd 		case 'm':
    124  1.1      cgd 			mflag = 0;
    125  1.1      cgd 			break;
    126  1.1      cgd 		case 'N':
    127  1.1      cgd 			Nflag++;
    128  1.1      cgd 			break;
    129  1.1      cgd 		case 'v':
    130  1.1      cgd 			vflag++;
    131  1.1      cgd 			break;
    132  1.1      cgd 		case 'y':
    133  1.1      cgd 			yflag++;
    134  1.1      cgd 			break;
    135  1.1      cgd 		case 'f':
    136  1.1      cgd 			if (argc < 1) {
    137  1.1      cgd 				fprintf(stderr, "missing device specifier\n");
    138  1.1      cgd 				done(1);
    139  1.1      cgd 			}
    140  1.1      cgd 			inputdev = *argv++;
    141  1.1      cgd 			argc--;
    142  1.1      cgd 			break;
    143  1.1      cgd 		case 'b':
    144  1.1      cgd 			/*
    145  1.1      cgd 			 * change default tape blocksize
    146  1.1      cgd 			 */
    147  1.1      cgd 			bflag++;
    148  1.1      cgd 			if (argc < 1) {
    149  1.1      cgd 				fprintf(stderr, "missing block size\n");
    150  1.1      cgd 				done(1);
    151  1.1      cgd 			}
    152  1.1      cgd 			ntrec = atoi(*argv++);
    153  1.1      cgd 			if (ntrec <= 0) {
    154  1.1      cgd 				fprintf(stderr, "Block size must be a positive integer\n");
    155  1.1      cgd 				done(1);
    156  1.1      cgd 			}
    157  1.1      cgd 			argc--;
    158  1.1      cgd 			break;
    159  1.1      cgd 		case 's':
    160  1.1      cgd 			/*
    161  1.1      cgd 			 * dumpnum (skip to) for multifile dump tapes
    162  1.1      cgd 			 */
    163  1.1      cgd 			if (argc < 1) {
    164  1.1      cgd 				fprintf(stderr, "missing dump number\n");
    165  1.1      cgd 				done(1);
    166  1.1      cgd 			}
    167  1.1      cgd 			dumpnum = atoi(*argv++);
    168  1.1      cgd 			if (dumpnum <= 0) {
    169  1.1      cgd 				fprintf(stderr, "Dump number must be a positive integer\n");
    170  1.1      cgd 				done(1);
    171  1.1      cgd 			}
    172  1.1      cgd 			argc--;
    173  1.1      cgd 			break;
    174  1.1      cgd 		case 't':
    175  1.1      cgd 		case 'R':
    176  1.1      cgd 		case 'r':
    177  1.1      cgd 		case 'x':
    178  1.1      cgd 		case 'i':
    179  1.1      cgd 			if (command != '\0') {
    180  1.1      cgd 				fprintf(stderr,
    181  1.1      cgd 					"%c and %c are mutually exclusive\n",
    182  1.1      cgd 					*cp, command);
    183  1.1      cgd 				goto usage;
    184  1.1      cgd 			}
    185  1.1      cgd 			command = *cp;
    186  1.1      cgd 			break;
    187  1.1      cgd 		default:
    188  1.1      cgd 			fprintf(stderr, "Bad key character %c\n", *cp);
    189  1.1      cgd 			goto usage;
    190  1.1      cgd 		}
    191  1.1      cgd 	}
    192  1.1      cgd 	if (command == '\0') {
    193  1.1      cgd 		fprintf(stderr, "must specify i, t, r, R, or x\n");
    194  1.1      cgd 		goto usage;
    195  1.1      cgd 	}
    196  1.1      cgd 	setinput(inputdev);
    197  1.1      cgd 	if (argc == 0) {
    198  1.1      cgd 		argc = 1;
    199  1.1      cgd 		*--argv = ".";
    200  1.1      cgd 	}
    201  1.1      cgd 	switch (command) {
    202  1.1      cgd 	/*
    203  1.1      cgd 	 * Interactive mode.
    204  1.1      cgd 	 */
    205  1.1      cgd 	case 'i':
    206  1.1      cgd 		setup();
    207  1.1      cgd 		extractdirs(1);
    208  1.1      cgd 		initsymtable((char *)0);
    209  1.1      cgd 		runcmdshell();
    210  1.1      cgd 		done(0);
    211  1.1      cgd 	/*
    212  1.1      cgd 	 * Incremental restoration of a file system.
    213  1.1      cgd 	 */
    214  1.1      cgd 	case 'r':
    215  1.1      cgd 		setup();
    216  1.1      cgd 		if (dumptime > 0) {
    217  1.1      cgd 			/*
    218  1.1      cgd 			 * This is an incremental dump tape.
    219  1.1      cgd 			 */
    220  1.1      cgd 			vprintf(stdout, "Begin incremental restore\n");
    221  1.1      cgd 			initsymtable(symtbl);
    222  1.1      cgd 			extractdirs(1);
    223  1.1      cgd 			removeoldleaves();
    224  1.1      cgd 			vprintf(stdout, "Calculate node updates.\n");
    225  1.1      cgd 			treescan(".", ROOTINO, nodeupdates);
    226  1.1      cgd 			findunreflinks();
    227  1.1      cgd 			removeoldnodes();
    228  1.1      cgd 		} else {
    229  1.1      cgd 			/*
    230  1.1      cgd 			 * This is a level zero dump tape.
    231  1.1      cgd 			 */
    232  1.1      cgd 			vprintf(stdout, "Begin level 0 restore\n");
    233  1.1      cgd 			initsymtable((char *)0);
    234  1.1      cgd 			extractdirs(1);
    235  1.1      cgd 			vprintf(stdout, "Calculate extraction list.\n");
    236  1.1      cgd 			treescan(".", ROOTINO, nodeupdates);
    237  1.1      cgd 		}
    238  1.1      cgd 		createleaves(symtbl);
    239  1.1      cgd 		createlinks();
    240  1.1      cgd 		setdirmodes();
    241  1.1      cgd 		checkrestore();
    242  1.1      cgd 		if (dflag) {
    243  1.1      cgd 			vprintf(stdout, "Verify the directory structure\n");
    244  1.1      cgd 			treescan(".", ROOTINO, verifyfile);
    245  1.1      cgd 		}
    246  1.1      cgd 		dumpsymtable(symtbl, (long)1);
    247  1.1      cgd 		done(0);
    248  1.1      cgd 	/*
    249  1.1      cgd 	 * Resume an incremental file system restoration.
    250  1.1      cgd 	 */
    251  1.1      cgd 	case 'R':
    252  1.1      cgd 		initsymtable(symtbl);
    253  1.1      cgd 		skipmaps();
    254  1.1      cgd 		skipdirs();
    255  1.1      cgd 		createleaves(symtbl);
    256  1.1      cgd 		createlinks();
    257  1.1      cgd 		setdirmodes();
    258  1.1      cgd 		checkrestore();
    259  1.1      cgd 		dumpsymtable(symtbl, (long)1);
    260  1.1      cgd 		done(0);
    261  1.1      cgd 	/*
    262  1.1      cgd 	 * List contents of tape.
    263  1.1      cgd 	 */
    264  1.1      cgd 	case 't':
    265  1.1      cgd 		setup();
    266  1.1      cgd 		extractdirs(0);
    267  1.1      cgd 		initsymtable((char *)0);
    268  1.1      cgd 		while (argc--) {
    269  1.1      cgd 			canon(*argv++, name);
    270  1.1      cgd 			ino = dirlookup(name);
    271  1.1      cgd 			if (ino == 0)
    272  1.1      cgd 				continue;
    273  1.1      cgd 			treescan(name, ino, listfile);
    274  1.1      cgd 		}
    275  1.1      cgd 		done(0);
    276  1.1      cgd 	/*
    277  1.1      cgd 	 * Batch extraction of tape contents.
    278  1.1      cgd 	 */
    279  1.1      cgd 	case 'x':
    280  1.1      cgd 		setup();
    281  1.1      cgd 		extractdirs(1);
    282  1.1      cgd 		initsymtable((char *)0);
    283  1.1      cgd 		while (argc--) {
    284  1.1      cgd 			canon(*argv++, name);
    285  1.1      cgd 			ino = dirlookup(name);
    286  1.1      cgd 			if (ino == 0)
    287  1.1      cgd 				continue;
    288  1.1      cgd 			if (mflag)
    289  1.1      cgd 				pathcheck(name);
    290  1.1      cgd 			treescan(name, ino, addfile);
    291  1.1      cgd 		}
    292  1.1      cgd 		createfiles();
    293  1.1      cgd 		createlinks();
    294  1.1      cgd 		setdirmodes();
    295  1.1      cgd 		if (dflag)
    296  1.1      cgd 			checkrestore();
    297  1.1      cgd 		done(0);
    298  1.1      cgd 	}
    299  1.1      cgd }
    300