xref: /csrg-svn/old/dump.4.1/dumpmain.c (revision 22028)
1*22028Sdist /*
2*22028Sdist  * Copyright (c) 1980 Regents of the University of California.
3*22028Sdist  * All rights reserved.  The Berkeley software License Agreement
4*22028Sdist  * specifies the terms and conditions for redistribution.
5*22028Sdist  */
6*22028Sdist 
7*22028Sdist #ifndef lint
8*22028Sdist static char sccsid[] = "@(#)dumpmain.c	5.1 (Berkeley) 06/05/85";
9*22028Sdist #endif not lint
10*22028Sdist 
111423Sroot #include "dump.h"
121423Sroot 
131423Sroot int	notify = 0;	/* notify operator flag */
141423Sroot int	blockswritten = 0;	/* number of blocks written on current tape */
151423Sroot int	tapeno = 0;	/* current tape number */
161423Sroot int	density = 160;	/* density in 0.1" units */
171423Sroot 
main(argc,argv)181423Sroot main(argc, argv)
191423Sroot 	int	argc;
201423Sroot 	char	*argv[];
211423Sroot {
221423Sroot 	char		*arg;
231423Sroot 	register	i;
241423Sroot 	float		fetapes;
251423Sroot 	register	struct	fstab	*dt;
261423Sroot 
271423Sroot 	time(&(spcl.c_date));
281423Sroot 
291423Sroot 	tsize = 2300L*12L*10L;
301423Sroot 	tape = TAPE;
311423Sroot 	disk = DISK;
321423Sroot 	increm = NINCREM;
331423Sroot 
341423Sroot 	incno = '9';
351423Sroot 	uflag = 0;
361423Sroot 	arg = "u";
371423Sroot 	if(argc > 1) {
381423Sroot 		argv++;
391423Sroot 		argc--;
401423Sroot 		arg = *argv;
411423Sroot 		if (*arg == '-')
421423Sroot 			argc++;
431423Sroot 	}
441423Sroot 	while(*arg)
451423Sroot 	switch (*arg++) {
461463Sroot 	case 'w':
471463Sroot 		lastdump('w');		/* tell us only what has to be done */
481463Sroot 		exit(0);
491463Sroot 		break;
501423Sroot 	case 'W':			/* what to do */
511463Sroot 		lastdump('W');		/* tell us the current state of what has been done */
521423Sroot 		exit(0);		/* do nothing else */
531423Sroot 		break;
541423Sroot 
551423Sroot 	case 'J':			/* update old to new */
561423Sroot 		o_nconvert();
571423Sroot 		exit(0);		/* do nothing else */
581423Sroot 		break;
591423Sroot 
601423Sroot 	case 'f':			/* output file */
611423Sroot 		if(argc > 1) {
621423Sroot 			argv++;
631423Sroot 			argc--;
641423Sroot 			tape = *argv;
651423Sroot 		}
661423Sroot 		break;
671423Sroot 
681423Sroot 	case 'd':			/* density, in bits per inch */
691423Sroot 		if (argc > 1) {
701423Sroot 			argv++;
711423Sroot 			argc--;
721423Sroot 			density = atoi(*argv) / 10;
731423Sroot 		}
741423Sroot 		break;
751423Sroot 
761423Sroot 	case 's':			/* tape size, feet */
771423Sroot 		if(argc > 1) {
781423Sroot 			argv++;
791423Sroot 			argc--;
801423Sroot 			tsize = atol(*argv);
811423Sroot 			tsize *= 12L*10L;
821423Sroot 		}
831423Sroot 		break;
841423Sroot 
851423Sroot 	case '0':			/* dump level */
861423Sroot 	case '1':
871423Sroot 	case '2':
881423Sroot 	case '3':
891423Sroot 	case '4':
901423Sroot 	case '5':
911423Sroot 	case '6':
921423Sroot 	case '7':
931423Sroot 	case '8':
941423Sroot 	case '9':
951423Sroot 		incno = arg[-1];
961423Sroot 		break;
971423Sroot 
981423Sroot 	case 'u':			/* update /etc/dumpdates */
991423Sroot 		uflag++;
1001423Sroot 		break;
1011423Sroot 
1021423Sroot 	case 'n':			/* notify operators */
1031423Sroot 		notify++;
1041423Sroot 		break;
1051423Sroot 
1061423Sroot 	default:
10712082Smckusick 		fprintf(stderr, "bad key '%c%'\n", arg[-1]);
1081423Sroot 		Exit(X_ABORT);
1091423Sroot 	}
11012082Smckusick 	if(strcmp(tape, "-") == 0) {
11112082Smckusick 		pipeout++;
11212082Smckusick 		tape = "standard output";
11312082Smckusick 	}
1141423Sroot 	if(argc > 1) {
1151423Sroot 		argv++;
1161423Sroot 		argc--;
1171423Sroot 		disk = *argv;
1181423Sroot 	}
1191423Sroot 
1201423Sroot 	if (signal(SIGHUP, sighup) == SIG_IGN)
1211423Sroot 		signal(SIGHUP, SIG_IGN);
1221423Sroot 	if (signal(SIGTRAP, sigtrap) == SIG_IGN)
1231423Sroot 		signal(SIGTRAP, SIG_IGN);
1241423Sroot 	if (signal(SIGFPE, sigfpe) == SIG_IGN)
1251423Sroot 		signal(SIGFPE, SIG_IGN);
1261423Sroot 	if (signal(SIGBUS, sigbus) == SIG_IGN)
1271423Sroot 		signal(SIGBUS, SIG_IGN);
1281423Sroot 	if (signal(SIGSEGV, sigsegv) == SIG_IGN)
1291423Sroot 		signal(SIGSEGV, SIG_IGN);
1301423Sroot 	if (signal(SIGTERM, sigterm) == SIG_IGN)
1311423Sroot 		signal(SIGTERM, SIG_IGN);
1321423Sroot 
1331423Sroot 
1341423Sroot 	if (signal(SIGINT, interrupt) == SIG_IGN)
1351423Sroot 		signal(SIGINT, SIG_IGN);
1361423Sroot 
1371423Sroot 	set_operators();	/* /etc/group snarfed */
1381423Sroot 	getfstab();		/* /etc/fstab snarfed */
1391423Sroot 	/*
1401423Sroot 	 *	disk can be either the full special file name,
1411423Sroot 	 *	the suffix of the special file name,
1421423Sroot 	 *	the special name missing the leading '/',
1431423Sroot 	 *	the file system name with or without the leading '/'.
1441423Sroot 	 */
1451423Sroot 	dt = fstabsearch(disk);
1461423Sroot 	if (dt != 0)
1471423Sroot 		disk = rawname(dt->fs_spec);
1481423Sroot 	getitime();		/* /etc/dumpdates snarfed */
1491423Sroot 
1501423Sroot 	msg("Date of this level %c dump: %s\n", incno, prdate(spcl.c_date));
1511423Sroot 	msg("Date of last level %c dump: %s\n", incno, prdate(spcl.c_ddate));
1521423Sroot 	msg("Dumping %s ", disk);
1531423Sroot 	if (dt != 0)
1541423Sroot 		msgtail("(%s) ", dt->fs_file);
1551423Sroot 	msgtail("to %s\n", tape);
1561423Sroot 
1571423Sroot 	fi = open(disk, 0);
1581423Sroot 	if (fi < 0) {
1591423Sroot 		msg("Cannot open %s\n", disk);
1601423Sroot 		Exit(X_ABORT);
1611423Sroot 	}
1621423Sroot 	CLR(clrmap);
1631423Sroot 	CLR(dirmap);
1641423Sroot 	CLR(nodmap);
1651423Sroot 	esize = 0;
1661423Sroot 
1671423Sroot 	msg("mapping (Pass I) [regular files]\n");
1681423Sroot 	pass(mark, (short *)NULL);		/* mark updates esize */
1691423Sroot 
1701423Sroot 	do {
1711423Sroot 		msg("mapping (Pass II) [directories]\n");
1721423Sroot 		nadded = 0;
1731423Sroot 		pass(add, dirmap);
1741423Sroot 	} while(nadded);
1751423Sroot 
1761423Sroot 	bmapest(clrmap);
1771423Sroot 	bmapest(nodmap);
1781423Sroot 
1791423Sroot 	fetapes =
1801423Sroot 		(	 esize		/* blocks */
1811423Sroot 			*BSIZE		/* bytes / block */
1821423Sroot 			*(1.0/density)	/* 0.1" / byte */
1831423Sroot 		  +
1841423Sroot 			 esize		/* blocks */
1851423Sroot 			*(1.0/NTREC)	/* IRG's / block */
1861423Sroot 			*7		/* 0.1" / IRG */
1871423Sroot 		) * (1.0 / tsize )	/* tape / 0.1" */
1881423Sroot 	;
1891423Sroot 	etapes = fetapes;		/* truncating assignment */
1901423Sroot 	etapes++;
1911423Sroot 	/*
1921423Sroot 	 *	esize is typically about 5% too low; we frob it here
1931423Sroot 	 */
1941423Sroot 	esize += ((5*esize)/100);
1951423Sroot 	msg("estimated %ld tape blocks on %3.2f tape(s).\n", esize, fetapes);
1961423Sroot 
1971423Sroot 	otape();			/* bitmap is the first to tape write */
1981423Sroot 	time(&(tstart_writing));
1991423Sroot 	bitmap(clrmap, TS_CLRI);
2001423Sroot 
2011423Sroot 	msg("dumping (Pass III) [directories]\n");
2021423Sroot 	pass(dump, dirmap);
2031423Sroot 
2041423Sroot 	msg("dumping (Pass IV) [regular files]\n");
2051423Sroot 	pass(dump, nodmap);
2061423Sroot 
2071423Sroot 	spcl.c_type = TS_END;
2081423Sroot 	for(i=0; i<NTREC; i++)
2091423Sroot 		spclrec();
2101423Sroot 	msg("DUMP: %ld tape blocks on %d tape(s)\n",spcl.c_tapea,spcl.c_volume);
2111423Sroot 	msg("DUMP IS DONE\n");
2121423Sroot 
2131423Sroot 	putitime();
21412082Smckusick 	if (!pipeout) {
21512082Smckusick 		close(to);
21612082Smckusick 		rewind();
21712082Smckusick 	}
2181423Sroot 	broadcast("DUMP IS DONE!\7\7\n");
2191423Sroot 	Exit(X_FINOK);
2201423Sroot }
2211423Sroot 
sighup()2221423Sroot int	sighup(){	msg("SIGHUP()  try rewriting\n"); sigAbort();}
sigtrap()2231423Sroot int	sigtrap(){	msg("SIGTRAP()  try rewriting\n"); sigAbort();}
sigfpe()2241423Sroot int	sigfpe(){	msg("SIGFPE()  try rewriting\n"); sigAbort();}
sigbus()2251423Sroot int	sigbus(){	msg("SIGBUS()  try rewriting\n"); sigAbort();}
sigsegv()2261423Sroot int	sigsegv(){	msg("SIGSEGV()  ABORTING!\n"); abort();}
sigalrm()2271423Sroot int	sigalrm(){	msg("SIGALRM()  try rewriting\n"); sigAbort();}
sigterm()2281423Sroot int	sigterm(){	msg("SIGTERM()  try rewriting\n"); sigAbort();}
2291423Sroot 
sigAbort()2301423Sroot sigAbort()
2311423Sroot {
2321423Sroot 	msg("Rewriting attempted as response to unknown signal.\n");
2331423Sroot 	fflush(stderr);
2341423Sroot 	fflush(stdout);
2351423Sroot 	close_rewind();
2361423Sroot 	exit(X_REWRITE);
2371423Sroot }
2381423Sroot 
rawname(cp)2391423Sroot char *rawname(cp)
2401423Sroot 	char *cp;
2411423Sroot {
2421423Sroot 	static char rawbuf[32];
24312082Smckusick 	char *dp = (char *)rindex(cp, '/');
2441423Sroot 
2451423Sroot 	if (dp == 0)
2461423Sroot 		return (0);
2471423Sroot 	*dp = 0;
2481423Sroot 	strcpy(rawbuf, cp);
2491423Sroot 	*dp = '/';
2501423Sroot 	strcat(rawbuf, "/r");
2511423Sroot 	strcat(rawbuf, dp+1);
2521423Sroot 	return (rawbuf);
2531423Sroot }
254