|
|
1.1 root 1: /*
2: * Copyright (c) 1980 Regents of the University of California.
3: * All rights reserved. The Berkeley software License Agreement
4: * specifies the terms and conditions for redistribution.
5: */
6:
7: #ifndef lint
8: static char sccsid[] = "@(#)dumpmain.c 5.4 (Berkeley) 5/28/86";
9: #endif not lint
10:
11: #include "dump.h"
12:
13: int notify = 0; /* notify operator flag */
14: int blockswritten = 0; /* number of blocks written on current tape */
15: int tapeno = 0; /* current tape number */
16: int density = 0; /* density in bytes/0.1" */
17: int ntrec = NTREC; /* # tape blocks in each tape record */
18: int cartridge = 0; /* Assume non-cartridge tape */
19: #ifdef RDUMP
20: char *host;
21: #endif
22: int anydskipped; /* set true in mark() if any directories are skipped */
23: /* this lets us avoid map pass 2 in some cases */
24:
25: main(argc, argv)
26: int argc;
27: char *argv[];
28: {
29: char *arg;
30: int bflag = 0, i;
31: float fetapes;
32: register struct fstab *dt;
33:
34: time(&(spcl.c_date));
35:
36: tsize = 0; /* Default later, based on 'c' option for cart tapes */
37: tape = TAPE;
38: disk = DISK;
39: increm = NINCREM;
40: temp = TEMP;
41: if (TP_BSIZE / DEV_BSIZE == 0 || TP_BSIZE % DEV_BSIZE != 0) {
42: msg("TP_BSIZE must be a multiple of DEV_BSIZE\n");
43: dumpabort();
44: }
45: incno = '9';
46: uflag = 0;
47: arg = "u";
48: if(argc > 1) {
49: argv++;
50: argc--;
51: arg = *argv;
52: if (*arg == '-')
53: argc++;
54: }
55: while(*arg)
56: switch (*arg++) {
57: case 'w':
58: lastdump('w'); /* tell us only what has to be done */
59: exit(0);
60: break;
61: case 'W': /* what to do */
62: lastdump('W'); /* tell us the current state of what has been done */
63: exit(0); /* do nothing else */
64: break;
65:
66: case 'f': /* output file */
67: if(argc > 1) {
68: argv++;
69: argc--;
70: tape = *argv;
71: }
72: break;
73:
74: case 'd': /* density, in bits per inch */
75: if (argc > 1) {
76: argv++;
77: argc--;
78: density = atoi(*argv) / 10;
79: if (density >= 625 && !bflag)
80: ntrec = HIGHDENSITYTREC;
81: }
82: break;
83:
84: case 's': /* tape size, feet */
85: if(argc > 1) {
86: argv++;
87: argc--;
88: tsize = atol(*argv);
89: tsize *= 12L*10L;
90: }
91: break;
92:
93: case 'b': /* blocks per tape write */
94: if(argc > 1) {
95: argv++;
96: argc--;
97: bflag++;
98: ntrec = atol(*argv);
99: }
100: break;
101:
102: case 'c': /* Tape is cart. not 9-track */
103: cartridge++;
104: break;
105:
106: case '0': /* dump level */
107: case '1':
108: case '2':
109: case '3':
110: case '4':
111: case '5':
112: case '6':
113: case '7':
114: case '8':
115: case '9':
116: incno = arg[-1];
117: break;
118:
119: case 'u': /* update /etc/dumpdates */
120: uflag++;
121: break;
122:
123: case 'n': /* notify operators */
124: notify++;
125: break;
126:
127: default:
128: fprintf(stderr, "bad key '%c%'\n", arg[-1]);
129: Exit(X_ABORT);
130: }
131: if(argc > 1) {
132: argv++;
133: argc--;
134: disk = *argv;
135: }
136: if (strcmp(tape, "-") == 0) {
137: pipeout++;
138: tape = "standard output";
139: }
140:
141: /*
142: * Determine how to default tape size and density
143: *
144: * density tape size
145: * 9-track 1600 bpi (160 bytes/.1") 2300 ft.
146: * 9-track 6250 bpi (625 bytes/.1") 2300 ft.
147: * cartridge 8000 bpi (100 bytes/.1") 1700 ft. (450*4 - slop)
148: */
149: if (density == 0)
150: density = cartridge ? 100 : 160;
151: if (tsize == 0)
152: tsize = cartridge ? 1700L*120L : 2300L*120L;
153:
154: #ifdef RDUMP
155: { char *index();
156: host = tape;
157: tape = index(host, ':');
158: if (tape == 0) {
159: msg("need keyletter ``f'' and device ``host:tape''\n");
160: exit(1);
161: }
162: *tape++ = 0;
163: if (rmthost(host) == 0)
164: exit(X_ABORT);
165: }
166: setuid(getuid()); /* rmthost() is the only reason to be setuid */
167: #endif
168: if (signal(SIGHUP, sighup) == SIG_IGN)
169: signal(SIGHUP, SIG_IGN);
170: if (signal(SIGTRAP, sigtrap) == SIG_IGN)
171: signal(SIGTRAP, SIG_IGN);
172: if (signal(SIGFPE, sigfpe) == SIG_IGN)
173: signal(SIGFPE, SIG_IGN);
174: if (signal(SIGBUS, sigbus) == SIG_IGN)
175: signal(SIGBUS, SIG_IGN);
176: if (signal(SIGSEGV, sigsegv) == SIG_IGN)
177: signal(SIGSEGV, SIG_IGN);
178: if (signal(SIGTERM, sigterm) == SIG_IGN)
179: signal(SIGTERM, SIG_IGN);
180:
181:
182: if (signal(SIGINT, interrupt) == SIG_IGN)
183: signal(SIGINT, SIG_IGN);
184:
185: set_operators(); /* /etc/group snarfed */
186: getfstab(); /* /etc/fstab snarfed */
187: /*
188: * disk can be either the full special file name,
189: * the suffix of the special file name,
190: * the special name missing the leading '/',
191: * the file system name with or without the leading '/'.
192: */
193: dt = fstabsearch(disk);
194: if (dt != 0)
195: disk = rawname(dt->fs_spec);
196: getitime(); /* /etc/dumpdates snarfed */
197:
198: msg("Date of this level %c dump: %s\n", incno, prdate(spcl.c_date));
199: msg("Date of last level %c dump: %s\n",
200: lastincno, prdate(spcl.c_ddate));
201: msg("Dumping %s ", disk);
202: if (dt != 0)
203: msgtail("(%s) ", dt->fs_file);
204: #ifdef RDUMP
205: msgtail("to %s on host %s\n", tape, host);
206: #else
207: msgtail("to %s\n", tape);
208: #endif
209:
210: fi = open(disk, 0);
211: if (fi < 0) {
212: msg("Cannot open %s\n", disk);
213: Exit(X_ABORT);
214: }
215: esize = 0;
216: sblock = (struct fs *)buf;
217: sync();
218: bread(SBLOCK, sblock, SBSIZE);
219: if (sblock->fs_magic != FS_MAGIC) {
220: msg("bad sblock magic number\n");
221: dumpabort();
222: }
223: msiz = roundup(howmany(sblock->fs_ipg * sblock->fs_ncg, NBBY),
224: TP_BSIZE);
225: clrmap = (char *)calloc(msiz, sizeof(char));
226: dirmap = (char *)calloc(msiz, sizeof(char));
227: nodmap = (char *)calloc(msiz, sizeof(char));
228:
229: anydskipped = 0;
230: msg("mapping (Pass I) [regular files]\n");
231: pass(mark, (char *)NULL); /* mark updates esize */
232:
233: if (anydskipped) {
234: do {
235: msg("mapping (Pass II) [directories]\n");
236: nadded = 0;
237: pass(add, dirmap);
238: } while(nadded);
239: } else /* keep the operators happy */
240: msg("mapping (Pass II) [directories]\n");
241:
242: bmapest(clrmap);
243: bmapest(nodmap);
244:
245: if (cartridge) {
246: /* Estimate number of tapes, assuming streaming stops at
247: the end of each block written, and not in mid-block.
248: Assume no erroneous blocks; this can be compensated for
249: with an artificially low tape size. */
250: fetapes =
251: ( esize /* blocks */
252: * TP_BSIZE /* bytes/block */
253: * (1.0/density) /* 0.1" / byte */
254: +
255: esize /* blocks */
256: * (1.0/ntrec) /* streaming-stops per block */
257: * 15.48 /* 0.1" / streaming-stop */
258: ) * (1.0 / tsize ); /* tape / 0.1" */
259: } else {
260: /* Estimate number of tapes, for old fashioned 9-track tape */
261: int tenthsperirg = (density == 625) ? 3 : 7;
262: fetapes =
263: ( esize /* blocks */
264: * TP_BSIZE /* bytes / block */
265: * (1.0/density) /* 0.1" / byte */
266: +
267: esize /* blocks */
268: * (1.0/ntrec) /* IRG's / block */
269: * tenthsperirg /* 0.1" / IRG */
270: ) * (1.0 / tsize ); /* tape / 0.1" */
271: }
272: etapes = fetapes; /* truncating assignment */
273: etapes++;
274: /* count the nodemap on each additional tape */
275: for (i = 1; i < etapes; i++)
276: bmapest(nodmap);
277: esize += i + 10; /* headers + 10 trailer blocks */
278: msg("estimated %ld tape blocks on %3.2f tape(s).\n", esize, fetapes);
279:
280: alloctape(); /* Allocate tape buffer */
281:
282: otape(); /* bitmap is the first to tape write */
283: time(&(tstart_writing));
284: bitmap(clrmap, TS_CLRI);
285:
286: msg("dumping (Pass III) [directories]\n");
287: pass(dirdump, dirmap);
288:
289: msg("dumping (Pass IV) [regular files]\n");
290: pass(dump, nodmap);
291:
292: spcl.c_type = TS_END;
293: #ifndef RDUMP
294: for(i=0; i<ntrec; i++)
295: spclrec();
296: #endif
297: msg("DUMP: %ld tape blocks on %d tape(s)\n",spcl.c_tapea,spcl.c_volume);
298: msg("DUMP IS DONE\n");
299:
300: putitime();
301: #ifndef RDUMP
302: if (!pipeout) {
303: close(to);
304: rewind();
305: }
306: #else
307: tflush(1);
308: rewind();
309: #endif
310: broadcast("DUMP IS DONE!\7\7\n");
311: Exit(X_FINOK);
312: }
313:
314: int sighup(){ msg("SIGHUP() try rewriting\n"); sigAbort();}
315: int sigtrap(){ msg("SIGTRAP() try rewriting\n"); sigAbort();}
316: int sigfpe(){ msg("SIGFPE() try rewriting\n"); sigAbort();}
317: int sigbus(){ msg("SIGBUS() try rewriting\n"); sigAbort();}
318: int sigsegv(){ msg("SIGSEGV() ABORTING!\n"); abort();}
319: int sigalrm(){ msg("SIGALRM() try rewriting\n"); sigAbort();}
320: int sigterm(){ msg("SIGTERM() try rewriting\n"); sigAbort();}
321:
322: sigAbort()
323: {
324: if (pipeout) {
325: msg("Unknown signal, cannot recover\n");
326: dumpabort();
327: }
328: msg("Rewriting attempted as response to unknown signal.\n");
329: fflush(stderr);
330: fflush(stdout);
331: close_rewind();
332: exit(X_REWRITE);
333: }
334:
335: char *rawname(cp)
336: char *cp;
337: {
338: static char rawbuf[32];
339: char *rindex();
340: char *dp = rindex(cp, '/');
341:
342: if (dp == 0)
343: return (0);
344: *dp = 0;
345: strcpy(rawbuf, cp);
346: *dp = '/';
347: strcat(rawbuf, "/r");
348: strcat(rawbuf, dp+1);
349: return (rawbuf);
350: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.