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