xref: /csrg-svn/old/dump.4.1/dumpmain.c (revision 1423)
1*1423Sroot static	char *sccsid = "@(#)dumpmain.c	1.1 (Berkeley) 10/13/80";
2*1423Sroot #include "dump.h"
3*1423Sroot 
4*1423Sroot int	notify = 0;	/* notify operator flag */
5*1423Sroot int	blockswritten = 0;	/* number of blocks written on current tape */
6*1423Sroot int	tapeno = 0;	/* current tape number */
7*1423Sroot int	density = 160;	/* density in 0.1" units */
8*1423Sroot 
9*1423Sroot main(argc, argv)
10*1423Sroot 	int	argc;
11*1423Sroot 	char	*argv[];
12*1423Sroot {
13*1423Sroot 	char		*arg;
14*1423Sroot 	register	i;
15*1423Sroot 	float		fetapes;
16*1423Sroot 	register	struct	fstab	*dt;
17*1423Sroot 
18*1423Sroot 	time(&(spcl.c_date));
19*1423Sroot 
20*1423Sroot 	tsize = 2300L*12L*10L;
21*1423Sroot 	tape = TAPE;
22*1423Sroot 	disk = DISK;
23*1423Sroot 	increm = NINCREM;
24*1423Sroot 
25*1423Sroot 	incno = '9';
26*1423Sroot 	uflag = 0;
27*1423Sroot 	arg = "u";
28*1423Sroot 	if(argc > 1) {
29*1423Sroot 		argv++;
30*1423Sroot 		argc--;
31*1423Sroot 		arg = *argv;
32*1423Sroot 		if (*arg == '-')
33*1423Sroot 			argc++;
34*1423Sroot 	}
35*1423Sroot 	while(*arg)
36*1423Sroot 	switch (*arg++) {
37*1423Sroot 	case 'W':			/* what to do */
38*1423Sroot 		lastdump();
39*1423Sroot 		exit(0);		/* do nothing else */
40*1423Sroot 		break;
41*1423Sroot 
42*1423Sroot 	case 'J':			/* update old to new */
43*1423Sroot 		o_nconvert();
44*1423Sroot 		exit(0);		/* do nothing else */
45*1423Sroot 		break;
46*1423Sroot 
47*1423Sroot 	case 'f':			/* output file */
48*1423Sroot 		if(argc > 1) {
49*1423Sroot 			argv++;
50*1423Sroot 			argc--;
51*1423Sroot 			tape = *argv;
52*1423Sroot 		}
53*1423Sroot 		break;
54*1423Sroot 
55*1423Sroot 	case 'd':			/* density, in bits per inch */
56*1423Sroot 		if (argc > 1) {
57*1423Sroot 			argv++;
58*1423Sroot 			argc--;
59*1423Sroot 			density = atoi(*argv) / 10;
60*1423Sroot 		}
61*1423Sroot 		break;
62*1423Sroot 
63*1423Sroot 	case 's':			/* tape size, feet */
64*1423Sroot 		if(argc > 1) {
65*1423Sroot 			argv++;
66*1423Sroot 			argc--;
67*1423Sroot 			tsize = atol(*argv);
68*1423Sroot 			tsize *= 12L*10L;
69*1423Sroot 		}
70*1423Sroot 		break;
71*1423Sroot 
72*1423Sroot 	case '0':			/* dump level */
73*1423Sroot 	case '1':
74*1423Sroot 	case '2':
75*1423Sroot 	case '3':
76*1423Sroot 	case '4':
77*1423Sroot 	case '5':
78*1423Sroot 	case '6':
79*1423Sroot 	case '7':
80*1423Sroot 	case '8':
81*1423Sroot 	case '9':
82*1423Sroot 		incno = arg[-1];
83*1423Sroot 		break;
84*1423Sroot 
85*1423Sroot 	case 'u':			/* update /etc/dumpdates */
86*1423Sroot 		uflag++;
87*1423Sroot 		break;
88*1423Sroot 
89*1423Sroot 	case 'n':			/* notify operators */
90*1423Sroot 		notify++;
91*1423Sroot 		break;
92*1423Sroot 
93*1423Sroot 	default:
94*1423Sroot 		printf("bad key '%c%'\n", arg[-1]);
95*1423Sroot 		Exit(X_ABORT);
96*1423Sroot 	}
97*1423Sroot 	if(argc > 1) {
98*1423Sroot 		argv++;
99*1423Sroot 		argc--;
100*1423Sroot 		disk = *argv;
101*1423Sroot 	}
102*1423Sroot 
103*1423Sroot 	if (signal(SIGHUP, sighup) == SIG_IGN)
104*1423Sroot 		signal(SIGHUP, SIG_IGN);
105*1423Sroot 	if (signal(SIGTRAP, sigtrap) == SIG_IGN)
106*1423Sroot 		signal(SIGTRAP, SIG_IGN);
107*1423Sroot 	if (signal(SIGFPE, sigfpe) == SIG_IGN)
108*1423Sroot 		signal(SIGFPE, SIG_IGN);
109*1423Sroot 	if (signal(SIGBUS, sigbus) == SIG_IGN)
110*1423Sroot 		signal(SIGBUS, SIG_IGN);
111*1423Sroot 	if (signal(SIGSEGV, sigsegv) == SIG_IGN)
112*1423Sroot 		signal(SIGSEGV, SIG_IGN);
113*1423Sroot 	if (signal(SIGTERM, sigterm) == SIG_IGN)
114*1423Sroot 		signal(SIGTERM, SIG_IGN);
115*1423Sroot 
116*1423Sroot 
117*1423Sroot 	if (signal(SIGINT, interrupt) == SIG_IGN)
118*1423Sroot 		signal(SIGINT, SIG_IGN);
119*1423Sroot 
120*1423Sroot 	set_operators();	/* /etc/group snarfed */
121*1423Sroot 	getfstab();		/* /etc/fstab snarfed */
122*1423Sroot 	/*
123*1423Sroot 	 *	disk can be either the full special file name,
124*1423Sroot 	 *	the suffix of the special file name,
125*1423Sroot 	 *	the special name missing the leading '/',
126*1423Sroot 	 *	the file system name with or without the leading '/'.
127*1423Sroot 	 */
128*1423Sroot 	dt = fstabsearch(disk);
129*1423Sroot 	if (dt != 0)
130*1423Sroot 		disk = rawname(dt->fs_spec);
131*1423Sroot 	getitime();		/* /etc/dumpdates snarfed */
132*1423Sroot 
133*1423Sroot 	msg("Date of this level %c dump: %s\n", incno, prdate(spcl.c_date));
134*1423Sroot 	msg("Date of last level %c dump: %s\n", incno, prdate(spcl.c_ddate));
135*1423Sroot 	msg("Dumping %s ", disk);
136*1423Sroot 	if (dt != 0)
137*1423Sroot 		msgtail("(%s) ", dt->fs_file);
138*1423Sroot 	msgtail("to %s\n", tape);
139*1423Sroot 
140*1423Sroot 	fi = open(disk, 0);
141*1423Sroot 	if (fi < 0) {
142*1423Sroot 		msg("Cannot open %s\n", disk);
143*1423Sroot 		Exit(X_ABORT);
144*1423Sroot 	}
145*1423Sroot 	CLR(clrmap);
146*1423Sroot 	CLR(dirmap);
147*1423Sroot 	CLR(nodmap);
148*1423Sroot 	esize = 0;
149*1423Sroot 
150*1423Sroot 	msg("mapping (Pass I) [regular files]\n");
151*1423Sroot 	pass(mark, (short *)NULL);		/* mark updates esize */
152*1423Sroot 
153*1423Sroot 	do {
154*1423Sroot 		msg("mapping (Pass II) [directories]\n");
155*1423Sroot 		nadded = 0;
156*1423Sroot 		pass(add, dirmap);
157*1423Sroot 	} while(nadded);
158*1423Sroot 
159*1423Sroot 	bmapest(clrmap);
160*1423Sroot 	bmapest(nodmap);
161*1423Sroot 
162*1423Sroot 	fetapes =
163*1423Sroot 		(	 esize		/* blocks */
164*1423Sroot 			*BSIZE		/* bytes / block */
165*1423Sroot 			*(1.0/density)	/* 0.1" / byte */
166*1423Sroot 		  +
167*1423Sroot 			 esize		/* blocks */
168*1423Sroot 			*(1.0/NTREC)	/* IRG's / block */
169*1423Sroot 			*7		/* 0.1" / IRG */
170*1423Sroot 		) * (1.0 / tsize )	/* tape / 0.1" */
171*1423Sroot 	;
172*1423Sroot 	etapes = fetapes;		/* truncating assignment */
173*1423Sroot 	etapes++;
174*1423Sroot 	/*
175*1423Sroot 	 *	esize is typically about 5% too low; we frob it here
176*1423Sroot 	 */
177*1423Sroot 	esize += ((5*esize)/100);
178*1423Sroot 	msg("estimated %ld tape blocks on %3.2f tape(s).\n", esize, fetapes);
179*1423Sroot 
180*1423Sroot 	otape();			/* bitmap is the first to tape write */
181*1423Sroot 	time(&(tstart_writing));
182*1423Sroot 	bitmap(clrmap, TS_CLRI);
183*1423Sroot 
184*1423Sroot 	msg("dumping (Pass III) [directories]\n");
185*1423Sroot 	pass(dump, dirmap);
186*1423Sroot 
187*1423Sroot 	msg("dumping (Pass IV) [regular files]\n");
188*1423Sroot 	pass(dump, nodmap);
189*1423Sroot 
190*1423Sroot 	spcl.c_type = TS_END;
191*1423Sroot 	for(i=0; i<NTREC; i++)
192*1423Sroot 		spclrec();
193*1423Sroot 	msg("DUMP: %ld tape blocks on %d tape(s)\n",spcl.c_tapea,spcl.c_volume);
194*1423Sroot 	msg("DUMP IS DONE\n");
195*1423Sroot 
196*1423Sroot 	putitime();
197*1423Sroot 	close(to);
198*1423Sroot 	rewind();
199*1423Sroot 	broadcast("DUMP IS DONE!\7\7\n");
200*1423Sroot 	Exit(X_FINOK);
201*1423Sroot }
202*1423Sroot 
203*1423Sroot int	sighup(){	msg("SIGHUP()  try rewriting\n"); sigAbort();}
204*1423Sroot int	sigtrap(){	msg("SIGTRAP()  try rewriting\n"); sigAbort();}
205*1423Sroot int	sigfpe(){	msg("SIGFPE()  try rewriting\n"); sigAbort();}
206*1423Sroot int	sigbus(){	msg("SIGBUS()  try rewriting\n"); sigAbort();}
207*1423Sroot int	sigsegv(){	msg("SIGSEGV()  ABORTING!\n"); abort();}
208*1423Sroot int	sigalrm(){	msg("SIGALRM()  try rewriting\n"); sigAbort();}
209*1423Sroot int	sigterm(){	msg("SIGTERM()  try rewriting\n"); sigAbort();}
210*1423Sroot 
211*1423Sroot sigAbort()
212*1423Sroot {
213*1423Sroot 	msg("Rewriting attempted as response to unknown signal.\n");
214*1423Sroot 	fflush(stderr);
215*1423Sroot 	fflush(stdout);
216*1423Sroot 	close_rewind();
217*1423Sroot 	exit(X_REWRITE);
218*1423Sroot }
219*1423Sroot 
220*1423Sroot char *rawname(cp)
221*1423Sroot 	char *cp;
222*1423Sroot {
223*1423Sroot 	static char rawbuf[32];
224*1423Sroot 	char *dp = rindex(cp, '/');
225*1423Sroot 
226*1423Sroot 	if (dp == 0)
227*1423Sroot 		return (0);
228*1423Sroot 	*dp = 0;
229*1423Sroot 	strcpy(rawbuf, cp);
230*1423Sroot 	*dp = '/';
231*1423Sroot 	strcat(rawbuf, "/r");
232*1423Sroot 	strcat(rawbuf, dp+1);
233*1423Sroot 	return (rawbuf);
234*1423Sroot }
235