Home | History | Annotate | Line # | Download | only in dump
main.c revision 1.76
      1  1.76  perseant /*	$NetBSD: main.c,v 1.76 2019/08/19 18:12:50 perseant 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.56       agc  * 3. Neither the name of the University nor the names of its contributors
     16   1.1       cgd  *    may be used to endorse or promote products derived from this software
     17   1.1       cgd  *    without specific prior written permission.
     18   1.1       cgd  *
     19   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29   1.1       cgd  * SUCH DAMAGE.
     30   1.1       cgd  */
     31   1.1       cgd 
     32  1.15     lukem #include <sys/cdefs.h>
     33   1.1       cgd #ifndef lint
     34  1.64     lukem __COPYRIGHT("@(#) Copyright (c) 1980, 1991, 1993, 1994\
     35  1.64     lukem  The Regents of the University of California.  All rights reserved.");
     36   1.1       cgd #endif /* not lint */
     37   1.1       cgd 
     38   1.1       cgd #ifndef lint
     39   1.6       cgd #if 0
     40  1.16     lukem static char sccsid[] = "@(#)main.c	8.6 (Berkeley) 5/1/95";
     41   1.6       cgd #else
     42  1.76  perseant __RCSID("$NetBSD: main.c,v 1.76 2019/08/19 18:12:50 perseant Exp $");
     43   1.6       cgd #endif
     44   1.1       cgd #endif /* not lint */
     45   1.1       cgd 
     46   1.3   mycroft #include <sys/param.h>
     47   1.3   mycroft #include <sys/time.h>
     48  1.14     lukem #include <sys/stat.h>
     49  1.14     lukem #include <sys/mount.h>
     50  1.72    bouyer #include <sys/sysctl.h>
     51  1.14     lukem 
     52   1.3   mycroft #include <ufs/ffs/fs.h>
     53  1.18    bouyer #include <ufs/ffs/ffs_extern.h>
     54   1.3   mycroft 
     55   1.3   mycroft #include <ctype.h>
     56   1.5   mycroft #include <err.h>
     57   1.3   mycroft #include <errno.h>
     58   1.1       cgd #include <fcntl.h>
     59   1.1       cgd #include <fstab.h>
     60   1.3   mycroft #include <signal.h>
     61   1.1       cgd #include <stdio.h>
     62   1.1       cgd #include <stdlib.h>
     63   1.1       cgd #include <string.h>
     64  1.10     lukem #include <time.h>
     65   1.3   mycroft #include <unistd.h>
     66  1.68  christos #include <util.h>
     67   1.3   mycroft 
     68   1.1       cgd #include "dump.h"
     69   1.1       cgd #include "pathnames.h"
     70  1.58   hannken #include "snapshot.h"
     71   1.1       cgd 
     72  1.44     lukem int	timestamp;		/* print message timestamps */
     73  1.27       scw int	notify;			/* notify operator flag */
     74  1.27       scw int	blockswritten;		/* number of blocks written on current tape */
     75  1.27       scw int	tapeno;			/* current tape number */
     76  1.27       scw int	density;		/* density in bytes/0.1" */
     77  1.17     lukem int	ntrec = NTREC;		/* # tape blocks in each tape record */
     78  1.27       scw int	cartridge;		/* Assume non-cartridge tape */
     79  1.17     lukem long	dev_bsize = 1;		/* recalculated below */
     80  1.27       scw long	blocksperfile;		/* output blocks per file */
     81  1.59  christos const char *host;		/* remote host (if any) */
     82  1.22    bouyer int	readcache = -1;		/* read cache size (in readblksize blks) */
     83  1.72    bouyer int	readblksize = -1;	/* read block size */
     84  1.39     blymn char    default_time_string[] = "%T %Z"; /* default timestamp string */
     85  1.39     blymn char    *time_string = default_time_string; /* timestamp string */
     86   1.1       cgd 
     87  1.59  christos static long numarg(const char *, long, long);
     88  1.31     lukem static void obsolete(int *, char **[]);
     89  1.31     lukem static void usage(void);
     90   1.3   mycroft 
     91   1.3   mycroft int
     92  1.31     lukem main(int argc, char *argv[])
     93   1.1       cgd {
     94  1.11     lukem 	ino_t ino;
     95  1.45     lukem 	int dirty;
     96  1.55      fvdl 	union dinode *dp;
     97  1.33     lukem 	struct fstab *dt;
     98  1.57  christos 	struct statvfs *mntinfo, fsbuf;
     99  1.59  christos 	char *map, *cp;
    100  1.11     lukem 	int ch;
    101  1.38     lukem 	int i, anydirskipped, bflag = 0, Tflag = 0, Fflag = 0, honorlevel = 1;
    102  1.58   hannken 	int snap_internal = 0;
    103   1.1       cgd 	ino_t maxino;
    104  1.18    bouyer 	time_t tnow, date;
    105  1.33     lukem 	int dirc;
    106  1.33     lukem 	char *mountpoint;
    107  1.17     lukem 	int just_estimate = 0;
    108  1.21     lukem 	char labelstr[LBLSIZE];
    109  1.69  christos 	char buf[MAXPATHLEN], rbuf[MAXPATHLEN];
    110  1.39     blymn 	char *new_time_format;
    111  1.58   hannken 	char *snap_backup = NULL;
    112  1.45     lukem 
    113   1.1       cgd 	spcl.c_date = 0;
    114  1.47     lukem 	(void)time(&tnow);
    115  1.47     lukem 	spcl.c_date = tnow;
    116  1.39     blymn 	tzset(); /* set up timezone for strftime */
    117  1.39     blymn 	if ((new_time_format = getenv("TIMEFORMAT")) != NULL)
    118  1.39     blymn 		time_string = new_time_format;
    119  1.45     lukem 
    120   1.1       cgd 	tsize = 0;	/* Default later, based on 'c' option for cart tapes */
    121   1.7       mrg 	if ((tape = getenv("TAPE")) == NULL)
    122   1.7       mrg 		tape = _PATH_DEFTAPE;
    123   1.1       cgd 	dumpdates = _PATH_DUMPDATES;
    124   1.1       cgd 	temp = _PATH_DTMP;
    125  1.21     lukem 	strcpy(labelstr, "none");	/* XXX safe strcpy. */
    126   1.1       cgd 	if (TP_BSIZE / DEV_BSIZE == 0 || TP_BSIZE % DEV_BSIZE != 0)
    127  1.74  christos 		quit("TP_BSIZE must be a multiple of DEV_BSIZE");
    128   1.1       cgd 	level = '0';
    129  1.39     blymn 	timestamp = 0;
    130  1.45     lukem 
    131   1.5   mycroft 	if (argc < 2)
    132   1.5   mycroft 		usage();
    133   1.5   mycroft 
    134   1.5   mycroft 	obsolete(&argc, &argv);
    135  1.17     lukem 	while ((ch = getopt(argc, argv,
    136  1.76  perseant 	    "0123456789aB:b:cd:D:eFf:h:ik:l:L:nr:s:StT:uU:Wwx:X")) != -1)
    137   1.5   mycroft 		switch (ch) {
    138   1.5   mycroft 		/* dump level */
    139   1.5   mycroft 		case '0': case '1': case '2': case '3': case '4':
    140   1.5   mycroft 		case '5': case '6': case '7': case '8': case '9':
    141   1.5   mycroft 			level = ch;
    142   1.3   mycroft 			break;
    143   1.1       cgd 
    144  1.49     lukem 		case 'a':		/* `auto-size', Write to EOM. */
    145  1.49     lukem 			unlimited = 1;
    146  1.49     lukem 			break;
    147  1.49     lukem 
    148   1.5   mycroft 		case 'B':		/* blocks per output file */
    149   1.5   mycroft 			blocksperfile = numarg("blocks per file", 1L, 0L);
    150   1.5   mycroft 			break;
    151   1.1       cgd 
    152   1.5   mycroft 		case 'b':		/* blocks per tape write */
    153   1.5   mycroft 			ntrec = numarg("blocks per write", 1L, 1000L);
    154   1.9     mikel 			bflag = 1;
    155   1.5   mycroft 			break;
    156   1.1       cgd 
    157   1.5   mycroft 		case 'c':		/* Tape is cart. not 9-track */
    158   1.5   mycroft 			cartridge = 1;
    159   1.3   mycroft 			break;
    160   1.1       cgd 
    161   1.1       cgd 		case 'd':		/* density, in bits per inch */
    162   1.5   mycroft 			density = numarg("density", 10L, 327670L) / 10;
    163   1.1       cgd 			if (density >= 625 && !bflag)
    164   1.1       cgd 				ntrec = HIGHDENSITYTREC;
    165  1.28      tron 			break;
    166  1.28      tron 
    167  1.76  perseant 		case 'D':		/* specify alt. dumpdates file */
    168  1.76  perseant 			dumpdates = optarg;
    169  1.76  perseant 			break;
    170  1.76  perseant 
    171  1.38     lukem 		case 'e':		/* eject full tapes */
    172  1.28      tron 			eflag = 1;
    173   1.3   mycroft 			break;
    174   1.1       cgd 
    175  1.38     lukem 		case 'F':		/* files-to-dump is an fs image */
    176  1.38     lukem 			Fflag = 1;
    177  1.38     lukem 			break;
    178  1.38     lukem 
    179   1.5   mycroft 		case 'f':		/* output file */
    180   1.5   mycroft 			tape = optarg;
    181   1.5   mycroft 			break;
    182   1.5   mycroft 
    183   1.5   mycroft 		case 'h':
    184   1.5   mycroft 			honorlevel = numarg("honor level", 0L, 10L);
    185   1.5   mycroft 			break;
    186   1.5   mycroft 
    187  1.66  christos 		case 'i':	/* "true incremental" regardless level */
    188  1.66  christos 			level = 'i';
    189  1.65  christos 			trueinc = 1;
    190  1.65  christos 			break;
    191  1.65  christos 
    192  1.22    bouyer 		case 'k':
    193  1.22    bouyer 			readblksize = numarg("read block size", 0, 64) * 1024;
    194  1.22    bouyer 			break;
    195  1.22    bouyer 
    196  1.41    bouyer 		case 'l':		/* autoload after eject full tapes */
    197  1.41    bouyer 			eflag = 1;
    198  1.50    bouyer 			lflag = numarg("timeout (in seconds)", 1, 0);
    199  1.41    bouyer 			break;
    200  1.41    bouyer 
    201  1.21     lukem 		case 'L':
    202  1.21     lukem 			/*
    203  1.21     lukem 			 * Note that although there are LBLSIZE characters,
    204  1.21     lukem 			 * the last must be '\0', so the limit on strlen()
    205  1.21     lukem 			 * is really LBLSIZE-1.
    206  1.21     lukem 			 */
    207  1.51    itojun 			if (strlcpy(labelstr, optarg, sizeof(labelstr))
    208  1.51    itojun 			    >= sizeof(labelstr)) {
    209  1.21     lukem 				msg(
    210  1.53    itojun 		"WARNING Label `%s' is larger than limit of %lu characters.\n",
    211  1.53    itojun 				    optarg,
    212  1.53    itojun 				    (unsigned long)sizeof(labelstr) - 1);
    213  1.21     lukem 				msg("WARNING: Using truncated label `%s'.\n",
    214  1.21     lukem 				    labelstr);
    215  1.21     lukem 			}
    216  1.21     lukem 			break;
    217   1.5   mycroft 		case 'n':		/* notify operators */
    218   1.5   mycroft 			notify = 1;
    219   1.5   mycroft 			break;
    220   1.5   mycroft 
    221  1.22    bouyer 		case 'r':		/* read cache size */
    222  1.22    bouyer 			readcache = numarg("read cache size", 0, 512);
    223  1.22    bouyer 			break;
    224  1.45     lukem 
    225   1.1       cgd 		case 's':		/* tape size, feet */
    226   1.5   mycroft 			tsize = numarg("tape size", 1L, 0L) * 12 * 10;
    227   1.3   mycroft 			break;
    228   1.1       cgd 
    229  1.17     lukem 		case 'S':		/* exit after estimating # of tapes */
    230  1.17     lukem 			just_estimate = 1;
    231  1.17     lukem 			break;
    232  1.17     lukem 
    233  1.39     blymn 		case 't':
    234  1.39     blymn 			timestamp = 1;
    235  1.39     blymn 			break;
    236  1.39     blymn 
    237   1.1       cgd 		case 'T':		/* time of last dump */
    238   1.5   mycroft 			spcl.c_ddate = unctime(optarg);
    239   1.1       cgd 			if (spcl.c_ddate < 0) {
    240   1.3   mycroft 				(void)fprintf(stderr, "bad time \"%s\"\n",
    241   1.5   mycroft 				    optarg);
    242  1.48     lukem 				exit(X_STARTUP);
    243   1.1       cgd 			}
    244   1.3   mycroft 			Tflag = 1;
    245   1.1       cgd 			lastlevel = '?';
    246   1.3   mycroft 			break;
    247   1.1       cgd 
    248   1.1       cgd 		case 'u':		/* update /etc/dumpdates */
    249   1.3   mycroft 			uflag = 1;
    250   1.3   mycroft 			break;
    251   1.1       cgd 
    252  1.75      manu 		case 'U':		/* dump device in /etc/dumpdates */
    253  1.75      manu 			dumpdev = optarg;
    254  1.75      manu 			break;
    255  1.75      manu 
    256   1.5   mycroft 		case 'W':		/* what to do */
    257   1.5   mycroft 		case 'w':
    258   1.5   mycroft 			lastdump(ch);
    259  1.48     lukem 			exit(X_FINOK);	/* do nothing else */
    260   1.1       cgd 
    261  1.58   hannken 		case 'x':
    262  1.58   hannken 			snap_backup = optarg;
    263  1.58   hannken 			break;
    264  1.58   hannken 
    265  1.58   hannken 		case 'X':
    266  1.58   hannken 			snap_internal = 1;
    267  1.58   hannken 			break;
    268  1.58   hannken 
    269   1.1       cgd 		default:
    270   1.5   mycroft 			usage();
    271   1.1       cgd 		}
    272   1.5   mycroft 	argc -= optind;
    273   1.5   mycroft 	argv += optind;
    274   1.5   mycroft 
    275   1.1       cgd 	if (argc < 1) {
    276  1.38     lukem 		(void)fprintf(stderr,
    277  1.38     lukem 		    "Must specify disk or image, or file list\n");
    278  1.48     lukem 		exit(X_STARTUP);
    279   1.1       cgd 	}
    280  1.14     lukem 
    281  1.33     lukem 
    282  1.14     lukem 	/*
    283  1.14     lukem 	 *	determine if disk is a subdirectory, and setup appropriately
    284  1.14     lukem 	 */
    285  1.33     lukem 	getfstab();		/* /etc/fstab snarfed */
    286  1.33     lukem 	disk = NULL;
    287  1.63   hannken 	disk_dev = NULL;
    288  1.33     lukem 	mountpoint = NULL;
    289  1.33     lukem 	dirc = 0;
    290  1.14     lukem 	for (i = 0; i < argc; i++) {
    291  1.14     lukem 		struct stat sb;
    292  1.71   mlelstv 		int error;
    293  1.14     lukem 
    294  1.71   mlelstv 		error = lstat(argv[i], &sb);
    295  1.71   mlelstv 		if (Fflag || (!error && (S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode)))) {
    296  1.71   mlelstv 			if (error)
    297  1.74  christos 				quite(errno, "can't stat %s", argv[i]);
    298  1.33     lukem 			disk = argv[i];
    299  1.33     lukem  multicheck:
    300  1.33     lukem 			if (dirc != 0)
    301  1.74  christos 				quit("can't dump a disk or image at the same"
    302  1.74  christos 				" time as a file list");
    303  1.14     lukem 			break;
    304  1.14     lukem 		}
    305  1.33     lukem 		if ((dt = fstabsearch(argv[i])) != NULL) {
    306  1.71   mlelstv 			disk = argv[i];
    307  1.34   hannken 			mountpoint = xstrdup(dt->fs_file);
    308  1.33     lukem 			goto multicheck;
    309  1.14     lukem 		}
    310  1.57  christos 		if (statvfs(argv[i], &fsbuf) == -1)
    311  1.74  christos 			quite(errno, "can't statvfs %s", argv[i]);
    312  1.33     lukem 		disk = fsbuf.f_mntfromname;
    313  1.33     lukem 		if (strcmp(argv[i], fsbuf.f_mntonname) == 0)
    314  1.33     lukem 			goto multicheck;
    315  1.33     lukem 		if (mountpoint == NULL) {
    316  1.33     lukem 			mountpoint = xstrdup(fsbuf.f_mntonname);
    317  1.14     lukem 			if (uflag) {
    318  1.14     lukem 				msg("Ignoring u flag for subdir dump\n");
    319  1.14     lukem 				uflag = 0;
    320  1.14     lukem 			}
    321  1.14     lukem 			if (level > '0') {
    322  1.14     lukem 				msg("Subdir dump is done at level 0\n");
    323  1.14     lukem 				level = '0';
    324  1.14     lukem 			}
    325  1.33     lukem 			msg("Dumping sub files/directories from %s\n",
    326  1.33     lukem 			    mountpoint);
    327  1.14     lukem 		} else {
    328  1.33     lukem 			if (strcmp(mountpoint, fsbuf.f_mntonname) != 0)
    329  1.74  christos 				quit("%s is not on %s", argv[i], mountpoint);
    330  1.14     lukem 		}
    331  1.14     lukem 		msg("Dumping file/directory %s\n", argv[i]);
    332  1.33     lukem 		dirc++;
    333  1.14     lukem 	}
    334  1.33     lukem 	if (mountpoint)
    335  1.33     lukem 		free(mountpoint);
    336  1.33     lukem 
    337  1.33     lukem 	if (dirc == 0) {
    338  1.33     lukem 		argv++;
    339  1.14     lukem 		if (argc != 1) {
    340  1.14     lukem 			(void)fprintf(stderr, "Excess arguments to dump:");
    341  1.14     lukem 			while (--argc)
    342  1.14     lukem 				(void)fprintf(stderr, " %s", *argv++);
    343  1.14     lukem 			(void)fprintf(stderr, "\n");
    344  1.48     lukem 			exit(X_STARTUP);
    345  1.14     lukem 		}
    346   1.1       cgd 	}
    347   1.1       cgd 	if (Tflag && uflag) {
    348  1.44     lukem 		(void)fprintf(stderr,
    349   1.1       cgd 		    "You cannot use the T and u flags together.\n");
    350  1.48     lukem 		exit(X_STARTUP);
    351   1.1       cgd 	}
    352   1.1       cgd 	if (strcmp(tape, "-") == 0) {
    353   1.1       cgd 		pipeout++;
    354   1.1       cgd 		tape = "standard output";
    355   1.1       cgd 	}
    356   1.1       cgd 
    357   1.1       cgd 	if (blocksperfile)
    358   1.1       cgd 		blocksperfile = blocksperfile / ntrec * ntrec; /* round down */
    359  1.49     lukem 	else if (!unlimited) {
    360   1.1       cgd 		/*
    361   1.1       cgd 		 * Determine how to default tape size and density
    362   1.1       cgd 		 *
    363  1.44     lukem 		 *		density				tape size
    364   1.1       cgd 		 * 9-track	1600 bpi (160 bytes/.1")	2300 ft.
    365   1.1       cgd 		 * 9-track	6250 bpi (625 bytes/.1")	2300 ft.
    366   1.1       cgd 		 * cartridge	8000 bpi (100 bytes/.1")	1700 ft.
    367   1.1       cgd 		 *						(450*4 - slop)
    368   1.1       cgd 		 */
    369   1.1       cgd 		if (density == 0)
    370   1.1       cgd 			density = cartridge ? 100 : 160;
    371   1.1       cgd 		if (tsize == 0)
    372   1.1       cgd 			tsize = cartridge ? 1700L*120L : 2300L*120L;
    373   1.1       cgd 	}
    374   1.1       cgd 
    375  1.59  christos 	if ((cp = strchr(tape, ':')) != NULL) {
    376   1.1       cgd 		host = tape;
    377  1.59  christos 		/* This is fine, because all the const strings don't have : */
    378  1.59  christos 		*cp++ = '\0';
    379  1.59  christos 		tape = cp;
    380   1.1       cgd #ifdef RDUMP
    381   1.1       cgd 		if (rmthost(host) == 0)
    382  1.48     lukem 			exit(X_STARTUP);
    383   1.1       cgd #else
    384   1.3   mycroft 		(void)fprintf(stderr, "remote dump not enabled\n");
    385  1.48     lukem 		exit(X_STARTUP);
    386   1.1       cgd #endif
    387   1.1       cgd 	}
    388   1.1       cgd 
    389   1.1       cgd 	if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
    390   1.1       cgd 		signal(SIGHUP, sig);
    391   1.1       cgd 	if (signal(SIGTRAP, SIG_IGN) != SIG_IGN)
    392   1.1       cgd 		signal(SIGTRAP, sig);
    393   1.1       cgd 	if (signal(SIGFPE, SIG_IGN) != SIG_IGN)
    394   1.1       cgd 		signal(SIGFPE, sig);
    395   1.1       cgd 	if (signal(SIGBUS, SIG_IGN) != SIG_IGN)
    396   1.1       cgd 		signal(SIGBUS, sig);
    397  1.55      fvdl #if 0
    398   1.1       cgd 	if (signal(SIGSEGV, SIG_IGN) != SIG_IGN)
    399   1.1       cgd 		signal(SIGSEGV, sig);
    400  1.55      fvdl #endif
    401   1.1       cgd 	if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
    402   1.1       cgd 		signal(SIGTERM, sig);
    403   1.1       cgd 	if (signal(SIGINT, interrupt) == SIG_IGN)
    404   1.1       cgd 		signal(SIGINT, SIG_IGN);
    405  1.14     lukem 
    406   1.1       cgd 	/*
    407  1.33     lukem 	 *	disk can be either the full special file name, or
    408  1.33     lukem 	 *	the file system name.
    409   1.1       cgd 	 */
    410  1.33     lukem 	mountpoint = NULL;
    411  1.58   hannken 	mntinfo = mntinfosearch(disk);
    412  1.33     lukem 	if ((dt = fstabsearch(disk)) != NULL) {
    413  1.68  christos 		if (getfsspecname(buf, sizeof(buf), dt->fs_spec) == NULL)
    414  1.74  christos 			quite(errno, "can't resolve mount %s (%s)", dt->fs_spec,
    415  1.74  christos 			    buf);
    416  1.69  christos 		if (getdiskrawname(rbuf, sizeof(rbuf), buf) == NULL)
    417  1.74  christos 			quite(errno, "can't get disk raw name for %s", buf);
    418  1.69  christos 		disk = rbuf;
    419  1.33     lukem 		mountpoint = dt->fs_file;
    420  1.33     lukem 		msg("Found %s on %s in %s\n", disk, mountpoint, _PATH_FSTAB);
    421  1.58   hannken 	} else if (mntinfo != NULL) {
    422  1.69  christos 		if (getdiskrawname(rbuf, sizeof(rbuf), mntinfo->f_mntfromname)
    423  1.69  christos 		    == NULL)
    424  1.74  christos 			quite(errno, "can't get disk raw name for %s",
    425  1.74  christos 			    mntinfo->f_mntfromname);
    426  1.71   mlelstv 		disk = rbuf;
    427  1.33     lukem 		mountpoint = mntinfo->f_mntonname;
    428  1.33     lukem 		msg("Found %s on %s in mount table\n", disk, mountpoint);
    429  1.33     lukem 	}
    430  1.33     lukem 	if (mountpoint != NULL) {
    431  1.33     lukem 		if (dirc != 0)
    432  1.51    itojun 			(void)snprintf(spcl.c_filesys, sizeof(spcl.c_filesys),
    433  1.33     lukem 			    "a subset of %s", mountpoint);
    434  1.14     lukem 		else
    435  1.51    itojun 			(void)strlcpy(spcl.c_filesys, mountpoint,
    436  1.51    itojun 			    sizeof(spcl.c_filesys));
    437  1.38     lukem 	} else if (Fflag) {
    438  1.51    itojun 		(void)strlcpy(spcl.c_filesys, "a file system image",
    439  1.51    itojun 		    sizeof(spcl.c_filesys));
    440   1.1       cgd 	} else {
    441  1.51    itojun 		(void)strlcpy(spcl.c_filesys, "an unlisted file system",
    442  1.51    itojun 		    sizeof(spcl.c_filesys));
    443   1.1       cgd 	}
    444  1.51    itojun 	(void)strlcpy(spcl.c_dev, disk, sizeof(spcl.c_dev));
    445  1.51    itojun 	(void)strlcpy(spcl.c_label, labelstr, sizeof(spcl.c_label));
    446  1.51    itojun 	(void)gethostname(spcl.c_host, sizeof(spcl.c_host));
    447  1.19       mrg 	spcl.c_host[sizeof(spcl.c_host) - 1] = '\0';
    448  1.18    bouyer 
    449  1.58   hannken 	if ((snap_backup != NULL || snap_internal) && mntinfo == NULL) {
    450  1.58   hannken 		msg("WARNING: Cannot use -x or -X on unmounted file system.\n");
    451  1.58   hannken 		snap_backup = NULL;
    452  1.58   hannken 		snap_internal = 0;
    453  1.58   hannken 	}
    454  1.62  perseant 
    455  1.62  perseant #ifdef DUMP_LFS
    456  1.62  perseant 	sync();
    457  1.62  perseant 	if (snap_backup != NULL || snap_internal) {
    458  1.62  perseant 		if (lfs_wrap_stop(mountpoint) < 0) {
    459  1.62  perseant 			msg("Cannot stop writing on %s\n", mountpoint);
    460  1.62  perseant 			exit(X_STARTUP);
    461  1.62  perseant 		}
    462  1.62  perseant 	}
    463  1.62  perseant 	if ((diskfd = open(disk, O_RDONLY)) < 0) {
    464  1.62  perseant 		msg("Cannot open %s\n", disk);
    465  1.62  perseant 		exit(X_STARTUP);
    466  1.62  perseant 	}
    467  1.63   hannken 	disk_dev = disk;
    468  1.62  perseant #else /* ! DUMP_LFS */
    469  1.58   hannken 	if (snap_backup != NULL || snap_internal) {
    470  1.63   hannken 		diskfd = snap_open(mntinfo->f_mntonname, snap_backup,
    471  1.63   hannken 		    &tnow, &disk_dev);
    472  1.58   hannken 		if (diskfd < 0) {
    473  1.58   hannken 			msg("Cannot open snapshot of %s\n",
    474  1.58   hannken 				mntinfo->f_mntonname);
    475  1.58   hannken 			exit(X_STARTUP);
    476  1.58   hannken 		}
    477  1.58   hannken 		spcl.c_date = tnow;
    478  1.58   hannken 	} else {
    479  1.58   hannken 		if ((diskfd = open(disk, O_RDONLY)) < 0) {
    480  1.58   hannken 			msg("Cannot open %s\n", disk);
    481  1.58   hannken 			exit(X_STARTUP);
    482  1.58   hannken 		}
    483  1.63   hannken 		disk_dev = disk;
    484  1.18    bouyer 	}
    485  1.18    bouyer 	sync();
    486  1.62  perseant #endif /* ! DUMP_LFS */
    487  1.25  perseant 
    488  1.25  perseant 	needswap = fs_read_sblock(sblock_buf);
    489  1.18    bouyer 
    490  1.66  christos 	/* true incremental is always a level 10 dump */
    491  1.66  christos 	spcl.c_level = trueinc? iswap32(10): iswap32(level - '0');
    492  1.18    bouyer 	spcl.c_type = iswap32(TS_TAPE);
    493  1.18    bouyer 	spcl.c_date = iswap32(spcl.c_date);
    494  1.18    bouyer 	spcl.c_ddate = iswap32(spcl.c_ddate);
    495   1.1       cgd 	if (!Tflag)
    496  1.44     lukem 		getdumptime();		/* /etc/dumpdates snarfed */
    497   1.1       cgd 
    498  1.18    bouyer 	date = iswap32(spcl.c_date);
    499   1.1       cgd 	msg("Date of this level %c dump: %s", level,
    500  1.18    bouyer 		spcl.c_date == 0 ? "the epoch\n" : ctime(&date));
    501  1.18    bouyer 	date = iswap32(spcl.c_ddate);
    502   1.1       cgd  	msg("Date of last level %c dump: %s", lastlevel,
    503  1.18    bouyer 		spcl.c_ddate == 0 ? "the epoch\n" : ctime(&date));
    504  1.17     lukem 	msg("Dumping ");
    505  1.61   hannken 	if (snap_backup != NULL || snap_internal)
    506  1.58   hannken 		msgtail("a snapshot of ");
    507  1.33     lukem 	if (dirc != 0)
    508  1.17     lukem 		msgtail("a subset of ");
    509  1.17     lukem 	msgtail("%s (%s) ", disk, spcl.c_filesys);
    510   1.1       cgd 	if (host)
    511   1.1       cgd 		msgtail("to %s on host %s\n", tape, host);
    512   1.1       cgd 	else
    513   1.1       cgd 		msgtail("to %s\n", tape);
    514  1.21     lukem 	msg("Label: %s\n", labelstr);
    515   1.1       cgd 
    516  1.25  perseant 	ufsib = fs_parametrize();
    517  1.25  perseant 
    518   1.1       cgd 	dev_bshift = ffs(dev_bsize) - 1;
    519   1.1       cgd 	if (dev_bsize != (1 << dev_bshift))
    520  1.26    briggs 		quit("dev_bsize (%ld) is not a power of 2", dev_bsize);
    521   1.1       cgd 	tp_bshift = ffs(TP_BSIZE) - 1;
    522   1.1       cgd 	if (TP_BSIZE != (1 << tp_bshift))
    523   1.1       cgd 		quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE);
    524  1.25  perseant 	maxino = fs_maxino();
    525   1.3   mycroft 	mapsize = roundup(howmany(maxino, NBBY), TP_BSIZE);
    526  1.33     lukem 	usedinomap = (char *)xcalloc((unsigned) mapsize, sizeof(char));
    527  1.33     lukem 	dumpdirmap = (char *)xcalloc((unsigned) mapsize, sizeof(char));
    528  1.33     lukem 	dumpinomap = (char *)xcalloc((unsigned) mapsize, sizeof(char));
    529   1.1       cgd 	tapesize = 3 * (howmany(mapsize * sizeof(char), TP_BSIZE) + 1);
    530   1.1       cgd 
    531  1.18    bouyer 	nonodump = iswap32(spcl.c_level) < honorlevel;
    532   1.3   mycroft 
    533  1.22    bouyer 	initcache(readcache, readblksize);
    534  1.45     lukem 
    535  1.14     lukem 	(void)signal(SIGINFO, statussig);
    536  1.14     lukem 
    537   1.1       cgd 	msg("mapping (Pass I) [regular files]\n");
    538  1.33     lukem 	anydirskipped = mapfiles(maxino, &tapesize, mountpoint,
    539  1.33     lukem 	    (dirc ? argv : NULL));
    540   1.1       cgd 
    541   1.1       cgd 	msg("mapping (Pass II) [directories]\n");
    542   1.1       cgd 	while (anydirskipped) {
    543   1.1       cgd 		anydirskipped = mapdirs(maxino, &tapesize);
    544   1.1       cgd 	}
    545   1.1       cgd 
    546  1.49     lukem 	if (pipeout || unlimited) {
    547   1.1       cgd 		tapesize += 10;	/* 10 trailer blocks */
    548  1.55      fvdl 		msg("estimated %llu tape blocks.\n",
    549  1.55      fvdl 		    (unsigned long long)tapesize);
    550   1.3   mycroft 	} else {
    551   1.3   mycroft 		double fetapes;
    552   1.3   mycroft 
    553   1.1       cgd 		if (blocksperfile)
    554   1.3   mycroft 			fetapes = (double) tapesize / blocksperfile;
    555   1.1       cgd 		else if (cartridge) {
    556   1.1       cgd 			/* Estimate number of tapes, assuming streaming stops at
    557   1.1       cgd 			   the end of each block written, and not in mid-block.
    558   1.1       cgd 			   Assume no erroneous blocks; this can be compensated
    559   1.1       cgd 			   for with an artificially low tape size. */
    560  1.45     lukem 			fetapes =
    561  1.48     lukem 			(	  (double) tapesize	/* blocks */
    562   1.1       cgd 				* TP_BSIZE	/* bytes/block */
    563   1.1       cgd 				* (1.0/density)	/* 0.1" / byte */
    564   1.1       cgd 			  +
    565  1.48     lukem 				  (double) tapesize	/* blocks */
    566   1.1       cgd 				* (1.0/ntrec)	/* streaming-stops per block */
    567   1.1       cgd 				* 15.48		/* 0.1" / streaming-stop */
    568   1.1       cgd 			) * (1.0 / tsize );	/* tape / 0.1" */
    569   1.1       cgd 		} else {
    570   1.1       cgd 			/* Estimate number of tapes, for old fashioned 9-track
    571   1.1       cgd 			   tape */
    572   1.1       cgd 			int tenthsperirg = (density == 625) ? 3 : 7;
    573   1.1       cgd 			fetapes =
    574   1.1       cgd 			(	  tapesize	/* blocks */
    575   1.1       cgd 				* TP_BSIZE	/* bytes / block */
    576   1.1       cgd 				* (1.0/density)	/* 0.1" / byte */
    577   1.1       cgd 			  +
    578   1.1       cgd 				  tapesize	/* blocks */
    579   1.1       cgd 				* (1.0/ntrec)	/* IRG's / block */
    580   1.1       cgd 				* tenthsperirg	/* 0.1" / IRG */
    581   1.1       cgd 			) * (1.0 / tsize );	/* tape / 0.1" */
    582   1.1       cgd 		}
    583   1.1       cgd 		etapes = fetapes;		/* truncating assignment */
    584   1.1       cgd 		etapes++;
    585   1.1       cgd 		/* count the dumped inodes map on each additional tape */
    586   1.1       cgd 		tapesize += (etapes - 1) *
    587   1.1       cgd 			(howmany(mapsize * sizeof(char), TP_BSIZE) + 1);
    588   1.1       cgd 		tapesize += etapes + 10;	/* headers + 10 trailer blks */
    589  1.55      fvdl 		msg("estimated %llu tape blocks on %3.2f tape(s).\n",
    590  1.55      fvdl 		    (unsigned long long)tapesize, fetapes);
    591   1.3   mycroft 	}
    592  1.17     lukem 	/*
    593  1.17     lukem 	 * If the user only wants an estimate of the number of
    594  1.17     lukem 	 * tapes, exit now.
    595  1.17     lukem 	 */
    596  1.17     lukem 	if (just_estimate)
    597  1.48     lukem 		exit(X_FINOK);
    598   1.1       cgd 
    599   1.1       cgd 	/*
    600   1.3   mycroft 	 * Allocate tape buffer.
    601   1.1       cgd 	 */
    602   1.1       cgd 	if (!alloctape())
    603  1.74  christos 		quit("can't allocate tape buffers - try a smaller"
    604  1.74  christos 		    " blocking factor.");
    605   1.1       cgd 
    606   1.1       cgd 	startnewtape(1);
    607   1.3   mycroft 	(void)time((time_t *)&(tstart_writing));
    608  1.10     lukem 	xferrate = 0;
    609   1.3   mycroft 	dumpmap(usedinomap, TS_CLRI, maxino - 1);
    610   1.1       cgd 
    611   1.1       cgd 	msg("dumping (Pass III) [directories]\n");
    612   1.3   mycroft 	dirty = 0;		/* XXX just to get gcc to shut up */
    613   1.3   mycroft 	for (map = dumpdirmap, ino = 1; ino < maxino; ino++) {
    614   1.3   mycroft 		if (((ino - 1) % NBBY) == 0)	/* map is offset by 1 */
    615   1.1       cgd 			dirty = *map++;
    616   1.1       cgd 		else
    617   1.1       cgd 			dirty >>= 1;
    618   1.1       cgd 		if ((dirty & 1) == 0)
    619   1.1       cgd 			continue;
    620   1.1       cgd 		/*
    621   1.1       cgd 		 * Skip directory inodes deleted and maybe reallocated
    622   1.1       cgd 		 */
    623   1.1       cgd 		dp = getino(ino);
    624  1.55      fvdl 		if ((DIP(dp, mode) & IFMT) != IFDIR)
    625   1.1       cgd 			continue;
    626   1.3   mycroft 		(void)dumpino(dp, ino);
    627   1.1       cgd 	}
    628   1.1       cgd 
    629   1.1       cgd 	msg("dumping (Pass IV) [regular files]\n");
    630   1.3   mycroft 	for (map = dumpinomap, ino = 1; ino < maxino; ino++) {
    631   1.3   mycroft 		int mode;
    632   1.3   mycroft 
    633   1.3   mycroft 		if (((ino - 1) % NBBY) == 0)	/* map is offset by 1 */
    634   1.1       cgd 			dirty = *map++;
    635   1.1       cgd 		else
    636   1.1       cgd 			dirty >>= 1;
    637   1.1       cgd 		if ((dirty & 1) == 0)
    638   1.1       cgd 			continue;
    639   1.1       cgd 		/*
    640   1.1       cgd 		 * Skip inodes deleted and reallocated as directories.
    641   1.1       cgd 		 */
    642   1.1       cgd 		dp = getino(ino);
    643  1.55      fvdl 		mode = DIP(dp, mode) & IFMT;
    644   1.3   mycroft 		if (mode == IFDIR)
    645   1.1       cgd 			continue;
    646   1.3   mycroft 		(void)dumpino(dp, ino);
    647   1.1       cgd 	}
    648   1.1       cgd 
    649  1.18    bouyer 	spcl.c_type = iswap32(TS_END);
    650   1.1       cgd 	for (i = 0; i < ntrec; i++)
    651   1.3   mycroft 		writeheader(maxino - 1);
    652   1.1       cgd 	if (pipeout)
    653  1.73    bouyer 		msg("%lld tape blocks\n",(long long)iswap64(spcl.c_tapea));
    654   1.1       cgd 	else
    655  1.73    bouyer 		msg("%lld tape blocks on %d volume%s\n",
    656  1.73    bouyer 		    (long long)iswap64(spcl.c_tapea), iswap32(spcl.c_volume),
    657  1.18    bouyer 		    (iswap32(spcl.c_volume) == 1) ? "" : "s");
    658  1.10     lukem 	tnow = do_stats();
    659  1.18    bouyer 	date = iswap32(spcl.c_date);
    660  1.10     lukem 	msg("Date of this level %c dump: %s", level,
    661  1.18    bouyer 		spcl.c_date == 0 ? "the epoch\n" : ctime(&date));
    662  1.10     lukem 	msg("Date this dump completed:  %s", ctime(&tnow));
    663  1.26    briggs 	msg("Average transfer rate: %d KB/s\n", xferrate / tapeno);
    664   1.1       cgd 	putdumptime();
    665  1.29      tron 	trewind(0);
    666  1.48     lukem 	broadcast("DUMP IS DONE!\a\a\n");
    667  1.62  perseant #ifdef DUMP_LFS
    668  1.62  perseant 	lfs_wrap_go();
    669  1.62  perseant #endif /* DUMP_LFS */
    670   1.1       cgd 	msg("DUMP IS DONE\n");
    671   1.1       cgd 	Exit(X_FINOK);
    672   1.1       cgd 	/* NOTREACHED */
    673  1.15     lukem 	exit(X_FINOK);		/* XXX: to satisfy gcc */
    674   1.1       cgd }
    675   1.1       cgd 
    676   1.5   mycroft static void
    677  1.31     lukem usage(void)
    678   1.5   mycroft {
    679  1.49     lukem 	const char *prog = getprogname();
    680   1.5   mycroft 
    681  1.49     lukem 	(void)fprintf(stderr,
    682  1.67  christos "usage: %s [-0123456789aceFinStuX] [-B records] [-b blocksize]\n"
    683  1.49     lukem "            [-d density] [-f file] [-h level] [-k read-blocksize]\n"
    684  1.67  christos "            [-L label] [-l timeout] [-r cachesize] [-s feet]\n"
    685  1.75      manu "            [-T date] [-U dumpdev] [-x snap-backup] files-to-dump\n"
    686  1.49     lukem "       %s [-W | -w]\n", prog, prog);
    687  1.48     lukem 	exit(X_STARTUP);
    688   1.5   mycroft }
    689   1.5   mycroft 
    690   1.3   mycroft /*
    691   1.3   mycroft  * Pick up a numeric argument.  It must be nonnegative and in the given
    692   1.3   mycroft  * range (except that a vmax of 0 means unlimited).
    693   1.3   mycroft  */
    694   1.3   mycroft static long
    695  1.59  christos numarg(const char *meaning, long vmin, long vmax)
    696   1.3   mycroft {
    697   1.5   mycroft 	char *p;
    698   1.3   mycroft 	long val;
    699   1.3   mycroft 
    700   1.5   mycroft 	val = strtol(optarg, &p, 10);
    701   1.5   mycroft 	if (*p)
    702  1.48     lukem 		errx(X_STARTUP, "illegal %s -- %s", meaning, optarg);
    703   1.3   mycroft 	if (val < vmin || (vmax && val > vmax))
    704  1.48     lukem 		errx(X_STARTUP, "%s must be between %ld and %ld",
    705  1.48     lukem 		    meaning, vmin, vmax);
    706   1.3   mycroft 	return (val);
    707   1.3   mycroft }
    708   1.3   mycroft 
    709   1.1       cgd void
    710  1.32     lukem sig(int signo)
    711   1.1       cgd {
    712  1.32     lukem 
    713   1.1       cgd 	switch(signo) {
    714   1.1       cgd 	case SIGALRM:
    715   1.1       cgd 	case SIGBUS:
    716   1.1       cgd 	case SIGFPE:
    717   1.1       cgd 	case SIGHUP:
    718   1.1       cgd 	case SIGTERM:
    719   1.1       cgd 	case SIGTRAP:
    720   1.1       cgd 		if (pipeout)
    721  1.74  christos 			quit("Signal on pipe: cannot recover");
    722  1.35       mrg 		msg("Rewriting attempted as response to signal %s.\n", sys_siglist[signo]);
    723   1.3   mycroft 		(void)fflush(stderr);
    724   1.3   mycroft 		(void)fflush(stdout);
    725   1.1       cgd 		close_rewind();
    726   1.3   mycroft 		exit(X_REWRITE);
    727   1.1       cgd 		/* NOTREACHED */
    728   1.1       cgd 	case SIGSEGV:
    729   1.1       cgd 		msg("SIGSEGV: ABORTING!\n");
    730   1.3   mycroft 		(void)signal(SIGSEGV, SIG_DFL);
    731   1.3   mycroft 		(void)kill(0, SIGSEGV);
    732   1.1       cgd 		/* NOTREACHED */
    733   1.1       cgd 	}
    734   1.1       cgd }
    735   1.1       cgd 
    736   1.5   mycroft /*
    737   1.5   mycroft  * obsolete --
    738   1.5   mycroft  *	Change set of key letters and ordered arguments into something
    739   1.5   mycroft  *	getopt(3) will like.
    740   1.5   mycroft  */
    741   1.5   mycroft static void
    742  1.32     lukem obsolete(int *argcp, char **argvp[])
    743   1.1       cgd {
    744   1.5   mycroft 	int argc, flags;
    745   1.5   mycroft 	char *ap, **argv, *flagsp, **nargv, *p;
    746   1.5   mycroft 
    747   1.5   mycroft 	/* Setup. */
    748   1.5   mycroft 	argv = *argvp;
    749   1.5   mycroft 	argc = *argcp;
    750   1.5   mycroft 
    751   1.5   mycroft 	/* Return if no arguments or first argument has leading dash. */
    752   1.5   mycroft 	ap = argv[1];
    753   1.5   mycroft 	if (argc == 1 || *ap == '-')
    754   1.5   mycroft 		return;
    755   1.5   mycroft 
    756   1.5   mycroft 	/* Allocate space for new arguments. */
    757  1.33     lukem 	*argvp = nargv = xmalloc((argc + 1) * sizeof(char *));
    758  1.33     lukem 	p = flagsp = xmalloc(strlen(ap) + 2);
    759   1.5   mycroft 
    760   1.5   mycroft 	*nargv++ = *argv;
    761   1.5   mycroft 	argv += 2;
    762   1.5   mycroft 
    763   1.5   mycroft 	for (flags = 0; *ap; ++ap) {
    764   1.5   mycroft 		switch (*ap) {
    765   1.5   mycroft 		case 'B':
    766   1.5   mycroft 		case 'b':
    767   1.5   mycroft 		case 'd':
    768   1.5   mycroft 		case 'f':
    769   1.5   mycroft 		case 'h':
    770   1.5   mycroft 		case 's':
    771   1.5   mycroft 		case 'T':
    772  1.58   hannken 		case 'x':
    773   1.5   mycroft 			if (*argv == NULL) {
    774   1.5   mycroft 				warnx("option requires an argument -- %c", *ap);
    775   1.5   mycroft 				usage();
    776   1.5   mycroft 			}
    777  1.33     lukem 			nargv[0] = xmalloc(strlen(*argv) + 2 + 1);
    778   1.5   mycroft 			nargv[0][0] = '-';
    779   1.5   mycroft 			nargv[0][1] = *ap;
    780  1.17     lukem 			(void)strcpy(&nargv[0][2], *argv); /* XXX safe strcpy */
    781   1.5   mycroft 			++argv;
    782   1.5   mycroft 			++nargv;
    783   1.5   mycroft 			break;
    784   1.5   mycroft 		default:
    785   1.5   mycroft 			if (!flags) {
    786   1.5   mycroft 				*p++ = '-';
    787   1.5   mycroft 				flags = 1;
    788   1.5   mycroft 			}
    789   1.5   mycroft 			*p++ = *ap;
    790   1.5   mycroft 			break;
    791   1.5   mycroft 		}
    792   1.5   mycroft 	}
    793   1.1       cgd 
    794   1.5   mycroft 	/* Terminate flags. */
    795   1.5   mycroft 	if (flags) {
    796   1.5   mycroft 		*p = '\0';
    797   1.5   mycroft 		*nargv++ = flagsp;
    798  1.60  christos 	} else
    799  1.60  christos 		free(flagsp);
    800   1.5   mycroft 
    801   1.5   mycroft 	/* Copy remaining arguments. */
    802  1.14     lukem 	while ((*nargv++ = *argv++) != NULL)
    803  1.14     lukem 		;
    804   1.5   mycroft 
    805   1.5   mycroft 	/* Update argument count. */
    806   1.5   mycroft 	*argcp = nargv - *argvp - 1;
    807  1.33     lukem }
    808  1.33     lukem 
    809  1.33     lukem 
    810  1.33     lukem void *
    811  1.33     lukem xcalloc(size_t number, size_t size)
    812  1.33     lukem {
    813  1.33     lukem 	void *p;
    814  1.33     lukem 
    815  1.33     lukem 	p = calloc(number, size);
    816  1.33     lukem 	if (p == NULL)
    817  1.74  christos 		quite(errno, "Can't allocate %zu bytes", size * number);
    818  1.33     lukem 	return (p);
    819  1.33     lukem }
    820  1.33     lukem 
    821  1.33     lukem void *
    822  1.33     lukem xmalloc(size_t size)
    823  1.33     lukem {
    824  1.33     lukem 	void *p;
    825  1.33     lukem 
    826  1.33     lukem 	p = malloc(size);
    827  1.33     lukem 	if (p == NULL)
    828  1.74  christos 		quite(errno, "Can't allocate %zu bytes", size);
    829  1.33     lukem 	return (p);
    830  1.33     lukem }
    831  1.33     lukem 
    832  1.33     lukem char *
    833  1.33     lukem xstrdup(const char *str)
    834  1.33     lukem {
    835  1.33     lukem 	char *p;
    836  1.33     lukem 
    837  1.33     lukem 	p = strdup(str);
    838  1.33     lukem 	if (p == NULL)
    839  1.74  christos 		quite(errno, "Can't copy %s", str);
    840  1.33     lukem 	return (p);
    841   1.1       cgd }
    842