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