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