main.c revision 1.5 1 1.1 cgd /*-
2 1.3 mycroft * Copyright (c) 1980, 1991, 1993, 1994
3 1.3 mycroft * The Regents of the University of California. All rights reserved.
4 1.1 cgd *
5 1.1 cgd * Redistribution and use in source and binary forms, with or without
6 1.1 cgd * modification, are permitted provided that the following conditions
7 1.1 cgd * are met:
8 1.1 cgd * 1. Redistributions of source code must retain the above copyright
9 1.1 cgd * notice, this list of conditions and the following disclaimer.
10 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer in the
12 1.1 cgd * documentation and/or other materials provided with the distribution.
13 1.1 cgd * 3. All advertising materials mentioning features or use of this software
14 1.1 cgd * must display the following acknowledgement:
15 1.1 cgd * This product includes software developed by the University of
16 1.1 cgd * California, Berkeley and its contributors.
17 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
18 1.1 cgd * may be used to endorse or promote products derived from this software
19 1.1 cgd * without specific prior written permission.
20 1.1 cgd *
21 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 cgd * SUCH DAMAGE.
32 1.1 cgd */
33 1.1 cgd
34 1.1 cgd #ifndef lint
35 1.3 mycroft static char copyright[] =
36 1.3 mycroft "@(#) Copyright (c) 1980, 1991, 1993, 1994\n\
37 1.3 mycroft The Regents of the University of California. All rights reserved.\n";
38 1.1 cgd #endif /* not lint */
39 1.1 cgd
40 1.1 cgd #ifndef lint
41 1.3 mycroft /*static char sccsid[] = "from: @(#)main.c 8.4 (Berkeley) 4/15/94";*/
42 1.5 mycroft static char *rcsid = "$Id: main.c,v 1.5 1995/02/20 22:36:01 mycroft Exp $";
43 1.1 cgd #endif /* not lint */
44 1.1 cgd
45 1.3 mycroft #include <sys/param.h>
46 1.3 mycroft #include <sys/time.h>
47 1.1 cgd #ifdef sunos
48 1.3 mycroft #include <sys/vnode.h>
49 1.3 mycroft
50 1.3 mycroft #include <ufs/inode.h>
51 1.1 cgd #include <ufs/fs.h>
52 1.1 cgd #else
53 1.3 mycroft #include <ufs/ffs/fs.h>
54 1.3 mycroft #include <ufs/ufs/dinode.h>
55 1.1 cgd #endif
56 1.3 mycroft
57 1.1 cgd #include <protocols/dumprestore.h>
58 1.3 mycroft
59 1.3 mycroft #include <ctype.h>
60 1.5 mycroft #include <err.h>
61 1.3 mycroft #include <errno.h>
62 1.1 cgd #include <fcntl.h>
63 1.1 cgd #include <fstab.h>
64 1.3 mycroft #include <signal.h>
65 1.1 cgd #include <stdio.h>
66 1.1 cgd #include <stdlib.h>
67 1.1 cgd #include <string.h>
68 1.3 mycroft #include <unistd.h>
69 1.3 mycroft
70 1.1 cgd #include "dump.h"
71 1.1 cgd #include "pathnames.h"
72 1.1 cgd
73 1.3 mycroft #ifndef SBOFF
74 1.3 mycroft #define SBOFF (SBLOCK * DEV_BSIZE)
75 1.3 mycroft #endif
76 1.3 mycroft
77 1.1 cgd int notify = 0; /* notify operator flag */
78 1.1 cgd int blockswritten = 0; /* number of blocks written on current tape */
79 1.1 cgd int tapeno = 0; /* current tape number */
80 1.1 cgd int density = 0; /* density in bytes/0.1" */
81 1.1 cgd int ntrec = NTREC; /* # tape blocks in each tape record */
82 1.1 cgd int cartridge = 0; /* Assume non-cartridge tape */
83 1.1 cgd long dev_bsize = 1; /* recalculated below */
84 1.1 cgd long blocksperfile; /* output blocks per file */
85 1.1 cgd char *host = NULL; /* remote host (if any) */
86 1.1 cgd
87 1.5 mycroft static long numarg __P((char *, long, long));
88 1.5 mycroft static void obsolete __P((int *, char **[]));
89 1.5 mycroft static void usage __P((void));
90 1.3 mycroft
91 1.3 mycroft int
92 1.1 cgd main(argc, argv)
93 1.1 cgd int argc;
94 1.5 mycroft char *argv[];
95 1.1 cgd {
96 1.1 cgd register ino_t ino;
97 1.1 cgd register int dirty;
98 1.1 cgd register struct dinode *dp;
99 1.1 cgd register struct fstab *dt;
100 1.1 cgd register char *map;
101 1.5 mycroft register int ch;
102 1.3 mycroft int i, anydirskipped, bflag = 0, Tflag = 0, honorlevel = 1;
103 1.1 cgd ino_t maxino;
104 1.1 cgd
105 1.1 cgd spcl.c_date = 0;
106 1.3 mycroft (void)time((time_t *)&spcl.c_date);
107 1.1 cgd
108 1.1 cgd tsize = 0; /* Default later, based on 'c' option for cart tapes */
109 1.1 cgd tape = _PATH_DEFTAPE;
110 1.1 cgd dumpdates = _PATH_DUMPDATES;
111 1.1 cgd temp = _PATH_DTMP;
112 1.1 cgd if (TP_BSIZE / DEV_BSIZE == 0 || TP_BSIZE % DEV_BSIZE != 0)
113 1.1 cgd quit("TP_BSIZE must be a multiple of DEV_BSIZE\n");
114 1.1 cgd level = '0';
115 1.5 mycroft
116 1.5 mycroft if (argc < 2)
117 1.5 mycroft usage();
118 1.5 mycroft
119 1.5 mycroft obsolete(&argc, &argv);
120 1.5 mycroft while ((ch = getopt(argc, argv, "0123456789B:b:cd:f:h:ns:T:uWw")) != -1)
121 1.5 mycroft switch (ch) {
122 1.5 mycroft /* dump level */
123 1.5 mycroft case '0': case '1': case '2': case '3': case '4':
124 1.5 mycroft case '5': case '6': case '7': case '8': case '9':
125 1.5 mycroft level = ch;
126 1.3 mycroft break;
127 1.1 cgd
128 1.5 mycroft case 'B': /* blocks per output file */
129 1.5 mycroft blocksperfile = numarg("blocks per file", 1L, 0L);
130 1.5 mycroft break;
131 1.1 cgd
132 1.5 mycroft case 'b': /* blocks per tape write */
133 1.5 mycroft ntrec = numarg("blocks per write", 1L, 1000L);
134 1.5 mycroft break;
135 1.1 cgd
136 1.5 mycroft case 'c': /* Tape is cart. not 9-track */
137 1.5 mycroft cartridge = 1;
138 1.3 mycroft break;
139 1.1 cgd
140 1.1 cgd case 'd': /* density, in bits per inch */
141 1.5 mycroft density = numarg("density", 10L, 327670L) / 10;
142 1.1 cgd if (density >= 625 && !bflag)
143 1.1 cgd ntrec = HIGHDENSITYTREC;
144 1.3 mycroft break;
145 1.1 cgd
146 1.5 mycroft case 'f': /* output file */
147 1.5 mycroft tape = optarg;
148 1.5 mycroft break;
149 1.5 mycroft
150 1.5 mycroft case 'h':
151 1.5 mycroft honorlevel = numarg("honor level", 0L, 10L);
152 1.5 mycroft break;
153 1.5 mycroft
154 1.5 mycroft case 'n': /* notify operators */
155 1.5 mycroft notify = 1;
156 1.5 mycroft break;
157 1.5 mycroft
158 1.1 cgd case 's': /* tape size, feet */
159 1.5 mycroft tsize = numarg("tape size", 1L, 0L) * 12 * 10;
160 1.3 mycroft break;
161 1.1 cgd
162 1.1 cgd case 'T': /* time of last dump */
163 1.5 mycroft spcl.c_ddate = unctime(optarg);
164 1.1 cgd if (spcl.c_ddate < 0) {
165 1.3 mycroft (void)fprintf(stderr, "bad time \"%s\"\n",
166 1.5 mycroft optarg);
167 1.3 mycroft exit(X_ABORT);
168 1.1 cgd }
169 1.3 mycroft Tflag = 1;
170 1.1 cgd lastlevel = '?';
171 1.3 mycroft break;
172 1.1 cgd
173 1.1 cgd case 'u': /* update /etc/dumpdates */
174 1.3 mycroft uflag = 1;
175 1.3 mycroft break;
176 1.1 cgd
177 1.5 mycroft case 'W': /* what to do */
178 1.5 mycroft case 'w':
179 1.5 mycroft lastdump(ch);
180 1.5 mycroft exit(0); /* do nothing else */
181 1.1 cgd
182 1.1 cgd default:
183 1.5 mycroft usage();
184 1.1 cgd }
185 1.5 mycroft argc -= optind;
186 1.5 mycroft argv += optind;
187 1.5 mycroft
188 1.1 cgd if (argc < 1) {
189 1.3 mycroft (void)fprintf(stderr, "Must specify disk or filesystem\n");
190 1.3 mycroft exit(X_ABORT);
191 1.1 cgd }
192 1.3 mycroft disk = *argv++;
193 1.3 mycroft argc--;
194 1.1 cgd if (argc >= 1) {
195 1.3 mycroft (void)fprintf(stderr, "Unknown arguments to dump:");
196 1.1 cgd while (argc--)
197 1.3 mycroft (void)fprintf(stderr, " %s", *argv++);
198 1.3 mycroft (void)fprintf(stderr, "\n");
199 1.3 mycroft exit(X_ABORT);
200 1.1 cgd }
201 1.1 cgd if (Tflag && uflag) {
202 1.3 mycroft (void)fprintf(stderr,
203 1.1 cgd "You cannot use the T and u flags together.\n");
204 1.3 mycroft exit(X_ABORT);
205 1.1 cgd }
206 1.1 cgd if (strcmp(tape, "-") == 0) {
207 1.1 cgd pipeout++;
208 1.1 cgd tape = "standard output";
209 1.1 cgd }
210 1.1 cgd
211 1.1 cgd if (blocksperfile)
212 1.1 cgd blocksperfile = blocksperfile / ntrec * ntrec; /* round down */
213 1.1 cgd else {
214 1.1 cgd /*
215 1.1 cgd * Determine how to default tape size and density
216 1.1 cgd *
217 1.1 cgd * density tape size
218 1.1 cgd * 9-track 1600 bpi (160 bytes/.1") 2300 ft.
219 1.1 cgd * 9-track 6250 bpi (625 bytes/.1") 2300 ft.
220 1.1 cgd * cartridge 8000 bpi (100 bytes/.1") 1700 ft.
221 1.1 cgd * (450*4 - slop)
222 1.1 cgd */
223 1.1 cgd if (density == 0)
224 1.1 cgd density = cartridge ? 100 : 160;
225 1.1 cgd if (tsize == 0)
226 1.1 cgd tsize = cartridge ? 1700L*120L : 2300L*120L;
227 1.1 cgd }
228 1.1 cgd
229 1.4 mycroft if (strchr(tape, ':')) {
230 1.1 cgd host = tape;
231 1.4 mycroft tape = strchr(host, ':');
232 1.3 mycroft *tape++ = '\0';
233 1.1 cgd #ifdef RDUMP
234 1.1 cgd if (rmthost(host) == 0)
235 1.3 mycroft exit(X_ABORT);
236 1.1 cgd #else
237 1.3 mycroft (void)fprintf(stderr, "remote dump not enabled\n");
238 1.3 mycroft exit(X_ABORT);
239 1.1 cgd #endif
240 1.1 cgd }
241 1.3 mycroft (void)setuid(getuid()); /* rmthost() is the only reason to be setuid */
242 1.1 cgd
243 1.1 cgd if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
244 1.1 cgd signal(SIGHUP, sig);
245 1.1 cgd if (signal(SIGTRAP, SIG_IGN) != SIG_IGN)
246 1.1 cgd signal(SIGTRAP, sig);
247 1.1 cgd if (signal(SIGFPE, SIG_IGN) != SIG_IGN)
248 1.1 cgd signal(SIGFPE, sig);
249 1.1 cgd if (signal(SIGBUS, SIG_IGN) != SIG_IGN)
250 1.1 cgd signal(SIGBUS, sig);
251 1.1 cgd if (signal(SIGSEGV, SIG_IGN) != SIG_IGN)
252 1.1 cgd signal(SIGSEGV, sig);
253 1.1 cgd if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
254 1.1 cgd signal(SIGTERM, sig);
255 1.1 cgd if (signal(SIGINT, interrupt) == SIG_IGN)
256 1.1 cgd signal(SIGINT, SIG_IGN);
257 1.1 cgd
258 1.1 cgd set_operators(); /* /etc/group snarfed */
259 1.1 cgd getfstab(); /* /etc/fstab snarfed */
260 1.1 cgd /*
261 1.1 cgd * disk can be either the full special file name,
262 1.1 cgd * the suffix of the special file name,
263 1.1 cgd * the special name missing the leading '/',
264 1.1 cgd * the file system name with or without the leading '/'.
265 1.1 cgd */
266 1.1 cgd dt = fstabsearch(disk);
267 1.3 mycroft if (dt != NULL) {
268 1.1 cgd disk = rawname(dt->fs_spec);
269 1.3 mycroft (void)strncpy(spcl.c_dev, dt->fs_spec, NAMELEN);
270 1.3 mycroft (void)strncpy(spcl.c_filesys, dt->fs_file, NAMELEN);
271 1.1 cgd } else {
272 1.3 mycroft (void)strncpy(spcl.c_dev, disk, NAMELEN);
273 1.3 mycroft (void)strncpy(spcl.c_filesys, "an unlisted file system",
274 1.1 cgd NAMELEN);
275 1.1 cgd }
276 1.3 mycroft (void)strcpy(spcl.c_label, "none");
277 1.3 mycroft (void)gethostname(spcl.c_host, NAMELEN);
278 1.1 cgd spcl.c_level = level - '0';
279 1.1 cgd spcl.c_type = TS_TAPE;
280 1.1 cgd if (!Tflag)
281 1.1 cgd getdumptime(); /* /etc/dumpdates snarfed */
282 1.1 cgd
283 1.1 cgd msg("Date of this level %c dump: %s", level,
284 1.1 cgd spcl.c_date == 0 ? "the epoch\n" : ctime(&spcl.c_date));
285 1.1 cgd msg("Date of last level %c dump: %s", lastlevel,
286 1.1 cgd spcl.c_ddate == 0 ? "the epoch\n" : ctime(&spcl.c_ddate));
287 1.1 cgd msg("Dumping %s ", disk);
288 1.3 mycroft if (dt != NULL)
289 1.1 cgd msgtail("(%s) ", dt->fs_file);
290 1.1 cgd if (host)
291 1.1 cgd msgtail("to %s on host %s\n", tape, host);
292 1.1 cgd else
293 1.1 cgd msgtail("to %s\n", tape);
294 1.1 cgd
295 1.1 cgd if ((diskfd = open(disk, O_RDONLY)) < 0) {
296 1.1 cgd msg("Cannot open %s\n", disk);
297 1.3 mycroft exit(X_ABORT);
298 1.1 cgd }
299 1.1 cgd sync();
300 1.1 cgd sblock = (struct fs *)sblock_buf;
301 1.1 cgd bread(SBOFF, (char *) sblock, SBSIZE);
302 1.1 cgd if (sblock->fs_magic != FS_MAGIC)
303 1.1 cgd quit("bad sblock magic number\n");
304 1.1 cgd dev_bsize = sblock->fs_fsize / fsbtodb(sblock, 1);
305 1.1 cgd dev_bshift = ffs(dev_bsize) - 1;
306 1.1 cgd if (dev_bsize != (1 << dev_bshift))
307 1.1 cgd quit("dev_bsize (%d) is not a power of 2", dev_bsize);
308 1.1 cgd tp_bshift = ffs(TP_BSIZE) - 1;
309 1.1 cgd if (TP_BSIZE != (1 << tp_bshift))
310 1.1 cgd quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE);
311 1.3 mycroft #ifdef FS_44INODEFMT
312 1.1 cgd if (sblock->fs_inodefmt >= FS_44INODEFMT)
313 1.1 cgd spcl.c_flags |= DR_NEWINODEFMT;
314 1.1 cgd #endif
315 1.3 mycroft maxino = sblock->fs_ipg * sblock->fs_ncg;
316 1.3 mycroft mapsize = roundup(howmany(maxino, NBBY), TP_BSIZE);
317 1.1 cgd usedinomap = (char *)calloc((unsigned) mapsize, sizeof(char));
318 1.1 cgd dumpdirmap = (char *)calloc((unsigned) mapsize, sizeof(char));
319 1.1 cgd dumpinomap = (char *)calloc((unsigned) mapsize, sizeof(char));
320 1.1 cgd tapesize = 3 * (howmany(mapsize * sizeof(char), TP_BSIZE) + 1);
321 1.1 cgd
322 1.3 mycroft nonodump = spcl.c_level < honorlevel;
323 1.3 mycroft
324 1.1 cgd msg("mapping (Pass I) [regular files]\n");
325 1.1 cgd anydirskipped = mapfiles(maxino, &tapesize);
326 1.1 cgd
327 1.1 cgd msg("mapping (Pass II) [directories]\n");
328 1.1 cgd while (anydirskipped) {
329 1.1 cgd anydirskipped = mapdirs(maxino, &tapesize);
330 1.1 cgd }
331 1.1 cgd
332 1.3 mycroft if (pipeout) {
333 1.1 cgd tapesize += 10; /* 10 trailer blocks */
334 1.3 mycroft msg("estimated %ld tape blocks.\n", tapesize);
335 1.3 mycroft } else {
336 1.3 mycroft double fetapes;
337 1.3 mycroft
338 1.1 cgd if (blocksperfile)
339 1.3 mycroft fetapes = (double) tapesize / blocksperfile;
340 1.1 cgd else if (cartridge) {
341 1.1 cgd /* Estimate number of tapes, assuming streaming stops at
342 1.1 cgd the end of each block written, and not in mid-block.
343 1.1 cgd Assume no erroneous blocks; this can be compensated
344 1.1 cgd for with an artificially low tape size. */
345 1.1 cgd fetapes =
346 1.1 cgd ( tapesize /* blocks */
347 1.1 cgd * TP_BSIZE /* bytes/block */
348 1.1 cgd * (1.0/density) /* 0.1" / byte */
349 1.1 cgd +
350 1.1 cgd tapesize /* blocks */
351 1.1 cgd * (1.0/ntrec) /* streaming-stops per block */
352 1.1 cgd * 15.48 /* 0.1" / streaming-stop */
353 1.1 cgd ) * (1.0 / tsize ); /* tape / 0.1" */
354 1.1 cgd } else {
355 1.1 cgd /* Estimate number of tapes, for old fashioned 9-track
356 1.1 cgd tape */
357 1.1 cgd int tenthsperirg = (density == 625) ? 3 : 7;
358 1.1 cgd fetapes =
359 1.1 cgd ( tapesize /* blocks */
360 1.1 cgd * TP_BSIZE /* bytes / block */
361 1.1 cgd * (1.0/density) /* 0.1" / byte */
362 1.1 cgd +
363 1.1 cgd tapesize /* blocks */
364 1.1 cgd * (1.0/ntrec) /* IRG's / block */
365 1.1 cgd * tenthsperirg /* 0.1" / IRG */
366 1.1 cgd ) * (1.0 / tsize ); /* tape / 0.1" */
367 1.1 cgd }
368 1.1 cgd etapes = fetapes; /* truncating assignment */
369 1.1 cgd etapes++;
370 1.1 cgd /* count the dumped inodes map on each additional tape */
371 1.1 cgd tapesize += (etapes - 1) *
372 1.1 cgd (howmany(mapsize * sizeof(char), TP_BSIZE) + 1);
373 1.1 cgd tapesize += etapes + 10; /* headers + 10 trailer blks */
374 1.1 cgd msg("estimated %ld tape blocks on %3.2f tape(s).\n",
375 1.1 cgd tapesize, fetapes);
376 1.3 mycroft }
377 1.1 cgd
378 1.1 cgd /*
379 1.3 mycroft * Allocate tape buffer.
380 1.1 cgd */
381 1.1 cgd if (!alloctape())
382 1.1 cgd quit("can't allocate tape buffers - try a smaller blocking factor.\n");
383 1.1 cgd
384 1.1 cgd startnewtape(1);
385 1.3 mycroft (void)time((time_t *)&(tstart_writing));
386 1.3 mycroft dumpmap(usedinomap, TS_CLRI, maxino - 1);
387 1.1 cgd
388 1.1 cgd msg("dumping (Pass III) [directories]\n");
389 1.3 mycroft dirty = 0; /* XXX just to get gcc to shut up */
390 1.3 mycroft for (map = dumpdirmap, ino = 1; ino < maxino; ino++) {
391 1.3 mycroft if (((ino - 1) % NBBY) == 0) /* map is offset by 1 */
392 1.1 cgd dirty = *map++;
393 1.1 cgd else
394 1.1 cgd dirty >>= 1;
395 1.1 cgd if ((dirty & 1) == 0)
396 1.1 cgd continue;
397 1.1 cgd /*
398 1.1 cgd * Skip directory inodes deleted and maybe reallocated
399 1.1 cgd */
400 1.1 cgd dp = getino(ino);
401 1.1 cgd if ((dp->di_mode & IFMT) != IFDIR)
402 1.1 cgd continue;
403 1.3 mycroft (void)dumpino(dp, ino);
404 1.1 cgd }
405 1.1 cgd
406 1.1 cgd msg("dumping (Pass IV) [regular files]\n");
407 1.3 mycroft for (map = dumpinomap, ino = 1; ino < maxino; ino++) {
408 1.3 mycroft int mode;
409 1.3 mycroft
410 1.3 mycroft if (((ino - 1) % NBBY) == 0) /* map is offset by 1 */
411 1.1 cgd dirty = *map++;
412 1.1 cgd else
413 1.1 cgd dirty >>= 1;
414 1.1 cgd if ((dirty & 1) == 0)
415 1.1 cgd continue;
416 1.1 cgd /*
417 1.1 cgd * Skip inodes deleted and reallocated as directories.
418 1.1 cgd */
419 1.1 cgd dp = getino(ino);
420 1.3 mycroft mode = dp->di_mode & IFMT;
421 1.3 mycroft if (mode == IFDIR)
422 1.1 cgd continue;
423 1.3 mycroft (void)dumpino(dp, ino);
424 1.1 cgd }
425 1.1 cgd
426 1.1 cgd spcl.c_type = TS_END;
427 1.1 cgd for (i = 0; i < ntrec; i++)
428 1.3 mycroft writeheader(maxino - 1);
429 1.1 cgd if (pipeout)
430 1.1 cgd msg("DUMP: %ld tape blocks\n",spcl.c_tapea);
431 1.1 cgd else
432 1.1 cgd msg("DUMP: %ld tape blocks on %d volumes(s)\n",
433 1.1 cgd spcl.c_tapea, spcl.c_volume);
434 1.1 cgd putdumptime();
435 1.1 cgd trewind();
436 1.1 cgd broadcast("DUMP IS DONE!\7\7\n");
437 1.1 cgd msg("DUMP IS DONE\n");
438 1.1 cgd Exit(X_FINOK);
439 1.1 cgd /* NOTREACHED */
440 1.1 cgd }
441 1.1 cgd
442 1.5 mycroft static void
443 1.5 mycroft usage()
444 1.5 mycroft {
445 1.5 mycroft
446 1.5 mycroft (void)fprintf(stderr, "usage: dump [-0123456789cnu] [-B records] [-b blocksize] [-d density] [-f file]\n [-h level] [-s feet] [-T date] filesystem\n");
447 1.5 mycroft (void)fprintf(stderr, " dump [-W | -w]\n");
448 1.5 mycroft exit(1);
449 1.5 mycroft }
450 1.5 mycroft
451 1.3 mycroft /*
452 1.3 mycroft * Pick up a numeric argument. It must be nonnegative and in the given
453 1.3 mycroft * range (except that a vmax of 0 means unlimited).
454 1.3 mycroft */
455 1.3 mycroft static long
456 1.5 mycroft numarg(meaning, vmin, vmax)
457 1.3 mycroft char *meaning;
458 1.3 mycroft long vmin, vmax;
459 1.3 mycroft {
460 1.5 mycroft char *p;
461 1.3 mycroft long val;
462 1.3 mycroft
463 1.5 mycroft val = strtol(optarg, &p, 10);
464 1.5 mycroft if (*p)
465 1.5 mycroft errx(1, "illegal %s -- %s", meaning, optarg);
466 1.3 mycroft if (val < vmin || (vmax && val > vmax))
467 1.5 mycroft errx(1, "%s must be between %ld and %ld", meaning, vmin, vmax);
468 1.3 mycroft return (val);
469 1.3 mycroft }
470 1.3 mycroft
471 1.1 cgd void
472 1.1 cgd sig(signo)
473 1.1 cgd int signo;
474 1.1 cgd {
475 1.1 cgd switch(signo) {
476 1.1 cgd case SIGALRM:
477 1.1 cgd case SIGBUS:
478 1.1 cgd case SIGFPE:
479 1.1 cgd case SIGHUP:
480 1.1 cgd case SIGTERM:
481 1.1 cgd case SIGTRAP:
482 1.1 cgd if (pipeout)
483 1.1 cgd quit("Signal on pipe: cannot recover\n");
484 1.1 cgd msg("Rewriting attempted as response to unknown signal.\n");
485 1.3 mycroft (void)fflush(stderr);
486 1.3 mycroft (void)fflush(stdout);
487 1.1 cgd close_rewind();
488 1.3 mycroft exit(X_REWRITE);
489 1.1 cgd /* NOTREACHED */
490 1.1 cgd case SIGSEGV:
491 1.1 cgd msg("SIGSEGV: ABORTING!\n");
492 1.3 mycroft (void)signal(SIGSEGV, SIG_DFL);
493 1.3 mycroft (void)kill(0, SIGSEGV);
494 1.1 cgd /* NOTREACHED */
495 1.1 cgd }
496 1.1 cgd }
497 1.1 cgd
498 1.1 cgd char *
499 1.1 cgd rawname(cp)
500 1.1 cgd char *cp;
501 1.1 cgd {
502 1.1 cgd static char rawbuf[MAXPATHLEN];
503 1.4 mycroft char *dp = strrchr(cp, '/');
504 1.1 cgd
505 1.3 mycroft if (dp == NULL)
506 1.3 mycroft return (NULL);
507 1.3 mycroft *dp = '\0';
508 1.3 mycroft (void)strcpy(rawbuf, cp);
509 1.1 cgd *dp = '/';
510 1.3 mycroft (void)strcat(rawbuf, "/r");
511 1.3 mycroft (void)strcat(rawbuf, dp + 1);
512 1.1 cgd return (rawbuf);
513 1.1 cgd }
514 1.1 cgd
515 1.5 mycroft /*
516 1.5 mycroft * obsolete --
517 1.5 mycroft * Change set of key letters and ordered arguments into something
518 1.5 mycroft * getopt(3) will like.
519 1.5 mycroft */
520 1.5 mycroft static void
521 1.5 mycroft obsolete(argcp, argvp)
522 1.5 mycroft int *argcp;
523 1.5 mycroft char **argvp[];
524 1.1 cgd {
525 1.5 mycroft int argc, flags;
526 1.5 mycroft char *ap, **argv, *flagsp, **nargv, *p;
527 1.5 mycroft
528 1.5 mycroft /* Setup. */
529 1.5 mycroft argv = *argvp;
530 1.5 mycroft argc = *argcp;
531 1.5 mycroft
532 1.5 mycroft /* Return if no arguments or first argument has leading dash. */
533 1.5 mycroft ap = argv[1];
534 1.5 mycroft if (argc == 1 || *ap == '-')
535 1.5 mycroft return;
536 1.5 mycroft
537 1.5 mycroft /* Allocate space for new arguments. */
538 1.5 mycroft if ((*argvp = nargv = malloc((argc + 1) * sizeof(char *))) == NULL ||
539 1.5 mycroft (p = flagsp = malloc(strlen(ap) + 2)) == NULL)
540 1.5 mycroft err(1, NULL);
541 1.5 mycroft
542 1.5 mycroft *nargv++ = *argv;
543 1.5 mycroft argv += 2;
544 1.5 mycroft
545 1.5 mycroft for (flags = 0; *ap; ++ap) {
546 1.5 mycroft switch (*ap) {
547 1.5 mycroft case 'B':
548 1.5 mycroft case 'b':
549 1.5 mycroft case 'd':
550 1.5 mycroft case 'f':
551 1.5 mycroft case 'h':
552 1.5 mycroft case 's':
553 1.5 mycroft case 'T':
554 1.5 mycroft if (*argv == NULL) {
555 1.5 mycroft warnx("option requires an argument -- %c", *ap);
556 1.5 mycroft usage();
557 1.5 mycroft }
558 1.5 mycroft if ((nargv[0] = malloc(strlen(*argv) + 2 + 1)) == NULL)
559 1.5 mycroft err(1, NULL);
560 1.5 mycroft nargv[0][0] = '-';
561 1.5 mycroft nargv[0][1] = *ap;
562 1.5 mycroft (void)strcpy(&nargv[0][2], *argv);
563 1.5 mycroft ++argv;
564 1.5 mycroft ++nargv;
565 1.5 mycroft break;
566 1.5 mycroft default:
567 1.5 mycroft if (!flags) {
568 1.5 mycroft *p++ = '-';
569 1.5 mycroft flags = 1;
570 1.5 mycroft }
571 1.5 mycroft *p++ = *ap;
572 1.5 mycroft break;
573 1.5 mycroft }
574 1.5 mycroft }
575 1.1 cgd
576 1.5 mycroft /* Terminate flags. */
577 1.5 mycroft if (flags) {
578 1.5 mycroft *p = '\0';
579 1.5 mycroft *nargv++ = flagsp;
580 1.5 mycroft }
581 1.5 mycroft
582 1.5 mycroft /* Copy remaining arguments. */
583 1.5 mycroft while (*nargv++ = *argv++);
584 1.5 mycroft
585 1.5 mycroft /* Update argument count. */
586 1.5 mycroft *argcp = nargv - *argvp - 1;
587 1.1 cgd }
588