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