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